aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/comment.rb5
-rw-r--r--activerecord/test/models/post.rb20
-rw-r--r--activerecord/test/models/topic.rb26
3 files changed, 21 insertions, 30 deletions
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
index 3bd7db7834..2a4c37089a 100644
--- a/activerecord/test/models/comment.rb
+++ b/activerecord/test/models/comment.rb
@@ -1,8 +1,5 @@
class Comment < ActiveRecord::Base
- def self.limit_by(l)
- limit(l)
- end
-
+ scope :limit_by, lambda {|l| limit(l) }
scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
scope :not_again, where("comments.body NOT LIKE '%again%'")
scope :for_first_post, :conditions => { :post_id => 1 }
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index a91c10276b..34cea60053 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -8,13 +8,12 @@ class Post < ActiveRecord::Base
scope :containing_the_letter_a, where("body LIKE '%a%'")
scope :ranked_by_comments, order("comments_count DESC")
- def self.limit_by(l)
- limit(l)
- end
-
- def self.with_authors_at_address(address)
- where('authors.author_address_id = ?', address.id).joins('JOIN authors ON authors.id = posts.author_id')
- end
+ scope :limit_by, lambda {|l| limit(l) }
+ scope :with_authors_at_address, lambda { |address| {
+ :conditions => [ 'authors.author_address_id = ?', address.id ],
+ :joins => 'JOIN authors ON authors.id = posts.author_id'
+ }
+ }
belongs_to :author do
def greeting
@@ -29,10 +28,9 @@ class Post < ActiveRecord::Base
scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} }
scope :with_very_special_comments, joins(:comments).where(:comments => {:type => 'VerySpecialComment'})
-
- def self.with_post(post_id)
- joins(:comments).where(:comments => { :post_id => post_id })
- end
+ scope :with_post, lambda {|post_id|
+ { :joins => :comments, :conditions => {:comments => {:post_id => post_id} } }
+ }
has_many :comments do
def find_most_recent
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 60e750e6c4..6440dbe8ab 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -1,20 +1,10 @@
class Topic < ActiveRecord::Base
scope :base
-
- ActiveSupport::Deprecation.silence do
- scope :written_before, lambda { |time|
- if time
- { :conditions => ['written_on < ?', time] }
- end
- }
-
- scope :with_object, Class.new(Struct.new(:klass)) {
- def call
- klass.where(:approved => true)
- end
- }.new(self)
- end
-
+ scope :written_before, lambda { |time|
+ if time
+ { :conditions => ['written_on < ?', time] }
+ end
+ }
scope :approved, :conditions => {:approved => true}
scope :rejected, :conditions => {:approved => false}
@@ -29,6 +19,12 @@ class Topic < ActiveRecord::Base
end
end
+ scope :with_object, Class.new(Struct.new(:klass)) {
+ def call
+ klass.where(:approved => true)
+ end
+ }.new(self)
+
module NamedExtension
def two
2