aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/naming_helpers_test.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-07-21 10:37:09 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-21 11:29:58 +0200
commit6807b080996ee4bd6b80abb4f5e9964632c421c8 (patch)
tree9ab10340178251987b5379b74948ba1ac6389a1b /activemodel/test/cases/naming_helpers_test.rb
parentfa8b290496789eb037d4fad89acea1cb0a534f35 (diff)
downloadrails-6807b080996ee4bd6b80abb4f5e9964632c421c8.tar.gz
rails-6807b080996ee4bd6b80abb4f5e9964632c421c8.tar.bz2
rails-6807b080996ee4bd6b80abb4f5e9964632c421c8.zip
Moved a few methods from RecordIdentifier to ActiveModel::Naming
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/test/cases/naming_helpers_test.rb')
-rw-r--r--activemodel/test/cases/naming_helpers_test.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/activemodel/test/cases/naming_helpers_test.rb b/activemodel/test/cases/naming_helpers_test.rb
new file mode 100644
index 0000000000..e7234e009e
--- /dev/null
+++ b/activemodel/test/cases/naming_helpers_test.rb
@@ -0,0 +1,63 @@
+require 'cases/helper'
+
+class Comment
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+
+ attr_reader :id
+ def to_key; id ? [id] : nil end
+ def save; @id = 1 end
+ def new_record?; @id.nil? end
+ def name
+ @id.nil? ? 'new comment' : "comment ##{@id}"
+ end
+end
+
+class Sheep
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+
+ attr_reader :id
+ def to_key; id ? [id] : nil end
+ def save; @id = 1 end
+ def new_record?; @id.nil? end
+ def name
+ @id.nil? ? 'new sheep' : "sheep ##{@id}"
+ end
+end
+
+class NamingHelpersTest < Test::Unit::TestCase
+ def setup
+ @klass = Comment
+ @record = @klass.new
+ @singular = 'comment'
+ @plural = 'comments'
+ @uncountable = Sheep
+ end
+
+ def test_singular
+ assert_equal @singular, singular(@record)
+ end
+
+ def test_singular_for_class
+ assert_equal @singular, singular(@klass)
+ end
+
+ def test_plural
+ assert_equal @plural, plural(@record)
+ end
+
+ def test_plural_for_class
+ assert_equal @plural, plural(@klass)
+ end
+
+ def test_uncountable
+ assert_equal true, uncountable?(@uncountable)
+ assert_equal false, uncountable?(@klass)
+ end
+
+ private
+ def method_missing(method, *args)
+ ActiveModel::Naming.send(method, *args)
+ end
+end