-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Starting with 17eeb176fc09f7b5d19f1617d42e55529afff81c, initializing a document with an embeds_many relation via a hash has regressed so that the embedded documents are not built correctly. I've added additional comments on that commit, but here I have a patch that adds a functional test case to verify the behavior we were using that now no longer works.
I and my coworkers have been trying to figure out the right way to fix this, but it's been difficult to figure out which class/module should be responsible for this method of building. embeds_many is the only type of relation that had any initialization behavior change because of this commit.
Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
diff --git a/spec/functional/mongoid/relations/embedded/many_spec.rb b/spec/functional/mongoid/relations/embedded/many_spec.rb index a5dba3a..557e234 100644 --- a/spec/functional/mongoid/relations/embedded/many_spec.rb +++ b/spec/functional/mongoid/relations/embedded/many_spec.rb @@ -1588,6 +1588,66 @@ describe Mongoid::Relations::Embedded::Many do context "when deeply embedding documents" do + context "when building the tree through hashes" do + + let(:circus) do + Circus.new(hash) + end + + let(:animal) do + circus.animals.first + end + + let(:animal_name) do + "Lion" + end + + let(:tag_list) do + "tigers, bears, oh my" + end + + context "when the hash uses stringified keys" do + + let(:hash) do + { 'animals' => [{ 'name' => animal_name, 'tag_list' => tag_list }] } + end + + it "sets up the hierarchy" do + animal.circus.should == circus + end + + it "assigns the attributes" do + animal.name.should == animal_name + end + + it "uses custom writer methods" do + animal.tag_list.should == tag_list + end + + end + + context "when the hash uses symbolized keys" do + + let(:hash) do + { :animals => [{ :name => animal_name, :tag_list => tag_list }] } + end + + it "sets up the hierarchy" do + animal.circus.should == circus + end + + it "assigns the attributes" do + animal.name.should == animal_name + end + + it "uses custom writer methods" do + animal.tag_list.should == tag_list + end + + end + + end + context "when building the tree through pushes" do let(:quiz) do diff --git a/spec/models/animal.rb b/spec/models/animal.rb index 45b2d23..efc65ed 100644 --- a/spec/models/animal.rb +++ b/spec/models/animal.rb @@ -5,6 +5,7 @@ class Animal key :name embedded_in :person + embedded_in :circus validates_format_of :name, :without => /\$\$\$/ diff --git a/spec/models/circus.rb b/spec/models/circus.rb new file mode 100644 index 0000000..cb8e19f --- /dev/null +++ b/spec/models/circus.rb @@ -0,0 +1,7 @@ +class Circus + include Mongoid::Document + + field :name + + embeds_many :animals +end