class NestedAttributesWithCallbacksTest
Public Instance Methods
assert_assignment_affects_records_in_target(association_name)
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 139 def assert_assignment_affects_records_in_target(association_name) association = @pirate.send(association_name) assert association.detect { |b| b == bird_to_update }.name_changed?, "Update record not updated" assert association.detect { |b| b == bird_to_destroy }.marked_for_destruction?, "Destroy record not marked for destruction" end
assert_callbacks_not_called()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 106 def assert_callbacks_not_called assert_empty new_birds assert_empty @@add_callback_called end
assert_new_bird_with_callback_called()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 77 def assert_new_bird_with_callback_called assert_equal(1, new_birds.size) assert_equal(new_birds, @@add_callback_called) end
bird_to_destroy()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 36 def bird_to_destroy @birds[1] end
bird_to_update()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 32 def bird_to_update @birds[0] end
destroy_bird_attributes()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 54 def destroy_bird_attributes [{ "id" => bird_to_destroy.id.to_s, "_destroy" => true }] end
existing_birds_attributes()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 40 def existing_birds_attributes @birds.map do |bird| bird.attributes.slice("id", "name") end end
new_bird_attributes()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 50 def new_bird_attributes [{ "name" => "New Bird" }] end
new_birds()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 46 def new_birds @pirate.birds_with_add.to_a - @birds end
setup()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 22 def setup @@add_callback_called = [] @pirate = Pirate.new.tap do |pirate| pirate.catchphrase = "Don't call me!" pirate.birds_attributes = [{ name: "Bird1" }, { name: "Bird2" }] pirate.save! end @birds = @pirate.birds.to_a end
update_new_and_destroy_bird_attributes()
click to toggle source
# File activerecord/test/cases/nested_attributes_with_callbacks_test.rb, line 58 def update_new_and_destroy_bird_attributes [{ "id" => @birds[0].id.to_s, "name" => "New Name" }, { "name" => "New Bird" }, { "id" => bird_to_destroy.id.to_s, "_destroy" => true }] end