Skip to content

Commit

Permalink
refactored shipment quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfroehler committed Jan 18, 2016
1 parent e6bc2b6 commit d4fea5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/shipcloud/shipment_quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ class ShipmentQuote < Base
include Shipcloud::Operations::Create

attr_accessor :from, :to, :carrier, :package, :service
attr_reader :shipment_quote
attr_reader :price

def self.base_url
"#{camel_to_snakecase(class_name)}s"
# Creates a new object
#
# @param [Hash] attributes The attributes of the created object
def self.create(attributes)
response = Shipcloud.request(:post, base_url, attributes)
new(response.fetch("shipment_quote", {}))
end

def self.price
shipment_quote.price
def self.base_url
"shipment_quotes"
end
end
end
16 changes: 15 additions & 1 deletion spec/shipcloud/shipment_quote_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,24 @@

describe ".create" do
it "makes a new POST request using the correct API endpoint" do
Shipcloud.should_receive(:request).
expect(Shipcloud).to receive(:request).
with(:post, "shipment_quotes", valid_attributes).
and_return("data" => {})

Shipcloud::ShipmentQuote.create(valid_attributes)
end

it "initializes a ShipmentQuote with price" do
allow(Shipcloud).to receive(:request).
and_return(
"shipment_quote" => {
"price" => 42.12
}
)

shipment_quote = Shipcloud::ShipmentQuote.create(valid_attributes)

expect(shipment_quote.price).to eq 42.12
end
end
end

0 comments on commit d4fea5f

Please sign in to comment.