Skip to content

Instantly share code, notes, and snippets.

@brapse
Created January 30, 2009 06:18
Show Gist options
  • Save brapse/54955 to your computer and use it in GitHub Desktop.
Save brapse/54955 to your computer and use it in GitHub Desktop.
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
describe FauxQuery do
it 'Determin the model being tested' do
#Simple case
a = FauxQuery.new("Bands in montreal")
a.query_model.should == Band
#quotted case
b = FauxQuery.new("\"wholy mountain places\" bands in montreal")
b.query_model.should == Band
#tagged
c = FauxQuery.new("indie-ish bands from montreal")
c.query_model.should == Band
end
# Test the difference distinguishment of simple and complex queries
it 'should determine the complexity of the query' do
a = FauxQuery.new("broken social scene")
a.query_type.should == :simple
b = FauxQuery.new("shows in montreal")
b.query_type.should == :complex
end
it 'should extract tags' do
#word preceeding -ish are to be concidered a tag
a = FauxQuery.new("indie-ish shows in montreal")
a.params.should include(:tag)
a.params[:tag].should == "indie"
#multiple words preceeding -ish are to be concidered a tag string
b = FauxQuery.new("indie folk-ish shows in toronto")
b.params[:tag].should == "indie folk"
#literal (serounded by quotes) found before -ish are to be concidered tags
c = FauxQuery.new("\"indie rock\"-ish shows in montreal")
c.params[:tag].should == "indie rock"
end
it 'should extract the proper place' do
#tolken preceeding "at" is concidered the name of a place
a = FauxQuery.new("shows at barfly")
a.params[:place].should == "barfly"
#tolken can be multiple workds
b = FauxQuery.new("shows at Sala Rossa")
b.params[:place].should == "sala rossa"
end
it 'detect the proper city' do
a = FauxQuery.new("shows in montreal")
a.params[:city].should == "montreal"
end
it 'detect the month of the show' do
a = FauxQuery.new("shows during december")
a.params[:month].should == "december"
end
it 'be able to extract the bill' do
a = FauxQuery.new("shows with cursed")
a.params[:bill].should == "cursed"
end
it 'should extract a date' do
q = FauxQuery.new("shows on december 20th")
q.params[:when].should == "december 20th"
end
it 'should work with multiple clauses' do
a = FauxQuery.new("shows in montreal with cursed")
a.params[:city].should == "montreal"
a.params[:bill].should == "cursed"
b = FauxQuery.new("shows in ottawa with cursed during december at sala rossa")
b.params[:city].should == "ottawa"
b.params[:bill].should == "cursed"
b.params[:place].should == "sala rossa"
b.params[:month].should == "december"
c = FauxQuery.new("\"omg in at with cool\"-ish shows in cool people town")
c.params[:tag].should == "omg in at with cool"
c.params[:city].should == "cool people town"
end
it 'should sythnesise the query' do
a = FauxQuery.new("shows in montreal")
a.query_type.should == :complex
a.rendered_string.should include("city:")
b = FauxQuery.new("indie-ish shows in montreal during december")
b.rendered_string.should include("tag:")
b.rendered_string.should include("city:")
b.rendered_string.should include("month:")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment