diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-04-18 23:15:38 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-04-18 23:15:38 +0100 |
commit | 6f84c73dc48538202766cff3d973a53d3c30848e (patch) | |
tree | b95728dfe8813ad3637fbe3a1e52c9207279663d /activerecord/test/models | |
parent | 0acc6bd6cb1d27fdbb0c00ac3a322bc8413e03cc (diff) | |
download | rails-6f84c73dc48538202766cff3d973a53d3c30848e.tar.gz rails-6f84c73dc48538202766cff3d973a53d3c30848e.tar.bz2 rails-6f84c73dc48538202766cff3d973a53d3c30848e.zip |
Un-deprecate using 'default_scope' as a macro, but if you are calling the macro multiple times that will give deprecation warnings, and in 3.2 we will simply overwrite the default scope when you call the macro multiple times.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/bulb.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/car.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/categorization.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 68 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/reference.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/without_table.rb | 4 |
7 files changed, 23 insertions, 77 deletions
diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 89ee5416bf..c68d008c26 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -1,8 +1,5 @@ class Bulb < ActiveRecord::Base - def self.default_scope - where :name => 'defaulty' - end - + default_scope where(:name => 'defaulty') belongs_to :car attr_reader :scope_after_initialize diff --git a/activerecord/test/models/car.rb b/activerecord/test/models/car.rb index a978debb58..b036f0f5c9 100644 --- a/activerecord/test/models/car.rb +++ b/activerecord/test/models/car.rb @@ -15,13 +15,9 @@ class Car < ActiveRecord::Base end class CoolCar < Car - def self.default_scope - order 'name desc' - end + default_scope :order => 'name desc' end class FastCar < Car - def self.default_scope - order 'name desc' - end + default_scope :order => 'name desc' end diff --git a/activerecord/test/models/categorization.rb b/activerecord/test/models/categorization.rb index 39441e8610..4bd980e606 100644 --- a/activerecord/test/models/categorization.rb +++ b/activerecord/test/models/categorization.rb @@ -12,10 +12,7 @@ end class SpecialCategorization < ActiveRecord::Base self.table_name = 'categorizations' - - def self.default_scope - where(:special => true) - end + default_scope where(:special => true) belongs_to :author belongs_to :category diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 10385ba899..93363f47c5 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -86,10 +86,7 @@ end class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' - - def self.default_scope - order('salary DESC') - end + default_scope :order => 'salary DESC' scope :by_name, order('name DESC') @@ -102,74 +99,41 @@ end class DeveloperCalledDavid < ActiveRecord::Base self.table_name = 'developers' - - def self.default_scope - where "name = 'David'" - end + default_scope where("name = 'David'") end -class DeveloperCalledJamis < ActiveRecord::Base +class ClassMethodDeveloperCalledDavid < ActiveRecord::Base self.table_name = 'developers' def self.default_scope - where :name => 'Jamis' + where(:name => 'David') end - - scope :poor, where('salary < 150000') end -class AbstractDeveloperCalledJamis < ActiveRecord::Base - self.abstract_class = true - - def self.default_scope - where :name => 'Jamis' - end +class DeveloperCalledJamis < ActiveRecord::Base + self.table_name = 'developers' + default_scope where(:name => 'Jamis') + scope :poor, where('salary < 150000') end class PoorDeveloperCalledJamis < ActiveRecord::Base self.table_name = 'developers' - - def self.default_scope - where :name => 'Jamis', :salary => 50000 - end + default_scope where(:name => 'Jamis', :salary => 50000) end class InheritedPoorDeveloperCalledJamis < DeveloperCalledJamis self.table_name = 'developers' - def self.default_scope - super.where :salary => 50000 + ActiveSupport::Deprecation.silence do + default_scope where(:salary => 50000) end end -ActiveSupport::Deprecation.silence do - class DeprecatedDeveloperOrderedBySalary < ActiveRecord::Base - self.table_name = 'developers' - default_scope :order => 'salary DESC' - - def self.by_name - order('name DESC') - end - - def self.all_ordered_by_name - with_scope(:find => { :order => 'name DESC' }) do - find(:all) - end - end - end - - class DeprecatedDeveloperCalledDavid < ActiveRecord::Base - self.table_name = 'developers' - default_scope :conditions => "name = 'David'" - end - - class DeprecatedDeveloperCalledJamis < ActiveRecord::Base - self.table_name = 'developers' - default_scope :conditions => { :name => 'Jamis' } - end +class MultiplePoorDeveloperCalledJamis < ActiveRecord::Base + self.table_name = 'developers' + default_scope where(:name => 'Jamis') - class DeprecatedPoorDeveloperCalledJamis < ActiveRecord::Base - self.table_name = 'developers' - default_scope :conditions => { :name => 'Jamis', :salary => 50000 } + ActiveSupport::Deprecation.silence do + default_scope where(:salary => 50000) end end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 34cea60053..80296032bb 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -157,10 +157,7 @@ end class FirstPost < ActiveRecord::Base self.table_name = 'posts' - - def self.default_scope - where(:id => 1) - end + default_scope where(:id => 1) has_many :comments, :foreign_key => :post_id has_one :comment, :foreign_key => :post_id diff --git a/activerecord/test/models/reference.rb b/activerecord/test/models/reference.rb index 76c0a1a32e..c5af0b5d5f 100644 --- a/activerecord/test/models/reference.rb +++ b/activerecord/test/models/reference.rb @@ -19,8 +19,5 @@ end class BadReference < ActiveRecord::Base self.table_name = 'references' - - def self.default_scope - where :favourite => false - end + default_scope where(:favourite => false) end diff --git a/activerecord/test/models/without_table.rb b/activerecord/test/models/without_table.rb index 1a63d6ceb6..184ab1649e 100644 --- a/activerecord/test/models/without_table.rb +++ b/activerecord/test/models/without_table.rb @@ -1,5 +1,3 @@ class WithoutTable < ActiveRecord::Base - def self.default_scope - where(:published => true) - end + default_scope where(:published => true) end |