-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
Models:
class Parent embeds_many :children accepts_nested_attributes_for :children end class Child field first_name field last_name embedded_in :parent end
Spec:
describe 'update' do let(:parent) { Parent.create } let(:child) { parent.children.create first_name: 'first', last_name: 'last' } subject{parent.update params} context "params have 'children_attributes' key " do let(:params) { children_attributes: [id: child.id, first_name: 'new']} it {expect{subject}.to change{parent.reload.children.first.first_name}.to('new')} # => pass it {expect{subject}.not_to change{parent.reload.children.first.last_name}} # => pass end context "params have 'children_attributes' key "do let(:params) { children: [id: child.id, first_name: 'new']} it {expect{subject}.to change{parent.reload.children.first.first_name}.to('new')} # => pass it {expect{subject}.not_to change{parent.reload.children.first.last_name}} # => fail. last_name is nil end context "children is a hash" do let(:params) { children: {"0" => {id: child.id, first_name: 'new'}}} it {expect{subject}.to change{parent.reload.children.first.first_name}.to('new')} # => pass it {expect{subject}.not_to change{parent.reload.children.first.last_name}} # => pass end end
Bug or feature?