Created
August 24, 2009 21:19
-
-
Save brentd/174204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/searchlogic/named_scopes/conditions.rb b/lib/searchlogic/named_scopes/conditions.rb | |
index 8329957..52faa82 100644 | |
--- a/lib/searchlogic/named_scopes/conditions.rb | |
+++ b/lib/searchlogic/named_scopes/conditions.rb | |
@@ -122,7 +122,7 @@ module Searchlogic | |
when "blank" | |
{:conditions => "#{table_name}.#{column} = '' OR #{table_name}.#{column} IS NULL"} | |
when "not_blank" | |
- {:conditions => "#{table_name}.#{column} != '' OR #{table_name}.#{column} IS NOT NULL"} | |
+ {:conditions => "#{table_name}.#{column} != '' AND #{table_name}.#{column} IS NOT NULL"} | |
end | |
named_scope("#{column}_#{condition}".to_sym, scope_options) | |
diff --git a/spec/named_scopes/conditions_spec.rb b/spec/named_scopes/conditions_spec.rb | |
index ffe6a97..3e2d469 100644 | |
--- a/spec/named_scopes/conditions_spec.rb | |
+++ b/spec/named_scopes/conditions_spec.rb | |
@@ -100,8 +100,10 @@ describe "Conditions" do | |
end | |
it "should have not blank" do | |
- ["bjohnson", "", nil].each { |username| User.create(:username => username) } | |
- User.username_not_blank.all.should == User.all(:conditions => "username IS NOT NULL OR username != ''") | |
+ bjohnson = User.create(:username => "bjohnson") | |
+ null = User.create(:username => nil) | |
+ blank = User.create(:username => '') | |
+ User.username_not_blank.all.should == [bjohnson] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment