diff options
author | Daniel Colson <danieljamescolson@gmail.com> | 2018-01-24 21:14:10 -0500 |
---|---|---|
committer | Daniel Colson <danieljamescolson@gmail.com> | 2018-01-25 23:32:58 -0500 |
commit | 0d50cae996c51630361e8514e1f168b0c48957e1 (patch) | |
tree | dfbf9609ff6f3d859e584874ac6d8bdc91304c08 /activemodel | |
parent | 8baca31dbe522cb407f0b3b8c8d3d4a6804e5aed (diff) | |
download | rails-0d50cae996c51630361e8514e1f168b0c48957e1.tar.gz rails-0d50cae996c51630361e8514e1f168b0c48957e1.tar.bz2 rails-0d50cae996c51630361e8514e1f168b0c48957e1.zip |
Use respond_to test helpers
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/lint.rb | 24 | ||||
-rw-r--r-- | activemodel/test/cases/attribute_methods_test.rb | 4 | ||||
-rw-r--r-- | activemodel/test/cases/callbacks_test.rb | 12 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 2 |
4 files changed, 21 insertions, 21 deletions
diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 34d9ac6c96..b7ceabb59a 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -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 diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index d2837ec894..0cfc6f4b6b 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -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 diff --git a/activemodel/test/cases/callbacks_test.rb b/activemodel/test/cases/callbacks_test.rb index a5d29d0f22..1ec12d8222 100644 --- a/activemodel/test/cases/callbacks_test.rb +++ b/activemodel/test/cases/callbacks_test.rb @@ -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 diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index d5c282b620..16ace62f26 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -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) } |