-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
[Spree 2 Upgrade] - Added adapted order.shipping_method #2654
Merged
sauloperez
merged 4 commits into
openfoodfoundation:2-0-stable
from
luisramos0:2-0-ship-method
Sep 11, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f24b20d
Added adapted implementation of order.shipping_method to order_decorator
luisramos0 62951f7
Removing duplicated factories inserted by previous PRs: 2668 and 2670
luisramos0 3577f37
Moved order.shipping_method to the OrderShippingMethod concern
luisramos0 c00e6a5
Added DB uniqueness constraint on order_id to shipments
luisramos0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.