aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/test/cases/naming_helpers_test.rb63
-rw-r--r--activemodel/test/cases/naming_test.rb39
-rw-r--r--activemodel/test/models/contact.rb1
-rw-r--r--activemodel/test/models/sheep.rb4
4 files changed, 44 insertions, 63 deletions
diff --git a/activemodel/test/cases/naming_helpers_test.rb b/activemodel/test/cases/naming_helpers_test.rb
deleted file mode 100644
index e7234e009e..0000000000
--- a/activemodel/test/cases/naming_helpers_test.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-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
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb
index dc39b84ed8..5a8bff378a 100644
--- a/activemodel/test/cases/naming_test.rb
+++ b/activemodel/test/cases/naming_test.rb
@@ -1,4 +1,6 @@
require 'cases/helper'
+require 'models/contact'
+require 'models/sheep'
require 'models/track_back'
class NamingTest < ActiveModel::TestCase
@@ -26,3 +28,40 @@ class NamingTest < ActiveModel::TestCase
assert_equal 'post/track_backs/track_back', @model_name.partial_path
end
end
+
+class NamingHelpersTest < Test::Unit::TestCase
+ def setup
+ @klass = Contact
+ @record = @klass.new
+ @singular = 'contact'
+ @plural = 'contacts'
+ @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 uncountable?(@uncountable), "Expected 'sheep' to be uncoutable"
+ assert !uncountable?(@klass), "Expected 'contact' to be countable"
+ end
+
+ private
+ def method_missing(method, *args)
+ ActiveModel::Naming.send(method, *args)
+ end
+end
+
diff --git a/activemodel/test/models/contact.rb b/activemodel/test/models/contact.rb
index 605e435f39..f4f3078473 100644
--- a/activemodel/test/models/contact.rb
+++ b/activemodel/test/models/contact.rb
@@ -1,4 +1,5 @@
class Contact
+ extend ActiveModel::Naming
include ActiveModel::Conversion
attr_accessor :id, :name, :age, :created_at, :awesome, :preferences
diff --git a/activemodel/test/models/sheep.rb b/activemodel/test/models/sheep.rb
new file mode 100644
index 0000000000..175dbe6477
--- /dev/null
+++ b/activemodel/test/models/sheep.rb
@@ -0,0 +1,4 @@
+class Sheep
+ extend ActiveModel::Naming
+end
+ \ No newline at end of file