Skip to content

Commit

Permalink
Merge branch 'master' of git@technicalpickles.com:ambitious_sphinx
Browse files Browse the repository at this point in the history
Conflicts:

	lib/ambition/adapters/ambitious_sphinx/select.rb
  • Loading branch information
Josh Nichols committed Feb 7, 2008
2 parents eeeece4 + 70ff31c commit e634061
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/ambition/adapters/ambitious_sphinx/select.rb
Expand Up @@ -61,15 +61,17 @@ def not_equal(left, right)
# >> select { |u| u.name =~ 'chris' }
# => #=~( call(:name), 'chris' )
def =~(left, right)
raise if right.is_a? Regexp
"#{left}#{quotify right}"
end

# !~
# >> select { |u| u.name !~ 'chris' }
# => #not_regexp( call(:name), 'chris' )
def not_regexp(left, right)
"NOT #{left}#{quotify right}"
# could be DRYer, but this is more readable than: "NOT #{self.=~(left,right)}"
raise if right.is_a? Regexp
"NOT #{left}#{quotify right}"
end

##
Expand Down
10 changes: 7 additions & 3 deletions test/select_test.rb
Expand Up @@ -44,14 +44,18 @@
query = User.select { |m| m.name =~ 'chris' && m.name =~ 'jon' }.to_hash[:query]
query.should == %Q(name:"chris" AND name:"jon")
end

specify "Ruby =~ with Regexp" do
should.raise { User.select { |m| m.name =~ /chris/ } }
end

specify "Ruby !~ with string" do
query = User.select { |m| m.name =~ 'chris' && m.name !~ 'jon' }.to_hash[:query]
query.should == %Q(name:"chris" AND NOT name:"jon")
end

xspecify "=~ with regexp" do
should.raise { User.select { |m| m.name =~ /chris/ } }
specify "Ruby !~ with Regexp" do
should.raise { User.select { |m| m.name !~ /chris/ } }
end

xspecify "=~ with regexp flags" do
Expand Down

0 comments on commit e634061

Please sign in to comment.