2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:50:17 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "controller/fake_models"
|
2007-04-29 21:17:56 -04:00
|
|
|
|
2012-01-05 20:01:45 -05:00
|
|
|
class RecordIdentifierTest < ActiveSupport::TestCase
|
2012-06-09 08:20:31 -04:00
|
|
|
include ActionView::RecordIdentifier
|
2007-04-29 21:17:56 -04:00
|
|
|
|
|
|
|
def setup
|
2007-05-14 13:30:35 -04:00
|
|
|
@klass = Comment
|
2007-04-29 21:17:56 -04:00
|
|
|
@record = @klass.new
|
2016-08-06 12:50:17 -04:00
|
|
|
@singular = "comment"
|
|
|
|
@plural = "comments"
|
2007-04-29 21:17:56 -04:00
|
|
|
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
|
2010-06-19 17:35:54 -04:00
|
|
|
|
2007-04-29 21:17:56 -04:00
|
|
|
def test_dom_class_with_prefix
|
|
|
|
assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix)
|
|
|
|
end
|
2012-08-25 07:34:52 -04:00
|
|
|
|
|
|
|
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
|
2007-04-29 21:17:56 -04:00
|
|
|
end
|
2014-12-19 15:49:50 -05:00
|
|
|
|
|
|
|
class RecordIdentifierWithoutActiveModelTest < ActiveSupport::TestCase
|
|
|
|
include ActionView::RecordIdentifier
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@record = Plane.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_id_with_new_record
|
|
|
|
assert_equal "new_airplane", dom_id(@record)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_id_with_new_record_and_prefix
|
|
|
|
assert_equal "custom_prefix_airplane", dom_id(@record, :custom_prefix)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_id_with_saved_record
|
|
|
|
@record.save
|
|
|
|
assert_equal "airplane_1", dom_id(@record)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_id_with_prefix
|
|
|
|
@record.save
|
|
|
|
assert_equal "edit_airplane_1", dom_id(@record, :edit)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_class
|
2016-08-06 12:50:17 -04:00
|
|
|
assert_equal "airplane", dom_class(@record)
|
2014-12-19 15:49:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_class_with_prefix
|
|
|
|
assert_equal "custom_prefix_airplane", dom_class(@record, :custom_prefix)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_id_as_singleton_method
|
|
|
|
@record.save
|
|
|
|
assert_equal "airplane_1", ActionView::RecordIdentifier.dom_id(@record)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dom_class_as_singleton_method
|
2016-08-06 12:50:17 -04:00
|
|
|
assert_equal "airplane", ActionView::RecordIdentifier.dom_class(@record)
|
2014-12-19 15:49:50 -05:00
|
|
|
end
|
|
|
|
end
|