-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Hi Guys,
I am trying to figure out what is happening here.
I have the following documents:
class X
include Mongoid::Document
accepts_nested_attributes_for :ys
embeds_many :ys
field :text, as: String
end
class Y
include Mongoid::Document
accepts_nested_attributes_for :zs
embeds_many :zs
embedded_in :x
field :text, as: String
end
class Z
include Mongoid::Document
embedded_in :y
field :text, as: String
end
When I try to create a new Y and a new Z (into an existing Y) using nested attributes, it doesn't save.
require "spec_helper"
describe X do
it "should save" do
z = Z.new text: "Z"
y = Y.new text: "Y", zs: [z]
x = X.create! text: "X", ys: [y]
x.reload
x.ys.should have(1).item
x.ys[0].zs.should have(1).item
x.update_attributes({
ys_attributes: {
a: {id: y.id, zs_attributes: {c:
}},
b:
}
})
x.ys.should have(2).items
x.ys[0].zs.should have(2).items
x.reload
x.ys.should have(2).items
x.ys[0].zs.should have(2).items
end
end
After the second reload the test fails:
Failures:
1) X should save
Failure/Error: x.ys.should have(2).items
expected 2 items, got 1
- ./spec/models/x_spec.rb:26:in `block (2 levels) in <top (required)>'
Is this a bug? Am I doing something wrong?
Thanks!