Sha256: d2877ae21c41e4e52ac96cef32c918fc7063e02cfc7383c37176c3e89fe6697f
Contents?: true
Size: 1.89 KB
Versions: 5
Compression:
Stored size: 1.89 KB
Contents
require File.dirname(__FILE__) + '/spec_helper' describe Pollyanna::Search do describe 'scope_options' do it "should hand a :by option to conditions_for_find" do search = Pollyanna::Search.new("foo", "movies") search.should_receive(:conditions_for_find).with(:title) search.scope_options(:by => :title) end it "should return an options hash for a Rails scope" do search = Pollyanna::Search.new("foo", "movies") search.should_receive(:conditions_for_find).and_return("sql query") search.scope_options.should == { :conditions => "sql query" } end end describe 'conditions_for_find' do it "should return a LIKE query for the given query, looking in the search_text column by default and using the table name to disambiguate things" do search = Pollyanna::Search.new("word", "movies") search.send(:conditions_for_find).should == ['movies.search_text LIKE ?', "%word%"] end it "should look in another column if the #by argument is given" do search = Pollyanna::Search.new("word", "movies") search.send(:conditions_for_find, "words").should == ['movies.words LIKE ?', "%word%"] end it "should return a conjunction of LIKE queries for queries with multiple words" do search = Pollyanna::Search.new("foo bar", "movies") search.send(:conditions_for_find).should == ['movies.search_text LIKE ? AND movies.search_text LIKE ?', '%foo%', '%bar%'] end it "should escape underscores in the query" do search = Pollyanna::Search.new("foo_bar", "movies") search.send(:conditions_for_find).should == ['movies.search_text LIKE ?', "%foo\\_bar%"] end it "should escape percent signs in the query" do search = Pollyanna::Search.new("foo%bar", "movies") search.send(:conditions_for_find).should == ['movies.search_text LIKE ?', "%foo\\%bar%"] end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
pollyanna-1.0.4 | spec/search_spec.rb |
pollyanna-1.0.3 | spec/search_spec.rb |
pollyanna-1.0.2 | spec/search_spec.rb |
pollyanna-1.0.1 | spec/search_spec.rb |
pollyanna-1.0.0 | spec/search_spec.rb |