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.

Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/Rakefile +15 -0
  4. data/script/rails +9 -0
  5. data/solidus_backend.gemspec +30 -0
  6. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  7. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  8. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  9. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  10. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  11. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  12. data/spec/controllers/spree/admin/orders_controller_spec.rb +460 -0
  13. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  14. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  15. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +69 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +162 -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 +124 -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 +240 -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 +351 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +257 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +50 -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 +124 -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 +234 -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 +395 -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/option_value_rule_spec.rb +65 -0
  75. data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
  76. data/spec/features/admin/reports_spec.rb +61 -0
  77. data/spec/features/admin/stock_transfer_spec.rb +104 -0
  78. data/spec/features/admin/store_credits_spec.rb +82 -0
  79. data/spec/features/admin/taxons_spec.rb +31 -0
  80. data/spec/features/admin/users_spec.rb +275 -0
  81. data/spec/helpers/admin/base_helper_spec.rb +18 -0
  82. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  83. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  84. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  85. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  86. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  87. data/spec/spec_helper.rb +116 -0
  88. data/spec/support/appear_before_matcher.rb +8 -0
  89. data/spec/support/ror_ringer.jpeg +0 -0
  90. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  91. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  92. metadata +96 -6
@@ -0,0 +1,533 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Order Details", type: :feature, js: true do
5
+ let!(:stock_location) { create(:stock_location_with_items) }
6
+ let!(:product) { create(:product, :name => 'spree t-shirt', :price => 20.00) }
7
+ let!(:tote) { create(:product, :name => "Tote", :price => 15.00) }
8
+ let(:order) { create(:order, :state => 'complete', :completed_at => "2011-02-01 12:36:15", :number => "R100") }
9
+ let(:state) { create(:state) }
10
+ #let(:shipment) { create(:shipment, :order => order, :stock_location => stock_location) }
11
+ let!(:shipping_method) { create(:shipping_method, :name => "Default") }
12
+
13
+ before do
14
+ order.shipments.create(stock_location_id: stock_location.id)
15
+ order.contents.add(product.master, 2)
16
+ end
17
+
18
+ context 'as Admin' do
19
+ stub_authorization!
20
+
21
+
22
+ context "cart edit page" do
23
+ before do
24
+ product.master.stock_items.first.update_column(:count_on_hand, 100)
25
+ visit spree.cart_admin_order_path(order)
26
+ end
27
+
28
+
29
+ it "should allow me to edit order details" do
30
+ expect(page).to have_content("spree t-shirt")
31
+ expect(page).to have_content("$40.00")
32
+
33
+ within_row(1) do
34
+ click_icon :edit
35
+ fill_in "quantity", :with => "1"
36
+ end
37
+ click_icon :ok
38
+
39
+ within("#order_total") do
40
+ expect(page).to have_content("$20.00")
41
+ end
42
+ end
43
+
44
+ it "can add an item to a shipment" do
45
+ select2_search "spree t-shirt", :from => Spree.t(:name_or_sku)
46
+ within("table.stock-levels") do
47
+ fill_in "quantity_0", :with => 2
48
+ end
49
+
50
+ click_icon :plus
51
+
52
+ within("#order_total") do
53
+ expect(page).to have_content("$80.00")
54
+ end
55
+ end
56
+
57
+ it "can remove an item from a shipment" do
58
+ expect(page).to have_content("spree t-shirt")
59
+
60
+ within_row(1) do
61
+ accept_alert do
62
+ click_icon :trash
63
+ end
64
+ end
65
+
66
+ expect(page).to have_content("YOUR ORDER IS EMPTY") # wait for page refresh
67
+ expect(page).not_to have_content("spree t-shirt")
68
+ end
69
+
70
+ # Regression test for #3862
71
+ it "can cancel removing an item from a shipment" do
72
+ expect(page).to have_content("spree t-shirt")
73
+
74
+ within_row(1) do
75
+ # Click "cancel" on confirmation dialog
76
+ dismiss_alert do
77
+ click_icon :trash
78
+ end
79
+ end
80
+
81
+ expect(page).to have_content("spree t-shirt")
82
+ end
83
+
84
+ it "can add tracking information" do
85
+ visit spree.edit_admin_order_path(order)
86
+
87
+ within(".show-tracking") do
88
+ click_icon :edit
89
+ end
90
+ fill_in "tracking", :with => "FOOBAR"
91
+ click_icon :check
92
+
93
+ expect(page).not_to have_css("input[name=tracking]")
94
+ expect(page).to have_content("Tracking: FOOBAR")
95
+ end
96
+
97
+ it "can change the shipping method" do
98
+ order = create(:completed_order_with_totals)
99
+ visit spree.edit_admin_order_path(order)
100
+ within("table.index tr.show-method") do
101
+ click_icon :edit
102
+ end
103
+ select2 "Default", :from => "Shipping Method"
104
+ click_icon :check
105
+
106
+ expect(page).not_to have_css('#selected_shipping_rate_id')
107
+ expect(page).to have_content("Default")
108
+ end
109
+
110
+ it "will show the variant sku" do
111
+ order = create(:completed_order_with_totals)
112
+ visit spree.edit_admin_order_path(order)
113
+ sku = order.line_items.first.variant.sku
114
+ expect(page).to have_content("SKU: #{sku}")
115
+ end
116
+
117
+ context "with special_instructions present" do
118
+ let(:order) { create(:order, :state => 'complete', :completed_at => "2011-02-01 12:36:15", :number => "R100", :special_instructions => "Very special instructions here") }
119
+ it "will show the special_instructions" do
120
+ visit spree.edit_admin_order_path(order)
121
+ expect(page).to have_content("Very special instructions here")
122
+ end
123
+ end
124
+
125
+ context "variant doesn't track inventory" do
126
+ before do
127
+ tote.master.update_column :track_inventory, false
128
+ # make sure there's no stock level for any item
129
+ tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
130
+ end
131
+
132
+ it "adds variant to order just fine" do
133
+ select2_search tote.name, :from => Spree.t(:name_or_sku)
134
+ within("table.stock-levels") do
135
+ fill_in "variant_quantity", :with => 1
136
+ end
137
+
138
+ click_icon :plus
139
+
140
+ within(".line-items") do
141
+ expect(page).to have_content(tote.name)
142
+ end
143
+ end
144
+ end
145
+
146
+ context "variant out of stock and not backorderable" do
147
+ before do
148
+ product.master.stock_items.first.update_column(:backorderable, false)
149
+ product.master.stock_items.first.update_column(:count_on_hand, 0)
150
+ end
151
+
152
+ it "doesn't display the out of stock variant in the search results" do
153
+ select2_search_without_selection product.name, from: ".variant_autocomplete"
154
+
155
+ expect(page).to have_selector('.select2-no-results')
156
+ within(".select2-no-results") do
157
+ expect(page).to have_content("NO MATCHES FOUND")
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+
164
+ context 'Shipment edit page' do
165
+ let!(:stock_location2) { create(:stock_location_with_items, name: 'Clarksville') }
166
+
167
+ before do
168
+ product.master.stock_items.first.update_column(:backorderable, true)
169
+ product.master.stock_items.first.update_column(:count_on_hand, 100)
170
+ product.master.stock_items.last.update_column(:count_on_hand, 100)
171
+ end
172
+
173
+ context 'splitting to location' do
174
+ before { visit spree.edit_admin_order_path(order) }
175
+ # can not properly implement until poltergeist supports checking alert text
176
+ # see https://github.com/teampoltergeist/poltergeist/pull/516
177
+ it 'should warn you if you have not selected a location or shipment'
178
+
179
+ context 'there is enough stock at the other location' do
180
+ it 'should allow me to make a split' do
181
+ expect(order.shipments.count).to eq(1)
182
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
183
+
184
+ within_row(1) { click_icon 'arrows-h' }
185
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
186
+ click_icon :ok
187
+
188
+ expect(page).to have_css('.shipment', count: 2)
189
+
190
+ expect(order.shipments.count).to eq(2)
191
+ expect(order.shipments.last.backordered?).to eq(false)
192
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
193
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
194
+ end
195
+
196
+ it 'should allow me to make a transfer via splitting off all stock' do
197
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
198
+
199
+ within_row(1) { click_icon 'arrows-h' }
200
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
201
+ fill_in 'item_quantity', with: 2
202
+ click_icon :ok
203
+
204
+ expect(page).to have_content("PENDING PACKAGE FROM 'CLARKSVILLE'")
205
+
206
+ expect(order.shipments.count).to eq(1)
207
+ expect(order.shipments.last.backordered?).to eq(false)
208
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
209
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
210
+ end
211
+
212
+ it 'should allow me to split more than I have if available there' do
213
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
214
+
215
+ within_row(1) { click_icon 'arrows-h' }
216
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
217
+ fill_in 'item_quantity', with: 5
218
+ click_icon :ok
219
+
220
+ expect(page).to have_content("PENDING PACKAGE FROM 'CLARKSVILLE'")
221
+
222
+ expect(order.shipments.count).to eq(1)
223
+ expect(order.shipments.last.backordered?).to eq(false)
224
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(5)
225
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
226
+ end
227
+
228
+ it 'should not split anything if the input quantity is garbage' do
229
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
230
+
231
+ within_row(1) { click_icon 'arrows-h' }
232
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
233
+ fill_in 'item_quantity', with: 'ff'
234
+ click_icon :ok
235
+
236
+ wait_for_ajax
237
+
238
+ expect(order.shipments.count).to eq(1)
239
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
240
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
241
+ end
242
+
243
+ it 'should not allow less than or equal to zero qty' do
244
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
245
+
246
+ within_row(1) { click_icon 'arrows-h' }
247
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
248
+ fill_in 'item_quantity', with: 0
249
+ click_icon :ok
250
+
251
+ wait_for_ajax
252
+
253
+ expect(order.shipments.count).to eq(1)
254
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
255
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
256
+
257
+
258
+ fill_in 'item_quantity', with: -1
259
+ click_icon :ok
260
+
261
+ wait_for_ajax
262
+
263
+ expect(order.shipments.count).to eq(1)
264
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
265
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
266
+ end
267
+
268
+ context 'A shipment has shipped' do
269
+
270
+ it 'should not show or let me back to the cart page, nor show the shipment edit buttons' do
271
+ order = create(:order, :state => 'payment', :number => "R100")
272
+ order.shipments.create!(stock_location_id: stock_location.id, state: 'shipped')
273
+
274
+ visit spree.cart_admin_order_path(order)
275
+
276
+ expect(page.current_path).to eq(spree.edit_admin_order_path(order))
277
+ expect(page).not_to have_text 'Cart'
278
+ expect(page).not_to have_selector('.fa-arrows-h')
279
+ expect(page).not_to have_selector('.fa-trash')
280
+ end
281
+
282
+ end
283
+ end
284
+
285
+ context 'there is not enough stock at the other location' do
286
+ context 'and it cannot backorder' do
287
+ it 'should not allow me to split stock' do
288
+ product.master.stock_items.last.update_column(:backorderable, false)
289
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
290
+
291
+ within_row(1) { click_icon 'arrows-h' }
292
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
293
+ fill_in 'item_quantity', with: 2
294
+ click_icon :ok
295
+
296
+ wait_for_ajax
297
+
298
+ expect(order.shipments.count).to eq(1)
299
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
300
+ expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
301
+ end
302
+
303
+ end
304
+
305
+ context 'but it can backorder' do
306
+ it 'should allow me to split and backorder the stock' do
307
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
308
+ product.master.stock_items.last.update_column(:backorderable, true)
309
+
310
+ within_row(1) { click_icon 'arrows-h' }
311
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
312
+ fill_in 'item_quantity', with: 2
313
+ click_icon :ok
314
+
315
+ expect(page).to have_content("PENDING PACKAGE FROM 'CLARKSVILLE'")
316
+
317
+ expect(order.shipments.count).to eq(1)
318
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
319
+ expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
320
+ end
321
+ end
322
+ end
323
+
324
+ context 'multiple items in cart' do
325
+ it 'should have no problem splitting if multiple items are in the from shipment' do
326
+ order.contents.add(create(:variant), 2)
327
+ expect(order.shipments.count).to eq(1)
328
+ expect(order.shipments.first.manifest.count).to eq(2)
329
+
330
+ within_row(1) { click_icon 'arrows-h' }
331
+ targetted_select2 stock_location2.name, from: '#s2id_item_stock_location'
332
+ click_icon :ok
333
+
334
+ expect(page).to have_css('.shipment', count: 2)
335
+
336
+ expect(order.shipments.count).to eq(2)
337
+ expect(order.shipments.last.backordered?).to eq(false)
338
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
339
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
340
+ end
341
+ end
342
+ end
343
+
344
+
345
+ context 'splitting to shipment' do
346
+ before do
347
+ @shipment2 = order.shipments.create(stock_location_id: stock_location2.id)
348
+ visit spree.edit_admin_order_path(order)
349
+ end
350
+
351
+ it 'should delete the old shipment if enough are split off' do
352
+ expect(order.shipments.count).to eq(2)
353
+
354
+ within_row(1) { click_icon 'arrows-h' }
355
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
356
+ fill_in 'item_quantity', with: 2
357
+ click_icon :ok
358
+
359
+ wait_for_ajax
360
+
361
+ expect(order.shipments.count).to eq(1)
362
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(2)
363
+ end
364
+
365
+ context 'receiving shipment can not backorder' do
366
+ before { product.master.stock_items.last.update_column(:backorderable, false) }
367
+
368
+ it 'should not allow a split if the receiving shipment qty plus the incoming is greater than the count_on_hand' do
369
+ expect(order.shipments.count).to eq(2)
370
+
371
+ within_row(1) { click_icon 'arrows-h' }
372
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
373
+ fill_in 'item_quantity', with: 1
374
+ click_icon :ok
375
+
376
+ wait_for_ajax
377
+
378
+ within_row(1) { click_icon 'arrows-h' }
379
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
380
+ fill_in 'item_quantity', with: 200
381
+ click_icon :ok
382
+
383
+ wait_for_ajax
384
+
385
+ expect(order.shipments.count).to eq(2)
386
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
387
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
388
+ end
389
+
390
+ it 'should not allow a shipment to split stock to itself' do
391
+ within_row(1) { click_icon 'arrows-h' }
392
+ targetted_select2 order.shipments.first.number, from: '#s2id_item_stock_location'
393
+ fill_in 'item_quantity', with: 1
394
+ click_icon :ok
395
+
396
+ wait_for_ajax
397
+
398
+ expect(order.shipments.count).to eq(2)
399
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
400
+ end
401
+
402
+ it 'should split fine if more than one line_item is in the receiving shipment' do
403
+ variant2 = create(:variant)
404
+ order.contents.add(variant2, 2, shipment: @shipment2)
405
+
406
+ within_row(1) { click_icon 'arrows-h' }
407
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
408
+ fill_in 'item_quantity', with: 1
409
+ click_icon :ok
410
+
411
+ wait_for_ajax
412
+
413
+ expect(order.shipments.count).to eq(2)
414
+ expect(order.shipments.first.inventory_units_for(product.master).count).to eq 1
415
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq 1
416
+ expect(order.shipments.first.inventory_units_for(variant2).count).to eq 0
417
+ expect(order.shipments.last.inventory_units_for(variant2).count).to eq 2
418
+ end
419
+ end
420
+
421
+ context 'receiving shipment can backorder' do
422
+ it 'should add more to the backorder' do
423
+ product.master.stock_items.last.update_column(:backorderable, true)
424
+ product.master.stock_items.last.update_column(:count_on_hand, 0)
425
+ expect(@shipment2.reload.backordered?).to eq(false)
426
+
427
+
428
+ within_row(1) { click_icon 'arrows-h' }
429
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
430
+ fill_in 'item_quantity', with: 1
431
+ click_icon :ok
432
+
433
+ wait_for_ajax
434
+
435
+ expect(@shipment2.reload.backordered?).to eq(true)
436
+
437
+ within_row(1) { click_icon 'arrows-h' }
438
+ targetted_select2 @shipment2.number, from: '#s2id_item_stock_location'
439
+ fill_in 'item_quantity', with: 1
440
+ click_icon :ok
441
+
442
+ wait_for_ajax
443
+
444
+ expect(order.shipments.count).to eq(1)
445
+ expect(order.shipments.last.inventory_units_for(product.master).count).to eq(2)
446
+ expect(@shipment2.reload.backordered?).to eq(true)
447
+ end
448
+ end
449
+ end
450
+ end
451
+ end
452
+
453
+ context 'with only read permissions' do
454
+ before do
455
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(nil)
456
+ end
457
+
458
+ custom_authorization! do |user|
459
+ can [:admin, :index, :read, :edit], Spree::Order
460
+ end
461
+ it "should not display forbidden links" do
462
+ visit spree.edit_admin_order_path(order)
463
+
464
+ expect(page).not_to have_button('cancel')
465
+ expect(page).not_to have_button('Resend')
466
+
467
+ # Order Tabs
468
+ expect(page).not_to have_link('Adjustments')
469
+ expect(page).not_to have_link('Payments')
470
+ expect(page).not_to have_link('Return Authorizations')
471
+
472
+ # Order item actions
473
+ expect(page).not_to have_css('.delete-item')
474
+ expect(page).not_to have_css('.split-item')
475
+ expect(page).not_to have_css('.edit-item')
476
+ expect(page).not_to have_css('.edit-tracking')
477
+
478
+ expect(page).not_to have_css('#add-line-item')
479
+ end
480
+ end
481
+
482
+ context 'as Fakedispatch' do
483
+ custom_authorization! do |user|
484
+ # allow dispatch to :admin, :index, and :edit on Spree::Order
485
+ can [:admin, :edit, :index, :read], Spree::Order
486
+ # allow dispatch to :index, :show, :create and :update shipments on the admin
487
+ can [:admin, :manage, :read, :ship], Spree::Shipment
488
+ end
489
+
490
+ before do
491
+ allow(Spree.user_class).to receive(:find_by).
492
+ with(hash_including(:spree_api_key)).
493
+ and_return(Spree.user_class.new)
494
+ end
495
+
496
+ it 'should not display order tabs or edit buttons without ability' do
497
+ visit spree.edit_admin_order_path(order)
498
+
499
+ # Order Form
500
+ expect(page).not_to have_css('.edit-item')
501
+ # Order Tabs
502
+ expect(page).not_to have_link('Adjustments')
503
+ expect(page).not_to have_link('Payments')
504
+ expect(page).not_to have_link('Return Authorizations')
505
+ end
506
+
507
+ it "can change the shipping method" do
508
+ order = create(:completed_order_with_totals)
509
+ visit spree.edit_admin_order_path(order)
510
+ within("table.index tr.show-method") do
511
+ click_icon :edit
512
+ end
513
+ select2 "Default", :from => "Shipping Method"
514
+ click_icon :check
515
+
516
+ expect(page).not_to have_css('#selected_shipping_rate_id')
517
+ expect(page).to have_content("Default")
518
+ end
519
+
520
+ it 'can ship' do
521
+ order = create(:order_ready_to_ship)
522
+ order.refresh_shipment_rates
523
+ visit spree.edit_admin_order_path(order)
524
+
525
+ find(".ship-shipment-button").click
526
+ wait_for_ajax
527
+
528
+ within '.carton-state' do
529
+ expect(page).to have_content('SHIPPED')
530
+ end
531
+ end
532
+ end
533
+ end