1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #18156 from claudiob/better-record-identifier-tests

Better tests for AV::RecordIdentifier
This commit is contained in:
Sean Griffin 2014-12-22 18:06:16 -07:00
commit d9d865aa40
2 changed files with 55 additions and 0 deletions

View file

@ -170,3 +170,15 @@ end
class Car < Struct.new(:color)
end
class Plane
attr_reader :to_key
def model_name
OpenStruct.new param_key: 'airplane'
end
def save
@to_key = [1]
end
end

View file

@ -46,3 +46,46 @@ class RecordIdentifierTest < ActiveSupport::TestCase
assert_equal @singular, ActionView::RecordIdentifier.dom_class(@record)
end
end
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
assert_equal 'airplane', dom_class(@record)
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
assert_equal 'airplane', ActionView::RecordIdentifier.dom_class(@record)
end
end