Permalink
Browse files

* named_scope_options should return the proper options for existing n…

…amed scopes with an arity greater than 0
  • Loading branch information...
1 parent 58e1326 commit e8a52ec052d954f9589e9e10b235488c9ac35c8d @binarylogic committed Jun 17, 2009
Showing with 10 additions and 2 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −1 lib/searchlogic/named_scopes/conditions.rb
  3. +8 −1 spec/search_spec.rb
View
@@ -3,6 +3,7 @@
* Allow the chaining of conditions off of a search object. Ex: search.username_like("bjohnson").age_gt(20).all
* Split out left outer join creation into its own method, allowing you to use it in your own named scopes.
* Make sure the search objects clone properly.
+* named_scope_options should return the proper options for existing named scopes with an arity greater than 0
== 2.0.0
@@ -46,7 +46,7 @@ module Conditions
# ActiveRecord hides this internally, so we have to try and pull it out with this
# method.
def named_scope_options(name)
- key = primary_condition_name(name)
+ key = scopes.key?(name.to_sym) ? name.to_sym : primary_condition_name(name)
if key
eval("options", scopes[key])
View
@@ -111,13 +111,20 @@
search.username_gt.should == "bjohnson2"
end
- it "should allow setting custom conditions individually" do
+ it "should allow setting custom conditions individually with an arity of 0" do
User.named_scope(:four_year_olds, :conditions => {:age => 4})
search = User.search
search.four_year_olds = true
search.four_year_olds.should == true
end
+ it "should allow setting custom conditions individually with an arity of 1" do
+ User.named_scope(:username_should_be, lambda { |u| {:conditions => {:username => u}} })
+ search = User.search
+ search.username_should_be = "bjohnson"
+ search.username_should_be.should == "bjohnson"
+ end
+
it "should not allow setting conditions that are not scopes" do
search = User.search
lambda { search.unknown = true }.should raise_error(Searchlogic::Search::UnknownConditionError)

0 comments on commit e8a52ec

Please sign in to comment.