117 lines
3.0 KiB
Ruby
117 lines
3.0 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe User do
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
before(:each) do
|
|
@geocode1 = FactoryGirl.create(:geocoder)
|
|
@geocode2 = FactoryGirl.create(:geocoder)
|
|
@user = FactoryGirl.create(:user)
|
|
@band = Band.save(nil, "Example Band", "www.bands.com", "zomg we rock", "Apex", "NC", "US", ["hip hop"], user.id, nil, nil)
|
|
|
|
end
|
|
|
|
it "should allow search of one band with an exact match" do
|
|
ws = Search.band_search("Example Band")
|
|
ws.length.should == 1
|
|
band_result = ws[0]
|
|
band_result.name.should == @band.name
|
|
band_result.id.should == @band.id
|
|
band_result.location.should == @band.location
|
|
end
|
|
|
|
it "should allow search of one band with partial matches" do
|
|
ws = Search.band_search("Ex")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Exa")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Exam")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Examp")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Exampl")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Example")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Ba")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
|
|
ws = Search.band_search("Ban")
|
|
ws.length.should == 1
|
|
ws[0].id.should == @band.id
|
|
end
|
|
|
|
it "should not match mid-word searchs" do
|
|
ws = Search.band_search("xa")
|
|
ws.length.should == 0
|
|
|
|
ws = Search.band_search("le")
|
|
ws.length.should == 0
|
|
end
|
|
|
|
it "should delete band" do
|
|
ws = Search.band_search("Example Band")
|
|
ws.length.should == 1
|
|
band_result = ws[0]
|
|
band_result.id.should == @band.id
|
|
|
|
@band.destroy # delete doesn't work; you have to use destroy.
|
|
|
|
ws = Search.band_search("Example Band")
|
|
ws.length.should == 0
|
|
end
|
|
|
|
it "should update band" do
|
|
ws = Search.band_search("Example Band")
|
|
ws.length.should == 1
|
|
band_result = ws[0]
|
|
band_result.id.should == @band.id
|
|
|
|
@band.name = "bonus-stuff"
|
|
@band.save
|
|
|
|
ws = Search.band_search("Example Band")
|
|
ws.length.should == 0
|
|
|
|
ws = Search.band_search("Bonus")
|
|
ws.length.should == 1
|
|
band_result = ws[0]
|
|
band_result.id.should == @band.id
|
|
band_result.name.should == "bonus-stuff"
|
|
end
|
|
|
|
it "should tokenize correctly" do
|
|
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "US", ["hip hop"], user.id, nil, nil)
|
|
ws = Search.band_search("pea")
|
|
ws.length.should == 1
|
|
user_result = ws[0]
|
|
user_result.id.should == @band2.id
|
|
end
|
|
|
|
|
|
it "should not return anything with a 1 character search" do
|
|
@band2 = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "US", ["hip hop"], user.id, nil, nil)
|
|
ws = Search.band_search("pe")
|
|
ws.length.should == 1
|
|
user_result = ws[0]
|
|
user_result.id.should == @band2.id
|
|
|
|
ws = Search.band_search("p")
|
|
ws.length.should == 0
|
|
end
|
|
end
|