Sha256: 1817af43e9fb12c7cf5c75cb884466966b43198ea39d062ddee0d2fd07c6aaf3

Contents?: true

Size: 1.6 KB

Versions: 23

Compression:

Stored size: 1.6 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) { [{id: 1}, {id: 2}] }
    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

23 entries across 23 versions & 1 rubygems

Version Path
quicktravel_client-3.7.0 spec/passenger_type_spec.rb
quicktravel_client-3.6.1 spec/passenger_type_spec.rb
quicktravel_client-3.6.0 spec/passenger_type_spec.rb
quicktravel_client-3.5.0 spec/passenger_type_spec.rb
quicktravel_client-3.4.0 spec/passenger_type_spec.rb
quicktravel_client-3.3.0 spec/passenger_type_spec.rb
quicktravel_client-3.2.0 spec/passenger_type_spec.rb
quicktravel_client-3.1.0 spec/passenger_type_spec.rb
quicktravel_client-3.0.0 spec/passenger_type_spec.rb
quicktravel_client-2.9.0 spec/passenger_type_spec.rb
quicktravel_client-2.8.0 spec/passenger_type_spec.rb
quicktravel_client-2.7.0 spec/passenger_type_spec.rb
quicktravel_client-2.6.0 spec/passenger_type_spec.rb
quicktravel_client-2.5.0 spec/passenger_type_spec.rb
quicktravel_client-2.4.1 spec/passenger_type_spec.rb
quicktravel_client-2.4.0 spec/passenger_type_spec.rb
quicktravel_client-2.3.1 spec/passenger_type_spec.rb
quicktravel_client-2.3.0 spec/passenger_type_spec.rb
quicktravel_client-2.2.2 spec/passenger_type_spec.rb
quicktravel_client-2.2.1 spec/passenger_type_spec.rb