require 'spec_helper' describe User do before(:each) do @user = FactoryGirl.create(:user, first_name: "Example", last_name: "User", email: "user@example.com", password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true, city: "Apex", state: "NC", country: "US") end it "should allow search of one user" do uu = FactoryGirl.create(:user, :musician => false) ws = Search.musician_search("Example User").results ws.length.should == 1 user_result = ws[0] user_result.first_name.should == @user.first_name user_result.last_name.should == @user.last_name user_result.id.should == @user.id user_result.location.should == @user.location user_result.musician.should == true end it "should allow search of one fan" do uu = FactoryGirl.create(:user, :musician => false) ws = Search.fan_search(uu.name).results expect(ws.length).to be(1) expect(ws[0].id).to eq(uu.id) end it "should delete user" do ws = Search.musician_search("Example User").results ws.length.should == 1 user_result = ws[0] user_result.id.should == @user.id @user.destroy ws = Search.musician_search("Example User").results ws.length.should == 0 end it "should update user" do ws = Search.musician_search("Example User").results ws.length.should == 1 user_result = ws[0] user_result.id.should == @user.id @user.first_name = "bonus-junk" @user.last_name = "more-junk" @user.save ws = Search.musician_search("Example User").results ws.length.should == 0 ws = Search.musician_search("Bonus").results ws.length.should == 1 user_result = ws[0] user_result.id.should == @user.id user_result.first_name.should == "bonus-junk" end it "should tokenize correctly" do @user2 = FactoryGirl.create(:user, first_name: "peaches", last_name: "test", email: "peach@example.com", password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true, city: "Apex", state: "NC", country: "US") ws = Search.musician_search("pea").results ws.length.should == 1 user_result = ws[0] user_result.id.should == @user2.id end it "users who have signed up, but not confirmed should show up in search index due to VRFS-378" do @user3 = FactoryGirl.create(:user, first_name: "unconfirmed", last_name: "unconfirmed", email: "unconfirmed@example.com", password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: false, city: "Apex", state: "NC", country: "US") ws = Search.musician_search("unconfirmed").results ws.length.should == 1 # Ok, confirm the user, and see them show up @user3.email_confirmed = true @user3.save ws = Search.musician_search("unconfirmed").results ws.length.should == 1 user_result = ws[0] user_result.id.should == @user3.id end end