aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/named_scope_test.rb6
-rw-r--r--activerecord/test/models/comment.rb6
-rw-r--r--activerecord/test/models/developer.rb4
-rw-r--r--activerecord/test/models/organization.rb2
-rw-r--r--activerecord/test/models/person.rb4
-rw-r--r--activerecord/test/models/post.rb14
-rw-r--r--activerecord/test/models/reply.rb2
-rw-r--r--activerecord/test/models/topic.rb22
8 files changed, 32 insertions, 28 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index ce1ac845cd..3e2bd58f9a 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -372,9 +372,13 @@ class NamedScopeTest < ActiveRecord::TestCase
def test_named_scopes_with_reserved_names
[:where, :with_scope].each do |protected_method|
- assert_raises(ArgumentError) { Topic.named_scope protected_method }
+ assert_raises(ArgumentError) { Topic.scope protected_method }
end
end
+
+ def test_deprecated_named_scope_method
+ assert_deprecated('named_scope has been deprecated') { Topic.named_scope :deprecated_named_scope }
+ end
end
class DynamicScopeMatchTest < ActiveRecord::TestCase
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/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 b5f9328139..939df7549b 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, where("body LIKE '%a%'")
- named_scope :ranked_by_comments, order("comments_count DESC")
- named_scope :limit_by, lambda {|l| limit(l) }
- 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,9 +19,9 @@ 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).where(: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} } }
}
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"