class TestNestedAttributesWithNonStandardPrimaryKeys

Public Instance Methods

setup() click to toggle source
# File activerecord/test/cases/nested_attributes_test.rb, line 954
def setup
  Owner.accepts_nested_attributes_for :pets, allow_destroy: true

  @owner = owners(:ashley)
  @pet1, @pet2 = pets(:chew), pets(:mochi)

  @params = {
    pets_attributes: {
      "0" => { id: @pet1.id, name: "Foo" },
      "1" => { id: @pet2.id, name: "Bar" }
    }
  }
end
test_attr_accessor_of_child_should_be_value_provided_during_update() click to toggle source
# File activerecord/test/cases/nested_attributes_test.rb, line 973
def test_attr_accessor_of_child_should_be_value_provided_during_update
  @owner = owners(:ashley)
  @pet1 = pets(:chew)
  attributes = { pets_attributes: { "1" => { id: @pet1.id,
                                              name: "Foo2",
                                              current_user: "John",
                                              _destroy: true } } }
  @owner.update(attributes)
  assert_equal "John", Pet.after_destroy_output
end
test_should_update_existing_records_with_non_standard_primary_key() click to toggle source
# File activerecord/test/cases/nested_attributes_test.rb, line 968
def test_should_update_existing_records_with_non_standard_primary_key
  @owner.update(@params)
  assert_equal ["Foo", "Bar"], @owner.pets.map(&:name)
end