diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/lint.rb | 23 | ||||
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/lint_test.rb | 8 |
3 files changed, 32 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 7bf0ad712d..c97286e61c 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -13,6 +13,29 @@ module ActiveModel module Lint module Tests + + # == Responds to <tt>key</tt> + # + # Returns an Enumerable of all (primary) key attributes + # or nil if model.new_record? is true + def test_key + assert model.respond_to?(:key), "The model should respond to key" + def model.new_record?() true end + assert model.key.nil? + def model.new_record?() false end + assert model.key.respond_to?(:each) + end + + # == Responds to <tt>to_param</tt> + # + # Returns a string representing the object's key suitable for use in URLs + # or nil if model.new_record? is true + def test_to_param + assert model.respond_to?(:to_param), "The model should respond to to_param" + def model.new_record?() true end + assert model.to_param.nil? + end + # == Responds to <tt>valid?</tt> # # Returns a boolean that specifies whether the object is in a valid or invalid diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 89e8f8b1ea..39512a427b 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -41,7 +41,7 @@ module ActiveModel # To implement, just extend ActiveModel::Naming in your object: # # class BookCover - # exten ActiveModel::Naming + # extend ActiveModel::Naming # end # # BookCover.model_name #=> "BookCover" diff --git a/activemodel/test/cases/lint_test.rb b/activemodel/test/cases/lint_test.rb index 63804004ee..58716cbf85 100644 --- a/activemodel/test/cases/lint_test.rb +++ b/activemodel/test/cases/lint_test.rb @@ -10,6 +10,14 @@ class LintTest < ActiveModel::TestCase self end + def key + new_record? ? nil : [1] + end + + def to_param + key ? key.first.to_s : nil + end + def valid?() true end def new_record?() true end def destroyed?() true end |