spree_repeat_order 2.1.3 → 2.1.4

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: d3d4d51d740fa6fb8b573e04c12d276d0b662b55
4
- data.tar.gz: 361d8c16bd20ec99e20a339f3da83636e22af948
3
+ metadata.gz: 1815b7096b2cd1a23e03de1c5303c3cb60e9bfa3
4
+ data.tar.gz: 1e349b1cbbc4309cb1325bacf54f3bb13cbcf299
5
5
  SHA512:
6
- metadata.gz: 970bc0cae22f10bf717161111f2ee334d7a6afd357a03e79165b3b61557aa2d2869dbb9a53afb7a8364d47bd194fba3b17053ce32a4c088a7cef7fb5d953d96f
7
- data.tar.gz: 8743a2a38956a776584b53bca928f24c22336d66198f724d1697285f95dd98ef62d529e9b94cfe2b629eac2d86047b7b0c25161bd82b3a8614dc3952aeda5013
6
+ metadata.gz: 9f2e01ca1f2f9109e5b1f41feb5c111198a1bdc58c9dc478afd8c3a61428c672e396420eacad092dc048c66efa83b07b69388e989e5bfbcfca9d5dead55d6af3
7
+ data.tar.gz: 6622583e85f00b6de6d61db5924633ceafcbc34e1856ccd53d93ed331d840effb15bda9698fa1ddc13fef69e9412a83caaa2f904d7e94217547f9c0098e4c04a
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
4
+
3
5
  gemspec
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ module Admin
3
+ class RepeatedOrdersController < Spree::Admin::BaseController
4
+
5
+ def create
6
+ past_order = Spree::Order.find_by(number: params[:number])
7
+ new_order = Spree::Order.new
8
+
9
+ duplicate_order(past_order, new_order)
10
+
11
+ if past_order.completed_at && new_order.save
12
+ flash[:success] = "The order has been duplicated. The new order id is #{new_order.number}"
13
+ redirect_to(admin_orders_path)
14
+ else
15
+ flash[:error] = 'Oops.. something went wrong and the order could not be duplicated'
16
+ redirect_to(admin_order_path(past_order.number))
17
+ end
18
+
19
+ end
20
+
21
+ private
22
+
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
+
31
+ new_ship_address = past_order.ship_address.dup
32
+ new_order.ship_address = new_ship_address
33
+ new_bill_address = past_order.bill_address.dup
34
+ new_order.bill_address = new_bill_address
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => "spree/admin/shared/_content_header",
2
+ :name => "repeat_order_button",
3
+ :insert_top => "[data-hook='toolbar']>ul",
4
+ :partial => "spree/admin/orders/repeat_button",
5
+ :disabled => false)
@@ -0,0 +1,2 @@
1
+ - if @order and @order.completed_at?
2
+ %li= button_link_to Spree.t(:repeat_order), spree.admin_repeat_order_path(@order.number), :method => :post, :icon => 'icon-copy'
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  Spree::Core::Engine.routes.draw do
2
2
 
3
3
  post '/orders/:number/repeated_order' => 'repeated_orders#create', as: :repeat_order
4
+ post '/admin/orders/:number/repeated_order/' => 'admin/repeated_orders#create', as: :admin_repeat_order
4
5
 
5
6
  end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::RepeatedOrdersController do
4
+
5
+ let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
6
+
7
+ let(:ship_address){ FactoryGirl.build(:address) }
8
+ let(:bill_address){ FactoryGirl.build(:address) }
9
+ let(:line_item_1){ FactoryGirl.build(:line_item) }
10
+ let(:line_item_2){ FactoryGirl.build(:line_item) }
11
+ let(:past_order){ FactoryGirl.build(:order, {
12
+ line_items: [line_item_1, line_item_2],
13
+ ship_address: ship_address,
14
+ bill_address: bill_address,
15
+ completed_at: Date.yesterday,
16
+ number: 'ABC1'
17
+ }) }
18
+
19
+ let(:new_order){ double(Spree::Order).as_null_object }
20
+ let(:new_bill_address){ Spree::Address.new }
21
+ let(:new_ship_address){ Spree::Address.new }
22
+ let(:line_item_clone_1){ Spree::LineItem.new }
23
+ let(:line_item_clone_2){ Spree::LineItem.new }
24
+
25
+ before :each do
26
+ controller.stub :spree_current_user => user
27
+ controller.stub :check_authorization
28
+ end
29
+
30
+ describe 'create' do
31
+
32
+ before :each do
33
+ Spree::Order.stub(:find_by).and_return(past_order)
34
+ end
35
+
36
+ it 'should create new order with old order items' do
37
+ Spree::Order.should_receive(:find_by).with(number: 'ABC1').and_return(past_order)
38
+ Spree::Order.stub(:new).and_return(new_order)
39
+
40
+ line_item_1.should_receive(:dup).and_return(line_item_clone_1)
41
+ line_item_2.should_receive(:dup).and_return(line_item_clone_2)
42
+
43
+ new_order.should_receive(:line_items=).with([line_item_clone_1, line_item_clone_2])
44
+ new_order.should_receive(:save).and_return(true)
45
+
46
+ spree_post :create, number: "ABC1"
47
+ response.should be_redirect
48
+ end
49
+
50
+ it 'should create order with old customer details' do
51
+ Spree::Order.stub(:new).and_return(new_order)
52
+
53
+ ship_address.should_receive(:dup).and_return(new_ship_address)
54
+ bill_address.should_receive(:dup).and_return(new_bill_address)
55
+
56
+ new_order.should_receive(:ship_address=).with(new_ship_address)
57
+ new_order.should_receive(:bill_address=).with(new_bill_address)
58
+
59
+ spree_post :create, number: "ABC1"
60
+ end
61
+
62
+ it 'should fail if original order is not complete' do
63
+ past_order.stub(:completed_at).and_return nil
64
+
65
+ spree_post :create, number: "ABC1"
66
+ response.should redirect_to('/admin/orders/ABC1')
67
+ end
68
+
69
+ end
70
+
71
+ describe 'integration' do
72
+
73
+ before :each do
74
+ controller.stub :spree_current_user => user
75
+ controller.stub :check_authorization
76
+ end
77
+
78
+ it 'should create new order with same line items' do
79
+ ship_address = FactoryGirl.create(:address)
80
+ bill_address = FactoryGirl.create(:address)
81
+ past_order = FactoryGirl.create(:order, ship_address: ship_address, bill_address: bill_address)
82
+ line_item = FactoryGirl.create(:line_item, order: past_order)
83
+
84
+ spree_post :create, number: past_order.number
85
+
86
+ last_order = Spree::Order.last
87
+ last_order.line_items.count.should == 1
88
+ end
89
+
90
+ it 'should save order in delivery state'
91
+
92
+ end
93
+
94
+
95
+
96
+ end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Spree::RepeatedOrdersController do
4
4
 
5
+ let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
6
+
5
7
  describe "create" do
6
8
 
7
9
  let(:line_item_1){ FactoryGirl.build(:line_item) }
@@ -15,10 +17,12 @@ describe Spree::RepeatedOrdersController do
15
17
  before :each do
16
18
  Spree::Order.stub(:find_by).and_return(past_order)
17
19
  controller.stub(:current_order).and_return(new_order)
20
+ controller.stub :spree_current_user => user
21
+ controller.stub :check_authorization
18
22
  end
19
23
 
20
24
  it 'should create new order with same line items' do
21
- controller.should_receive(:current_order).and_return(new_order)
25
+ controller.should_receive(:current_order).at_least(:once).and_return(new_order)
22
26
  line_item_1.should_receive(:dup).and_return(line_item_clone_1)
23
27
  line_item_2.should_receive(:dup).and_return(line_item_clone_2)
24
28
 
@@ -44,6 +48,11 @@ describe Spree::RepeatedOrdersController do
44
48
 
45
49
  describe "integration" do
46
50
 
51
+ before :each do
52
+ controller.stub :spree_current_user => user
53
+ controller.stub :check_authorization
54
+ end
55
+
47
56
  it 'should create new order with same line items' do
48
57
  past_order = FactoryGirl.create(:order)
49
58
  line_item = FactoryGirl.create(:line_item, order: past_order)
data/spec/spec_helper.rb CHANGED
@@ -29,9 +29,6 @@ require 'spree/testing_support/controller_requests'
29
29
  require 'spree/testing_support/authorization_helpers'
30
30
  require 'spree/testing_support/url_helpers'
31
31
 
32
- # Requires factories defined in lib/spree_repeat_order/factories.rb
33
- require 'spree_repeat_order/factories'
34
-
35
32
  RSpec.configure do |config|
36
33
  config.include FactoryGirl::Syntax::Methods
37
34
 
@@ -2,7 +2,7 @@
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.3'
5
+ s.version = '2.1.4'
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'
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.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Trindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-22 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -208,8 +208,11 @@ files:
208
208
  - app/assets/javascripts/store/spree_repeat_order.js
209
209
  - app/assets/stylesheets/admin/spree_repeat_order.css
210
210
  - app/assets/stylesheets/store/spree_repeat_order.css
211
+ - app/controllers/spree/admin/repeated_orders_controller.rb
211
212
  - app/controllers/spree/repeated_orders_controller.rb
212
213
  - app/overrides/my_account_table.rb
214
+ - app/overrides/repeat_order_button.rb
215
+ - app/views/spree/admin/orders/_repeat_button.haml
213
216
  - app/views/spree/users/_my_account_table.haml
214
217
  - bin/rails
215
218
  - config/locales/en.yml
@@ -217,7 +220,7 @@ files:
217
220
  - lib/generators/spree_repeat_order/install/install_generator.rb
218
221
  - lib/spree_repeat_order.rb
219
222
  - lib/spree_repeat_order/engine.rb
220
- - lib/spree_repeat_order/factories.rb
223
+ - spec/controllers/admin/repeated_orders_controller_spec.rb
221
224
  - spec/controllers/repeated_orders_controller_spec.rb
222
225
  - spec/spec_helper.rb
223
226
  - spree_repeat_order.gemspec
@@ -246,5 +249,6 @@ signing_key:
246
249
  specification_version: 4
247
250
  summary: Makes it possible to repeat an existing order with one click
248
251
  test_files:
252
+ - spec/controllers/admin/repeated_orders_controller_spec.rb
249
253
  - spec/controllers/repeated_orders_controller_spec.rb
250
254
  - spec/spec_helper.rb
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
- #
4
- # Example adding this to your spec_helper will load these Factories for use:
5
- # require 'spree_repeat_order/factories'
6
- end