diff options
author | José Valim <jose.valim@gmail.com> | 2010-02-21 11:09:21 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-02-21 11:12:14 +0100 |
commit | 250c8092461f5e6bf62751b313f6605a37fd1b2b (patch) | |
tree | 7ef84aa83bd41eb023b9d4323d7208bd75d1b994 /activemodel/test | |
parent | 9dd67fce25d3993a0ee494506ba246a45d395e3f (diff) | |
download | rails-250c8092461f5e6bf62751b313f6605a37fd1b2b.tar.gz rails-250c8092461f5e6bf62751b313f6605a37fd1b2b.tar.bz2 rails-250c8092461f5e6bf62751b313f6605a37fd1b2b.zip |
Require persisted? in ActiveModel::Lint and remove new_record? and destroyed? methods. ActionPack does not care if the resource is new or if it was destroyed, it cares only if it's persisted somewhere or not.
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/conversion_test.rb | 4 | ||||
-rw-r--r-- | activemodel/test/cases/lint_test.rb | 3 | ||||
-rw-r--r-- | activemodel/test/models/contact.rb | 6 |
3 files changed, 6 insertions, 7 deletions
diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb index 373424df2f..7669bf5f65 100644 --- a/activemodel/test/cases/conversion_test.rb +++ b/activemodel/test/cases/conversion_test.rb @@ -12,7 +12,7 @@ class ConversionTest < ActiveModel::TestCase 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 + assert_equal [1], Contact.new(:id => 1).to_key end test "to_param default implementation returns nil for new records" do @@ -20,6 +20,6 @@ class ConversionTest < ActiveModel::TestCase 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 + assert_equal "1", Contact.new(: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 e4c069e1ab..68372160cd 100644 --- a/activemodel/test/cases/lint_test.rb +++ b/activemodel/test/cases/lint_test.rb @@ -8,8 +8,7 @@ class LintTest < ActiveModel::TestCase include ActiveModel::Conversion def valid?() true end - def new_record?() true end - def destroyed?() true end + def persisted?() false end def errors obj = Object.new diff --git a/activemodel/test/models/contact.rb b/activemodel/test/models/contact.rb index dbdb8539b7..a583b89aa1 100644 --- a/activemodel/test/models/contact.rb +++ b/activemodel/test/models/contact.rb @@ -1,13 +1,13 @@ class Contact include ActiveModel::Conversion - attr_accessor :id, :name, :age, :created_at, :awesome, :preferences, :new_record + attr_accessor :id, :name, :age, :created_at, :awesome, :preferences def initialize(options = {}) options.each { |name, value| send("#{name}=", value) } end - def new_record? - defined?(@new_record) ? @new_record : true + def persisted? + id.present? end end |