require 'spec_helper'

describe Search do

  before(:each) do
  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:"US")
    @fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Pit", email: "fan@example.com", musician: false, city: "Apex", state: "NC", country:"US")
    @band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock", city: "Apex", state: "NC", country:"US")
  end

  def assert_peachy_data
    search = Search.musician_search('peach')
    search.results.length.should == 1
    obj = search.results[0]
    obj.should be_a_kind_of User
    obj.id.should == @user.id

    search = Search.fan_search('peach')
    search.results.length.should == 1
    obj = search.results[0]
    obj.should be_a_kind_of User
    obj.id.should == @fan.id

    search = Search.band_search('peach')
    search.results.length.should == 1
    obj = search.results[0]
    obj.should be_a_kind_of Band
    obj.id.should == @band.id

  end

  # it "search for band & musician " do
  #   create_peachy_data
  #   assert_peachy_data
  # end

  let(:user1) { FactoryGirl.create(:user, :first_name => Faker::Name.first_name, :last_name => Faker::Name.last_name) }
  let(:user2) { FactoryGirl.create(:user, :first_name => Faker::Name.first_name, :last_name => Faker::Name.last_name) }
  let(:user3) { FactoryGirl.create(:user, :first_name => Faker::Name.first_name, :last_name => Faker::Name.last_name) }

  it 'find autocomplete friend musicians' do
    Friendship.save_using_models(user1, user2)
    Friendship.save_using_models(user1, user3)

    srch = Search.session_invite_search(user1.first_name[0..3], user2)
    expect(srch.results.size).to eq(1)

    srch = Search.session_invite_search(user1.last_name[0..3], user2)
    expect(srch.results.size).to eq(1)
  end
  
end
