Skip to content

Commit

Permalink
add services attribute to carriers call
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecedik committed Oct 26, 2015
1 parent f130c61 commit 3ca307e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/shipcloud/carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Shipcloud
class Carrier < Base
include Shipcloud::Operations::All

attr_reader :name, :display_name
attr_reader :name, :display_name, :services
end
end

64 changes: 53 additions & 11 deletions spec/shipcloud/carrier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
describe Shipcloud::Carrier do
describe '#initialize' do
it 'initializes all attributes correctly' do
valid_attributes = { name: 'bogus', display_name: 'Bogus Carrier' }
valid_attributes = {
name: 'bogus',
display_name: 'Bogus Carrier',
services: %w(
standard,
returns,
one_day,
one_day_early
)
}
carrier = Shipcloud::Carrier.new(valid_attributes)

expect(carrier.name).to eq 'bogus'
expect(carrier.display_name).to eq 'Bogus Carrier'
expect(carrier.services).to eq %w(standard, returns, one_day, one_day_early)
end
end

Expand All @@ -33,22 +43,54 @@
stub_carriers_request
allow(Shipcloud::Carrier).to receive(:new)

carriers = Shipcloud::Carrier.all
Shipcloud::Carrier.all

expect(Shipcloud::Carrier).to have_received(:new).
with({ 'name' => 'carrier_1', 'display_name' => 'Carrier 1' })
expect(Shipcloud::Carrier).to have_received(:new).
with({ 'name' => 'carrier_2', 'display_name' => 'Carrier 2' })
expect(Shipcloud::Carrier).to have_received(:new)
.with(
'name' => 'carrier_1',
'display_name' => 'Carrier 1',
'services' => %w(
standard,
returns,
one_day,
one_day_early
)
)
expect(Shipcloud::Carrier).to have_received(:new)
.with(
'name' => 'carrier_2',
'display_name' => 'Carrier 2',
'services' => %w(
standard,
returns
)
)
end
end

def stub_carriers_request
allow(Shipcloud).to receive(:request).
with(:get, 'carriers', {}).
and_return(
allow(Shipcloud).to receive(:request)
.with(:get, 'carriers', {})
.and_return(
[
{ 'name' => 'carrier_1', 'display_name' => 'Carrier 1' },
{ 'name' => 'carrier_2', 'display_name' => 'Carrier 2' },
{
'name' => 'carrier_1',
'display_name' => 'Carrier 1',
'services' => %w(
standard,
returns,
one_day,
one_day_early
)
},
{
'name' => 'carrier_2',
'display_name' => 'Carrier 2',
'services' => %w(
standard,
returns
)
}
]
)
end
Expand Down

0 comments on commit 3ca307e

Please sign in to comment.