jam-cloud/web/spec/requests/search_api_spec.rb

50 lines
1.5 KiB
Ruby

require 'spec_helper'
describe "Search API", :type => :api do
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
let(:band_params) {
{
name: "The Band",
biography: "Biography",
city: 'Austin',
state: 'TX',
country: 'US',
genres: ['country']
}
}
before(:each) do
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
end
it "empty search" do
get '/api/search.json'
last_response.status.should == 200
JSON.parse(last_response.body).should eql({'search_type'=>nil})
end
it "simple search" do
@musician = FactoryGirl.create(:user, first_name: "Peach", last_name: "Nothing", email: "user@example.com", musician: true)
@fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Grovery", email: "fan@example.com", musician: false)
band_params[:name] = "Peach pit"
@band = Band.save(user, band_params)
band_params[:name] = "Peach"
@band2 = Band.save(user, band_params)
get '/api/search.json?query=peach&search_text_type=bands'
last_response.status.should == 200
response = JSON.parse(last_response.body)
response["bands"].length.should == 2
bands = response["bands"]
bands = [bands[0]["id"], bands[1]["id"]]
bands.should include(@band.id)
bands.should include(@band2.id)
end
end
end