aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/lint.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-03-12 16:00:01 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-03-12 16:00:01 +0000
commite68bfaf1fe1a7890a67af6f444281185f507cf9e (patch)
tree5e73caccdcdd65d0ac97f9eb92195928f30925f2 /activemodel/lib/active_model/lint.rb
parentef6462c73003b28c8e060a06120abb9cd67b6d52 (diff)
parent16846553b8866eab2aa3b128a2a23a221a25f7e3 (diff)
downloadrails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.gz
rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.bz2
rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.zip
Merge remote branch 'mainstream/master'
Conflicts: activerecord/lib/active_record/base.rb railties/lib/rails/configuration.rb railties/lib/rails/log_subscriber.rb
Diffstat (limited to 'activemodel/lib/active_model/lint.rb')
-rw-r--r--activemodel/lib/active_model/lint.rb40
1 files changed, 31 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb
index 7bf0ad712d..13ddb622d1 100644
--- a/activemodel/lib/active_model/lint.rb
+++ b/activemodel/lib/active_model/lint.rb
@@ -13,6 +13,33 @@
module ActiveModel
module Lint
module Tests
+
+ # == Responds to <tt>to_key</tt>
+ #
+ # Returns an Enumerable of all (primary) key attributes
+ # or nil if model.persisted? is false
+ def test_to_key
+ assert model.respond_to?(:to_key), "The model should respond to to_key"
+ def model.persisted?() false end
+ assert model.to_key.nil?
+ end
+
+ # == Responds to <tt>to_param</tt>
+ #
+ # Returns a string representing the object's key suitable for use in URLs
+ # or nil if model.persisted? is false.
+ #
+ # Implementers can decide to either raise an exception or provide a default
+ # in case the record uses a composite primary key. There are no tests for this
+ # behavior in lint because it doesn't make sense to force any of the possible
+ # implementation strategies on the implementer. However, if the resource is
+ # not persisted?, then to_param should always return nil.
+ def test_to_param
+ assert model.respond_to?(:to_param), "The model should respond to to_param"
+ def model.persisted?() false 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
@@ -22,21 +49,16 @@ module ActiveModel
assert_boolean model.valid?, "valid?"
end
- # == Responds to <tt>new_record?</tt>
+ # == Responds to <tt>persisted?</tt>
#
# Returns a boolean that specifies whether the object has been persisted yet.
# This is used when calculating the URL for an object. If the object is
# not persisted, a form for that object, for instance, will be POSTed to the
# collection. If it is persisted, a form for the object will put PUTed to the
# URL for the object.
- def test_new_record?
- assert model.respond_to?(:new_record?), "The model should respond to new_record?"
- assert_boolean model.new_record?, "new_record?"
- end
-
- def test_destroyed?
- assert model.respond_to?(:destroyed?), "The model should respond to destroyed?"
- assert_boolean model.destroyed?, "destroyed?"
+ def test_persisted?
+ assert model.respond_to?(:persisted?), "The model should respond to persisted?"
+ assert_boolean model.persisted?, "persisted?"
end
# == Naming