diff options
author | utilum <oz@utilum.com> | 2018-04-22 13:31:43 +0200 |
---|---|---|
committer | utilum <oz@utilum.com> | 2018-04-26 08:02:08 +0200 |
commit | e4e25cc8dc76f641a304251ba37e1db99713e584 (patch) | |
tree | 9984a9ba7b4f594e52f39e9e971025f450e982c0 /activerecord | |
parent | 1a1650a012f03b62f0b19a58d3cdfa536cf9c4b7 (diff) | |
download | rails-e4e25cc8dc76f641a304251ba37e1db99713e584.tar.gz rails-e4e25cc8dc76f641a304251ba37e1db99713e584.tar.bz2 rails-e4e25cc8dc76f641a304251ba37e1db99713e584.zip |
assert_not_called
Diffstat (limited to 'activerecord')
3 files changed, 47 insertions, 34 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 33fe5ccabc..d1bf98a8e3 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1986,8 +1986,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_calling_many_should_defer_to_collection_if_using_a_block firm = companies(:first_firm) assert_queries(1) do - firm.clients.expects(:size).never - firm.clients.many? { true } + assert_not_called(firm.clients, :size) do + firm.clients.many? { true } + end end assert_predicate firm.clients, :loaded? end @@ -2025,8 +2026,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_calling_none_should_defer_to_collection_if_using_a_block firm = companies(:first_firm) assert_queries(1) do - firm.clients.expects(:size).never - firm.clients.none? { true } + assert_not_called(firm.clients, :size) do + firm.clients.none? { true } + end end assert_predicate firm.clients, :loaded? end @@ -2060,8 +2062,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_calling_one_should_defer_to_collection_if_using_a_block firm = companies(:first_firm) assert_queries(1) do - firm.clients.expects(:size).never - firm.clients.one? { true } + assert_not_called(firm.clients, :size) do + firm.clients.one? { true } + end end assert_predicate firm.clients, :loaded? end diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 7915599f72..0c212ecc22 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -769,8 +769,9 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase assert_not_predicate @pirate, :valid? @pirate.ship.mark_for_destruction - @pirate.ship.expects(:valid?).never - assert_difference("Ship.count", -1) { @pirate.save! } + assert_not_called(@pirate.ship, :valid?) do + assert_difference("Ship.count", -1) { @pirate.save! } + end end def test_a_child_marked_for_destruction_should_not_be_destroyed_twice @@ -806,8 +807,9 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase end def test_should_not_save_changed_has_one_unchanged_object_if_child_is_saved - @pirate.ship.expects(:save).never - assert @pirate.save + assert_not_called(@pirate.ship, :save) do + assert @pirate.save + end end # belongs_to @@ -830,8 +832,9 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase assert_not_predicate @ship, :valid? @ship.pirate.mark_for_destruction - @ship.pirate.expects(:valid?).never - assert_difference("Pirate.count", -1) { @ship.save! } + assert_not_called(@ship.pirate, :valid?) do + assert_difference("Pirate.count", -1) { @ship.save! } + end end def test_a_parent_marked_for_destruction_should_not_be_destroyed_twice @@ -898,11 +901,13 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase @pirate.birds.each { |bird| bird.name = "" } assert_not_predicate @pirate, :valid? - @pirate.birds.each do |bird| - bird.mark_for_destruction - bird.expects(:valid?).never + @pirate.birds.each(&:mark_for_destruction) + + assert_not_called(@pirate.birds.first, :valid?) do + assert_not_called(@pirate.birds.last, :valid?) do + assert_difference("Bird.count", -2) { @pirate.save! } + end end - assert_difference("Bird.count", -2) { @pirate.save! } end def test_should_skip_validation_on_has_many_if_destroyed @@ -921,8 +926,11 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase @pirate.birds.each(&:mark_for_destruction) assert @pirate.save - @pirate.birds.each { |bird| bird.expects(:destroy).never } - assert @pirate.save + @pirate.birds.each do |bird| + assert_not_called(bird, :destroy) do + assert @pirate.save + end + end end def test_should_rollback_destructions_if_an_exception_occurred_while_saving_has_many @@ -1022,12 +1030,14 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase @pirate.parrots.each { |parrot| parrot.name = "" } assert_not_predicate @pirate, :valid? - @pirate.parrots.each do |parrot| - parrot.mark_for_destruction - parrot.expects(:valid?).never + @pirate.parrots.each { |parrot| parrot.mark_for_destruction } + + assert_not_called(@pirate.parrots.first, :valid?) do + assert_not_called(@pirate.parrots.last, :valid?) do + @pirate.save! + end end - @pirate.save! assert_empty @pirate.reload.parrots end diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 48d1fc7eb0..54f07a9e98 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -127,18 +127,18 @@ module ActiveRecord def test_ignores_configurations_without_databases @configurations["development"].merge!("database" => nil) - ActiveRecord::Tasks::DatabaseTasks.expects(:create).never - - ActiveRecord::Tasks::DatabaseTasks.create_all + assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do + ActiveRecord::Tasks::DatabaseTasks.create_all + end end def test_ignores_remote_databases @configurations["development"].merge!("host" => "my.server.tld") $stderr.stubs(:puts).returns(nil) - ActiveRecord::Tasks::DatabaseTasks.expects(:create).never - - ActiveRecord::Tasks::DatabaseTasks.create_all + assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do + ActiveRecord::Tasks::DatabaseTasks.create_all + end end def test_warning_for_remote_databases @@ -343,18 +343,18 @@ module ActiveRecord def test_ignores_configurations_without_databases @configurations[:development].merge!("database" => nil) - ActiveRecord::Tasks::DatabaseTasks.expects(:drop).never - - ActiveRecord::Tasks::DatabaseTasks.drop_all + assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do + ActiveRecord::Tasks::DatabaseTasks.drop_all + end end def test_ignores_remote_databases @configurations[:development].merge!("host" => "my.server.tld") $stderr.stubs(:puts).returns(nil) - ActiveRecord::Tasks::DatabaseTasks.expects(:drop).never - - ActiveRecord::Tasks::DatabaseTasks.drop_all + assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do + ActiveRecord::Tasks::DatabaseTasks.drop_all + end end def test_warning_for_remote_databases |