spree_frontend 3.0.2 → 3.0.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 653f9c14b1a63ca204d89de7d6e2bf888d264717
|
4
|
+
data.tar.gz: 1863ba346f67cb4d96cbae63c5827c07e184cc16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2c0710cfb65b3d961a88f0502dddcc1e75d7aaf4988d8af1cede68d94b6fb4f21247f5e8f9ab4e34247de0295c4d77fd42194b54708bf5c71c0994e1436796
|
7
|
+
data.tar.gz: 0f8dc1d3e821a1a3d7afb7204f3cdd942ea1d4cd59be960b3902447f51605fd3ccf81d6ef040bd0c82fe38eedf965930c714f5d58bea0c3560aadc8f21040f95
|
@@ -21,7 +21,7 @@ module Spree
|
|
21
21
|
|
22
22
|
helper 'spree/orders'
|
23
23
|
|
24
|
-
rescue_from Spree::Core::GatewayError, :
|
24
|
+
rescue_from Spree::Core::GatewayError, with: :rescue_from_spree_gateway_error
|
25
25
|
|
26
26
|
# Updates the order and advances to the next state (when possible.)
|
27
27
|
def update
|
@@ -29,7 +29,7 @@ module Spree
|
|
29
29
|
@order.temporary_address = !params[:save_user_address]
|
30
30
|
unless @order.next
|
31
31
|
flash[:error] = @order.errors.full_messages.join("\n")
|
32
|
-
redirect_to
|
32
|
+
redirect_to(checkout_state_path(@order.state)) && return
|
33
33
|
end
|
34
34
|
|
35
35
|
if @order.completed?
|
@@ -76,106 +76,120 @@ module Spree
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
# Should be overriden if you have areas of your checkout that don't match
|
80
|
+
# up to a step within checkout_steps, such as a registration step
|
81
|
+
def skip_state_validation?
|
82
|
+
false
|
83
|
+
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
def load_order_with_lock
|
86
|
+
@order = current_order(lock: true)
|
87
|
+
redirect_to(spree.cart_path) && return unless @order
|
88
|
+
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
@order.increment!(:state_lock_version)
|
90
|
+
def ensure_valid_state_lock_version
|
91
|
+
if params[:order] && params[:order][:state_lock_version]
|
92
|
+
@order.with_lock do
|
93
|
+
unless @order.state_lock_version == params[:order].delete(:state_lock_version).to_i
|
94
|
+
flash[:error] = Spree.t(:order_already_updated)
|
95
|
+
redirect_to(checkout_state_path(@order.state)) && return
|
98
96
|
end
|
97
|
+
@order.increment!(:state_lock_version)
|
99
98
|
end
|
100
99
|
end
|
100
|
+
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@order.state
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def ensure_checkout_allowed
|
110
|
-
unless @order.checkout_allowed?
|
111
|
-
redirect_to spree.cart_path
|
102
|
+
def set_state_if_present
|
103
|
+
if params[:state]
|
104
|
+
if @order.can_go_to_state?(params[:state]) && !skip_state_validation?
|
105
|
+
redirect_to checkout_state_path(@order.state)
|
112
106
|
end
|
107
|
+
@order.state = params[:state]
|
113
108
|
end
|
109
|
+
end
|
114
110
|
|
115
|
-
|
116
|
-
|
111
|
+
def ensure_checkout_allowed
|
112
|
+
unless @order.checkout_allowed?
|
113
|
+
redirect_to spree.cart_path
|
117
114
|
end
|
115
|
+
end
|
118
116
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
redirect_to spree.cart_path
|
123
|
-
end
|
124
|
-
end
|
117
|
+
def ensure_order_not_completed
|
118
|
+
redirect_to spree.cart_path if @order.completed?
|
119
|
+
end
|
125
120
|
|
126
|
-
|
127
|
-
|
128
|
-
|
121
|
+
def ensure_sufficient_stock_lines
|
122
|
+
if @order.insufficient_stock_lines.present?
|
123
|
+
flash[:error] = Spree.t(:inventory_error_flash_for_insufficient_quantity)
|
124
|
+
redirect_to spree.cart_path
|
129
125
|
end
|
126
|
+
end
|
130
127
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
# Provides a route to redirect after order completion
|
129
|
+
def completion_route(custom_params = nil)
|
130
|
+
spree.order_path(@order, custom_params)
|
131
|
+
end
|
135
132
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
@order.ship_address ||= Address.build_default if @order.checkout_steps.include?('delivery')
|
141
|
-
end
|
133
|
+
def setup_for_current_state
|
134
|
+
method_name = :"before_#{@order.state}"
|
135
|
+
send(method_name) if respond_to?(method_name, true)
|
136
|
+
end
|
142
137
|
|
143
|
-
|
144
|
-
|
138
|
+
def before_address
|
139
|
+
# if the user has a default address, a callback takes care of setting
|
140
|
+
# that; but if he doesn't, we need to build an empty one here
|
141
|
+
@order.bill_address ||= Address.build_default
|
142
|
+
@order.ship_address ||= Address.build_default if @order.checkout_steps.include?('delivery')
|
143
|
+
end
|
145
144
|
|
146
|
-
|
147
|
-
|
148
|
-
end
|
145
|
+
def before_delivery
|
146
|
+
return if params[:order].present?
|
149
147
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
@differentiator = Spree::Stock::Differentiator.new(@order, packages)
|
154
|
-
@differentiator.missing.each do |variant, quantity|
|
155
|
-
@order.contents.remove(variant, quantity)
|
156
|
-
end
|
148
|
+
packages = @order.shipments.map(&:to_package)
|
149
|
+
@differentiator = Spree::Stock::Differentiator.new(@order, packages)
|
150
|
+
end
|
157
151
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
@order.
|
152
|
+
def before_payment
|
153
|
+
if @order.checkout_steps.include? "delivery"
|
154
|
+
packages = @order.shipments.map(&:to_package)
|
155
|
+
@differentiator = Spree::Stock::Differentiator.new(@order, packages)
|
156
|
+
@differentiator.missing.each do |variant, quantity|
|
157
|
+
@order.contents.remove(variant, quantity)
|
164
158
|
end
|
165
159
|
|
166
|
-
|
167
|
-
|
168
|
-
|
160
|
+
# @order.contents.remove did transitively call reload in the past.
|
161
|
+
# Hiding the fact that the machine advanced already to "payment" state.
|
162
|
+
#
|
163
|
+
# As an intermediary step to optimize reloads out of high volume code path
|
164
|
+
# the reload was lifted here and will be removed by later passes.
|
165
|
+
@order.reload
|
169
166
|
end
|
170
167
|
|
171
|
-
|
172
|
-
|
173
|
-
@order.errors.add(:base, exception.message)
|
174
|
-
render :edit
|
168
|
+
if try_spree_current_user && try_spree_current_user.respond_to?(:payment_sources)
|
169
|
+
@payment_sources = try_spree_current_user.payment_sources
|
175
170
|
end
|
171
|
+
end
|
176
172
|
|
177
|
-
|
178
|
-
|
179
|
-
|
173
|
+
def rescue_from_spree_gateway_error(exception)
|
174
|
+
flash.now[:error] = Spree.t(:spree_gateway_error_flash_for_checkout)
|
175
|
+
@order.errors.add(:base, exception.message)
|
176
|
+
render :edit
|
177
|
+
end
|
178
|
+
|
179
|
+
def check_authorization
|
180
|
+
authorize!(:edit, current_order, cookies.signed[:guest_token])
|
181
|
+
end
|
182
|
+
|
183
|
+
def sanitize_zip_code
|
184
|
+
order_params = params[:order]
|
185
|
+
return unless order_params
|
186
|
+
strip_zip(order_params[:bill_address_attributes])
|
187
|
+
strip_zip(order_params[:ship_address_attributes])
|
188
|
+
end
|
189
|
+
|
190
|
+
def strip_zip(address_params)
|
191
|
+
return unless address_params
|
192
|
+
address_params[:zipcode] = address_params[:zipcode].strip if address_params[:zipcode]
|
193
|
+
end
|
180
194
|
end
|
181
195
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Spree::CheckoutController, :
|
3
|
+
describe Spree::CheckoutController, type: :controller do
|
4
4
|
let(:token) { 'some_token' }
|
5
5
|
let(:user) { stub_model(Spree::LegacyUser) }
|
6
6
|
let(:order) { FactoryGirl.create(:order_with_totals) }
|
@@ -20,31 +20,31 @@ describe Spree::CheckoutController, :type => :controller do
|
|
20
20
|
it 'should check if the user is authorized for :edit' do
|
21
21
|
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
22
22
|
request.cookie_jar.signed[:guest_token] = token
|
23
|
-
spree_get :edit,
|
23
|
+
spree_get :edit, state: 'address'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should redirect to the cart path unless checkout_allowed?" do
|
27
|
-
allow(order).to receive_messages
|
28
|
-
spree_get :edit,
|
27
|
+
allow(order).to receive_messages checkout_allowed?: false
|
28
|
+
spree_get :edit, state: "delivery"
|
29
29
|
expect(response).to redirect_to(spree.cart_path)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should redirect to the cart path if current_order is nil" do
|
33
33
|
allow(controller).to receive(:current_order).and_return(nil)
|
34
|
-
spree_get :edit,
|
34
|
+
spree_get :edit, state: "delivery"
|
35
35
|
expect(response).to redirect_to(spree.cart_path)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should redirect to cart if order is completed" do
|
39
|
-
allow(order).to receive_messages(
|
40
|
-
spree_get :edit,
|
39
|
+
allow(order).to receive_messages(completed?: true)
|
40
|
+
spree_get :edit, state: "address"
|
41
41
|
expect(response).to redirect_to(spree.cart_path)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Regression test for #2280
|
45
45
|
it "should redirect to current step trying to access a future step" do
|
46
46
|
order.update_column(:state, "address")
|
47
|
-
spree_get :edit,
|
47
|
+
spree_get :edit, state: "delivery"
|
48
48
|
expect(response).to redirect_to spree.checkout_state_path("address")
|
49
49
|
end
|
50
50
|
|
@@ -67,36 +67,38 @@ describe Spree::CheckoutController, :type => :controller do
|
|
67
67
|
it 'should check if the user is authorized for :edit' do
|
68
68
|
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
69
69
|
request.cookie_jar.signed[:guest_token] = token
|
70
|
-
spree_post :update,
|
70
|
+
spree_post :update, state: 'address'
|
71
71
|
end
|
72
72
|
|
73
73
|
context "save successful" do
|
74
74
|
def spree_post_address
|
75
|
-
spree_post :update,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
75
|
+
spree_post :update,
|
76
|
+
state: "address",
|
77
|
+
order: {
|
78
|
+
bill_address_attributes: address_params,
|
79
|
+
use_billing: true
|
80
|
+
}
|
82
81
|
end
|
83
82
|
|
84
83
|
before do
|
85
84
|
# Must have *a* shipping method and a payment method so updating from address works
|
86
|
-
allow(order).to
|
87
|
-
|
88
|
-
allow(order).to
|
85
|
+
allow(order).to receive(:available_shipping_methods).
|
86
|
+
and_return [stub_model(Spree::ShippingMethod)]
|
87
|
+
allow(order).to receive(:available_payment_methods).
|
88
|
+
and_return [stub_model(Spree::PaymentMethod)]
|
89
|
+
allow(order).to receive(:ensure_available_shipping_rates).
|
90
|
+
and_return true
|
89
91
|
order.line_items << FactoryGirl.create(:line_item)
|
90
92
|
end
|
91
93
|
|
92
94
|
context "with the order in the cart state" do
|
93
95
|
before do
|
94
96
|
order.update_column(:state, "cart")
|
95
|
-
allow(order).to receive_messages :
|
97
|
+
allow(order).to receive_messages user: user
|
96
98
|
end
|
97
99
|
|
98
100
|
it "should assign order" do
|
99
|
-
spree_post :update,
|
101
|
+
spree_post :update, state: "address"
|
100
102
|
expect(assigns[:order]).not_to be_nil
|
101
103
|
end
|
102
104
|
|
@@ -113,29 +115,27 @@ describe Spree::CheckoutController, :type => :controller do
|
|
113
115
|
context "current_user respond to save address method" do
|
114
116
|
it "calls persist order address on user" do
|
115
117
|
expect(user).to receive(:persist_order_address)
|
116
|
-
spree_post :update,
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
}
|
118
|
+
spree_post :update,
|
119
|
+
state: "address",
|
120
|
+
order: {
|
121
|
+
bill_address_attributes: address_params,
|
122
|
+
use_billing: true
|
123
|
+
},
|
124
|
+
save_user_address: "1"
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
context "current_user doesnt respond to persist_order_address" do
|
128
129
|
it "doesnt raise any error" do
|
129
|
-
expect
|
130
|
-
spree_post :update,
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
}.to_not raise_error
|
130
|
+
expect do
|
131
|
+
spree_post :update,
|
132
|
+
state: "address",
|
133
|
+
order: {
|
134
|
+
bill_address_attributes: address_params,
|
135
|
+
use_billing: true
|
136
|
+
},
|
137
|
+
save_user_address: "1"
|
138
|
+
end.to_not raise_error
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -147,19 +147,28 @@ describe Spree::CheckoutController, :type => :controller do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
context "with a billing and shipping address" do
|
150
|
+
let(:bill_address_params) do
|
151
|
+
order.bill_address.attributes.except("created_at", "updated_at")
|
152
|
+
end
|
153
|
+
let(:ship_address_params) do
|
154
|
+
order.ship_address.attributes.except("created_at", "updated_at")
|
155
|
+
end
|
156
|
+
let(:update_params) do
|
157
|
+
{
|
158
|
+
state: "address",
|
159
|
+
order: {
|
160
|
+
bill_address_attributes: bill_address_params,
|
161
|
+
ship_address_attributes: ship_address_params,
|
162
|
+
use_billing: false
|
163
|
+
}
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
150
167
|
before do
|
151
168
|
@expected_bill_address_id = order.bill_address.id
|
152
169
|
@expected_ship_address_id = order.ship_address.id
|
153
170
|
|
154
|
-
spree_post :update,
|
155
|
-
:state => "address",
|
156
|
-
:order => {
|
157
|
-
:bill_address_attributes => order.bill_address.attributes.except("created_at", "updated_at"),
|
158
|
-
:ship_address_attributes => order.ship_address.attributes.except("created_at", "updated_at"),
|
159
|
-
:use_billing => false
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
171
|
+
spree_post :update, update_params
|
163
172
|
order.reload
|
164
173
|
end
|
165
174
|
|
@@ -172,28 +181,28 @@ describe Spree::CheckoutController, :type => :controller do
|
|
172
181
|
|
173
182
|
context "when in the confirm state" do
|
174
183
|
before do
|
175
|
-
allow(order).to receive_messages
|
184
|
+
allow(order).to receive_messages confirmation_required?: true
|
176
185
|
order.update_column(:state, "confirm")
|
177
|
-
allow(order).to receive_messages :
|
186
|
+
allow(order).to receive_messages user: user
|
178
187
|
# An order requires a payment to reach the complete state
|
179
188
|
# This is because payment_required? is true on the order
|
180
|
-
create(:payment, :
|
189
|
+
create(:payment, amount: order.total, order: order)
|
181
190
|
order.payments.reload
|
182
191
|
end
|
183
192
|
|
184
193
|
# This inadvertently is a regression test for #2694
|
185
194
|
it "should redirect to the order view" do
|
186
|
-
spree_post :update,
|
195
|
+
spree_post :update, state: "confirm"
|
187
196
|
expect(response).to redirect_to spree.order_path(order)
|
188
197
|
end
|
189
198
|
|
190
199
|
it "should populate the flash message" do
|
191
|
-
spree_post :update,
|
200
|
+
spree_post :update, state: "confirm"
|
192
201
|
expect(flash.notice).to eq(Spree.t(:order_processed_successfully))
|
193
202
|
end
|
194
203
|
|
195
204
|
it "should remove completed order from current_order" do
|
196
|
-
spree_post :update, {:
|
205
|
+
spree_post :update, { state: "confirm" }, order_id: "foofah"
|
197
206
|
expect(assigns(:current_order)).to be_nil
|
198
207
|
expect(assigns(:order)).to eql controller.current_order
|
199
208
|
end
|
@@ -201,7 +210,7 @@ describe Spree::CheckoutController, :type => :controller do
|
|
201
210
|
|
202
211
|
# Regression test for #4190
|
203
212
|
context "state_lock_version" do
|
204
|
-
let(:post_params)
|
213
|
+
let(:post_params) do
|
205
214
|
{
|
206
215
|
state: "address",
|
207
216
|
order: {
|
@@ -210,7 +219,7 @@ describe Spree::CheckoutController, :type => :controller do
|
|
210
219
|
use_billing: true
|
211
220
|
}
|
212
221
|
}
|
213
|
-
|
222
|
+
end
|
214
223
|
|
215
224
|
context "correct" do
|
216
225
|
it "should properly update and increment version" do
|
@@ -245,44 +254,44 @@ describe Spree::CheckoutController, :type => :controller do
|
|
245
254
|
|
246
255
|
context "save unsuccessful" do
|
247
256
|
before do
|
248
|
-
allow(order).to receive_messages :
|
249
|
-
allow(order).to receive_messages :
|
257
|
+
allow(order).to receive_messages user: user
|
258
|
+
allow(order).to receive_messages update_attributes: false
|
250
259
|
end
|
251
260
|
|
252
261
|
it "should not assign order" do
|
253
|
-
spree_post :update,
|
262
|
+
spree_post :update, state: "address"
|
254
263
|
expect(assigns[:order]).not_to be_nil
|
255
264
|
end
|
256
265
|
|
257
266
|
it "should not change the order state" do
|
258
|
-
spree_post :update,
|
267
|
+
spree_post :update, state: 'address'
|
259
268
|
end
|
260
269
|
|
261
270
|
it "should render the edit template" do
|
262
|
-
spree_post :update,
|
271
|
+
spree_post :update, state: 'address'
|
263
272
|
expect(response).to render_template :edit
|
264
273
|
end
|
265
274
|
end
|
266
275
|
|
267
276
|
context "when current_order is nil" do
|
268
|
-
before { allow(controller).to receive_messages :
|
277
|
+
before { allow(controller).to receive_messages current_order: nil }
|
269
278
|
|
270
279
|
it "should not change the state if order is completed" do
|
271
280
|
expect(order).not_to receive(:update_attribute)
|
272
|
-
spree_post :update,
|
281
|
+
spree_post :update, state: "confirm"
|
273
282
|
end
|
274
283
|
|
275
284
|
it "should redirect to the cart_path" do
|
276
|
-
spree_post :update,
|
285
|
+
spree_post :update, state: "confirm"
|
277
286
|
expect(response).to redirect_to spree.cart_path
|
278
287
|
end
|
279
288
|
end
|
280
289
|
|
281
290
|
context "Spree::Core::GatewayError" do
|
282
291
|
before do
|
283
|
-
allow(order).to receive_messages :
|
292
|
+
allow(order).to receive_messages user: user
|
284
293
|
allow(order).to receive(:update_attributes).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
|
285
|
-
spree_post :update,
|
294
|
+
spree_post :update, state: "address"
|
286
295
|
end
|
287
296
|
|
288
297
|
it "should render the edit template and display exception message" do
|
@@ -301,15 +310,15 @@ describe Spree::CheckoutController, :type => :controller do
|
|
301
310
|
end
|
302
311
|
|
303
312
|
before do
|
304
|
-
allow(controller).to receive_messages :
|
305
|
-
allow(controller).to receive_messages :
|
313
|
+
allow(controller).to receive_messages current_order: order
|
314
|
+
allow(controller).to receive_messages check_authorization: true
|
306
315
|
end
|
307
316
|
|
308
317
|
context "when the country is not a shippable country" do
|
309
318
|
before do
|
310
319
|
order.ship_address.tap do |address|
|
311
320
|
# A different country which is not included in the list of shippable countries
|
312
|
-
address.country = FactoryGirl.create(:country, :
|
321
|
+
address.country = FactoryGirl.create(:country, name: "Australia")
|
313
322
|
address.state_name = 'Victoria'
|
314
323
|
address.save
|
315
324
|
end
|
@@ -319,7 +328,7 @@ describe Spree::CheckoutController, :type => :controller do
|
|
319
328
|
expect(order.shipments.count).to eq(1)
|
320
329
|
order.shipments.first.shipping_rates.delete_all
|
321
330
|
|
322
|
-
spree_put :update, state: order.state, :
|
331
|
+
spree_put :update, state: order.state, order: {}
|
323
332
|
expect(flash[:error]).to eq(Spree.t(:items_cannot_be_shipped))
|
324
333
|
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
325
334
|
end
|
@@ -333,7 +342,7 @@ describe Spree::CheckoutController, :type => :controller do
|
|
333
342
|
end
|
334
343
|
|
335
344
|
it "due to the order having errors" do
|
336
|
-
spree_put :update, state: order.state, :
|
345
|
+
spree_put :update, state: order.state, order: {}
|
337
346
|
expect(flash[:error]).to eql("Base error\nAdjustments error")
|
338
347
|
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
339
348
|
end
|
@@ -348,32 +357,32 @@ describe Spree::CheckoutController, :type => :controller do
|
|
348
357
|
end
|
349
358
|
# So that the confirmation step is skipped and we get straight to the action.
|
350
359
|
payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
|
351
|
-
payment = FactoryGirl.create(:payment, :
|
360
|
+
payment = FactoryGirl.create(:payment, payment_method: payment_method)
|
352
361
|
order.payments << payment
|
353
362
|
end
|
354
363
|
end
|
355
364
|
|
356
365
|
before do
|
357
|
-
allow(controller).to receive_messages :
|
358
|
-
allow(controller).to receive_messages :
|
366
|
+
allow(controller).to receive_messages current_order: order
|
367
|
+
allow(controller).to receive_messages check_authorization: true
|
359
368
|
end
|
360
369
|
|
361
370
|
it "when GatewayError is raised" do
|
362
371
|
allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(Spree.t(:payment_processing_failed)))
|
363
|
-
spree_put :update, state: order.state, :
|
372
|
+
spree_put :update, state: order.state, order: {}
|
364
373
|
expect(flash[:error]).to eq(Spree.t(:payment_processing_failed))
|
365
374
|
end
|
366
375
|
end
|
367
376
|
end
|
368
377
|
|
369
378
|
context "When last inventory item has been purchased" do
|
370
|
-
let(:product) { mock_model(Spree::Product, :
|
379
|
+
let(:product) { mock_model(Spree::Product, name: "Amazing Object") }
|
371
380
|
let(:variant) { mock_model(Spree::Variant) }
|
372
|
-
let(:line_item) { mock_model Spree::LineItem,
|
381
|
+
let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true, amount: 0 }
|
373
382
|
let(:order) { create(:order) }
|
374
383
|
|
375
384
|
before do
|
376
|
-
allow(order).to receive_messages(:
|
385
|
+
allow(order).to receive_messages(line_items: [line_item], state: "payment")
|
377
386
|
|
378
387
|
configure_spree_preferences do |config|
|
379
388
|
config.track_inventory_levels = true
|
@@ -382,7 +391,7 @@ describe Spree::CheckoutController, :type => :controller do
|
|
382
391
|
|
383
392
|
context "and back orders are not allowed" do
|
384
393
|
before do
|
385
|
-
spree_post :update,
|
394
|
+
spree_post :update, state: "payment"
|
386
395
|
end
|
387
396
|
|
388
397
|
it "should redirect to cart" do
|
@@ -390,16 +399,17 @@ describe Spree::CheckoutController, :type => :controller do
|
|
390
399
|
end
|
391
400
|
|
392
401
|
it "should set flash message for no inventory" do
|
393
|
-
expect(flash[:error]).to eq(
|
402
|
+
expect(flash[:error]).to eq(
|
403
|
+
Spree.t(:inventory_error_flash_for_insufficient_quantity, names: "'#{product.name}'"))
|
394
404
|
end
|
395
405
|
end
|
396
406
|
end
|
397
407
|
|
398
408
|
context "order doesn't have a delivery step" do
|
399
409
|
before do
|
400
|
-
allow(order).to receive_messages(:
|
410
|
+
allow(order).to receive_messages(checkout_steps: ["cart", "address", "payment"])
|
401
411
|
allow(order).to receive_messages state: "address"
|
402
|
-
allow(controller).to receive_messages :
|
412
|
+
allow(controller).to receive_messages check_authorization: true
|
403
413
|
end
|
404
414
|
|
405
415
|
it "doesn't set shipping address on the order" do
|
@@ -408,18 +418,16 @@ describe Spree::CheckoutController, :type => :controller do
|
|
408
418
|
end
|
409
419
|
|
410
420
|
it "doesn't remove unshippable items before payment" do
|
411
|
-
expect {
|
412
|
-
|
413
|
-
}.to_not change { order.line_items }
|
421
|
+
expect { spree_post :update, state: "payment" }.
|
422
|
+
to_not change { order.line_items }
|
414
423
|
end
|
415
424
|
end
|
416
425
|
|
417
426
|
it "does remove unshippable items before payment" do
|
418
|
-
allow(order).to receive_messages
|
419
|
-
allow(controller).to receive_messages :
|
427
|
+
allow(order).to receive_messages payment_required?: true
|
428
|
+
allow(controller).to receive_messages check_authorization: true
|
420
429
|
|
421
|
-
expect {
|
422
|
-
|
423
|
-
}.to change { order.reload.line_items.length }
|
430
|
+
expect { spree_post :update, state: "payment" }.
|
431
|
+
to change { order.reload.line_items.length }
|
424
432
|
end
|
425
433
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_frontend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Schofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_api
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.0.
|
19
|
+
version: 3.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.0.
|
26
|
+
version: 3.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: spree_core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.0.
|
33
|
+
version: 3.0.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.0.
|
40
|
+
version: 3.0.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bootstrap-sass
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|