File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -2176,7 +2176,7 @@ def subclasses #:nodoc:
2176
2176
# default_scope :order => 'last_name, first_name'
2177
2177
# end
2178
2178
def default_scope ( options = { } )
2179
- self . default_scoping << { :find => options , :create => ( options . is_a? ( Hash ) && options . has_key? ( :conditions ) ) ? options [ :conditions ] : { } }
2179
+ self . default_scoping << { :find => options , :create => options [ :conditions ] . is_a? ( Hash ) ? options [ :conditions ] : { } }
2180
2180
end
2181
2181
2182
2182
# Test whether the given method and optional key are scoped.
Original file line number Diff line number Diff line change @@ -591,6 +591,16 @@ def test_default_scope
591
591
assert_equal expected , received
592
592
end
593
593
594
+ def test_default_scope_with_conditions_string
595
+ assert_equal Developer . find_all_by_name ( 'David' ) . map ( &:id ) . sort , DeveloperCalledDavid . all . map ( &:id ) . sort
596
+ assert_equal nil , DeveloperCalledDavid . create! . name
597
+ end
598
+
599
+ def test_default_scope_with_conditions_hash
600
+ assert_equal Developer . find_all_by_name ( 'Jamis' ) . map ( &:id ) . sort , DeveloperCalledJamis . all . map ( &:id ) . sort
601
+ assert_equal 'Jamis' , DeveloperCalledJamis . create! . name
602
+ end
603
+
594
604
def test_default_scoping_with_threads
595
605
scope = [ { :create => { } , :find => { :order => 'salary DESC' } } ]
596
606
Original file line number Diff line number Diff line change @@ -89,3 +89,13 @@ def self.all_ordered_by_name
89
89
end
90
90
end
91
91
end
92
+
93
+ class DeveloperCalledDavid < ActiveRecord ::Base
94
+ self . table_name = 'developers'
95
+ default_scope :conditions => "name = 'David'"
96
+ end
97
+
98
+ class DeveloperCalledJamis < ActiveRecord ::Base
99
+ self . table_name = 'developers'
100
+ default_scope :conditions => { :name => 'Jamis' }
101
+ end
You can’t perform that action at this time.
0 commit comments