spree_frontend 3.2.9 → 3.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/checkout_controller.rb +8 -2
- data/app/controllers/spree/orders_controller.rb +7 -3
- data/app/controllers/spree/products_controller.rb +3 -1
- data/app/helpers/spree/frontend_helper.rb +1 -1
- data/app/helpers/spree/taxons_helper.rb +2 -3
- data/app/views/spree/checkout/_confirm.html.erb +3 -0
- data/app/views/spree/checkout/_summary.html.erb +1 -1
- data/app/views/spree/checkout/payment/_storecredit.html.erb +1 -0
- data/app/views/spree/products/_cart_form.html.erb +3 -3
- data/app/views/spree/shared/_main_nav_bar.html.erb +1 -1
- data/app/views/spree/shared/_order_details.html.erb +0 -1
- data/app/views/spree/shared/_products.html.erb +4 -1
- data/spec/controllers/controller_extension_spec.rb +126 -0
- data/spec/controllers/controller_helpers_spec.rb +122 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +547 -0
- data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
- data/spec/controllers/spree/content_controller_spec.rb +12 -0
- data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
- data/spec/controllers/spree/home_controller_spec.rb +47 -0
- data/spec/controllers/spree/orders_controller_ability_spec.rb +96 -0
- data/spec/controllers/spree/orders_controller_spec.rb +134 -0
- data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
- data/spec/controllers/spree/products_controller_spec.rb +87 -0
- data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
- data/spec/features/address_spec.rb +93 -0
- data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
- data/spec/features/caching/products_spec.rb +59 -0
- data/spec/features/caching/taxons_spec.rb +22 -0
- data/spec/features/cart_spec.rb +132 -0
- data/spec/features/checkout_spec.rb +723 -0
- data/spec/features/checkout_unshippable_spec.rb +34 -0
- data/spec/features/coupon_code_spec.rb +88 -0
- data/spec/features/currency_spec.rb +18 -0
- data/spec/features/delivery_spec.rb +64 -0
- data/spec/features/free_shipping_promotions_spec.rb +59 -0
- data/spec/features/locale_spec.rb +60 -0
- data/spec/features/microdata_spec.rb +0 -0
- data/spec/features/order_spec.rb +107 -0
- data/spec/features/page_promotions_spec.rb +36 -0
- data/spec/features/products_spec.rb +345 -0
- data/spec/features/taxons_spec.rb +147 -0
- data/spec/features/template_rendering_spec.rb +19 -0
- data/spec/helpers/frontend_helper_spec.rb +57 -0
- data/spec/helpers/taxons_helper_spec.rb +17 -0
- data/spec/spec_helper.rb +128 -0
- data/spec/support/shared_contexts/checkout_setup.rb +10 -0
- data/spec/support/shared_contexts/custom_products.rb +25 -0
- data/spec/support/shared_contexts/product_prototypes.rb +30 -0
- data/spec/views/spree/checkout/_summary_spec.rb +11 -0
- data/spree_frontend.gemspec +5 -4
- metadata +90 -15
@@ -0,0 +1,547 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::CheckoutController, type: :controller do
|
4
|
+
let(:token) { 'some_token' }
|
5
|
+
let(:user) { stub_model(Spree::LegacyUser) }
|
6
|
+
let(:order) { FactoryGirl.create(:order_with_totals) }
|
7
|
+
|
8
|
+
let(:address_params) do
|
9
|
+
address = FactoryGirl.build(:address)
|
10
|
+
address.attributes.except("created_at", "updated_at")
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
15
|
+
allow(controller).to receive_messages spree_current_user: user
|
16
|
+
allow(controller).to receive_messages current_order: order
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#edit" do
|
20
|
+
it 'should check if the user is authorized for :edit' do
|
21
|
+
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
22
|
+
request.cookie_jar.signed[:guest_token] = token
|
23
|
+
spree_get :edit, state: 'address'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should redirect to the cart path unless checkout_allowed?" do
|
27
|
+
allow(order).to receive_messages checkout_allowed?: false
|
28
|
+
spree_get :edit, state: "delivery"
|
29
|
+
expect(response).to redirect_to(spree.cart_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should redirect to the cart path if current_order is nil" do
|
33
|
+
allow(controller).to receive(:current_order).and_return(nil)
|
34
|
+
spree_get :edit, state: "delivery"
|
35
|
+
expect(response).to redirect_to(spree.cart_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should redirect to cart if order is completed" do
|
39
|
+
allow(order).to receive_messages(completed?: true)
|
40
|
+
spree_get :edit, state: "address"
|
41
|
+
expect(response).to redirect_to(spree.cart_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Regression test for #2280
|
45
|
+
it "should redirect to current step trying to access a future step" do
|
46
|
+
order.update_column(:state, "address")
|
47
|
+
spree_get :edit, state: "delivery"
|
48
|
+
expect(response).to redirect_to spree.checkout_state_path("address")
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when entering the checkout" do
|
52
|
+
before do
|
53
|
+
# The first step for checkout controller is address
|
54
|
+
# Transitioning into this state first is required
|
55
|
+
order.update_column(:state, "address")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should associate the order with a user" do
|
59
|
+
order.update_column :user_id, nil
|
60
|
+
expect(order).to receive(:associate_user!).with(user)
|
61
|
+
spree_get :edit, {}, order_id: 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "#update" do
|
67
|
+
it 'should check if the user is authorized for :edit' do
|
68
|
+
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
69
|
+
request.cookie_jar.signed[:guest_token] = token
|
70
|
+
spree_post :update, state: 'address'
|
71
|
+
end
|
72
|
+
|
73
|
+
context "save successful" do
|
74
|
+
def spree_post_address
|
75
|
+
spree_post :update,
|
76
|
+
state: "address",
|
77
|
+
order: {
|
78
|
+
bill_address_attributes: address_params,
|
79
|
+
use_billing: true
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
before do
|
84
|
+
# Must have *a* shipping method and a payment method so updating from address works
|
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
|
91
|
+
order.line_items << FactoryGirl.create(:line_item)
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with the order in the cart state" do
|
95
|
+
before do
|
96
|
+
order.update_column(:state, "cart")
|
97
|
+
allow(order).to receive_messages user: user
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should assign order" do
|
101
|
+
spree_post :update, state: "address"
|
102
|
+
expect(assigns[:order]).not_to be_nil
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should advance the state" do
|
106
|
+
spree_post_address
|
107
|
+
expect(order.reload.state).to eq("delivery")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should redirect the next state" do
|
111
|
+
spree_post_address
|
112
|
+
expect(response).to redirect_to spree.checkout_state_path("delivery")
|
113
|
+
end
|
114
|
+
|
115
|
+
context "current_user respond to save address method" do
|
116
|
+
it "calls persist order address on user" do
|
117
|
+
expect(user).to receive(:persist_order_address)
|
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"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "current_user doesnt respond to persist_order_address" do
|
129
|
+
it "doesnt raise any error" do
|
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
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with the order in the address state" do
|
144
|
+
before do
|
145
|
+
order.update_columns(ship_address_id: create(:address).id, state: "address")
|
146
|
+
allow(order).to receive_messages user: user
|
147
|
+
end
|
148
|
+
|
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
|
+
|
167
|
+
before do
|
168
|
+
@expected_bill_address_id = order.bill_address.id
|
169
|
+
@expected_ship_address_id = order.ship_address.id
|
170
|
+
|
171
|
+
spree_post :update, update_params
|
172
|
+
order.reload
|
173
|
+
end
|
174
|
+
|
175
|
+
it "updates the same billing and shipping address" do
|
176
|
+
expect(order.bill_address.id).to eq(@expected_bill_address_id)
|
177
|
+
expect(order.ship_address.id).to eq(@expected_ship_address_id)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when in the confirm state" do
|
183
|
+
before do
|
184
|
+
allow(order).to receive_messages confirmation_required?: true
|
185
|
+
order.update_column(:state, "confirm")
|
186
|
+
allow(order).to receive_messages user: user
|
187
|
+
# An order requires a payment to reach the complete state
|
188
|
+
# This is because payment_required? is true on the order
|
189
|
+
create(:payment, amount: order.total, order: order)
|
190
|
+
order.payments.reload
|
191
|
+
end
|
192
|
+
|
193
|
+
# This inadvertently is a regression test for #2694
|
194
|
+
it "should redirect to the order view" do
|
195
|
+
spree_post :update, state: "confirm"
|
196
|
+
expect(response).to redirect_to spree.order_path(order)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should populate the flash message" do
|
200
|
+
spree_post :update, state: "confirm"
|
201
|
+
expect(flash.notice).to eq(Spree.t(:order_processed_successfully))
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should remove completed order from current_order" do
|
205
|
+
spree_post :update, { state: "confirm" }, order_id: "foofah"
|
206
|
+
expect(assigns(:current_order)).to be_nil
|
207
|
+
expect(assigns(:order)).to eql controller.current_order
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Regression test for #4190
|
212
|
+
context "state_lock_version" do
|
213
|
+
let(:post_params) do
|
214
|
+
{
|
215
|
+
state: "address",
|
216
|
+
order: {
|
217
|
+
bill_address_attributes: order.bill_address.attributes.except("created_at", "updated_at"),
|
218
|
+
state_lock_version: 0,
|
219
|
+
use_billing: true
|
220
|
+
}
|
221
|
+
}
|
222
|
+
end
|
223
|
+
|
224
|
+
context "correct" do
|
225
|
+
it "should properly update and increment version" do
|
226
|
+
spree_post :update, post_params
|
227
|
+
expect(order.state_lock_version).to eq 1
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "incorrect" do
|
232
|
+
before do
|
233
|
+
order.update_columns(state_lock_version: 1, state: "address")
|
234
|
+
end
|
235
|
+
|
236
|
+
it "order should receieve ensure_valid_order_version callback" do
|
237
|
+
expect_any_instance_of(described_class).to receive(:ensure_valid_state_lock_version)
|
238
|
+
spree_post :update, post_params
|
239
|
+
end
|
240
|
+
|
241
|
+
it "order should receieve with_lock message" do
|
242
|
+
expect(order).to receive(:with_lock)
|
243
|
+
spree_post :update, post_params
|
244
|
+
end
|
245
|
+
|
246
|
+
it "redirects back to current state" do
|
247
|
+
spree_post :update, post_params
|
248
|
+
expect(response).to redirect_to spree.checkout_state_path('address')
|
249
|
+
expect(flash[:error]).to eq "The order has already been updated."
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "save unsuccessful" do
|
256
|
+
before do
|
257
|
+
allow(order).to receive_messages user: user
|
258
|
+
allow(order).to receive_messages update_attributes: false
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should not assign order" do
|
262
|
+
spree_post :update, state: "address"
|
263
|
+
expect(assigns[:order]).not_to be_nil
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should not change the order state" do
|
267
|
+
spree_post :update, state: 'address'
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should render the edit template" do
|
271
|
+
spree_post :update, state: 'address'
|
272
|
+
expect(response).to render_template :edit
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should render order in payment state when payment fails" do
|
276
|
+
order.update_column(:state, 'confirm')
|
277
|
+
allow(controller).to receive(:insufficient_payment?).and_return(true)
|
278
|
+
spree_post :update, state: 'confirm'
|
279
|
+
expect(order.state).to eq('payment')
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context "when current_order is nil" do
|
284
|
+
before { allow(controller).to receive_messages current_order: nil }
|
285
|
+
|
286
|
+
it "should not change the state if order is completed" do
|
287
|
+
expect(order).not_to receive(:update_attribute)
|
288
|
+
spree_post :update, state: "confirm"
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should redirect to the cart_path" do
|
292
|
+
spree_post :update, state: "confirm"
|
293
|
+
expect(response).to redirect_to spree.cart_path
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "Spree::Core::GatewayError" do
|
298
|
+
before do
|
299
|
+
allow(order).to receive_messages user: user
|
300
|
+
allow(order).to receive(:update_attributes).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
|
301
|
+
spree_post :update, state: "address"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should render the edit template and display exception message" do
|
305
|
+
expect(response).to render_template :edit
|
306
|
+
expect(flash.now[:error]).to eq(Spree.t(:spree_gateway_error_flash_for_checkout))
|
307
|
+
expect(assigns(:order).errors[:base]).to include("Invalid something or other.")
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "fails to transition from address" do
|
312
|
+
let(:order) do
|
313
|
+
FactoryGirl.create(:order_with_line_items).tap do |order|
|
314
|
+
order.next!
|
315
|
+
expect(order.state).to eq('address')
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
before do
|
320
|
+
allow(controller).to receive_messages current_order: order
|
321
|
+
allow(controller).to receive_messages check_authorization: true
|
322
|
+
end
|
323
|
+
|
324
|
+
context "when the country is not a shippable country" do
|
325
|
+
before do
|
326
|
+
order.ship_address.tap do |address|
|
327
|
+
# A different country which is not included in the list of shippable countries
|
328
|
+
address.country = FactoryGirl.create(:country, name: "Australia")
|
329
|
+
address.state_name = 'Victoria'
|
330
|
+
address.save
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
it "due to no available shipping rates for any of the shipments" do
|
335
|
+
expect(order.shipments.count).to eq(1)
|
336
|
+
order.shipments.first.shipping_rates.delete_all
|
337
|
+
|
338
|
+
spree_put :update, state: order.state, order: {}
|
339
|
+
expect(flash[:error]).to eq(Spree.t(:items_cannot_be_shipped))
|
340
|
+
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context "when the order is invalid" do
|
345
|
+
before do
|
346
|
+
allow(order).to receive_messages(update_from_params: true, next: nil)
|
347
|
+
order.errors.add(:base, 'Base error')
|
348
|
+
order.errors.add(:adjustments, 'error')
|
349
|
+
end
|
350
|
+
|
351
|
+
it "due to the order having errors" do
|
352
|
+
spree_put :update, state: order.state, order: {}
|
353
|
+
expect(flash[:error]).to eql("Base error\nAdjustments error")
|
354
|
+
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context "fails to transition from payment to complete" do
|
360
|
+
let(:order) do
|
361
|
+
FactoryGirl.create(:order_with_line_items).tap do |order|
|
362
|
+
until order.state == 'payment'
|
363
|
+
order.next!
|
364
|
+
end
|
365
|
+
# So that the confirmation step is skipped and we get straight to the action.
|
366
|
+
payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
|
367
|
+
payment = FactoryGirl.create(:payment, payment_method: payment_method)
|
368
|
+
order.payments << payment
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
before do
|
373
|
+
allow(controller).to receive_messages current_order: order
|
374
|
+
allow(controller).to receive_messages check_authorization: true
|
375
|
+
end
|
376
|
+
|
377
|
+
it "when GatewayError is raised" do
|
378
|
+
allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(Spree.t(:payment_processing_failed)))
|
379
|
+
spree_put :update, state: order.state, order: {}
|
380
|
+
expect(flash[:error]).to eq(Spree.t(:payment_processing_failed))
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context "When last inventory item has been purchased" do
|
386
|
+
let(:product) { mock_model(Spree::Product, name: "Amazing Object") }
|
387
|
+
let(:variant) { mock_model(Spree::Variant) }
|
388
|
+
let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true, amount: 0 }
|
389
|
+
let(:order) { create(:order) }
|
390
|
+
|
391
|
+
before do
|
392
|
+
allow(order).to receive_messages(line_items: [line_item], state: "payment")
|
393
|
+
|
394
|
+
configure_spree_preferences do |config|
|
395
|
+
config.track_inventory_levels = true
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
context "and back orders are not allowed" do
|
400
|
+
before do
|
401
|
+
spree_post :update, state: "payment"
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should redirect to cart" do
|
405
|
+
expect(response).to redirect_to spree.cart_path
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should set flash message for no inventory" do
|
409
|
+
expect(flash[:error]).to eq(
|
410
|
+
Spree.t(:inventory_error_flash_for_insufficient_quantity, names: "'#{product.name}'"))
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
context "order doesn't have a delivery step" do
|
416
|
+
before do
|
417
|
+
allow(order).to receive_messages(checkout_steps: ["cart", "address", "payment"])
|
418
|
+
allow(order).to receive_messages state: "address"
|
419
|
+
allow(controller).to receive_messages check_authorization: true
|
420
|
+
end
|
421
|
+
|
422
|
+
it "doesn't set shipping address on the order" do
|
423
|
+
expect(order).to_not receive(:ship_address=)
|
424
|
+
spree_post :update, state: order.state
|
425
|
+
end
|
426
|
+
|
427
|
+
it "doesn't remove unshippable items before payment" do
|
428
|
+
expect { spree_post :update, state: "payment" }.
|
429
|
+
to_not change { order.line_items }
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
it "does remove unshippable items before payment" do
|
434
|
+
allow(order).to receive_messages payment_required?: true
|
435
|
+
allow(controller).to receive_messages check_authorization: true
|
436
|
+
|
437
|
+
expect { spree_post :update, state: "payment" }.
|
438
|
+
to change { order.reload.line_items.length }
|
439
|
+
end
|
440
|
+
|
441
|
+
context 'in the payment step' do
|
442
|
+
let(:order) { OrderWalkthrough.up_to(:payment) }
|
443
|
+
let(:payment_method_id) { Spree::PaymentMethod.first.id }
|
444
|
+
|
445
|
+
before do
|
446
|
+
expect(order.state).to eq 'payment'
|
447
|
+
allow(order).to receive_messages user: user
|
448
|
+
allow(order).to receive_messages confirmation_required?: true
|
449
|
+
end
|
450
|
+
|
451
|
+
it 'does not advance the order extra even when called twice' do
|
452
|
+
spree_put :update, state: 'payment',
|
453
|
+
order: { payments_attributes: [{ payment_method_id: payment_method_id }] }
|
454
|
+
order.reload
|
455
|
+
expect(order.state).to eq 'confirm'
|
456
|
+
spree_put :update, state: 'payment',
|
457
|
+
order: { payments_attributes: [{ payment_method_id: payment_method_id }] }
|
458
|
+
order.reload
|
459
|
+
expect(order.state).to eq 'confirm'
|
460
|
+
end
|
461
|
+
|
462
|
+
context 'with store credits payment' do
|
463
|
+
let(:user) { create(:user) }
|
464
|
+
let(:credit_amount) { order.total + 1.00 }
|
465
|
+
let(:put_attrs) do
|
466
|
+
{
|
467
|
+
state: 'payment',
|
468
|
+
apply_store_credit: 'Apply Store Credit',
|
469
|
+
order: {
|
470
|
+
payments_attributes: [{ payment_method_id: payment_method_id }],
|
471
|
+
}
|
472
|
+
}
|
473
|
+
end
|
474
|
+
before do
|
475
|
+
create(:store_credit_payment_method)
|
476
|
+
create(:store_credit, user: user, amount: credit_amount)
|
477
|
+
end
|
478
|
+
|
479
|
+
def expect_one_store_credit_payment(order, amount)
|
480
|
+
expect(order.payments.count).to eq 1
|
481
|
+
expect(order.payments.first.source).to be_a Spree::StoreCredit
|
482
|
+
expect(order.payments.first.amount).to eq amount
|
483
|
+
end
|
484
|
+
|
485
|
+
it 'can fully pay with store credits while removing other payment attributes' do
|
486
|
+
spree_put :update, put_attrs
|
487
|
+
|
488
|
+
order.reload
|
489
|
+
expect(order.state).to eq 'confirm'
|
490
|
+
expect_one_store_credit_payment(order, order.total)
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'can fully pay with store credits while removing an existing card' do
|
494
|
+
credit_card = create(:credit_card, user: user, payment_method: Spree::PaymentMethod.first)
|
495
|
+
put_attrs[:order][:existing_card] = credit_card.id
|
496
|
+
spree_put :update, put_attrs
|
497
|
+
|
498
|
+
order.reload
|
499
|
+
expect(order.state).to eq 'confirm'
|
500
|
+
expect_one_store_credit_payment(order, order.total)
|
501
|
+
end
|
502
|
+
|
503
|
+
context 'partial payment' do
|
504
|
+
let(:credit_amount) { order.total - 1.00 }
|
505
|
+
it 'returns to payment for partial store credit' do
|
506
|
+
spree_put :update, put_attrs
|
507
|
+
|
508
|
+
order.reload
|
509
|
+
expect(order.state).to eq 'payment'
|
510
|
+
expect_one_store_credit_payment(order, credit_amount)
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
context 'remove store credits payment' do
|
516
|
+
let(:user) { create(:user) }
|
517
|
+
let(:credit_amount) { order.total - 1.00 }
|
518
|
+
let(:put_attrs) do
|
519
|
+
{
|
520
|
+
state: 'payment',
|
521
|
+
remove_store_credit: 'Remove Store Credit',
|
522
|
+
order: {
|
523
|
+
payments_attributes: [{ payment_method_id: payment_method_id }],
|
524
|
+
}
|
525
|
+
}
|
526
|
+
end
|
527
|
+
before do
|
528
|
+
create(:store_credit_payment_method)
|
529
|
+
create(:store_credit, user: user, amount: credit_amount)
|
530
|
+
order.add_store_credit_payments
|
531
|
+
end
|
532
|
+
|
533
|
+
def expect_invalid_store_credit_payment(order)
|
534
|
+
expect(order.payments.store_credits.with_state(:invalid).count).to eq 1
|
535
|
+
expect(order.payments.store_credits.with_state(:invalid).first.source).to be_a Spree::StoreCredit
|
536
|
+
end
|
537
|
+
|
538
|
+
it 'can fully pay with store credits while removing other payment attributes' do
|
539
|
+
spree_put :update, put_attrs
|
540
|
+
|
541
|
+
order.reload
|
542
|
+
expect(order.state).to eq 'payment'
|
543
|
+
expect_invalid_store_credit_payment(order)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# This spec is useful for when we just want to make sure a view is rendering correctly
|
5
|
+
# Walking through the entire checkout process is rather tedious, don't you think?
|
6
|
+
describe Spree::CheckoutController, type: :controller do
|
7
|
+
render_views
|
8
|
+
let(:token) { 'some_token' }
|
9
|
+
let(:user) { stub_model(Spree::LegacyUser) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
13
|
+
end
|
14
|
+
|
15
|
+
# Regression test for #3246
|
16
|
+
context "when using GBP" do
|
17
|
+
before do
|
18
|
+
Spree::Config[:currency] = "GBP"
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when order is in delivery" do
|
22
|
+
before do
|
23
|
+
# Using a let block won't acknowledge the currency setting
|
24
|
+
# Therefore we just do it like this...
|
25
|
+
order = OrderWalkthrough.up_to(:delivery)
|
26
|
+
allow(controller).to receive_messages current_order: order
|
27
|
+
end
|
28
|
+
|
29
|
+
it "displays rate cost in correct currency" do
|
30
|
+
spree_get :edit
|
31
|
+
html = Nokogiri::HTML(response.body)
|
32
|
+
expect(html.css('.rate-cost').text).to eq "£10.00"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Spree::ContentController, type: :controller do
|
3
|
+
it "should not display a local file" do
|
4
|
+
spree_get :show, path: "../../Gemfile"
|
5
|
+
expect(response.response_code).to eq(404)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should display CVV page" do
|
9
|
+
spree_get :cvv
|
10
|
+
expect(response.response_code).to eq(200)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'current order tracking', type: :controller do
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
|
6
|
+
controller(Spree::StoreController) do
|
7
|
+
def index
|
8
|
+
head :ok
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:order) { FactoryGirl.create(:order) }
|
13
|
+
|
14
|
+
it 'automatically tracks who the order was created by & IP address' do
|
15
|
+
allow(controller).to receive_messages(try_spree_current_user: user)
|
16
|
+
get :index
|
17
|
+
expect(controller.current_order(create_order_if_necessary: true).created_by).to eq controller.try_spree_current_user
|
18
|
+
expect(controller.current_order.last_ip_address).to eq "0.0.0.0"
|
19
|
+
end
|
20
|
+
|
21
|
+
context "current order creation" do
|
22
|
+
before { allow(controller).to receive_messages(try_spree_current_user: user) }
|
23
|
+
|
24
|
+
it "doesn't create a new order out of the blue" do
|
25
|
+
expect {
|
26
|
+
spree_get :index
|
27
|
+
}.not_to change { Spree::Order.count }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Spree::OrdersController, type: :controller do
|
33
|
+
let(:user) { create(:user) }
|
34
|
+
|
35
|
+
before { allow(controller).to receive_messages(try_spree_current_user: user) }
|
36
|
+
|
37
|
+
describe Spree::OrdersController do
|
38
|
+
it "doesn't create a new order out of the blue" do
|
39
|
+
expect {
|
40
|
+
spree_get :edit
|
41
|
+
}.not_to change { Spree::Order.count }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::HomeController, type: :controller do
|
4
|
+
it "provides current user to the searcher class" do
|
5
|
+
user = mock_model(Spree.user_class, last_incomplete_spree_order: nil, spree_api_key: 'fake')
|
6
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
7
|
+
expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
|
8
|
+
spree_get :index
|
9
|
+
expect(response.status).to eq(200)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "layout" do
|
13
|
+
it "renders default layout" do
|
14
|
+
spree_get :index
|
15
|
+
expect(response).to render_template(layout: 'spree/layouts/spree_application')
|
16
|
+
end
|
17
|
+
|
18
|
+
context "different layout specified in config" do
|
19
|
+
before { Spree::Config.layout = 'layouts/application' }
|
20
|
+
|
21
|
+
it "renders specified layout" do
|
22
|
+
spree_get :index
|
23
|
+
expect(response).to render_template(layout: 'layouts/application')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "index products" do
|
29
|
+
it "calls includes when the retrieved_products object responds to it" do
|
30
|
+
searcher = double("Searcher")
|
31
|
+
allow(controller).to receive_messages build_searcher: searcher
|
32
|
+
expect(searcher).to receive_message_chain("retrieve_products.includes")
|
33
|
+
|
34
|
+
spree_get :index
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not call includes when it's not available" do
|
38
|
+
searcher = double("Searcher")
|
39
|
+
allow(controller).to receive_messages build_searcher: searcher
|
40
|
+
allow(searcher).to receive(:retrieve_products).and_return([])
|
41
|
+
|
42
|
+
spree_get :index
|
43
|
+
|
44
|
+
expect(assigns(:products)).to eq([])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|