mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
assert_not_called
This commit is contained in:
parent
1a1650a012
commit
e4e25cc8dc
5 changed files with 59 additions and 38 deletions
|
@ -2,8 +2,11 @@
|
|||
|
||||
require "test_helper"
|
||||
require "stubs/test_server"
|
||||
require "active_support/testing/method_call_assertions"
|
||||
|
||||
class ActionCable::Connection::ClientSocketTest < ActionCable::TestCase
|
||||
include ActiveSupport::Testing::MethodCallAssertions
|
||||
|
||||
class Connection < ActionCable::Connection::Base
|
||||
attr_reader :connected, :websocket, :errors
|
||||
|
||||
|
@ -41,9 +44,10 @@ class ActionCable::Connection::ClientSocketTest < ActionCable::TestCase
|
|||
# Internal hax = :(
|
||||
client = connection.websocket.send(:websocket)
|
||||
client.instance_variable_get("@stream").expects(:write).raises("foo")
|
||||
client.expects(:client_gone).never
|
||||
|
||||
client.write("boo")
|
||||
assert_not_called(client, :client_gone) do
|
||||
client.write("boo")
|
||||
end
|
||||
assert_equal %w[ foo ], connection.errors
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require "active_support/testing/method_call_assertions"
|
||||
require "stubs/test_server"
|
||||
require "stubs/user"
|
||||
|
||||
class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
|
||||
include ActiveSupport::Testing::MethodCallAssertions
|
||||
|
||||
class Connection < ActionCable::Connection::Base
|
||||
identified_by :current_user
|
||||
attr_reader :websocket
|
||||
|
@ -50,8 +53,9 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
|
|||
run_in_eventmachine do
|
||||
open_connection_with_stubbed_pubsub
|
||||
|
||||
@connection.websocket.expects(:close).never
|
||||
@connection.process_internal_message "type" => "unknown"
|
||||
assert_not_called(@connection.websocket, :close) do
|
||||
@connection.process_internal_message "type" => "unknown"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue