spree_repeat_order 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d04d79d2b954afbfe23147331f9bf51452e4e0
4
- data.tar.gz: d86789bd49ffeb0f086b67f45cc5d8a1ccc097dc
3
+ metadata.gz: 4b0c2201cb257a1fb5b4717c31cd6b35075ee6f6
4
+ data.tar.gz: f77c367e1782e156d3b246409ff89736d6c988f7
5
5
  SHA512:
6
- metadata.gz: c0f286aa13040aa5d4acd92704f5ffd13ac3ca4adeb5cc542b27d044e08cf48ab0ac9b961b26e5888e86afb7c64a59c2729dc199639781a0c87ce3b69bdcf040
7
- data.tar.gz: 3a080db2e8c0d044ef1ede5041a805d5870c70e032d853818bd79701b54b082899a35fb01e87668312f7aa0d46cc77f406c651ba0fae971036834f14d41e45a5
6
+ metadata.gz: d75ede7215d5bf6d5e6f6f708416f0a607f9881bff05d50ffecbc54ac52c9b0a961346c6577c132fda2b5be0461008cb89589a36f9e50cdc8b764b2886a99d87
7
+ data.tar.gz: c2d46b1ec41f9de2e4114b49f9ac379e5be70eb4807655c7a312e3cd790b7a944c84f82697eef4db94e9edcfdf4def44ecd528961fc8b416dec994bfcfc0c9a6
@@ -2,11 +2,14 @@ module Spree
2
2
  module Admin
3
3
  class RepeatedOrdersController < Spree::Admin::BaseController
4
4
 
5
+ include Spree::SpreeRepeatedOrder::ControllerHelpers::RepeatedOrder
6
+
5
7
  def create
6
8
  past_order = Spree::Order.find_by(number: params[:number])
7
9
  new_order = Spree::Order.new
8
10
 
9
11
  duplicate_order(past_order, new_order)
12
+ duplicate_address(past_order, new_order)
10
13
 
11
14
  success = true
12
15
  success = success && !past_order.completed_at.blank?
@@ -33,17 +36,10 @@ module Spree
33
36
  new_order.save
34
37
  end
35
38
 
36
- def duplicate_order(past_order, new_order)
39
+ def duplicate_address(past_order, new_order)
37
40
  new_order.email = past_order.email
38
41
  new_order.user = past_order.user
39
42
 
40
- new_line_items = []
41
- past_order.line_items.each do |line_item|
42
- new_line_items << line_item.dup
43
- end
44
-
45
- new_order.line_items = new_line_items
46
-
47
43
  new_ship_address = past_order.ship_address.dup
48
44
  new_order.ship_address = new_ship_address
49
45
  new_bill_address = past_order.bill_address.dup
@@ -55,7 +51,7 @@ module Spree
55
51
  def duplicate_extension(past_order, new_order)
56
52
  #do nothing - only here so it can be overriden
57
53
  end
58
-
54
+
59
55
  end
60
56
  end
61
57
  end
@@ -1,6 +1,8 @@
1
1
  module Spree
2
2
  class RepeatedOrdersController < Spree::StoreController
3
3
 
4
+ include Spree::SpreeRepeatedOrder::ControllerHelpers::RepeatedOrder
5
+
4
6
  before_filter :check_authorization
5
7
 
6
8
  def create
@@ -20,15 +22,6 @@ module Spree
20
22
 
21
23
  private
22
24
 
23
- def duplicate_order(past_order, new_order)
24
- new_line_items = []
25
- past_order.line_items.each do |line_item|
26
- new_line_items << line_item.dup
27
- end
28
-
29
- new_order.line_items = new_line_items
30
- end
31
-
32
25
  def check_authorization
33
26
  session[:access_token] ||= params[:token]
34
27
 
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ module SpreeRepeatedOrder
3
+ module ControllerHelpers
4
+ module RepeatedOrder
5
+
6
+ def duplicate_order(past_order, new_order)
7
+ new_line_items = []
8
+ past_order.line_items.each do |line_item|
9
+ new_line_items << line_item.dup if (line_item.product && line_item.product.available? && !line_item.product.deleted?)
10
+ end
11
+
12
+ new_order.line_items = new_line_items
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,8 @@ describe Spree::Admin::RepeatedOrdersController do
5
5
  let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
6
6
  let(:order_user) { mock_model(Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake').as_null_object }
7
7
 
8
+ let(:unavailable_product){ FactoryGirl.build(:product, available_on: nil)}
9
+
8
10
  let(:ship_address){ FactoryGirl.build(:address) }
9
11
  let(:bill_address){ FactoryGirl.build(:address) }
10
12
  let(:line_item_1){ FactoryGirl.build(:line_item) }
@@ -49,6 +51,23 @@ describe Spree::Admin::RepeatedOrdersController do
49
51
  response.should be_redirect
50
52
  end
51
53
 
54
+ it 'should skip items that dont exist or are not available' do
55
+ Spree::Order.should_receive(:find_by).with(number: 'ABC1').and_return(past_order)
56
+ Spree::Order.stub(:new).and_return(new_order)
57
+
58
+ line_item_1.should_receive(:product).at_least(:once).and_return nil
59
+ line_item_2.should_receive(:product).at_least(:once).and_return unavailable_product
60
+
61
+ line_item_1.should_not_receive(:dup)
62
+ line_item_2.should_not_receive(:dup)
63
+
64
+ new_order.should_receive(:line_items=).with([])
65
+ new_order.should_receive(:save).and_return(true)
66
+
67
+ spree_post :create, number: "ABC1"
68
+
69
+ end
70
+
52
71
  it 'should create order with old customer details' do
53
72
  Spree::Order.stub(:new).and_return(new_order)
54
73
 
@@ -9,6 +9,7 @@ describe Spree::RepeatedOrdersController do
9
9
  let(:line_item_1){ FactoryGirl.build(:line_item) }
10
10
  let(:line_item_2){ FactoryGirl.build(:line_item) }
11
11
  let(:past_order){ FactoryGirl.build(:order, line_items: [line_item_1, line_item_2]) }
12
+ let(:unavailable_product){ FactoryGirl.build(:product, available_on: nil)}
12
13
 
13
14
  let(:new_order){ FactoryGirl.build(:order) }
14
15
  let(:line_item_clone_1){ FactoryGirl.build(:line_item) }
@@ -33,6 +34,22 @@ describe Spree::RepeatedOrdersController do
33
34
  response.should be_redirect
34
35
  end
35
36
 
37
+ it 'should skip items that dont exist or are not available' do
38
+ Spree::Order.should_receive(:find_by).with(number: 'ABC1').and_return(past_order)
39
+ Spree::Order.stub(:new).and_return(new_order)
40
+
41
+ line_item_1.should_receive(:product).at_least(:once).and_return nil
42
+ line_item_2.should_receive(:product).at_least(:once).and_return unavailable_product
43
+
44
+ line_item_1.should_not_receive(:dup)
45
+ line_item_2.should_not_receive(:dup)
46
+
47
+ new_order.should_receive(:line_items=).with([])
48
+ new_order.should_receive(:save).and_return(true)
49
+
50
+ spree_post :create, number: "ABC1"
51
+ end
52
+
36
53
  it 'should show success flash message' do
37
54
  spree_post :create, number: "ABC1"
38
55
  flash[:success].should =~ /added your past order items to the cart/
@@ -2,14 +2,13 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_repeat_order'
5
- s.version = '2.1.6'
5
+ s.version = '2.1.7'
6
6
  s.summary = 'Makes it possible to repeat an existing order with one click'
7
7
  s.description = ''
8
8
  s.required_ruby_version = '>= 2.0.0'
9
9
 
10
10
  s.author = 'Francisco Trindade'
11
11
  s.email = 'frank.trindade@gmail.com'
12
- # s.homepage = 'http://www.spreecommerce.com'
13
12
 
14
13
  s.files = `git ls-files`.split("\n")
15
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_repeat_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Trindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -218,6 +218,7 @@ files:
218
218
  - config/locales/en.yml
219
219
  - config/routes.rb
220
220
  - lib/generators/spree_repeat_order/install/install_generator.rb
221
+ - lib/spree/spree_repeated_order/controller_helpers/repeated_order.rb
221
222
  - lib/spree_repeat_order.rb
222
223
  - lib/spree_repeat_order/engine.rb
223
224
  - spec/controllers/admin/repeated_orders_controller_spec.rb