-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2654 from luisramos0/2-0-ship-method
[Spree 2 Upgrade] - Added adapted order.shipping_method
- Loading branch information
Showing
6 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'active_support/concern' | ||
|
||
# This module is an adapter for OFN to work with Spree 2 code. | ||
# | ||
# Although Spree 2 supports multiple shipments per order, in OFN we have only one shipment per order. | ||
# A shipment is associated to a shipping_method through a selected shipping_rate. | ||
# See https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-Upgrade:-Migration-to-multiple-shipments | ||
# for details. | ||
# | ||
# Methods in this module may become deprecated. | ||
module OrderShippingMethod | ||
extend ActiveSupport::Concern | ||
|
||
# Returns the shipping method of the first and only shipment in the order | ||
# | ||
# @return [ShippingMethod] | ||
def shipping_method | ||
return if shipments.empty? | ||
shipments.first.shipping_method | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20180910155506_add_uniqueness_of_order_id_to_spree_shipments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddUniquenessOfOrderIdToSpreeShipments < ActiveRecord::Migration | ||
def change | ||
remove_index :spree_shipments, :order_id | ||
add_index :spree_shipments, :order_id, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
describe OrderShippingMethod do | ||
let(:order) { create(:order) } | ||
|
||
describe '#shipping_method' do | ||
context 'when order has no shipments' do | ||
it 'returns nil' do | ||
expect(order.shipping_method).to be_nil | ||
end | ||
end | ||
|
||
context 'when order has single shipment' do | ||
it 'returns the shipments shipping_method' do | ||
shipment = create(:shipment_with_flat_rate) | ||
order.shipments = [shipment] | ||
|
||
expect(order.shipping_method).to eq shipment.shipping_method | ||
end | ||
end | ||
end | ||
end |