Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add services attribute to carriers call #5

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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