solidus_backend 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::SearchController, :type => :controller do
4
+ stub_authorization!
5
+
6
+ # Regression test for ernie/ransack#176
7
+ let(:user) { create(:user, email: "spree_commerce@example.com") }
8
+
9
+ before do
10
+ user.ship_address = create(:address)
11
+ user.bill_address = create(:address)
12
+ user.save
13
+ end
14
+
15
+ describe 'GET #users' do
16
+ subject { spree_xhr_get :users, params }
17
+
18
+ shared_examples_for 'user found by search' do
19
+ it "should include users matching query" do
20
+ subject
21
+ expect(assigns[:users]).to include(user)
22
+ end
23
+ end
24
+
25
+ context 'when searching by user attributes' do
26
+ let(:params) { { q: user_attribute } }
27
+
28
+ context 'when searching by email' do
29
+ it_should_behave_like 'user found by search' do
30
+ let(:user_attribute) { user.email }
31
+ end
32
+ end
33
+
34
+ context 'when searching by ship addresss first name' do
35
+ it_should_behave_like 'user found by search' do
36
+ let(:user_attribute) { user.ship_address.firstname }
37
+ end
38
+ end
39
+
40
+ context 'when searching by ship address last name' do
41
+ it_should_behave_like 'user found by search' do
42
+ let(:user_attribute) { user.ship_address.lastname }
43
+ end
44
+ end
45
+
46
+ context 'when searching by bill address first name' do
47
+ it_should_behave_like 'user found by search' do
48
+ let(:user_attribute) { user.bill_address.firstname }
49
+ end
50
+ end
51
+
52
+ context 'when searching by bill address last name' do
53
+ it_should_behave_like 'user found by search' do
54
+ let(:user_attribute) { user.bill_address.lastname }
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'when searching by user ids' do
60
+ let(:params) { { ids: user.id.to_s } }
61
+ it_should_behave_like 'user found by search'
62
+ end
63
+ end
64
+
65
+ describe 'get #products' do
66
+ let!(:product_one) { create(:product, name: 'jersey') }
67
+ let!(:product_two) { create(:product, name: 'better jersey') }
68
+
69
+ subject { spree_get :products, params }
70
+
71
+ shared_examples_for 'product search' do
72
+ it 'should respond with http success' do
73
+ subject
74
+ expect(response).to be_success
75
+ end
76
+
77
+ it 'should set the Surrogate-Control header' do
78
+ subject
79
+ expect(response.headers['Surrogate-Control']).to eq 'max-age=900'
80
+ end
81
+
82
+ it 'should find the correct products' do
83
+ subject
84
+ expect(assigns(:products)).to match_array expected_products
85
+ end
86
+ end
87
+
88
+ context 'when ids param is present' do
89
+ let(:params) { { ids: product_one.id } }
90
+
91
+ it_should_behave_like 'product search' do
92
+ let(:expected_products) { [product_one] }
93
+ end
94
+ end
95
+
96
+ context 'when idds param is not present' do
97
+ let(:params) { { q: {name_cont: 'jersey'} } }
98
+
99
+ it_should_behave_like 'product search' do
100
+ let(:expected_products) { [product_one, product_two] }
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::ShippingMethodsController, :type => :controller do
4
+ stub_authorization!
5
+
6
+ # Regression test for #1240
7
+ it "should not hard-delete shipping methods" do
8
+ shipping_method = stub_model(Spree::ShippingMethod)
9
+ allow(Spree::ShippingMethod).to receive_messages :find => shipping_method
10
+ expect(shipping_method.deleted_at).to be_nil
11
+ spree_delete :destroy, :id => 1
12
+ expect(shipping_method.reload.deleted_at).not_to be_nil
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockItemsController, :type => :controller do
6
+ stub_authorization!
7
+
8
+ describe "#create" do
9
+ let!(:variant) { create(:variant) }
10
+ let!(:stock_location) { variant.stock_locations.first }
11
+ let(:stock_item) { variant.stock_items.first }
12
+ let!(:user) { create :user }
13
+
14
+ before { expect(controller).to receive(:spree_current_user).and_return(user) }
15
+ before { request.env["HTTP_REFERER"] = "product_admin_page" }
16
+
17
+ subject do
18
+ spree_post :create, { variant_id: variant, stock_location_id: stock_location, stock_movement: { quantity: 1, stock_item_id: stock_item.id } }
19
+ end
20
+
21
+ it "creates a stock movement with originator" do
22
+ expect { subject }.to change { Spree::StockMovement.count }.by(1)
23
+ stock_movement = Spree::StockMovement.last
24
+ expect(stock_movement.originator_type).to eq "Spree::LegacyUser"
25
+ end
26
+ end
27
+
28
+ describe "#index" do
29
+ let!(:variant_1) { create(:variant) }
30
+ let!(:variant_2) { create(:variant) }
31
+
32
+ context "with product_slug param" do
33
+ it "scopes the variants by the product" do
34
+ spree_get :index, product_slug: variant_1.product.slug
35
+ expect(assigns(:variants)).to include variant_1
36
+ expect(assigns(:variants)).not_to include variant_2
37
+ end
38
+ end
39
+
40
+ context "without product_slug params" do
41
+ it "allows all accessible variants to be returned" do
42
+ spree_get :index
43
+ expect(assigns(:variants)).to include variant_1
44
+ expect(assigns(:variants)).to include variant_2
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockLocationsController, :type => :controller do
6
+ stub_authorization!
7
+
8
+ # Regression for #4272
9
+ context "with no countries present" do
10
+ it "cannot create a new stock location" do
11
+ spree_get :new
12
+ expect(flash[:error]).to eq(Spree.t(:stock_locations_need_a_default_country))
13
+ expect(response).to redirect_to(spree.admin_stock_locations_path)
14
+ end
15
+ end
16
+
17
+ context "with a default country present" do
18
+ before do
19
+ country = FactoryGirl.create(:country)
20
+ Spree::Config[:default_country_id] = country.id
21
+ end
22
+
23
+ it "can create a new stock location" do
24
+ spree_get :new
25
+ expect(response).to be_success
26
+ end
27
+ end
28
+
29
+ context "with a country with the ISO code of 'US' existing" do
30
+ before do
31
+ FactoryGirl.create(:country, iso: 'US')
32
+ end
33
+
34
+ it "can create a new stock location" do
35
+ spree_get :new
36
+ expect(response).to be_success
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,351 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Admin::StockTransfersController, :type => :controller do
5
+ stub_authorization!
6
+
7
+ let(:warehouse) { StockLocation.create(name: "Warehouse")}
8
+ let(:ny_store) { StockLocation.create(name: "NY Store")}
9
+ let(:la_store) { StockLocation.create(name: "LA Store")}
10
+
11
+ context "#index" do
12
+
13
+ let!(:stock_transfer1) {
14
+ StockTransfer.create do |transfer|
15
+ transfer.source_location_id = warehouse.id
16
+ transfer.destination_location_id = ny_store.id
17
+ end }
18
+
19
+ let!(:stock_transfer2) {
20
+ StockTransfer.create do |transfer|
21
+ transfer.source_location_id = warehouse.id
22
+ transfer.destination_location_id = la_store.id
23
+ transfer.finalized_at = DateTime.now
24
+ transfer.closed_at = DateTime.now
25
+ end }
26
+
27
+ describe "stock location filtering" do
28
+ let(:user) { create(:admin_user) }
29
+ let(:ability) { Spree::Ability.new(user) }
30
+ let!(:sf_store) { StockLocation.create(name: "SF Store")}
31
+
32
+ before do
33
+ ability.cannot :manage, Spree::StockLocation
34
+ ability.can :transfer_from, Spree::StockLocation, id: [warehouse.id]
35
+ ability.can :transfer_to, Spree::StockLocation, id: [ny_store.id, la_store.id]
36
+
37
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(user)
38
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
39
+ end
40
+
41
+ it "doesn't display stock locations the user doesn't have access to" do
42
+ spree_get :index
43
+ expect(assigns(:stock_locations)).to match_array [warehouse, ny_store, la_store]
44
+ end
45
+ end
46
+
47
+ it "searches by stock location" do
48
+ spree_get :index, :q => { :source_location_id_or_destination_location_id_eq => ny_store.id }
49
+ expect(assigns(:stock_transfers).count).to eq 1
50
+ expect(assigns(:stock_transfers)).to include(stock_transfer1)
51
+ end
52
+
53
+ it "filters the closed stock transfers" do
54
+ spree_get :index, :q => { :closed_at_null => '1' }
55
+ expect(assigns(:stock_transfers)).to match_array [stock_transfer1]
56
+ end
57
+
58
+ it "doesn't filter any stock transfers" do
59
+ spree_get :index, :q => { :closed_at_null => '0' }
60
+ expect(assigns(:stock_transfers)).to match_array [stock_transfer1, stock_transfer2]
61
+ end
62
+ end
63
+
64
+ context "#create" do
65
+ let(:warehouse) { StockLocation.create(name: "Warehouse", active: false)}
66
+
67
+ subject do
68
+ spree_post :create, stock_transfer: { source_location_id: warehouse.id, description: nil }
69
+ end
70
+
71
+ context "user doesn't have read access to the selected stock location" do
72
+ before do
73
+ expect(controller).to receive(:authorize!) { raise CanCan::AccessDenied }
74
+ end
75
+
76
+ it "redirects to authorization_failure" do
77
+ subject
78
+ expect(response).to redirect_to('/unauthorized')
79
+ end
80
+ end
81
+
82
+ context "valid parameters" do
83
+ let!(:user) { create(:user) }
84
+
85
+ before do
86
+ allow(controller).to receive(:try_spree_current_user) { user }
87
+ end
88
+
89
+ it "redirects to the edit page" do
90
+ subject
91
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(assigns(:stock_transfer)))
92
+ end
93
+
94
+ it "sets the created_by to the current user" do
95
+ subject
96
+ expect(assigns(:stock_transfer).created_by).to eq(user)
97
+ end
98
+ end
99
+ end
100
+
101
+ context "#receive" do
102
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items) }
103
+ let(:variant_1) { transfer_with_items.transfer_items[0].variant }
104
+ let(:variant_2) { transfer_with_items.transfer_items[1].variant }
105
+ let(:parameters) { { id: transfer_with_items.to_param } }
106
+
107
+ subject do
108
+ spree_get :receive, parameters
109
+ end
110
+
111
+ context 'stock transfer is not receivable' do
112
+ before do
113
+ transfer_with_items.update_attributes(finalized_at: nil, shipped_at: nil)
114
+ end
115
+
116
+ it 'redirects back to index' do
117
+ subject
118
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_must_be_receivable)
119
+ expect(response).to redirect_to(spree.admin_stock_transfers_path)
120
+ end
121
+ end
122
+
123
+ context "no items have been received" do
124
+ let(:parameters) do
125
+ { id: transfer_with_items.to_param }
126
+ end
127
+
128
+ before { subject }
129
+
130
+ it "doesn't assign received_items" do
131
+ expect(assigns(:received_items)).to be_empty
132
+ end
133
+ end
134
+
135
+ context "some items have been received" do
136
+ let(:transfer_item) { transfer_with_items.transfer_items.first }
137
+ let(:parameters) do
138
+ { id: transfer_with_items.to_param, variant_search_term: variant_1.sku }
139
+ end
140
+
141
+ before do
142
+ transfer_item.update_attributes(received_quantity: 1)
143
+ subject
144
+ end
145
+
146
+ it "assigns received_items correctly" do
147
+ expect(assigns(:received_items)).to match_array [transfer_item]
148
+ end
149
+ end
150
+ end
151
+
152
+ context "#finalize" do
153
+ let!(:user) { create(:user) }
154
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items, finalized_at: nil, shipped_at: nil) }
155
+
156
+ before do
157
+ allow(controller).to receive(:try_spree_current_user) { user }
158
+ end
159
+
160
+ subject do
161
+ spree_put :finalize, id: transfer_with_items.to_param
162
+ end
163
+
164
+ context 'stock transfer is not finalizable' do
165
+ before do
166
+ transfer_with_items.update_attributes(finalized_at: Time.now)
167
+ end
168
+
169
+ it 'redirects back to edit' do
170
+ subject
171
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_cannot_be_finalized)
172
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(transfer_with_items))
173
+ end
174
+ end
175
+
176
+ context "successfully finalized" do
177
+ it "redirects to tracking_info" do
178
+ subject
179
+ expect(response).to redirect_to(spree.tracking_info_admin_stock_transfer_path(transfer_with_items))
180
+ end
181
+
182
+ it "sets the finalized_by to the current user" do
183
+ subject
184
+ expect(transfer_with_items.reload.finalized_by).to eq(user)
185
+ end
186
+
187
+ it "sets the finalized_at date" do
188
+ subject
189
+ expect(transfer_with_items.reload.finalized_at).to_not be_nil
190
+ end
191
+ end
192
+
193
+ context "error finalizing the stock transfer" do
194
+ before do
195
+ transfer_with_items.update_attributes(destination_location_id: nil)
196
+ end
197
+
198
+ it "redirects back to edit" do
199
+ subject
200
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(transfer_with_items))
201
+ end
202
+
203
+ it "displays a flash error message" do
204
+ subject
205
+ expect(flash[:error]).to eq "Destination location can't be blank"
206
+ end
207
+ end
208
+ end
209
+
210
+ context "#close" do
211
+ let!(:user) { create(:user) }
212
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items) }
213
+
214
+ before do
215
+ allow(controller).to receive(:try_spree_current_user) { user }
216
+ end
217
+
218
+ subject do
219
+ spree_put :close, id: transfer_with_items.to_param
220
+ end
221
+
222
+ context 'stock transfer is not receivable' do
223
+ before do
224
+ transfer_with_items.update_attributes(finalized_at: nil, shipped_at: nil)
225
+ end
226
+
227
+ it 'redirects back to receive' do
228
+ subject
229
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_must_be_receivable)
230
+ expect(response).to redirect_to(spree.receive_admin_stock_transfer_path(transfer_with_items))
231
+ end
232
+ end
233
+
234
+ context "successfully closed" do
235
+ it "redirects back to index" do
236
+ subject
237
+ expect(response).to redirect_to(spree.admin_stock_transfers_path)
238
+ end
239
+
240
+ it "sets the closed_by to the current user" do
241
+ subject
242
+ expect(transfer_with_items.reload.closed_by).to eq(user)
243
+ end
244
+
245
+ it "sets the closed_at date" do
246
+ subject
247
+ expect(transfer_with_items.reload.closed_at).to_not be_nil
248
+ end
249
+
250
+ context "stock movements" do
251
+ let(:source) { transfer_with_items.source_location }
252
+ let(:destination) { transfer_with_items.destination_location }
253
+ let(:transfer_item_1) { transfer_with_items.transfer_items[0] }
254
+ let(:transfer_item_2) { transfer_with_items.transfer_items[1] }
255
+
256
+ before do
257
+ transfer_item_1.update_columns(received_quantity: 2)
258
+ transfer_item_2.update_columns(received_quantity: 5)
259
+ subject
260
+ end
261
+
262
+ it 'creates 2 stock movements' do
263
+ expect(assigns(:stock_movements).length).to eq 2
264
+ end
265
+
266
+ it 'sets the stock transfer as the originator of the stock movements' do
267
+ subject
268
+ originators = assigns(:stock_movements).map(&:originator)
269
+ expect(originators).to match_array [transfer_with_items, transfer_with_items]
270
+ end
271
+
272
+ it 'only creates stock movements for the destination stock location' do
273
+ subject
274
+ locations = assigns(:stock_movements).map(&:stock_item).flat_map(&:stock_location)
275
+ expect(locations).to match_array [destination, destination]
276
+ end
277
+
278
+ it 'creates the stock movements for the received quantities' do
279
+ subject
280
+ movement_for_transfer_item_1 = assigns(:stock_movements).find { |sm| sm.stock_item.variant == transfer_item_1.variant }
281
+ expect(movement_for_transfer_item_1.quantity).to eq 2
282
+ movement_for_transfer_item_2 = assigns(:stock_movements).find { |sm| sm.stock_item.variant == transfer_item_2.variant }
283
+ expect(movement_for_transfer_item_2.quantity).to eq 5
284
+ end
285
+ end
286
+ end
287
+
288
+ context "error closing the stock transfer" do
289
+ before do
290
+ transfer_with_items.update_columns(destination_location_id: nil)
291
+ end
292
+
293
+ it "redirects back to receive" do
294
+ subject
295
+ expect(response).to redirect_to(spree.receive_admin_stock_transfer_path(transfer_with_items))
296
+ end
297
+
298
+ it "displays a flash error message" do
299
+ subject
300
+ expect(flash[:error]).to eq "Destination location can't be blank"
301
+ end
302
+ end
303
+ end
304
+
305
+ context "#finish" do
306
+ let(:stock_transfer) { Spree::StockTransfer.create(source_location: warehouse, destination_location: ny_store, created_by: create(:admin_user))}
307
+ let(:transfer_variant) { create(:variant) }
308
+ let(:warehouse_stock_item) { warehouse.stock_items.find_by(variant: transfer_variant) }
309
+ let(:ny_stock_item) { ny_store.stock_items.find_by(variant: transfer_variant) }
310
+
311
+ before do
312
+ warehouse_stock_item.set_count_on_hand(1)
313
+ stock_transfer.transfer_items.create!(variant: transfer_variant, expected_quantity: 1)
314
+ end
315
+
316
+ context "with transferable items" do
317
+
318
+ it "marks the transfer shipped" do
319
+ spree_put :ship, :id => stock_transfer.number
320
+
321
+ expect(stock_transfer.reload.shipped_at).to_not be_nil
322
+ expect(flash[:success]).to be_present
323
+ end
324
+
325
+ it "makes stock movements for the transferred items" do
326
+ spree_put :ship, :id => stock_transfer.number
327
+
328
+ expect(Spree::StockMovement.count).to eq 1
329
+ expect(warehouse_stock_item.reload.count_on_hand).to eq 0
330
+ end
331
+ end
332
+
333
+ context "with non-transferable items" do
334
+ before { warehouse_stock_item.set_count_on_hand(0) }
335
+
336
+ it "does not mark the transfer shipped" do
337
+ spree_put :ship, :id => stock_transfer.number
338
+
339
+ expect(stock_transfer.reload.shipped_at).to be_nil
340
+ end
341
+
342
+ it "errors and redirects to tracking_info page" do
343
+ spree_put :ship, :id => stock_transfer.number
344
+
345
+ expect(flash[:error]).to match /not enough inventory/
346
+ expect(response).to redirect_to(spree.tracking_info_admin_stock_transfer_path(stock_transfer))
347
+ end
348
+ end
349
+ end
350
+ end
351
+ end