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:"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

    assert_peachy_data
  end
  
end
