2008-01-05 13:32:06 +00:00
|
|
|
require 'abstract_unit'
|
2007-04-30 01:17:56 +00:00
|
|
|
|
2007-05-14 17:30:35 +00:00
|
|
|
class Comment
|
2009-07-21 05:51:57 +00:00
|
|
|
extend ActiveModel::Naming
|
|
|
|
include ActiveModel::Conversion
|
2009-06-17 15:37:39 +00:00
|
|
|
|
2007-04-30 01:17:56 +00:00
|
|
|
attr_reader :id
|
2010-02-21 02:05:28 +00:00
|
|
|
def to_key; id ? [id] : nil end
|
2007-04-30 01:17:56 +00:00
|
|
|
def save; @id = 1 end
|
|
|
|
def new_record?; @id.nil? end
|
|
|
|
def name
|
2007-05-14 17:30:35 +00:00
|
|
|
@id.nil? ? 'new comment' : "comment ##{@id}"
|
2007-04-30 01:17:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-19 21:35:54 +00:00
|
|
|
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
|
|
|
|
|
2007-04-30 01:17:56 +00:00
|
|
|
class RecordIdentifierTest < Test::Unit::TestCase
|
|
|
|
include ActionController::RecordIdentifier
|
|
|
|
|
|
|
|
def setup
|
2007-05-14 17:30:35 +00:00
|
|
|
@klass = Comment
|
2007-04-30 01:17:56 +00:00
|
|
|
@record = @klass.new
|
2007-05-14 17:30:35 +00:00
|
|
|
@singular = 'comment'
|
|
|
|
@plural = 'comments'
|
2010-06-19 21:35:54 +00:00
|
|
|
@uncountable = Sheep
|
2007-04-30 01:17:56 +00: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 21:35:54 +00:00
|
|
|
|
2007-04-30 01:17:56 +00:00
|
|
|
def test_dom_class_with_prefix
|
|
|
|
assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix)
|
|
|
|
end
|
|
|
|
end
|