solidus_backend 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_backend might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Rakefile +15 -0
- data/script/rails +9 -0
- data/solidus_backend.gemspec +30 -0
- data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
- data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
- data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +460 -0
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
- data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
- data/spec/controllers/spree/admin/product_properties_controller_spec.rb +69 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +162 -0
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +124 -0
- data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
- data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +240 -0
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
- data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +351 -0
- data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
- data/spec/controllers/spree/admin/users_controller_spec.rb +257 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +50 -0
- data/spec/features/admin/configuration/countries_spec.rb +22 -0
- data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
- data/spec/features/admin/configuration/payment_methods_spec.rb +124 -0
- data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
- data/spec/features/admin/configuration/states_spec.rb +64 -0
- data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
- data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
- data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
- data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
- data/spec/features/admin/configuration/zones_spec.rb +39 -0
- data/spec/features/admin/homepage_spec.rb +78 -0
- data/spec/features/admin/locale_spec.rb +30 -0
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
- data/spec/features/admin/orders/adjustments_spec.rb +126 -0
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
- data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
- data/spec/features/admin/orders/customer_details_spec.rb +163 -0
- data/spec/features/admin/orders/line_items_spec.rb +50 -0
- data/spec/features/admin/orders/listing_spec.rb +130 -0
- data/spec/features/admin/orders/log_entries_spec.rb +55 -0
- data/spec/features/admin/orders/new_order_spec.rb +185 -0
- data/spec/features/admin/orders/order_details_spec.rb +533 -0
- data/spec/features/admin/orders/payments_spec.rb +234 -0
- data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
- data/spec/features/admin/orders/shipments_spec.rb +65 -0
- data/spec/features/admin/payments/store_credits_spec.rb +21 -0
- data/spec/features/admin/products/edit/images_spec.rb +87 -0
- data/spec/features/admin/products/edit/products_spec.rb +66 -0
- data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
- data/spec/features/admin/products/edit/variants_spec.rb +61 -0
- data/spec/features/admin/products/option_types_spec.rb +114 -0
- data/spec/features/admin/products/products_spec.rb +395 -0
- data/spec/features/admin/products/properties_spec.rb +139 -0
- data/spec/features/admin/products/prototypes_spec.rb +110 -0
- data/spec/features/admin/products/stock_management_spec.rb +82 -0
- data/spec/features/admin/products/variant_spec.rb +51 -0
- data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
- data/spec/features/admin/promotions/option_value_rule_spec.rb +65 -0
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
- data/spec/features/admin/reports_spec.rb +61 -0
- data/spec/features/admin/stock_transfer_spec.rb +104 -0
- data/spec/features/admin/store_credits_spec.rb +82 -0
- data/spec/features/admin/taxons_spec.rb +31 -0
- data/spec/features/admin/users_spec.rb +275 -0
- data/spec/helpers/admin/base_helper_spec.rb +18 -0
- data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
- data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
- data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
- data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
- data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/support/appear_before_matcher.rb +8 -0
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
- metadata +96 -6
@@ -0,0 +1,460 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cancan'
|
3
|
+
require 'spree/testing_support/bar_ability'
|
4
|
+
|
5
|
+
describe Spree::Admin::OrdersController, :type => :controller do
|
6
|
+
|
7
|
+
context "with authorization" do
|
8
|
+
stub_authorization!
|
9
|
+
|
10
|
+
before do
|
11
|
+
request.env["HTTP_REFERER"] = "http://localhost:3000"
|
12
|
+
|
13
|
+
# ensure no respond_overrides are in effect
|
14
|
+
if Spree::BaseController.spree_responders[:OrdersController].present?
|
15
|
+
Spree::BaseController.spree_responders[:OrdersController].clear
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:order) do
|
20
|
+
mock_model(
|
21
|
+
Spree::Order,
|
22
|
+
completed?: true,
|
23
|
+
total: 100,
|
24
|
+
number: 'R123456789',
|
25
|
+
all_adjustments: adjustments,
|
26
|
+
ship_address: mock_model(Spree::Address),
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:adjustments) { double('adjustments') }
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(Spree::Order).to receive_messages(find_by_number!: order)
|
34
|
+
allow(order).to receive_messages(contents: Spree::OrderContents.new(order))
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#approve" do
|
38
|
+
it "approves an order" do
|
39
|
+
expect(order.contents).to receive(:approve).with(user: controller.try_spree_current_user)
|
40
|
+
spree_put :approve, id: order.number
|
41
|
+
expect(flash[:success]).to eq Spree.t(:order_approved)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#cancel" do
|
46
|
+
it "cancels an order" do
|
47
|
+
expect(order).to receive(:canceled_by).with(controller.try_spree_current_user)
|
48
|
+
spree_put :cancel, id: order.number
|
49
|
+
expect(flash[:success]).to eq Spree.t(:order_canceled)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#resume" do
|
54
|
+
it "resumes an order" do
|
55
|
+
expect(order).to receive(:resume!)
|
56
|
+
spree_put :resume, id: order.number
|
57
|
+
expect(flash[:success]).to eq Spree.t(:order_resumed)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "pagination" do
|
62
|
+
it "can page through the orders" do
|
63
|
+
spree_get :index, :page => 2, :per_page => 10
|
64
|
+
expect(assigns[:orders].offset_value).to eq(10)
|
65
|
+
expect(assigns[:orders].limit_value).to eq(10)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Test for #3346
|
70
|
+
context "#new" do
|
71
|
+
let(:user) { create(:user) }
|
72
|
+
before do
|
73
|
+
allow(controller).to receive_messages :spree_current_user => user
|
74
|
+
end
|
75
|
+
|
76
|
+
it "imports a new order and sets the current user as a creator" do
|
77
|
+
expect(Spree::Core::Importer::Order).to receive(:import)
|
78
|
+
.with(nil, hash_including(created_by_id: controller.try_spree_current_user.id))
|
79
|
+
.and_return(order)
|
80
|
+
spree_get :new
|
81
|
+
end
|
82
|
+
|
83
|
+
it "sets frontend_viewable to false" do
|
84
|
+
expect(Spree::Core::Importer::Order).to receive(:import)
|
85
|
+
.with(nil, hash_including(frontend_viewable: false ))
|
86
|
+
.and_return(order)
|
87
|
+
spree_get :new
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should associate the order with a store" do
|
91
|
+
expect(Spree::Core::Importer::Order).to receive(:import)
|
92
|
+
.with(user, hash_including(store_id: controller.current_store.id))
|
93
|
+
.and_return(order)
|
94
|
+
spree_get :new, { user_id: user.id }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when a user_id is passed as a parameter" do
|
98
|
+
let(:user) { mock_model(Spree.user_class) }
|
99
|
+
before { allow(Spree.user_class).to receive_messages :find_by_id => user }
|
100
|
+
|
101
|
+
it "imports a new order and assigns the user to the order" do
|
102
|
+
expect(Spree::Core::Importer::Order).to receive(:import)
|
103
|
+
.with(user, hash_including(created_by_id: controller.try_spree_current_user.id))
|
104
|
+
.and_return(order)
|
105
|
+
spree_get :new, { user_id: user.id }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should redirect to cart" do
|
110
|
+
spree_get :new
|
111
|
+
expect(response).to redirect_to(spree.cart_admin_order_path(Spree::Order.last))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Regression test for #3684
|
116
|
+
context "#edit" do
|
117
|
+
it "does not refresh rates if the order is completed" do
|
118
|
+
allow(order).to receive_messages :completed? => true
|
119
|
+
expect(order).not_to receive :refresh_shipment_rates
|
120
|
+
spree_get :edit, :id => order.number
|
121
|
+
end
|
122
|
+
|
123
|
+
it "does refresh the rates if the order is incomplete" do
|
124
|
+
allow(order).to receive_messages :completed? => false
|
125
|
+
expect(order).to receive :refresh_shipment_rates
|
126
|
+
spree_get :edit, :id => order.number
|
127
|
+
end
|
128
|
+
|
129
|
+
context "when order does not have a ship address" do
|
130
|
+
before do
|
131
|
+
allow(order).to receive_messages :ship_address => nil
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when order_bill_address_used is true' do
|
135
|
+
before { Spree::Config[:order_bill_address_used] = true }
|
136
|
+
|
137
|
+
it "should redirect to the customer details page" do
|
138
|
+
spree_get :edit, :id => order.number
|
139
|
+
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when order_bill_address_used is false' do
|
144
|
+
before { Spree::Config[:order_bill_address_used] = false }
|
145
|
+
|
146
|
+
it "should redirect to the customer details page" do
|
147
|
+
spree_get :edit, :id => order.number
|
148
|
+
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#advance' do
|
155
|
+
subject do
|
156
|
+
spree_put :advance, id: order.number
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when incomplete' do
|
160
|
+
before do
|
161
|
+
allow(order).to receive(:completed?).and_return(false, true)
|
162
|
+
allow(order).to receive(:next).and_return(true, false)
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when successful' do
|
166
|
+
before { allow(order).to receive(:confirm?).and_return(true) }
|
167
|
+
|
168
|
+
it 'messages and redirects' do
|
169
|
+
subject
|
170
|
+
expect(flash[:success]).to eq Spree.t('order_ready_for_confirm')
|
171
|
+
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when unsuccessful' do
|
176
|
+
before do
|
177
|
+
allow(order).to receive(:confirm?).and_return(false)
|
178
|
+
allow(order).to receive(:errors).and_return(double(full_messages: ['failed']))
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'messages and redirects' do
|
182
|
+
subject
|
183
|
+
expect(flash[:error]) == order.errors.full_messages
|
184
|
+
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when already completed' do
|
190
|
+
before { allow(order).to receive_messages :completed? => true }
|
191
|
+
|
192
|
+
it 'messages and redirects' do
|
193
|
+
subject
|
194
|
+
expect(flash[:notice]).to eq Spree.t('order_already_completed')
|
195
|
+
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context '#confirm' do
|
201
|
+
subject do
|
202
|
+
spree_get :confirm, id: order.number
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when in confirm' do
|
206
|
+
before { allow(order).to receive_messages completed?: false, confirm?: true }
|
207
|
+
|
208
|
+
it 'renders the confirm page' do
|
209
|
+
subject
|
210
|
+
expect(response.status).to eq 200
|
211
|
+
expect(response).to render_template(:confirm)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when before confirm' do
|
216
|
+
before { allow(order).to receive_messages completed?: false, confirm?: false }
|
217
|
+
|
218
|
+
it 'renders the confirm_advance template (to allow refreshing of the order)' do
|
219
|
+
subject
|
220
|
+
expect(response.status).to eq 200
|
221
|
+
expect(response).to render_template(:confirm_advance)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context 'when already completed' do
|
226
|
+
before { allow(order).to receive_messages completed?: true }
|
227
|
+
|
228
|
+
it 'redirects to edit' do
|
229
|
+
subject
|
230
|
+
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "#complete" do
|
236
|
+
subject do
|
237
|
+
spree_put :complete, id: order.number
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'when successful' do
|
241
|
+
before { allow(order).to receive(:complete!) }
|
242
|
+
|
243
|
+
it 'completes the order' do
|
244
|
+
expect(order).to receive(:complete!)
|
245
|
+
subject
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'messages and redirects' do
|
249
|
+
subject
|
250
|
+
expect(flash[:success]).to eq Spree.t(:order_completed)
|
251
|
+
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with an StateMachines::InvalidTransition error' do
|
256
|
+
let(:order) { create(:order) }
|
257
|
+
|
258
|
+
it 'messages and redirects' do
|
259
|
+
subject
|
260
|
+
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
261
|
+
expect(flash[:error].to_s).to include("Cannot transition state via :complete from :cart")
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'insufficient stock to complete the order' do
|
266
|
+
before do
|
267
|
+
expect(order).to receive(:complete!).and_raise Spree::Order::InsufficientStock
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'messages and redirects' do
|
271
|
+
subject
|
272
|
+
expect(response).to redirect_to(spree.cart_admin_order_path(order))
|
273
|
+
expect(flash[:error].to_s).to eq Spree.t(:insufficient_stock_for_order)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# Test for #3919
|
279
|
+
context "search" do
|
280
|
+
let(:user) { create(:user) }
|
281
|
+
|
282
|
+
before do
|
283
|
+
allow(controller).to receive_messages :spree_current_user => user
|
284
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
285
|
+
|
286
|
+
create(:completed_order_with_totals)
|
287
|
+
expect(Spree::Order.count).to eq 1
|
288
|
+
end
|
289
|
+
|
290
|
+
it "does not display duplicated results" do
|
291
|
+
spree_get :index, q: {
|
292
|
+
line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
|
293
|
+
}
|
294
|
+
expect(assigns[:orders].map { |o| o.number }.count).to eq 1
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "#not_finalized_adjustments" do
|
299
|
+
let(:order) { create(:order) }
|
300
|
+
let!(:finalized_adjustment) { create(:adjustment, finalized: true, adjustable: order, order: order) }
|
301
|
+
|
302
|
+
it "changes all the closed adjustments to open" do
|
303
|
+
spree_post :open_adjustments, id: order.number
|
304
|
+
expect(finalized_adjustment.reload.finalized).to eq(false)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "sets the flash success message" do
|
308
|
+
spree_post :open_adjustments, id: order.number
|
309
|
+
expect(flash[:success]).to eql('All adjustments successfully opened!')
|
310
|
+
end
|
311
|
+
|
312
|
+
it "redirects back" do
|
313
|
+
spree_post :open_adjustments, id: order.number
|
314
|
+
expect(response).to redirect_to(:back)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context "#close_adjustments" do
|
319
|
+
let(:order) { create(:order) }
|
320
|
+
let!(:not_finalized_adjustment) { create(:adjustment, finalized: false, adjustable: order, order: order) }
|
321
|
+
|
322
|
+
it "changes all the open adjustments to closed" do
|
323
|
+
spree_post :close_adjustments, id: order.number
|
324
|
+
expect(not_finalized_adjustment.reload.finalized).to eq(true)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "sets the flash success message" do
|
328
|
+
spree_post :close_adjustments, id: order.number
|
329
|
+
expect(flash[:success]).to eql('All adjustments successfully closed!')
|
330
|
+
end
|
331
|
+
|
332
|
+
it "redirects back" do
|
333
|
+
spree_post :close_adjustments, id: order.number
|
334
|
+
expect(response).to redirect_to(:back)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context '#authorize_admin' do
|
340
|
+
let(:user) { create(:user) }
|
341
|
+
let(:order) { create(:completed_order_with_totals, :number => 'R987654321') }
|
342
|
+
|
343
|
+
before do
|
344
|
+
allow(Spree::Order).to receive_messages :find_by_number! => order
|
345
|
+
allow(controller).to receive_messages :spree_current_user => user
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'should grant access to users with an admin role' do
|
349
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
350
|
+
spree_post :index
|
351
|
+
expect(response).to render_template :index
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should grant access to users with an bar role' do
|
355
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
356
|
+
Spree::Ability.register_ability(BarAbility)
|
357
|
+
spree_post :index
|
358
|
+
expect(response).to render_template :index
|
359
|
+
Spree::Ability.remove_ability(BarAbility)
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'should deny access to users with an bar role' do
|
363
|
+
allow(order).to receive(:update_attributes).and_return true
|
364
|
+
allow(order).to receive(:user).and_return Spree.user_class.new
|
365
|
+
allow(order).to receive(:token).and_return nil
|
366
|
+
user.spree_roles.clear
|
367
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
368
|
+
Spree::Ability.register_ability(BarAbility)
|
369
|
+
spree_put :update, { :id => 'R123' }
|
370
|
+
expect(response).to redirect_to('/unauthorized')
|
371
|
+
Spree::Ability.remove_ability(BarAbility)
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should deny access to users without an admin role' do
|
375
|
+
allow(user).to receive_messages :has_spree_role? => false
|
376
|
+
spree_post :index
|
377
|
+
expect(response).to redirect_to('/unauthorized')
|
378
|
+
end
|
379
|
+
|
380
|
+
context 'with only permissions on Order' do
|
381
|
+
stub_authorization! do |ability|
|
382
|
+
can [:admin, :manage], Spree::Order, :number => 'R987654321'
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should restrict returned order(s) on index when using OrderSpecificAbility' do
|
386
|
+
number = order.number
|
387
|
+
|
388
|
+
3.times { create(:completed_order_with_totals) }
|
389
|
+
expect(Spree::Order.complete.count).to eq 4
|
390
|
+
|
391
|
+
allow(user).to receive_messages :has_spree_role? => false
|
392
|
+
spree_get :index
|
393
|
+
expect(response).to render_template :index
|
394
|
+
expect(assigns['orders'].size).to eq 1
|
395
|
+
expect(assigns['orders'].first.number).to eq number
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context "order number not given" do
|
401
|
+
stub_authorization!
|
402
|
+
|
403
|
+
it "raise active record not found" do
|
404
|
+
expect {
|
405
|
+
spree_get :edit, id: 0
|
406
|
+
}.to raise_error ActiveRecord::RecordNotFound
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "#update" do
|
411
|
+
stub_authorization!
|
412
|
+
|
413
|
+
let(:order) { create(:order) }
|
414
|
+
let(:payload) do
|
415
|
+
{
|
416
|
+
id: order.number,
|
417
|
+
order: { email: "foo@bar.com" }
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
before do
|
422
|
+
allow(order.contents).to receive(:update_cart)
|
423
|
+
expect(Spree::Order).to receive(:find_by_number!) { order }
|
424
|
+
end
|
425
|
+
subject { spree_put :update, payload }
|
426
|
+
|
427
|
+
it "attempts to update the order" do
|
428
|
+
expect(order.contents).to receive(:update_cart).with(payload[:order])
|
429
|
+
subject
|
430
|
+
end
|
431
|
+
|
432
|
+
context "the order is already completed" do
|
433
|
+
before { allow(order).to receive(:completed?) { true } }
|
434
|
+
|
435
|
+
it "renders the edit route" do
|
436
|
+
subject
|
437
|
+
expect(response).to render_template(:edit)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
context "the order is not completed" do
|
442
|
+
before { allow(order).to receive(:completed?) { false } }
|
443
|
+
|
444
|
+
it "redirects to the customer path" do
|
445
|
+
subject
|
446
|
+
expect(response).to redirect_to(spree.admin_order_customer_path(order))
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
context "the order has no line items" do
|
451
|
+
let(:order) { Spree::Order.new(:number => "1234") }
|
452
|
+
|
453
|
+
it "includes an error on the order" do
|
454
|
+
subject
|
455
|
+
expect(order.errors[:line_items]).to include Spree.t('errors.messages.blank')
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
end
|
460
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class GatewayWithPassword < PaymentMethod
|
5
|
+
preference :password, :string, :default => "password"
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Admin::PaymentMethodsController, :type => :controller do
|
9
|
+
stub_authorization!
|
10
|
+
|
11
|
+
let(:payment_method) { GatewayWithPassword.create!(:name => "Bogus", :preferred_password => "haxme") }
|
12
|
+
|
13
|
+
# regression test for #2094
|
14
|
+
it "does not clear password on update" do
|
15
|
+
expect(payment_method.preferred_password).to eq("haxme")
|
16
|
+
spree_put :update, :id => payment_method.id, :payment_method => { :type => payment_method.class.to_s, :preferred_password => "" }
|
17
|
+
expect(response).to redirect_to(spree.edit_admin_payment_method_path(payment_method))
|
18
|
+
|
19
|
+
payment_method.reload
|
20
|
+
expect(payment_method.preferred_password).to eq("haxme")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "tries to save invalid payment" do
|
24
|
+
it "doesn't break, responds nicely" do
|
25
|
+
expect {
|
26
|
+
spree_post :create, :payment_method => { :name => "", :type => "Spree::Gateway::Bogus" }
|
27
|
+
}.not_to raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can create a payment method of a valid type" do
|
32
|
+
expect {
|
33
|
+
spree_post :create, :payment_method => { :name => "Test Method", :type => "Spree::Gateway::Bogus" }
|
34
|
+
}.to change(Spree::PaymentMethod, :count).by(1)
|
35
|
+
|
36
|
+
expect(response).to be_redirect
|
37
|
+
expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can not create a payment method of an invalid type" do
|
41
|
+
expect {
|
42
|
+
spree_post :create, :payment_method => { :name => "Invalid Payment Method", :type => "Spree::InvalidType" }
|
43
|
+
}.to change(Spree::PaymentMethod, :count).by(0)
|
44
|
+
|
45
|
+
expect(response).to be_redirect
|
46
|
+
expect(response).to redirect_to spree.new_admin_payment_method_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Admin
|
5
|
+
describe PaymentsController, :type => :controller do
|
6
|
+
before do
|
7
|
+
allow(controller).to receive_messages :spree_current_user => user
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:user) { create(:admin_user) }
|
11
|
+
let(:order) { create(:order) }
|
12
|
+
|
13
|
+
context "with a valid credit card" do
|
14
|
+
let(:order) { create(:order_with_line_items, :state => "payment") }
|
15
|
+
let(:payment_method) { create(:credit_card_payment_method, :display_on => "back_end") }
|
16
|
+
let(:attributes) do
|
17
|
+
{
|
18
|
+
:order_id => order.number,
|
19
|
+
:card => "new",
|
20
|
+
:payment => {
|
21
|
+
:amount => order.total,
|
22
|
+
:payment_method_id => payment_method.id.to_s,
|
23
|
+
:source_attributes => {
|
24
|
+
:name => "Test User",
|
25
|
+
:number => "4111 1111 1111 1111",
|
26
|
+
:expiry => "09 / #{Time.now.year + 1}",
|
27
|
+
:verification_value => "123"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
spree_post :create, attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should process payment correctly" do
|
38
|
+
expect(order.payments.count).to eq(1)
|
39
|
+
expect(order.payments.last.state).to eq 'checkout'
|
40
|
+
expect(response).to redirect_to(spree.admin_order_payments_path(order))
|
41
|
+
expect(order.reload.state).to eq('confirm')
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with credit card address fields' do
|
45
|
+
let(:address) { build(:address) }
|
46
|
+
|
47
|
+
let(:attributes) do
|
48
|
+
attrs = super()
|
49
|
+
attrs[:payment][:source_attributes][:address_attributes] = address_attributes
|
50
|
+
attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:address_attributes) do
|
54
|
+
{
|
55
|
+
'firstname' => address.firstname,
|
56
|
+
'lastname' => address.lastname,
|
57
|
+
'address1' => address.address1,
|
58
|
+
'city' => address.city,
|
59
|
+
'country_id' => address.country_id,
|
60
|
+
'state_id' => address.state_id,
|
61
|
+
'zipcode' => address.zipcode,
|
62
|
+
'phone' => address.phone,
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'associates the address' do
|
67
|
+
expect(order.payments.count).to eq(1)
|
68
|
+
credit_card = order.payments.last.source
|
69
|
+
expect(credit_card.address.attributes).to include(address_attributes)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Regression test for #3233
|
75
|
+
context "with a backend payment method" do
|
76
|
+
before do
|
77
|
+
@payment_method = create(:check_payment_method, :display_on => "back_end")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "loads backend payment methods" do
|
81
|
+
spree_get :new, :order_id => order.number
|
82
|
+
expect(response.status).to eq(200)
|
83
|
+
expect(assigns[:payment_methods]).to include(@payment_method)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "order has billing address" do
|
88
|
+
before do
|
89
|
+
order.bill_address = create(:address)
|
90
|
+
order.save!
|
91
|
+
end
|
92
|
+
|
93
|
+
context "order does not have payments" do
|
94
|
+
it "redirect to new payments page" do
|
95
|
+
spree_get :index, { amount: 100, order_id: order.number }
|
96
|
+
expect(response).to redirect_to(spree.new_admin_order_payment_path(order))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "order has payments" do
|
101
|
+
before do
|
102
|
+
order.payments << create(:payment, amount: order.total, order: order, state: 'completed')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "shows the payments page" do
|
106
|
+
spree_get :index, { amount: 100, order_id: order.number }
|
107
|
+
expect(response.code).to eq "200"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
context "order does not have a billing address" do
|
114
|
+
before do
|
115
|
+
order.bill_address = nil
|
116
|
+
order.save
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should redirect to the customer details page" do
|
120
|
+
spree_get :index, { amount: 100, order_id: order.number }
|
121
|
+
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'fire' do
|
126
|
+
describe 'authorization' do
|
127
|
+
let(:payment) { create(:payment, state: 'checkout') }
|
128
|
+
let(:order) { payment.order }
|
129
|
+
|
130
|
+
context 'the user is authorized' do
|
131
|
+
class CaptureAllowedAbility
|
132
|
+
include CanCan::Ability
|
133
|
+
|
134
|
+
def initialize(user)
|
135
|
+
can :capture, Spree::Payment
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
before do
|
140
|
+
Spree::Ability.register_ability(CaptureAllowedAbility)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'allows the action' do
|
144
|
+
expect {
|
145
|
+
spree_post(:fire, id: payment.to_param, e: 'capture', order_id: order.to_param)
|
146
|
+
}.to change { payment.reload.state }.from('checkout').to('completed')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'the user is not authorized' do
|
151
|
+
class CaptureNotAllowedAbility
|
152
|
+
include CanCan::Ability
|
153
|
+
|
154
|
+
def initialize(user)
|
155
|
+
cannot :capture, Spree::Payment
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
before do
|
160
|
+
Spree::Ability.register_ability(CaptureNotAllowedAbility)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'does not allow the action' do
|
164
|
+
expect {
|
165
|
+
spree_post(:fire, id: payment.to_param, e: 'capture', order_id: order.to_param)
|
166
|
+
}.to_not change { payment.reload.state }
|
167
|
+
expect(flash[:error]).to eq('Authorization Failure')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|