Sha256: 5bfc0833108358464ec34d3d246075d84ad6ff95879682e7f9e4a3152d56b95d

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'
require 'quick_travel/passenger_type'

describe QuickTravel::PassengerType do
  context '#all' do
    subject(:all) do
      VCR.use_cassette('passenger_all') { QuickTravel::PassengerType.all }
    end

    its(:class) { should == Array }
    its(:length) { should == 3 }

    context 'first element' do
      subject { all.first }
      its(:class) { should == QuickTravel::PassengerType }
      its(:name)  { should == 'Adult' }
    end
  end

  context '#passenger_count_to_s' do
    subject(:count) { QuickTravel::PassengerType.passenger_counts(hash) }
    context 'when passengers types have zero counts' do
      let(:hash) { { 1 => 2, 2 => 1, 3 => 0 } }
      it { should eq ['2 Adults', '1 Child'] }
    end

    context 'when passenger types are not specified' do
      let(:hash) { { 1 => 2 } }
      it { should eq ['2 Adults'] }
    end
  end

  context 'caching of collection' do
    subject(:all) do
      VCR.use_cassette('passenger_all') { QuickTravel::PassengerType.all }
    end

    let(:api) { double }

    before do
      stub_const('QuickTravel::Api', api)
      allow(api).to receive(:call_and_validate) { double(parsed_response: [{id: 1}, {id: 2}], headers: {}) }
    end
    
    context 'when called the first time' do
      before do
        QuickTravel::Cache.cache_store.clear
        all
      end
      
      specify { expect(api).to have_received(:call_and_validate).once }
      
      context 'when called again' do
        before do
          QuickTravel::PassengerType.all
        end
        
        specify { expect(api).to have_received(:call_and_validate).once } # not called again
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
quicktravel_client-4.7.0 spec/passenger_type_spec.rb
quicktravel_client-4.6.0 spec/passenger_type_spec.rb
quicktravel_client-4.5.0 spec/passenger_type_spec.rb
quicktravel_client-4.4.0 spec/passenger_type_spec.rb
quicktravel_client-4.3.2 spec/passenger_type_spec.rb
quicktravel_client-4.3.1 spec/passenger_type_spec.rb
quicktravel_client-4.3.0 spec/passenger_type_spec.rb
quicktravel_client-4.2.0 spec/passenger_type_spec.rb
quicktravel_client-4.1.0 spec/passenger_type_spec.rb
quicktravel_client-4.0.0 spec/passenger_type_spec.rb
quicktravel_client-3.9.0 spec/passenger_type_spec.rb
quicktravel_client-3.8.1 spec/passenger_type_spec.rb
quicktravel_client-3.8.0 spec/passenger_type_spec.rb