diff options
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/conversion_test.rb | 25 | ||||
-rw-r--r-- | activemodel/test/cases/lint_test.rb | 17 |
2 files changed, 27 insertions, 15 deletions
diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb new file mode 100644 index 0000000000..373424df2f --- /dev/null +++ b/activemodel/test/cases/conversion_test.rb @@ -0,0 +1,25 @@ +require 'cases/helper' +require 'models/contact' + +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(:new_record => false, :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(:new_record => false, :id => 1).to_param + end +end
\ No newline at end of file diff --git a/activemodel/test/cases/lint_test.rb b/activemodel/test/cases/lint_test.rb index 99f8eff5d8..e4c069e1ab 100644 --- a/activemodel/test/cases/lint_test.rb +++ b/activemodel/test/cases/lint_test.rb @@ -1,24 +1,11 @@ -require "cases/helper" +require 'cases/helper' class LintTest < ActiveModel::TestCase include ActiveModel::Lint::Tests class CompliantModel extend ActiveModel::Naming - - def to_model - self - end - - def to_key - new_record? ? nil : [id] - end - - def to_param - return nil if to_key.nil? - # some default for CPKs, real implementations will differ - to_key.length > 1 ? to_key.join('-') : to_key.first.to_s - end + include ActiveModel::Conversion def valid?() true end def new_record?() true end |