diff options
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/comment.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/company.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/organization.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/person.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 18 | ||||
-rw-r--r-- | activerecord/test/models/reply.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 22 |
8 files changed, 32 insertions, 34 deletions
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index 399dea9f12..a8a99f6dce 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -1,7 +1,7 @@ class Comment < ActiveRecord::Base - named_scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'" - named_scope :for_first_post, :conditions => { :post_id => 1 } - named_scope :for_first_author, + scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'" + scope :for_first_post, :conditions => { :post_id => 1 } + scope :for_first_author, :joins => :post, :conditions => { "posts.author_id" => 1 } diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 7e93fda1eb..df5fd10b6b 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -45,7 +45,7 @@ class Firm < Company has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all - has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1 + has_many :limited_clients, :class_name => "Client", :limit => 1 has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}' has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id" @@ -91,10 +91,8 @@ class Firm < Company end class DependentFirm < Company - # added order by id as in fixtures there are two accounts for Rails Core - # Oracle tests were failing because of that as the second fixture was selected - has_one :account, :foreign_key => "firm_id", :dependent => :nullify, :order => "id" - has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify + has_one :account, :foreign_key => "firm_id", :dependent => :nullify + has_many :companies, :foreign_key => 'client_of', :dependent => :nullify end class Client < Company diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 058970336b..e7a1e110d7 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -43,7 +43,7 @@ class Developer < ActiveRecord::Base has_many :audit_logs - named_scope :jamises, :conditions => {:name => 'Jamis'} + scope :jamises, :conditions => {:name => 'Jamis'} validates_inclusion_of :salary, :in => 50000..200000 validates_length_of :name, :within => 3..20 @@ -81,7 +81,7 @@ end class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' default_scope :order => 'salary DESC' - named_scope :by_name, :order => 'name DESC' + scope :by_name, :order => 'name DESC' def self.all_ordered_by_name with_scope(:find => { :order => 'name DESC' }) do diff --git a/activerecord/test/models/organization.rb b/activerecord/test/models/organization.rb index c85726169e..1da342a0bd 100644 --- a/activerecord/test/models/organization.rb +++ b/activerecord/test/models/organization.rb @@ -2,5 +2,5 @@ class Organization < ActiveRecord::Base has_many :member_details has_many :members, :through => :member_details - named_scope :clubs, { :from => 'clubs' } + scope :clubs, { :from => 'clubs' } end
\ No newline at end of file diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index 57fa6418f1..2a73b1ee01 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -12,6 +12,6 @@ class Person < ActiveRecord::Base has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id' belongs_to :number1_fan, :class_name => 'Person' - named_scope :males, :conditions => { :gender => 'M' } - named_scope :females, :conditions => { :gender => 'F' } + scope :males, :conditions => { :gender => 'M' } + scope :females, :conditions => { :gender => 'F' } end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 7392515ec7..f48b35486c 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -1,8 +1,8 @@ class Post < ActiveRecord::Base - named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'" - named_scope :ranked_by_comments, :order => "comments_count DESC" - named_scope :limit, lambda {|limit| {:limit => limit} } - named_scope :with_authors_at_address, lambda { |address| { + scope :containing_the_letter_a, where("body LIKE '%a%'") + scope :ranked_by_comments, order("comments_count DESC") + 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' } @@ -19,13 +19,13 @@ class Post < ActiveRecord::Base has_one :last_comment, :class_name => 'Comment', :order => 'id desc' - named_scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} } - named_scope :with_very_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'VerySpecialComment'} } - named_scope :with_post, lambda {|post_id| + scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} } + scope :with_very_special_comments, joins(:comments).where(:comments => {:type => 'VerySpecialComment'}) + scope :with_post, lambda {|post_id| { :joins => :comments, :conditions => {:comments => {:post_id => post_id} } } } - has_many :comments, :order => "body" do + has_many :comments do def find_most_recent find(:first, :order => "id DESC") end @@ -73,7 +73,7 @@ class Post < ActiveRecord::Base has_many :impatient_people, :through => :skimmers, :source => :person def self.top(limit) - ranked_by_comments.limit(limit) + ranked_by_comments.limit_by(limit) end def self.reset_log diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index f1ba45b528..264a49b465 100644 --- a/activerecord/test/models/reply.rb +++ b/activerecord/test/models/reply.rb @@ -1,7 +1,7 @@ require 'models/topic' class Reply < Topic - named_scope :base + scope :base belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true belongs_to :topic_with_primary_key, :class_name => "Topic", :primary_key => "title", :foreign_key => "parent_title", :counter_cache => "replies_count" diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index baca4972cb..91fc7c9416 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -1,19 +1,19 @@ class Topic < ActiveRecord::Base - named_scope :base - named_scope :written_before, lambda { |time| + scope :base + scope :written_before, lambda { |time| if time { :conditions => ['written_on < ?', time] } end } - named_scope :approved, :conditions => {:approved => true} - named_scope :rejected, :conditions => {:approved => false} + scope :approved, :conditions => {:approved => true} + scope :rejected, :conditions => {:approved => false} - named_scope :by_lifo, :conditions => {:author_name => 'lifo'} + scope :by_lifo, :conditions => {:author_name => 'lifo'} - named_scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}} - named_scope 'approved_as_string', :conditions => {:approved => true} - named_scope :replied, :conditions => ['replies_count > 0'] - named_scope :anonymous_extension do + scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}} + scope 'approved_as_string', :conditions => {:approved => true} + scope :replied, :conditions => ['replies_count > 0'] + scope :anonymous_extension do def one 1 end @@ -33,8 +33,8 @@ class Topic < ActiveRecord::Base 2 end end - named_scope :named_extension, :extend => NamedExtension - named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne] + scope :named_extension, :extend => NamedExtension + scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne] has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" has_many :replies_with_primary_key, :class_name => "Reply", :dependent => :destroy, :primary_key => "title", :foreign_key => "parent_title" |