Permalink
Browse files

fixed shipment specs

  • Loading branch information...
1 parent d24f6c6 commit 5cc2200e405bc4fc7c787d4a9af0c8f73c5ccb7d @cmar cmar committed Mar 12, 2013
Showing with 13 additions and 4 deletions.
  1. +7 −2 core/app/models/spree/shipment.rb
  2. +6 −2 core/spec/models/spree/shipment_spec.rb
@@ -55,8 +55,12 @@ def add_shipping_method(shipping_method, selected=false)
:selected => selected)
end
+ def selected_shipping_rate
+ shipping_rates.where(selected: true).first
+ end
+
def selected_shipping_rate_id
- shipping_rates.where(selected: true).first.try(:id)
+ selected_shipping_rate.try(:id)
end
def selected_shipping_rate_id=(id)
@@ -70,6 +74,7 @@ def ensure_selected_shipping_rate
shipping_rates.limit(1).update_all(selected: true)
end
+
def currency
order.nil? ? Spree::Config[:currency] : order.currency
end
@@ -191,7 +196,7 @@ def ensure_correct_adjustment
if adjustment
adjustment.originator = shipping_method
adjustment.label = shipping_method.name
- adjustment.amount = shipping_rates.where(selected: true).first.cost
+ adjustment.amount = selected_shipping_rate.cost
adjustment.save!
adjustment.reload
@@ -158,6 +158,7 @@
shipment.stub(:require_inventory => false, :update_order => true, :state => 'ready')
shipment.stub(:adjustment => charge)
shipping_method.stub(:create_adjustment)
+ shipment.stub(:ensure_correct_adjustment)
end
it "should update shipped_at timestamp" do
@@ -201,10 +202,13 @@
end
it "should update originator when adjustment is present" do
+ shipment.stub(:selected_shipping_rate => mock_model(Spree::ShippingRate, :cost => 10.00))
shipment.stub_chain(:adjustment, :originator)
shipment.adjustment.should_receive(:originator=).with(shipping_method)
- shipment.adjustment.should_receive(:save)
- shipment.adjustment.should_receive(:label=).with("Shipping")
+ shipment.adjustment.should_receive(:label=).with(shipping_method.name)
+ shipment.adjustment.should_receive(:amount=).with(10.00)
+ shipment.adjustment.should_receive(:save!)
+ shipment.adjustment.should_receive(:reload)
shipment.send(:ensure_correct_adjustment)
end
end

0 comments on commit 5cc2200

Please sign in to comment.