jam-cloud/spec/jam_ruby/models/search_spec.rb

57 lines
1.5 KiB
Ruby

require 'spec_helper'
describe Search do
before(:each) do
Band.delete_search_index
Band.create_search_index
User.delete_search_index
User.create_search_index
end
def create_peachy_data
@user = FactoryGirl.create(:user, first_name: "Peach", last_name: "Pit", email: "user@example.com", musician: true, city: "Apex", state: "NC", country:"USA")
@fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Pit", email: "fan@example.com", musician: false, city: "Apex", state: "NC", country:"USA")
@band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock", city: "Apex", state: "NC", country:"USA")
end
def assert_peachy_data
search = Search.search('peach')
search.recordings.length.should == 0
search.bands.length.should == 1
search.musicians.length.should == 1
search.fans.length.should == 1
musician = search.musicians[0]
musician.should be_a_kind_of User
musician.id.should == @user.id
band = search.bands[0]
band.should be_a_kind_of Band
band.id.should == @band.id
fan = search.fans[0]
fan.should be_a_kind_of User
fan.id.should == @fan.id
end
it "search for band & musician " do
create_peachy_data
User.search_index.refresh
Band.search_index.refresh
assert_peachy_data
end
it "validates rebuild_indexes method of TireTasks" do
create_peachy_data
TireTasks.rebuild_indexes
assert_peachy_data
end
end