aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/record_identifier_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/template/record_identifier_test.rb')
-rw-r--r--actionview/test/template/record_identifier_test.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/actionview/test/template/record_identifier_test.rb b/actionview/test/template/record_identifier_test.rb
new file mode 100644
index 0000000000..22038110a5
--- /dev/null
+++ b/actionview/test/template/record_identifier_test.rb
@@ -0,0 +1,49 @@
+require 'abstract_unit'
+require 'controller/fake_models'
+
+class RecordIdentifierTest < ActiveSupport::TestCase
+ include ActionView::RecordIdentifier
+
+ def setup
+ @klass = Comment
+ @record = @klass.new
+ @singular = 'comment'
+ @plural = 'comments'
+ @uncountable = Sheep
+ end
+
+ def test_dom_id_with_new_record
+ assert_equal "new_#{@singular}", dom_id(@record)
+ end
+
+ def test_dom_id_with_new_record_and_prefix
+ assert_equal "custom_prefix_#{@singular}", dom_id(@record, :custom_prefix)
+ end
+
+ def test_dom_id_with_saved_record
+ @record.save
+ assert_equal "#{@singular}_1", dom_id(@record)
+ end
+
+ def test_dom_id_with_prefix
+ @record.save
+ assert_equal "edit_#{@singular}_1", dom_id(@record, :edit)
+ end
+
+ def test_dom_class
+ assert_equal @singular, dom_class(@record)
+ end
+
+ def test_dom_class_with_prefix
+ assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix)
+ end
+
+ def test_dom_id_as_singleton_method
+ @record.save
+ assert_equal "#{@singular}_1", ActionView::RecordIdentifier.dom_id(@record)
+ end
+
+ def test_dom_class_as_singleton_method
+ assert_equal @singular, ActionView::RecordIdentifier.dom_class(@record)
+ end
+end