require 'spec_helper'

describe "Instruments API ", :type => :api do

  include Rack::Test::Methods

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before do
      post '/sessions', "session[email]" => user.email, "session[password]" => user.password
      rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
    end

    it "list instruments" do
      get '/api/instruments.json'
      instruments = JSON.parse(last_response.body)

      found_high = false
      found_mid = false
      found_low = false
      found_user = false
      found_junk = false
      
      instruments.each do |instrument|

        if instrument["popularity"] == 3
          found_mid.should == false
          found_low.should == false
          found_high = true
        elsif instrument["popularity"] == 2
          found_high.should == true
          found_low.should == false
          found_mid = true
        elsif instrument["popularity"] == 1
          found_high.should == true
          found_mid.should == true
          found_low = true
        elsif instrument["popularity"] == 0
          found_user = true
        else
          found_junk = true
        end
      end

      found_high.should == true
      found_mid.should == true
      found_low.should == true
      found_user.should == false
      found_junk.should == false
    end
    end
end
