mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use respond_to test helpers
This commit is contained in:
parent
8baca31dbe
commit
0d50cae996
43 changed files with 158 additions and 158 deletions
|
@ -506,8 +506,8 @@ class BaseTest < ActiveSupport::TestCase
|
|||
test "should respond to action methods" do
|
||||
assert_respond_to BaseMailer, :welcome
|
||||
assert_respond_to BaseMailer, :implicit_multipart
|
||||
assert !BaseMailer.respond_to?(:mail)
|
||||
assert !BaseMailer.respond_to?(:headers)
|
||||
assert_not_respond_to BaseMailer, :mail
|
||||
assert_not_respond_to BaseMailer, :headers
|
||||
end
|
||||
|
||||
test "calling just the action should return the generated mail object" do
|
||||
|
|
|
@ -289,7 +289,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
|
|||
else
|
||||
test "ActionController::Parameters does not respond to #dig on Ruby 2.2" do
|
||||
assert_not ActionController::Parameters.method_defined?(:dig)
|
||||
assert_not @params.respond_to?(:dig)
|
||||
assert_not_respond_to @params, :dig
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,8 +17,8 @@ module ActionDispatch
|
|||
|
||||
def test_respond_to?
|
||||
runner = MyRunner.new(Class.new { def x; end }.new)
|
||||
assert runner.respond_to?(:hi)
|
||||
assert runner.respond_to?(:x)
|
||||
assert_respond_to runner, :hi
|
||||
assert_respond_to runner, :x
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -838,7 +838,7 @@ XML
|
|||
|
||||
def test_fixture_file_upload_should_be_able_access_to_tempfile
|
||||
file = fixture_file_upload(FILES_DIR + "/ruby_on_rails.jpg", "image/jpg")
|
||||
assert file.respond_to?(:tempfile), "expected tempfile should respond on fixture file object, got nothing"
|
||||
assert_respond_to file, :tempfile
|
||||
end
|
||||
|
||||
def test_fixture_file_upload
|
||||
|
|
|
@ -288,7 +288,7 @@ module AbstractController
|
|||
kls = Class.new { include set.url_helpers }
|
||||
|
||||
controller = kls.new
|
||||
assert controller.respond_to?(:home_url)
|
||||
assert_respond_to controller, :home_url
|
||||
assert_equal "http://www.basecamphq.com/home/sweet/home/again",
|
||||
controller.send(:home_url, host: "www.basecamphq.com", user: "again")
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ class MimeTypeTest < ActiveSupport::TestCase
|
|||
|
||||
types.each do |type|
|
||||
mime = Mime[type]
|
||||
assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?"
|
||||
assert_respond_to mime, "#{type}?"
|
||||
assert_equal type, mime.symbol, "#{mime.inspect} is not #{type}?"
|
||||
invalid_types = types - [type]
|
||||
invalid_types.delete(:html)
|
||||
|
|
|
@ -356,7 +356,7 @@ class ResponseTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "respond_to? accepts include_private" do
|
||||
assert_not @response.respond_to?(:method_missing)
|
||||
assert_not_respond_to @response, :method_missing
|
||||
assert @response.respond_to?(:method_missing, true)
|
||||
end
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ module ActionDispatch
|
|||
def test_respond_to?
|
||||
tf = Class.new { def read; yield end }
|
||||
uf = Http::UploadedFile.new(tempfile: tf.new)
|
||||
assert uf.respond_to?(:headers), "responds to headers"
|
||||
assert uf.respond_to?(:read), "responds to read"
|
||||
assert_respond_to uf, :headers
|
||||
assert_respond_to uf, :read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveModel
|
|||
# <tt>to_key</tt> returns an Enumerable of all (primary) key attributes
|
||||
# of the model, and is used to a generate unique DOM id for the object.
|
||||
def test_to_key
|
||||
assert model.respond_to?(:to_key), "The model should respond to to_key"
|
||||
assert_respond_to model, :to_key
|
||||
def model.persisted?() false end
|
||||
assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false"
|
||||
end
|
||||
|
@ -44,7 +44,7 @@ module ActiveModel
|
|||
# tests for this behavior in lint because it doesn't make sense to force
|
||||
# any of the possible implementation strategies on the implementer.
|
||||
def test_to_param
|
||||
assert model.respond_to?(:to_param), "The model should respond to to_param"
|
||||
assert_respond_to model, :to_param
|
||||
def model.to_key() [1] end
|
||||
def model.persisted?() false end
|
||||
assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false"
|
||||
|
@ -56,7 +56,7 @@ module ActiveModel
|
|||
# <tt>to_partial_path</tt> is used for looking up partials. For example,
|
||||
# a BlogPost model might return "blog_posts/blog_post".
|
||||
def test_to_partial_path
|
||||
assert model.respond_to?(:to_partial_path), "The model should respond to to_partial_path"
|
||||
assert_respond_to model, :to_partial_path
|
||||
assert_kind_of String, model.to_partial_path
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ module ActiveModel
|
|||
# will route to the create action. If it is persisted, a form for the
|
||||
# object will route to the update action.
|
||||
def test_persisted?
|
||||
assert model.respond_to?(:persisted?), "The model should respond to persisted?"
|
||||
assert_respond_to model, :persisted?
|
||||
assert_boolean model.persisted?, "persisted?"
|
||||
end
|
||||
|
||||
|
@ -79,14 +79,14 @@ module ActiveModel
|
|||
#
|
||||
# Check ActiveModel::Naming for more information.
|
||||
def test_model_naming
|
||||
assert model.class.respond_to?(:model_name), "The model class should respond to model_name"
|
||||
assert_respond_to model.class, :model_name
|
||||
model_name = model.class.model_name
|
||||
assert model_name.respond_to?(:to_str)
|
||||
assert model_name.human.respond_to?(:to_str)
|
||||
assert model_name.singular.respond_to?(:to_str)
|
||||
assert model_name.plural.respond_to?(:to_str)
|
||||
assert_respond_to model_name, :to_str
|
||||
assert_respond_to model_name.human, :to_str
|
||||
assert_respond_to model_name.singular, :to_str
|
||||
assert_respond_to model_name.plural, :to_str
|
||||
|
||||
assert model.respond_to?(:model_name), "The model instance should respond to model_name"
|
||||
assert_respond_to model, :model_name
|
||||
assert_equal model.model_name, model.class.model_name
|
||||
end
|
||||
|
||||
|
@ -100,13 +100,13 @@ module ActiveModel
|
|||
# If localization is used, the strings should be localized for the current
|
||||
# locale. If no error is present, the method should return an empty array.
|
||||
def test_errors_aref
|
||||
assert model.respond_to?(:errors), "The model should respond to errors"
|
||||
assert_respond_to model, :errors
|
||||
assert model.errors[:hello].is_a?(Array), "errors#[] should return an Array"
|
||||
end
|
||||
|
||||
private
|
||||
def model
|
||||
assert @model.respond_to?(:to_model), "The object should respond to to_model"
|
||||
assert_respond_to @model, :to_model
|
||||
@model.to_model
|
||||
end
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
|
|||
ModelWithAttributes.define_attribute_methods(:foo)
|
||||
ModelWithAttributes.undefine_attribute_methods
|
||||
|
||||
assert !ModelWithAttributes.new.respond_to?(:foo)
|
||||
assert_not_respond_to ModelWithAttributes.new, :foo
|
||||
assert_raises(NoMethodError) { ModelWithAttributes.new.foo }
|
||||
end
|
||||
|
||||
|
@ -255,7 +255,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
|
|||
m = ModelWithAttributes2.new
|
||||
m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
|
||||
|
||||
assert !m.respond_to?(:private_method)
|
||||
assert_not_respond_to m, :private_method
|
||||
assert m.respond_to?(:private_method, true)
|
||||
|
||||
c = ClassWithProtected.new
|
||||
|
|
|
@ -85,21 +85,21 @@ class CallbacksTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
test "only selects which types of callbacks should be created" do
|
||||
assert !ModelCallbacks.respond_to?(:before_initialize)
|
||||
assert !ModelCallbacks.respond_to?(:around_initialize)
|
||||
assert_not_respond_to ModelCallbacks, :before_initialize
|
||||
assert_not_respond_to ModelCallbacks, :around_initialize
|
||||
assert_respond_to ModelCallbacks, :after_initialize
|
||||
end
|
||||
|
||||
test "only selects which types of callbacks should be created from an array list" do
|
||||
assert_respond_to ModelCallbacks, :before_multiple
|
||||
assert_respond_to ModelCallbacks, :around_multiple
|
||||
assert !ModelCallbacks.respond_to?(:after_multiple)
|
||||
assert_not_respond_to ModelCallbacks, :after_multiple
|
||||
end
|
||||
|
||||
test "no callbacks should be created" do
|
||||
assert !ModelCallbacks.respond_to?(:before_empty)
|
||||
assert !ModelCallbacks.respond_to?(:around_empty)
|
||||
assert !ModelCallbacks.respond_to?(:after_empty)
|
||||
assert_not_respond_to ModelCallbacks, :before_empty
|
||||
assert_not_respond_to ModelCallbacks, :around_empty
|
||||
assert_not_respond_to ModelCallbacks, :after_empty
|
||||
end
|
||||
|
||||
class Violin
|
||||
|
|
|
@ -320,7 +320,7 @@ class ErrorsTest < ActiveModel::TestCase
|
|||
|
||||
test "generate_message works without i18n_scope" do
|
||||
person = Person.new
|
||||
assert !Person.respond_to?(:i18n_scope)
|
||||
assert_not_respond_to Person, :i18n_scope
|
||||
assert_nothing_raised {
|
||||
person.errors.generate_message(:name, :blank)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class PostgresqlHstoreTest < ActiveRecord::PostgreSQLTestCase
|
|||
end
|
||||
|
||||
def test_hstore_included_in_extensions
|
||||
assert @connection.respond_to?(:extensions), "connection should have a list of extensions"
|
||||
assert_respond_to @connection, :extensions
|
||||
assert_includes @connection.extensions, "hstore", "extension list should include hstore"
|
||||
end
|
||||
|
||||
|
|
|
@ -475,11 +475,11 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def test_respond_to_enable_extension
|
||||
assert @conn.respond_to?(:enable_extension)
|
||||
assert_respond_to @conn, :enable_extension
|
||||
end
|
||||
|
||||
def test_respond_to_disable_extension
|
||||
assert @conn.respond_to?(:disable_extension)
|
||||
assert_respond_to @conn, :disable_extension
|
||||
end
|
||||
|
||||
def test_statement_closed
|
||||
|
|
|
@ -77,7 +77,7 @@ class LeftOuterJoinAssociationTest < ActiveRecord::TestCase
|
|||
def test_does_not_override_select
|
||||
authors = Author.select("authors.name, #{%{(authors.author_address_id || ' ' || authors.author_address_extra_id) as addr_id}}").left_outer_joins(:posts)
|
||||
assert authors.any?
|
||||
assert authors.first.respond_to?(:addr_id)
|
||||
assert_respond_to authors.first, :addr_id
|
||||
end
|
||||
|
||||
test "the default scope of the target is applied when joining associations" do
|
||||
|
|
|
@ -142,16 +142,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
assert_respond_to topic, :title=
|
||||
assert_respond_to topic, "author_name"
|
||||
assert_respond_to topic, "attribute_names"
|
||||
assert !topic.respond_to?("nothingness")
|
||||
assert !topic.respond_to?(:nothingness)
|
||||
assert_not_respond_to topic, "nothingness"
|
||||
assert_not_respond_to topic, :nothingness
|
||||
end
|
||||
|
||||
test "respond_to? with a custom primary key" do
|
||||
keyboard = Keyboard.create
|
||||
assert_not_nil keyboard.key_number
|
||||
assert_equal keyboard.key_number, keyboard.id
|
||||
assert keyboard.respond_to?("key_number")
|
||||
assert keyboard.respond_to?("id")
|
||||
assert_respond_to keyboard, "key_number"
|
||||
assert_respond_to keyboard, "id"
|
||||
end
|
||||
|
||||
test "id_before_type_cast with a custom primary key" do
|
||||
|
@ -170,8 +170,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
topic = klass.allocate
|
||||
assert !topic.respond_to?("nothingness")
|
||||
assert !topic.respond_to?(:nothingness)
|
||||
assert_not_respond_to topic, "nothingness"
|
||||
assert_not_respond_to topic, :nothingness
|
||||
assert_respond_to topic, "title"
|
||||
assert_respond_to topic, :title
|
||||
end
|
||||
|
@ -471,16 +471,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
|
||||
test "non-attribute read and write" do
|
||||
topic = Topic.new
|
||||
assert !topic.respond_to?("mumbo")
|
||||
assert_not_respond_to topic, "mumbo"
|
||||
assert_raise(NoMethodError) { topic.mumbo }
|
||||
assert_raise(NoMethodError) { topic.mumbo = 5 }
|
||||
end
|
||||
|
||||
test "undeclared attribute method does not affect respond_to? and method_missing" do
|
||||
topic = @target.new(title: "Budget")
|
||||
assert topic.respond_to?("title")
|
||||
assert_respond_to topic, "title"
|
||||
assert_equal "Budget", topic.title
|
||||
assert !topic.respond_to?("title_hello_world")
|
||||
assert_not_respond_to topic, "title_hello_world"
|
||||
assert_raise(NoMethodError) { topic.title_hello_world }
|
||||
end
|
||||
|
||||
|
@ -491,7 +491,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
@target.attribute_method_prefix prefix
|
||||
|
||||
meth = "#{prefix}title"
|
||||
assert topic.respond_to?(meth)
|
||||
assert_respond_to topic, meth
|
||||
assert_equal ["title"], topic.send(meth)
|
||||
assert_equal ["title", "a"], topic.send(meth, "a")
|
||||
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
|
||||
|
@ -505,7 +505,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
topic = @target.new(title: "Budget")
|
||||
|
||||
meth = "title#{suffix}"
|
||||
assert topic.respond_to?(meth)
|
||||
assert_respond_to topic, meth
|
||||
assert_equal ["title"], topic.send(meth)
|
||||
assert_equal ["title", "a"], topic.send(meth, "a")
|
||||
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
|
||||
|
@ -519,7 +519,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
topic = @target.new(title: "Budget")
|
||||
|
||||
meth = "#{prefix}title#{suffix}"
|
||||
assert topic.respond_to?(meth)
|
||||
assert_respond_to topic, meth
|
||||
assert_equal ["title"], topic.send(meth)
|
||||
assert_equal ["title", "a"], topic.send(meth, "a")
|
||||
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
|
||||
|
@ -767,7 +767,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
privatize("title")
|
||||
|
||||
topic = @target.new(title: "The pros and cons of programming naked.")
|
||||
assert !topic.respond_to?(:title)
|
||||
assert_not_respond_to topic, :title
|
||||
exception = assert_raise(NoMethodError) { topic.title }
|
||||
assert_includes exception.message, "private method"
|
||||
assert_equal "I'm private", topic.send(:title)
|
||||
|
@ -777,7 +777,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
privatize("title=(value)")
|
||||
|
||||
topic = @target.new
|
||||
assert !topic.respond_to?(:title=)
|
||||
assert_not_respond_to topic, :title=
|
||||
exception = assert_raise(NoMethodError) { topic.title = "Pants" }
|
||||
assert_includes exception.message, "private method"
|
||||
topic.send(:title=, "Very large pants")
|
||||
|
@ -787,7 +787,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|||
privatize("title?")
|
||||
|
||||
topic = @target.new(title: "Isaac Newton's pants")
|
||||
assert !topic.respond_to?(:title?)
|
||||
assert_not_respond_to topic, :title?
|
||||
exception = assert_raise(NoMethodError) { topic.title? }
|
||||
assert_includes exception.message, "private method"
|
||||
assert topic.send(:title?)
|
||||
|
|
|
@ -1686,7 +1686,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas
|
|||
end
|
||||
|
||||
test "should not generate validation methods for has_one associations without :validate => true" do
|
||||
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_ship)
|
||||
assert_not_respond_to @pirate, :validate_associated_records_for_non_validated_ship
|
||||
end
|
||||
|
||||
test "should generate validation methods for belongs_to associations with :validate => true" do
|
||||
|
@ -1694,7 +1694,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas
|
|||
end
|
||||
|
||||
test "should not generate validation methods for belongs_to associations without :validate => true" do
|
||||
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_parrot)
|
||||
assert_not_respond_to @pirate, :validate_associated_records_for_non_validated_parrot
|
||||
end
|
||||
|
||||
test "should generate validation methods for HABTM associations with :validate => true" do
|
||||
|
|
|
@ -1447,27 +1447,27 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
test "ignored columns have no attribute methods" do
|
||||
refute Developer.new.respond_to?(:first_name)
|
||||
refute Developer.new.respond_to?(:first_name=)
|
||||
refute Developer.new.respond_to?(:first_name?)
|
||||
refute SubDeveloper.new.respond_to?(:first_name)
|
||||
refute SubDeveloper.new.respond_to?(:first_name=)
|
||||
refute SubDeveloper.new.respond_to?(:first_name?)
|
||||
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name)
|
||||
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name=)
|
||||
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name?)
|
||||
assert_not_respond_to Developer.new, :first_name
|
||||
assert_not_respond_to Developer.new, :first_name=
|
||||
assert_not_respond_to Developer.new, :first_name?
|
||||
assert_not_respond_to SubDeveloper.new, :first_name
|
||||
assert_not_respond_to SubDeveloper.new, :first_name=
|
||||
assert_not_respond_to SubDeveloper.new, :first_name?
|
||||
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name
|
||||
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name=
|
||||
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name?
|
||||
end
|
||||
|
||||
test "ignored columns don't prevent explicit declaration of attribute methods" do
|
||||
assert Developer.new.respond_to?(:last_name)
|
||||
assert Developer.new.respond_to?(:last_name=)
|
||||
assert Developer.new.respond_to?(:last_name?)
|
||||
assert SubDeveloper.new.respond_to?(:last_name)
|
||||
assert SubDeveloper.new.respond_to?(:last_name=)
|
||||
assert SubDeveloper.new.respond_to?(:last_name?)
|
||||
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name)
|
||||
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name=)
|
||||
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name?)
|
||||
assert_respond_to Developer.new, :last_name
|
||||
assert_respond_to Developer.new, :last_name=
|
||||
assert_respond_to Developer.new, :last_name?
|
||||
assert_respond_to SubDeveloper.new, :last_name
|
||||
assert_respond_to SubDeveloper.new, :last_name=
|
||||
assert_respond_to SubDeveloper.new, :last_name?
|
||||
assert_respond_to SymbolIgnoredDeveloper.new, :last_name
|
||||
assert_respond_to SymbolIgnoredDeveloper.new, :last_name=
|
||||
assert_respond_to SymbolIgnoredDeveloper.new, :last_name?
|
||||
end
|
||||
|
||||
test "ignored columns are stored as an array of string" do
|
||||
|
@ -1477,13 +1477,13 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
|
||||
test "when #reload called, ignored columns' attribute methods are not defined" do
|
||||
developer = Developer.create!(name: "Developer")
|
||||
refute developer.respond_to?(:first_name)
|
||||
refute developer.respond_to?(:first_name=)
|
||||
assert_not_respond_to developer, :first_name
|
||||
assert_not_respond_to developer, :first_name=
|
||||
|
||||
developer.reload
|
||||
|
||||
refute developer.respond_to?(:first_name)
|
||||
refute developer.respond_to?(:first_name=)
|
||||
assert_not_respond_to developer, :first_name
|
||||
assert_not_respond_to developer, :first_name=
|
||||
end
|
||||
|
||||
test "ignored columns not included in SELECT" do
|
||||
|
|
|
@ -85,7 +85,7 @@ module ActiveRecord
|
|||
body = Class.new(String) { def to_path; "/path"; end }.new
|
||||
app = lambda { |_| [200, {}, body] }
|
||||
response_body = middleware(app).call(@env)[2]
|
||||
assert response_body.respond_to?(:to_path)
|
||||
assert_respond_to response_body, :to_path
|
||||
assert_equal "/path", response_body.to_path
|
||||
end
|
||||
|
||||
|
|
|
@ -459,17 +459,17 @@ class EnumTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
test "enum methods with custom suffix defined" do
|
||||
assert @book.class.respond_to?(:easy_to_read)
|
||||
assert @book.class.respond_to?(:medium_to_read)
|
||||
assert @book.class.respond_to?(:hard_to_read)
|
||||
assert_respond_to @book.class, :easy_to_read
|
||||
assert_respond_to @book.class, :medium_to_read
|
||||
assert_respond_to @book.class, :hard_to_read
|
||||
|
||||
assert @book.respond_to?(:easy_to_read?)
|
||||
assert @book.respond_to?(:medium_to_read?)
|
||||
assert @book.respond_to?(:hard_to_read?)
|
||||
assert_respond_to @book, :easy_to_read?
|
||||
assert_respond_to @book, :medium_to_read?
|
||||
assert_respond_to @book, :hard_to_read?
|
||||
|
||||
assert @book.respond_to?(:easy_to_read!)
|
||||
assert @book.respond_to?(:medium_to_read!)
|
||||
assert @book.respond_to?(:hard_to_read!)
|
||||
assert_respond_to @book, :easy_to_read!
|
||||
assert_respond_to @book, :medium_to_read!
|
||||
assert_respond_to @book, :hard_to_read!
|
||||
end
|
||||
|
||||
test "update enum attributes with custom suffix" do
|
||||
|
|
|
@ -8,7 +8,7 @@ class FinderRespondToTest < ActiveRecord::TestCase
|
|||
|
||||
def test_should_preserve_normal_respond_to_behaviour_on_base
|
||||
assert_respond_to ActiveRecord::Base, :new
|
||||
assert !ActiveRecord::Base.respond_to?(:find_by_something)
|
||||
assert_not_respond_to ActiveRecord::Base, :find_by_something
|
||||
end
|
||||
|
||||
def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method
|
||||
|
@ -43,14 +43,14 @@ class FinderRespondToTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_should_not_respond_to_find_by_one_missing_attribute
|
||||
assert !Topic.respond_to?(:find_by_undertitle)
|
||||
assert_not_respond_to Topic, :find_by_undertitle
|
||||
end
|
||||
|
||||
def test_should_not_respond_to_find_by_invalid_method_syntax
|
||||
assert !Topic.respond_to?(:fail_to_find_by_title)
|
||||
assert !Topic.respond_to?(:find_by_title?)
|
||||
assert !Topic.respond_to?(:fail_to_find_or_create_by_title)
|
||||
assert !Topic.respond_to?(:find_or_create_by_title?)
|
||||
assert_not_respond_to Topic, :fail_to_find_by_title
|
||||
assert_not_respond_to Topic, :find_by_title?
|
||||
assert_not_respond_to Topic, :fail_to_find_or_create_by_title
|
||||
assert_not_respond_to Topic, :find_or_create_by_title?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -252,7 +252,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
|
|||
def @david.favorite_quote; "Constraints are liberating"; end
|
||||
json = @david.to_json(include: :posts, methods: :favorite_quote)
|
||||
|
||||
assert !@david.posts.first.respond_to?(:favorite_quote)
|
||||
assert_not_respond_to @david.posts.first, :favorite_quote
|
||||
assert_match %r{"favorite_quote":"Constraints are liberating"}, json
|
||||
assert_equal 1, %r{"favorite_quote":}.match(json).size
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module ActiveRecord
|
|||
recorder = CommandRecorder.new(Class.new {
|
||||
def america; end
|
||||
}.new)
|
||||
assert recorder.respond_to?(:america)
|
||||
assert_respond_to recorder, :america
|
||||
end
|
||||
|
||||
def test_send_calls_super
|
||||
|
@ -27,7 +27,7 @@ module ActiveRecord
|
|||
recorder = CommandRecorder.new(Class.new {
|
||||
def create_table(name); end
|
||||
}.new)
|
||||
assert recorder.respond_to?(:create_table), "respond_to? create_table"
|
||||
assert_respond_to recorder, :create_table
|
||||
recorder.send(:create_table, :horses)
|
||||
assert_equal [[:create_table, [:horses], nil]], recorder.commands
|
||||
end
|
||||
|
|
|
@ -227,7 +227,7 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase
|
|||
topic = Topic.find(1)
|
||||
topic.attributes = attributes
|
||||
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
|
||||
assert_equal false, topic.written_on.respond_to?(:time_zone)
|
||||
assert_not_respond_to topic.written_on, :time_zone
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -242,7 +242,7 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase
|
|||
topic = Topic.find(1)
|
||||
topic.attributes = attributes
|
||||
assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on
|
||||
assert_equal false, topic.written_on.respond_to?(:time_zone)
|
||||
assert_not_respond_to topic.written_on, :time_zone
|
||||
end
|
||||
ensure
|
||||
Topic.skip_time_zone_conversion_for_attributes = []
|
||||
|
|
|
@ -242,10 +242,10 @@ module ActiveRecord
|
|||
|
||||
def test_respond_to_for_non_selected_element
|
||||
post = Post.select(:title).first
|
||||
assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception"
|
||||
assert_not_respond_to post, :body, "post should not respond_to?(:body) since invoking it raises exception"
|
||||
|
||||
silence_warnings { post = Post.select("'title' as post_title").first }
|
||||
assert_equal false, post.respond_to?(:title), "post should not respond_to?(:body) since invoking it raises exception"
|
||||
assert_not_respond_to post, :title, "post should not respond_to?(:body) since invoking it raises exception"
|
||||
end
|
||||
|
||||
def test_select_quotes_when_using_from_clause
|
||||
|
|
|
@ -56,7 +56,7 @@ class RelationTest < ActiveRecord::TestCase
|
|||
|
||||
def test_dynamic_finder
|
||||
x = Post.where("author_id = ?", 1)
|
||||
assert x.klass.respond_to?(:find_by_id), "@klass should handle dynamic finders"
|
||||
assert_respond_to x.klass, :find_by_id
|
||||
end
|
||||
|
||||
def test_multivalue_where
|
||||
|
@ -501,12 +501,12 @@ class RelationTest < ActiveRecord::TestCase
|
|||
relation = Topic.all
|
||||
|
||||
["find_by_title", "find_by_title_and_author_name"].each do |method|
|
||||
assert_respond_to relation, method, "Topic.all should respond to #{method.inspect}"
|
||||
assert_respond_to relation, method
|
||||
end
|
||||
end
|
||||
|
||||
def test_respond_to_class_methods_and_scopes
|
||||
assert Topic.all.respond_to?(:by_lifo)
|
||||
assert_respond_to Topic.all, :by_lifo
|
||||
end
|
||||
|
||||
def test_find_with_readonly_option
|
||||
|
@ -601,7 +601,7 @@ class RelationTest < ActiveRecord::TestCase
|
|||
reader = Reader.create! post_id: post.id, person_id: 1
|
||||
comment = Comment.create! post_id: post.id, body: "body"
|
||||
|
||||
assert !comment.respond_to?(:readers)
|
||||
assert_not_respond_to comment, :readers
|
||||
|
||||
post_rel = Post.preload(:readers).joins(:readers).where(title: "Uhuu")
|
||||
result_comment = Comment.joins(:post).merge(post_rel).to_a.first
|
||||
|
@ -1846,7 +1846,7 @@ class RelationTest < ActiveRecord::TestCase
|
|||
test "delegations do not leak to other classes" do
|
||||
Topic.all.by_lifo
|
||||
assert Topic.all.class.method_defined?(:by_lifo)
|
||||
assert !Post.all.respond_to?(:by_lifo)
|
||||
assert_not_respond_to Post.all, :by_lifo
|
||||
end
|
||||
|
||||
def test_unscope_with_subquery
|
||||
|
|
|
@ -65,9 +65,9 @@ class NamedScopingTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy
|
||||
assert Topic.approved.respond_to?(:limit)
|
||||
assert Topic.approved.respond_to?(:count)
|
||||
assert Topic.approved.respond_to?(:length)
|
||||
assert_respond_to Topic.approved, :limit
|
||||
assert_respond_to Topic.approved, :count
|
||||
assert_respond_to Topic.approved, :length
|
||||
end
|
||||
|
||||
def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
|
||||
|
|
|
@ -91,7 +91,7 @@ class ConcernTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
@klass.include test_module
|
||||
assert_equal false, Object.respond_to?(:test)
|
||||
assert_not_respond_to Object, :test
|
||||
Qux.class_eval do
|
||||
remove_const :ClassMethods
|
||||
end
|
||||
|
|
|
@ -43,11 +43,11 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase
|
|||
test "configuration accessors are not available on instance" do
|
||||
instance = Parent.new
|
||||
|
||||
assert !instance.respond_to?(:bar)
|
||||
assert !instance.respond_to?(:bar=)
|
||||
assert_not_respond_to instance, :bar
|
||||
assert_not_respond_to instance, :bar=
|
||||
|
||||
assert !instance.respond_to?(:baz)
|
||||
assert !instance.respond_to?(:baz=)
|
||||
assert_not_respond_to instance, :baz
|
||||
assert_not_respond_to instance, :baz=
|
||||
end
|
||||
|
||||
test "configuration accessors can take a default value" do
|
||||
|
|
|
@ -43,22 +43,22 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase
|
|||
assert_respond_to @class, :foo
|
||||
assert_respond_to @class, :foo=
|
||||
assert_respond_to @object, :bar
|
||||
assert !@object.respond_to?(:bar=)
|
||||
assert_not_respond_to @object, :bar=
|
||||
end.join
|
||||
end
|
||||
|
||||
def test_should_not_create_instance_reader
|
||||
Thread.new do
|
||||
assert_respond_to @class, :shaq
|
||||
assert !@object.respond_to?(:shaq)
|
||||
assert_not_respond_to @object, :shaq
|
||||
end.join
|
||||
end
|
||||
|
||||
def test_should_not_create_instance_accessors
|
||||
Thread.new do
|
||||
assert_respond_to @class, :camp
|
||||
assert !@object.respond_to?(:camp)
|
||||
assert !@object.respond_to?(:camp=)
|
||||
assert_not_respond_to @object, :camp
|
||||
assert_not_respond_to @object, :camp=
|
||||
end.join
|
||||
end
|
||||
|
||||
|
|
|
@ -65,18 +65,18 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase
|
|||
assert_respond_to @module, :foo
|
||||
assert_respond_to @module, :foo=
|
||||
assert_respond_to @object, :bar
|
||||
assert !@object.respond_to?(:bar=)
|
||||
assert_not_respond_to @object, :bar=
|
||||
end
|
||||
|
||||
def test_should_not_create_instance_reader
|
||||
assert_respond_to @module, :shaq
|
||||
assert !@object.respond_to?(:shaq)
|
||||
assert_not_respond_to @object, :shaq
|
||||
end
|
||||
|
||||
def test_should_not_create_instance_accessors
|
||||
assert_respond_to @module, :camp
|
||||
assert !@object.respond_to?(:camp)
|
||||
assert !@object.respond_to?(:camp=)
|
||||
assert_not_respond_to @object, :camp
|
||||
assert_not_respond_to @object, :camp=
|
||||
end
|
||||
|
||||
def test_should_raise_name_error_if_attribute_name_is_invalid
|
||||
|
|
|
@ -55,10 +55,10 @@ class ModuleConcernTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_using_class_methods_blocks_instead_of_ClassMethods_module
|
||||
assert !Foo.respond_to?(:will_be_orphaned)
|
||||
assert Foo.respond_to?(:hacked_on)
|
||||
assert Foo.respond_to?(:nicer_dsl)
|
||||
assert Foo.respond_to?(:doesnt_clobber)
|
||||
assert_not_respond_to Foo, :will_be_orphaned
|
||||
assert_respond_to Foo, :hacked_on
|
||||
assert_respond_to Foo, :nicer_dsl
|
||||
assert_respond_to Foo, :doesnt_clobber
|
||||
|
||||
# Orphan in Foo::ClassMethods, not Bar::ClassMethods.
|
||||
assert Foo.const_defined?(:ClassMethods)
|
||||
|
|
|
@ -32,14 +32,14 @@ class RemoveMethodTest < ActiveSupport::TestCase
|
|||
RemoveMethodTests::A.class_eval {
|
||||
remove_possible_method(:do_something)
|
||||
}
|
||||
assert !RemoveMethodTests::A.new.respond_to?(:do_something)
|
||||
assert_not_respond_to RemoveMethodTests::A.new, :do_something
|
||||
end
|
||||
|
||||
def test_remove_singleton_method_from_an_object
|
||||
RemoveMethodTests::A.class_eval {
|
||||
remove_possible_singleton_method(:do_something_else)
|
||||
}
|
||||
assert !RemoveMethodTests::A.respond_to?(:do_something_else)
|
||||
assert_not_respond_to RemoveMethodTests::A, :do_something_else
|
||||
end
|
||||
|
||||
def test_redefine_method_in_an_object
|
||||
|
|
|
@ -383,9 +383,9 @@ class ModuleTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_delegate_missing_to_affects_respond_to
|
||||
assert DecoratedTester.new(@david).respond_to?(:name)
|
||||
assert_not DecoratedTester.new(@david).respond_to?(:private_name)
|
||||
assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method)
|
||||
assert_respond_to DecoratedTester.new(@david), :name
|
||||
assert_not_respond_to DecoratedTester.new(@david), :private_name
|
||||
assert_not_respond_to DecoratedTester.new(@david), :my_fake_method
|
||||
|
||||
assert DecoratedTester.new(@david).respond_to?(:name, true)
|
||||
assert_not DecoratedTester.new(@david).respond_to?(:private_name, true)
|
||||
|
@ -414,8 +414,8 @@ class ModuleTest < ActiveSupport::TestCase
|
|||
|
||||
place = location.new(Somewhere.new("Such street", "Sad city"))
|
||||
|
||||
assert_not place.respond_to?(:street)
|
||||
assert_not place.respond_to?(:city)
|
||||
assert_not_respond_to place, :street
|
||||
assert_not_respond_to place, :city
|
||||
|
||||
assert place.respond_to?(:street, true) # Asking for private method
|
||||
assert place.respond_to?(:city, true)
|
||||
|
@ -432,12 +432,12 @@ class ModuleTest < ActiveSupport::TestCase
|
|||
|
||||
place = location.new(Somewhere.new("Such street", "Sad city"))
|
||||
|
||||
assert_not place.respond_to?(:street)
|
||||
assert_not place.respond_to?(:city)
|
||||
assert_not_respond_to place, :street
|
||||
assert_not_respond_to place, :city
|
||||
|
||||
assert_not place.respond_to?(:the_street)
|
||||
assert_not_respond_to place, :the_street
|
||||
assert place.respond_to?(:the_street, true)
|
||||
assert_not place.respond_to?(:the_city)
|
||||
assert_not_respond_to place, :the_city
|
||||
assert place.respond_to?(:the_city, true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,25 +10,25 @@ class ObjectTryTest < ActiveSupport::TestCase
|
|||
|
||||
def test_nonexisting_method
|
||||
method = :undefined_method
|
||||
assert !@string.respond_to?(method)
|
||||
assert_not_respond_to @string, method
|
||||
assert_nil @string.try(method)
|
||||
end
|
||||
|
||||
def test_nonexisting_method_with_arguments
|
||||
method = :undefined_method
|
||||
assert !@string.respond_to?(method)
|
||||
assert_not_respond_to @string, method
|
||||
assert_nil @string.try(method, "llo", "y")
|
||||
end
|
||||
|
||||
def test_nonexisting_method_bang
|
||||
method = :undefined_method
|
||||
assert !@string.respond_to?(method)
|
||||
assert_not_respond_to @string, method
|
||||
assert_raise(NoMethodError) { @string.try!(method) }
|
||||
end
|
||||
|
||||
def test_nonexisting_method_with_arguments_bang
|
||||
method = :undefined_method
|
||||
assert !@string.respond_to?(method)
|
||||
assert_not_respond_to @string, method
|
||||
assert_raise(NoMethodError) { @string.try!(method, "llo", "y") }
|
||||
end
|
||||
|
||||
|
|
|
@ -1035,8 +1035,8 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase
|
|||
|
||||
def test_nil_time_zone
|
||||
Time.use_zone nil do
|
||||
assert !@t.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert !@dt.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert_not_respond_to @t.in_time_zone, :period, "no period method"
|
||||
assert_not_respond_to @dt.in_time_zone, :period, "no period method"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1224,7 +1224,7 @@ class TimeWithZoneMethodsForDate < ActiveSupport::TestCase
|
|||
|
||||
def test_nil_time_zone
|
||||
with_tz_default nil do
|
||||
assert !@d.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert_not_respond_to @d.in_time_zone, :period, "no period method"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1273,9 +1273,9 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase
|
|||
|
||||
def test_nil_time_zone
|
||||
with_tz_default nil do
|
||||
assert !@s.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert !@u.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert !@z.in_time_zone.respond_to?(:period), "no period method"
|
||||
assert_not_respond_to @s.in_time_zone, :period, "no period method"
|
||||
assert_not_respond_to @u.in_time_zone, :period, "no period method"
|
||||
assert_not_respond_to @z.in_time_zone, :period, "no period method"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -752,7 +752,7 @@ class DependenciesTest < ActiveSupport::TestCase
|
|||
Object.const_set :C, Class.new { def self.before_remove_const; end }
|
||||
C.unloadable
|
||||
assert_called(C, :before_remove_const, times: 1) do
|
||||
assert C.respond_to?(:before_remove_const)
|
||||
assert_respond_to C, :before_remove_const
|
||||
ActiveSupport::Dependencies.clear
|
||||
assert !defined?(C)
|
||||
end
|
||||
|
|
|
@ -469,10 +469,10 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_respond_to_knows_which_methods_the_proxy_responds_to
|
||||
assert "".mb_chars.respond_to?(:slice) # Defined on Chars
|
||||
assert "".mb_chars.respond_to?(:capitalize!) # Defined on Chars
|
||||
assert "".mb_chars.respond_to?(:gsub) # Defined on String
|
||||
assert !"".mb_chars.respond_to?(:undefined_method) # Not defined
|
||||
assert_respond_to "".mb_chars, :slice # Defined on Chars
|
||||
assert_respond_to "".mb_chars, :capitalize! # Defined on Chars
|
||||
assert_respond_to "".mb_chars, :gsub # Defined on String
|
||||
assert_not_respond_to "".mb_chars, :undefined_method # Not defined
|
||||
end
|
||||
|
||||
def test_method_works_for_proxyed_methods
|
||||
|
|
|
@ -82,8 +82,8 @@ class OrderedOptionsTest < ActiveSupport::TestCase
|
|||
|
||||
def test_introspection
|
||||
a = ActiveSupport::OrderedOptions.new
|
||||
assert a.respond_to?(:blah)
|
||||
assert a.respond_to?(:blah=)
|
||||
assert_respond_to a, :blah
|
||||
assert_respond_to a, :blah=
|
||||
assert_equal 42, a.method(:blah=).call(42)
|
||||
assert_equal 42, a.method(:blah).call
|
||||
end
|
||||
|
@ -91,7 +91,7 @@ class OrderedOptionsTest < ActiveSupport::TestCase
|
|||
def test_raises_with_bang
|
||||
a = ActiveSupport::OrderedOptions.new
|
||||
a[:foo] = :bar
|
||||
assert a.respond_to?(:foo!)
|
||||
assert_respond_to a, :foo!
|
||||
|
||||
assert_nothing_raised { a.foo! }
|
||||
assert_equal a.foo, a.foo!
|
||||
|
|
|
@ -21,7 +21,7 @@ class TaggedLoggingTest < ActiveSupport::TestCase
|
|||
assert_nil logger.formatter
|
||||
ActiveSupport::TaggedLogging.new(logger)
|
||||
assert_not_nil logger.formatter
|
||||
assert logger.formatter.respond_to?(:tagged)
|
||||
assert_respond_to logger.formatter, :tagged
|
||||
end
|
||||
|
||||
test "tagged once" do
|
||||
|
|
|
@ -33,7 +33,7 @@ module ApplicationTests
|
|||
assert_nil x.i_do_not_exist.zomg
|
||||
|
||||
# test that custom configuration responds to all messages
|
||||
assert_equal true, x.respond_to?(:i_do_not_exist)
|
||||
assert_respond_to x, :i_do_not_exist
|
||||
assert_kind_of Method, x.method(:i_do_not_exist)
|
||||
assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist
|
||||
end
|
||||
|
|
|
@ -1478,7 +1478,7 @@ module ApplicationTests
|
|||
test "respond_to? accepts include_private" do
|
||||
make_basic_app
|
||||
|
||||
assert_not Rails.configuration.respond_to?(:method_missing)
|
||||
assert_not_respond_to Rails.configuration, :method_missing
|
||||
assert Rails.configuration.respond_to?(:method_missing, true)
|
||||
end
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class ConsoleTest < ActiveSupport::TestCase
|
|||
MODEL
|
||||
|
||||
load_environment
|
||||
assert User.new.respond_to?(:name)
|
||||
assert_respond_to User.new, :name
|
||||
|
||||
app_file "app/models/user.rb", <<-MODEL
|
||||
class User
|
||||
|
@ -81,9 +81,9 @@ class ConsoleTest < ActiveSupport::TestCase
|
|||
end
|
||||
MODEL
|
||||
|
||||
assert !User.new.respond_to?(:age)
|
||||
assert_not_respond_to User.new, :age
|
||||
irb_context.reload!(false)
|
||||
assert User.new.respond_to?(:age)
|
||||
assert_respond_to User.new, :age
|
||||
end
|
||||
|
||||
def test_access_to_helpers
|
||||
|
|
Loading…
Reference in a new issue