Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Fixed bug when dealing with scopes that return nil.

  • Loading branch information...
commit 256dfa819b1f903f4b9a5c34abc3769cf5c926f8 1 parent 142e7c7
@binarylogic authored
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== 2.1.12 released 2009-07-28
+
+* Fixed bug when dealing with scopes that return nil.
+
== 2.1.11 released 2009-07-28
* Reworked how alias conditions are created on the fly, uses scope(:find) instead of proxy_options to create the scope. This allows using association alias named scopes.
View
3  lib/searchlogic/named_scopes/association_conditions.rb
@@ -131,7 +131,8 @@ def association_condition_options(association_name, association_condition, args)
eval <<-"end_eval"
searchlogic_lambda(:#{arg_type}) { |#{proc_args.join(",")}|
- options = association.klass.send(association_condition, #{proc_args.join(",")}).scope(:find)
+ scope = association.klass.send(association_condition, #{proc_args.join(",")})
+ options = scope ? scope.scope(:find) : {}
options.delete(:readonly)
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
options
View
4 spec/named_scopes/association_conditions_spec.rb
@@ -17,6 +17,10 @@
Company.users_username_has("bjohnson").proxy_options.should == User.username_has("bjohnson").proxy_options.merge(:joins => :users)
end
+ it "should not raise errors for scopes that don't return anything" do
+ Company.users_blank_scope("bjohnson").proxy_options.should == {:joins => :users}
+ end
+
it "should ignore polymorphic associations" do
lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
end
View
6 spec/search_spec.rb
@@ -115,6 +115,12 @@
search.users_uname.should == "bjohnson"
end
+ it "should allow setting pre-existing association alias conditions" do
+ search = Company.search
+ search.users_username_has = "bjohnson"
+ search.users_username_has.should == "bjohnson"
+ end
+
it "should allow using custom conditions" do
User.named_scope(:four_year_olds, { :conditions => { :age => 4 } })
search = User.search
View
1  spec/spec_helper.rb
@@ -73,6 +73,7 @@ class User < ActiveRecord::Base
has_many :orders, :dependent => :destroy
named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
alias_scope :username_has, lambda { |value| username_like(value) }
+ alias_scope :blank_scope, lambda { |value| }
end
class Order < ActiveRecord::Base
Please sign in to comment.
Something went wrong with that request. Please try again.