rails/activemodel/test/cases/conversion_test.rb
Grant Hutchins & Peter Jaros bf812074fd Let ActiveModel instances define partial paths.
Deprecate ActiveModel::Name#partial_path. Now you
should call #to_path directly on ActiveModel
instances.
2011-07-25 16:05:24 -04:00

33 lines
1.0 KiB
Ruby

require 'cases/helper'
require 'models/contact'
require 'models/helicopter'
class ConversionTest < ActiveModel::TestCase
test "to_model default implementation returns self" do
contact = Contact.new
assert_equal contact, contact.to_model
end
test "to_key default implementation returns nil for new records" do
assert_nil Contact.new.to_key
end
test "to_key default implementation returns the id in an array for persisted records" do
assert_equal [1], Contact.new(:id => 1).to_key
end
test "to_param default implementation returns nil for new records" do
assert_nil Contact.new.to_param
end
test "to_param default implementation returns a string of ids for persisted records" do
assert_equal "1", Contact.new(:id => 1).to_param
end
test "to_path default implementation returns a string giving a relative path" do
assert_equal "contacts/contact", Contact.new.to_path
assert_equal "helicopters/helicopter", Helicopter.new.to_path,
"ActiveModel::Conversion#to_path caching should be class-specific"
end
end