Skip to content

Commit

Permalink
Applied patch for bind variables in conditions (http://code.google.co…
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Feb 19, 2009
1 parent a133a97 commit 674660a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/acts_as_tsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ def find_by_tsearch(search_string, options = nil, tsearch_options = nil, page =

#add vector condition
where_part = "#{table_name}.#{tsearch_options[:vector]} @@ tsearch_query"
if options[:conditions]
if options[:conditions] and options[:conditions].is_a? String
options[:conditions] << " and #{where_part}"
elsif options[:conditions] and options[:conditions].is_a? Array
options[:conditions].first << " and #{where_part}"
else
options[:conditions] = where_part
end
Expand Down
11 changes: 11 additions & 0 deletions test/acts_as_tsearch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,15 @@ def test_find_using_include_option
assert_equal 2, c.size
assert_equal 'Bob eats lunch', c[0].blog_entry.title
end

def test_find_using_conditions
BlogComment.acts_as_tsearch :fields => %w{name}
BlogComment.update_vectors

c = BlogComment.find_by_tsearch('jim', :include => :blog_entry, :conditions => "email = '[email protected]'")
assert_equal 2, c.size

c = BlogComment.find_by_tsearch('jim', :include => :blog_entry, :conditions => ["email = ?", '[email protected]'])
assert_equal 2, c.size
end
end

0 comments on commit 674660a

Please sign in to comment.