aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/lib/controller/fake_models.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-02-21 11:09:21 +0100
committerJosé Valim <jose.valim@gmail.com>2010-02-21 11:12:14 +0100
commit250c8092461f5e6bf62751b313f6605a37fd1b2b (patch)
tree7ef84aa83bd41eb023b9d4323d7208bd75d1b994 /actionpack/test/lib/controller/fake_models.rb
parent9dd67fce25d3993a0ee494506ba246a45d395e3f (diff)
downloadrails-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 'actionpack/test/lib/controller/fake_models.rb')
-rw-r--r--actionpack/test/lib/controller/fake_models.rb40
1 files changed, 12 insertions, 28 deletions
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 4475d40f63..bf3e175f1f 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -6,14 +6,6 @@ class Customer < Struct.new(:name, :id)
undef_method :to_json
- def to_key
- id ? [id] : nil
- end
-
- def to_param
- id.to_s
- end
-
def to_xml(options={})
if options[:builder]
options[:builder].name name
@@ -31,8 +23,8 @@ class Customer < Struct.new(:name, :id)
[]
end
- def destroyed?
- false
+ def persisted?
+ id.present?
end
end
@@ -47,12 +39,8 @@ module Quiz
extend ActiveModel::Naming
include ActiveModel::Conversion
- def to_key
- id ? [id] : nil
- end
-
- def to_param
- id.to_s
+ def persisted?
+ id.present?
end
end
@@ -67,16 +55,12 @@ class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost
alias_method :secret?, :secret
- def to_key
- id ? [id] : nil
- end
-
- def new_record=(boolean)
- @new_record = boolean
+ def persisted=(boolean)
+ @persisted = boolean
end
- def new_record?
- @new_record
+ def persisted?
+ @persisted
end
attr_accessor :author
@@ -98,7 +82,7 @@ class Comment
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def to_key; id ? [id] : nil end
def save; @id = 1; @post_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def name
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -118,7 +102,7 @@ class Tag
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def to_key; id ? [id] : nil end
def save; @id = 1; @post_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -138,7 +122,7 @@ class CommentRelevance
def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
def to_key; id ? [id] : nil end
def save; @id = 1; @comment_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -154,7 +138,7 @@ class TagRelevance
def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
def to_key; id ? [id] : nil end
def save; @id = 1; @tag_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"