solidus_backend 1.0.2 → 1.0.3

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.

Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +15 -0
  5. data/script/rails +9 -0
  6. data/solidus_backend.gemspec +28 -0
  7. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  8. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  9. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  10. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  11. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  12. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  13. data/spec/controllers/spree/admin/orders_controller_spec.rb +472 -0
  14. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  15. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +45 -0
  17. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  18. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
  19. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  20. data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
  21. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  22. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +75 -0
  23. data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
  24. data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
  25. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +226 -0
  26. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  27. data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
  28. data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
  29. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  30. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
  31. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  32. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +331 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +236 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +54 -0
  37. data/spec/features/admin/configuration/countries_spec.rb +22 -0
  38. data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
  39. data/spec/features/admin/configuration/payment_methods_spec.rb +125 -0
  40. data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
  41. data/spec/features/admin/configuration/states_spec.rb +64 -0
  42. data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
  43. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  44. data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
  45. data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
  46. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  47. data/spec/features/admin/homepage_spec.rb +78 -0
  48. data/spec/features/admin/locale_spec.rb +30 -0
  49. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  50. data/spec/features/admin/orders/adjustments_spec.rb +126 -0
  51. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
  52. data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
  53. data/spec/features/admin/orders/customer_details_spec.rb +163 -0
  54. data/spec/features/admin/orders/line_items_spec.rb +50 -0
  55. data/spec/features/admin/orders/listing_spec.rb +130 -0
  56. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  57. data/spec/features/admin/orders/new_order_spec.rb +185 -0
  58. data/spec/features/admin/orders/order_details_spec.rb +533 -0
  59. data/spec/features/admin/orders/payments_spec.rb +228 -0
  60. data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
  61. data/spec/features/admin/orders/shipments_spec.rb +65 -0
  62. data/spec/features/admin/payments/store_credits_spec.rb +21 -0
  63. data/spec/features/admin/products/edit/images_spec.rb +87 -0
  64. data/spec/features/admin/products/edit/products_spec.rb +66 -0
  65. data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
  66. data/spec/features/admin/products/edit/variants_spec.rb +61 -0
  67. data/spec/features/admin/products/option_types_spec.rb +114 -0
  68. data/spec/features/admin/products/products_spec.rb +392 -0
  69. data/spec/features/admin/products/properties_spec.rb +139 -0
  70. data/spec/features/admin/products/prototypes_spec.rb +110 -0
  71. data/spec/features/admin/products/stock_management_spec.rb +82 -0
  72. data/spec/features/admin/products/variant_spec.rb +51 -0
  73. data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
  74. data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
  75. data/spec/features/admin/reports_spec.rb +61 -0
  76. data/spec/features/admin/stock_transfer_spec.rb +86 -0
  77. data/spec/features/admin/store_credits_spec.rb +82 -0
  78. data/spec/features/admin/taxons_spec.rb +31 -0
  79. data/spec/features/admin/users_spec.rb +270 -0
  80. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  81. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  82. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  83. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  84. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  85. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  86. data/spec/spec_helper.rb +108 -0
  87. data/spec/support/appear_before_matcher.rb +8 -0
  88. data/spec/support/ror_ringer.jpeg +0 -0
  89. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  90. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  91. metadata +95 -6
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ # This test exists in this file because in the standard admin/products_controller spec
3
+ # There is the stub_authorization call. This call is not triggered for this test because
4
+ # the load_resource filter in Spree::Admin::ResourceController is prepended to the filter chain
5
+ # this means this call is triggered before the authorize_admin call and in this case
6
+ # the load_resource filter halts the request meaning authorize_admin is not called at all.
7
+ describe Spree::Admin::ProductsController, :type => :controller do
8
+ stub_authorization!
9
+
10
+ # Regression test for GH #538
11
+ it "cannot find a non-existent product" do
12
+ spree_get :edit, :id => "non-existent-product"
13
+ expect(response).to redirect_to(spree.admin_products_path)
14
+ expect(flash[:error]).to eql("Product is not found")
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+ require "cancan"
3
+ require "spree/testing_support/bar_ability"
4
+
5
+ describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
6
+
7
+ context "with authorization" do
8
+ stub_authorization!
9
+
10
+ let(:order) { create(:order, number: "R123456789") }
11
+
12
+ before { allow(Spree::Order).to receive(:find_by_number!) { order } }
13
+
14
+ context "#update" do
15
+ it "updates + progresses the order" do
16
+ expect(order).to receive(:update_attributes) { true }
17
+ expect(order).to receive(:next) { false }
18
+ attributes = { order_id: order.number, order: { email: "" } }
19
+ spree_put :update, attributes
20
+ end
21
+
22
+ it "does refresh the shipment rates with all shipping methods" do
23
+ expect(order).to receive(:refresh_shipment_rates)
24
+ attributes = { order_id: order.number, order: { email: "" } }
25
+ spree_put :update, attributes
26
+ end
27
+
28
+ # Regression spec
29
+ context 'completed order' do
30
+ let(:order) { create(:shipped_order) }
31
+ let(:attributes) do
32
+ {
33
+ order_id: order.number,
34
+ guest_checkout: 'false',
35
+ user_id: order.user_id,
36
+ order: { email: "foo@bar.com" }
37
+ }
38
+ end
39
+
40
+ it 'allows the updating of an email address' do
41
+ expect { spree_put :update, attributes }.to change { order.reload.email }.to eq 'foo@bar.com'
42
+ expect(response).to be_redirect
43
+ end
44
+ end
45
+
46
+ context "false guest checkout param" do
47
+ let!(:assigned_user){ create :user }
48
+ it "attempts to associate the user" do
49
+ attributes = {
50
+ order_id: order.number,
51
+ user_id: assigned_user.id,
52
+ guest_checkout: 'false',
53
+ order: { email: "" }
54
+ }
55
+
56
+ expect {
57
+ spree_put :update, attributes
58
+ }.to change{ order.reload.user }.to(assigned_user)
59
+ end
60
+ end
61
+
62
+ context "not false guest checkout param" do
63
+ it "does not attempt to associate the user" do
64
+ allow(order).to receive_messages(update_attributes: true,
65
+ next: false,
66
+ refresh_shipment_rates: true)
67
+
68
+ attributes = {
69
+ order_id: order.number,
70
+ order: { email: "foo@example.com" }
71
+ }
72
+
73
+ expect {
74
+ spree_put :update, attributes
75
+ }.not_to change{ order.reload.user }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,472 @@
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 { order.stub 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 "#open_adjustments" do
299
+ let(:closed) { double('closed_adjustments') }
300
+
301
+ before do
302
+ allow(adjustments).to receive(:where).and_return(closed)
303
+ allow(closed).to receive(:update_all)
304
+ end
305
+
306
+ it "changes all the closed adjustments to open" do
307
+ expect(adjustments).to receive(:where).with(state: 'closed')
308
+ .and_return(closed)
309
+ expect(closed).to receive(:update_all).with(state: 'open')
310
+ spree_post :open_adjustments, id: order.number
311
+ end
312
+
313
+ it "sets the flash success message" do
314
+ spree_post :open_adjustments, id: order.number
315
+ expect(flash[:success]).to eql('All adjustments successfully opened!')
316
+ end
317
+
318
+ it "redirects back" do
319
+ spree_post :open_adjustments, id: order.number
320
+ expect(response).to redirect_to(:back)
321
+ end
322
+ end
323
+
324
+ context "#close_adjustments" do
325
+ let(:open) { double('open_adjustments') }
326
+
327
+ before do
328
+ allow(adjustments).to receive(:where).and_return(open)
329
+ allow(open).to receive(:update_all)
330
+ end
331
+
332
+ it "changes all the open adjustments to closed" do
333
+ expect(adjustments).to receive(:where).with(state: 'open')
334
+ .and_return(open)
335
+ expect(open).to receive(:update_all).with(state: 'closed')
336
+ spree_post :close_adjustments, id: order.number
337
+ end
338
+
339
+ it "sets the flash success message" do
340
+ spree_post :close_adjustments, id: order.number
341
+ expect(flash[:success]).to eql('All adjustments successfully closed!')
342
+ end
343
+
344
+ it "redirects back" do
345
+ spree_post :close_adjustments, id: order.number
346
+ expect(response).to redirect_to(:back)
347
+ end
348
+ end
349
+ end
350
+
351
+ context '#authorize_admin' do
352
+ let(:user) { create(:user) }
353
+ let(:order) { create(:completed_order_with_totals, :number => 'R987654321') }
354
+
355
+ before do
356
+ allow(Spree::Order).to receive_messages :find_by_number! => order
357
+ allow(controller).to receive_messages :spree_current_user => user
358
+ end
359
+
360
+ it 'should grant access to users with an admin role' do
361
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
362
+ spree_post :index
363
+ expect(response).to render_template :index
364
+ end
365
+
366
+ it 'should grant access to users with an bar role' do
367
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
368
+ Spree::Ability.register_ability(BarAbility)
369
+ spree_post :index
370
+ expect(response).to render_template :index
371
+ Spree::Ability.remove_ability(BarAbility)
372
+ end
373
+
374
+ it 'should deny access to users with an bar role' do
375
+ allow(order).to receive(:update_attributes).and_return true
376
+ allow(order).to receive(:user).and_return Spree.user_class.new
377
+ allow(order).to receive(:token).and_return nil
378
+ user.spree_roles.clear
379
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
380
+ Spree::Ability.register_ability(BarAbility)
381
+ spree_put :update, { :id => 'R123' }
382
+ expect(response).to redirect_to('/unauthorized')
383
+ Spree::Ability.remove_ability(BarAbility)
384
+ end
385
+
386
+ it 'should deny access to users without an admin role' do
387
+ allow(user).to receive_messages :has_spree_role? => false
388
+ spree_post :index
389
+ expect(response).to redirect_to('/unauthorized')
390
+ end
391
+
392
+ context 'with only permissions on Order' do
393
+ stub_authorization! do |ability|
394
+ can [:admin, :manage], Spree::Order, :number => 'R987654321'
395
+ end
396
+
397
+ it 'should restrict returned order(s) on index when using OrderSpecificAbility' do
398
+ number = order.number
399
+
400
+ 3.times { create(:completed_order_with_totals) }
401
+ expect(Spree::Order.complete.count).to eq 4
402
+
403
+ allow(user).to receive_messages :has_spree_role? => false
404
+ spree_get :index
405
+ expect(response).to render_template :index
406
+ expect(assigns['orders'].size).to eq 1
407
+ expect(assigns['orders'].first.number).to eq number
408
+ end
409
+ end
410
+ end
411
+
412
+ context "order number not given" do
413
+ stub_authorization!
414
+
415
+ it "raise active record not found" do
416
+ expect {
417
+ spree_get :edit, id: 0
418
+ }.to raise_error ActiveRecord::RecordNotFound
419
+ end
420
+ end
421
+
422
+ describe "#update" do
423
+ stub_authorization!
424
+
425
+ let(:order) { create(:order) }
426
+ let(:payload) do
427
+ {
428
+ id: order.number,
429
+ order: { email: "foo@bar.com" }
430
+ }
431
+ end
432
+
433
+ before do
434
+ allow(order.contents).to receive(:update_cart)
435
+ expect(Spree::Order).to receive(:find_by_number!) { order }
436
+ end
437
+ subject { spree_put :update, payload }
438
+
439
+ it "attempts to update the order" do
440
+ expect(order.contents).to receive(:update_cart).with(payload[:order])
441
+ subject
442
+ end
443
+
444
+ context "the order is already completed" do
445
+ before { allow(order).to receive(:completed?) { true } }
446
+
447
+ it "renders the edit route" do
448
+ subject
449
+ expect(response).to render_template(:edit)
450
+ end
451
+ end
452
+
453
+ context "the order is not completed" do
454
+ before { allow(order).to receive(:completed?) { false } }
455
+
456
+ it "redirects to the customer path" do
457
+ subject
458
+ expect(response).to redirect_to(spree.admin_order_customer_path(order))
459
+ end
460
+ end
461
+
462
+ context "the order has no line items" do
463
+ let(:order) { Spree::Order.new(:number => "1234") }
464
+
465
+ it "includes an error on the order" do
466
+ subject
467
+ expect(order.errors[:line_items]).to include Spree.t('errors.messages.blank')
468
+ end
469
+ end
470
+
471
+ end
472
+ end