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,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::ReturnItemsController, :type => :controller do
4
+ stub_authorization!
5
+
6
+ describe '#update' do
7
+ let(:customer_return) { create(:customer_return) }
8
+ let(:return_item) { customer_return.return_items.first }
9
+ let(:old_acceptance_status) { 'pending' }
10
+ let(:new_acceptance_status) { 'rejected' }
11
+
12
+ subject do
13
+ spree_put :update, id: return_item.to_param, return_item: {acceptance_status: new_acceptance_status}
14
+ end
15
+
16
+ it 'updates the return item' do
17
+ expect {
18
+ subject
19
+ }.to change { return_item.reload.acceptance_status }.from(old_acceptance_status).to(new_acceptance_status)
20
+ end
21
+
22
+ it 'redirects to the custome return' do
23
+ subject
24
+ expect(response).to redirect_to spree.edit_admin_order_customer_return_path(customer_return.order, customer_return)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::RootController do
4
+ describe "GET index" do
5
+ subject { get :index }
6
+
7
+ let(:user) { build(:user) }
8
+ let(:ability) { Spree::Ability.new(user) }
9
+
10
+ before do
11
+ allow_any_instance_of(Spree::Admin::RootController).to receive(:try_spree_current_user).and_return(user)
12
+ allow_any_instance_of(Spree::Admin::RootController).to receive(:current_ability).and_return(ability)
13
+ end
14
+
15
+ context "when a user can admin and display spree orders" do
16
+ before do
17
+ ability.can :admin, Spree::Order
18
+ ability.can :display, Spree::Order
19
+ end
20
+
21
+ it { is_expected.to redirect_to(spree.admin_orders_path) }
22
+ end
23
+
24
+ context "when a user cannot admin and display spree orders" do
25
+ context "when a user can admin and home dashboards" do
26
+ before do
27
+ ability.can :admin, :dashboards
28
+ ability.can :home, :dashboards
29
+ end
30
+
31
+ it { is_expected.to redirect_to(spree.home_admin_dashboards_path) }
32
+ end
33
+
34
+ context "when a user cannot admin and home dashboards" do
35
+ # The default exception handler redirects to /unauthorized.
36
+ # Extensions may change this.
37
+ it { is_expected.to redirect_to('/unauthorized') }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -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,331 @@
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
+ it "searches by stock location" do
28
+ spree_get :index, :q => { :source_location_id_or_destination_location_id_eq => ny_store.id }
29
+ expect(assigns(:stock_transfers).count).to eq 1
30
+ expect(assigns(:stock_transfers)).to include(stock_transfer1)
31
+ end
32
+
33
+ it "filters the closed stock transfers" do
34
+ spree_get :index, :q => { :closed_at_null => '1' }
35
+ expect(assigns(:stock_transfers)).to match_array [stock_transfer1]
36
+ end
37
+
38
+ it "doesn't filter any stock transfers" do
39
+ spree_get :index, :q => { :closed_at_null => '0' }
40
+ expect(assigns(:stock_transfers)).to match_array [stock_transfer1, stock_transfer2]
41
+ end
42
+ end
43
+
44
+ context "#create" do
45
+ let(:warehouse) { StockLocation.create(name: "Warehouse", active: false)}
46
+
47
+ subject do
48
+ spree_post :create, stock_transfer: { source_location_id: warehouse.id, description: nil }
49
+ end
50
+
51
+ context "user doesn't have read access to the selected stock location" do
52
+ before do
53
+ expect(controller).to receive(:authorize!) { raise CanCan::AccessDenied }
54
+ end
55
+
56
+ it "redirects to authorization_failure" do
57
+ subject
58
+ expect(response).to redirect_to('/unauthorized')
59
+ end
60
+ end
61
+
62
+ context "valid parameters" do
63
+ let!(:user) { create(:user) }
64
+
65
+ before do
66
+ allow(controller).to receive(:try_spree_current_user) { user }
67
+ end
68
+
69
+ it "redirects to the edit page" do
70
+ subject
71
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(assigns(:stock_transfer)))
72
+ end
73
+
74
+ it "sets the created_by to the current user" do
75
+ subject
76
+ expect(assigns(:stock_transfer).created_by).to eq(user)
77
+ end
78
+ end
79
+ end
80
+
81
+ context "#receive" do
82
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items) }
83
+ let(:variant_1) { transfer_with_items.transfer_items[0].variant }
84
+ let(:variant_2) { transfer_with_items.transfer_items[1].variant }
85
+ let(:parameters) { { id: transfer_with_items.to_param } }
86
+
87
+ subject do
88
+ spree_get :receive, parameters
89
+ end
90
+
91
+ context 'stock transfer is not receivable' do
92
+ before do
93
+ transfer_with_items.update_attributes(finalized_at: nil, shipped_at: nil)
94
+ end
95
+
96
+ it 'redirects back to index' do
97
+ subject
98
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_must_be_receivable)
99
+ expect(response).to redirect_to(spree.admin_stock_transfers_path)
100
+ end
101
+ end
102
+
103
+ context "no items have been received" do
104
+ let(:parameters) do
105
+ { id: transfer_with_items.to_param }
106
+ end
107
+
108
+ before { subject }
109
+
110
+ it "doesn't assign received_items" do
111
+ expect(assigns(:received_items)).to be_empty
112
+ end
113
+ end
114
+
115
+ context "some items have been received" do
116
+ let(:transfer_item) { transfer_with_items.transfer_items.first }
117
+ let(:parameters) do
118
+ { id: transfer_with_items.to_param, variant_search_term: variant_1.sku }
119
+ end
120
+
121
+ before do
122
+ transfer_item.update_attributes(received_quantity: 1)
123
+ subject
124
+ end
125
+
126
+ it "assigns received_items correctly" do
127
+ expect(assigns(:received_items)).to match_array [transfer_item]
128
+ end
129
+ end
130
+ end
131
+
132
+ context "#finalize" do
133
+ let!(:user) { create(:user) }
134
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items, finalized_at: nil, shipped_at: nil) }
135
+
136
+ before do
137
+ allow(controller).to receive(:try_spree_current_user) { user }
138
+ end
139
+
140
+ subject do
141
+ spree_put :finalize, id: transfer_with_items.to_param
142
+ end
143
+
144
+ context 'stock transfer is not finalizable' do
145
+ before do
146
+ transfer_with_items.update_attributes(finalized_at: Time.now)
147
+ end
148
+
149
+ it 'redirects back to edit' do
150
+ subject
151
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_cannot_be_finalized)
152
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(transfer_with_items))
153
+ end
154
+ end
155
+
156
+ context "successfully finalized" do
157
+ it "redirects to tracking_info" do
158
+ subject
159
+ expect(response).to redirect_to(spree.tracking_info_admin_stock_transfer_path(transfer_with_items))
160
+ end
161
+
162
+ it "sets the finalized_by to the current user" do
163
+ subject
164
+ expect(transfer_with_items.reload.finalized_by).to eq(user)
165
+ end
166
+
167
+ it "sets the finalized_at date" do
168
+ subject
169
+ expect(transfer_with_items.reload.finalized_at).to_not be_nil
170
+ end
171
+ end
172
+
173
+ context "error finalizing the stock transfer" do
174
+ before do
175
+ transfer_with_items.update_attributes(destination_location_id: nil)
176
+ end
177
+
178
+ it "redirects back to edit" do
179
+ subject
180
+ expect(response).to redirect_to(spree.edit_admin_stock_transfer_path(transfer_with_items))
181
+ end
182
+
183
+ it "displays a flash error message" do
184
+ subject
185
+ expect(flash[:error]).to eq "Destination location can't be blank"
186
+ end
187
+ end
188
+ end
189
+
190
+ context "#close" do
191
+ let!(:user) { create(:user) }
192
+ let!(:transfer_with_items) { create(:receivable_stock_transfer_with_items) }
193
+
194
+ before do
195
+ allow(controller).to receive(:try_spree_current_user) { user }
196
+ end
197
+
198
+ subject do
199
+ spree_put :close, id: transfer_with_items.to_param
200
+ end
201
+
202
+ context 'stock transfer is not receivable' do
203
+ before do
204
+ transfer_with_items.update_attributes(finalized_at: nil, shipped_at: nil)
205
+ end
206
+
207
+ it 'redirects back to receive' do
208
+ subject
209
+ expect(flash[:error]).to eq Spree.t(:stock_transfer_must_be_receivable)
210
+ expect(response).to redirect_to(spree.receive_admin_stock_transfer_path(transfer_with_items))
211
+ end
212
+ end
213
+
214
+ context "successfully closed" do
215
+ it "redirects back to index" do
216
+ subject
217
+ expect(response).to redirect_to(spree.admin_stock_transfers_path)
218
+ end
219
+
220
+ it "sets the closed_by to the current user" do
221
+ subject
222
+ expect(transfer_with_items.reload.closed_by).to eq(user)
223
+ end
224
+
225
+ it "sets the closed_at date" do
226
+ subject
227
+ expect(transfer_with_items.reload.closed_at).to_not be_nil
228
+ end
229
+
230
+ context "stock movements" do
231
+ let(:source) { transfer_with_items.source_location }
232
+ let(:destination) { transfer_with_items.destination_location }
233
+ let(:transfer_item_1) { transfer_with_items.transfer_items[0] }
234
+ let(:transfer_item_2) { transfer_with_items.transfer_items[1] }
235
+
236
+ before do
237
+ transfer_item_1.update_columns(received_quantity: 2)
238
+ transfer_item_2.update_columns(received_quantity: 5)
239
+ subject
240
+ end
241
+
242
+ it 'creates 2 stock movements' do
243
+ expect(assigns(:stock_movements).length).to eq 2
244
+ end
245
+
246
+ it 'sets the stock transfer as the originator of the stock movements' do
247
+ subject
248
+ originators = assigns(:stock_movements).map(&:originator)
249
+ expect(originators).to match_array [transfer_with_items, transfer_with_items]
250
+ end
251
+
252
+ it 'only creates stock movements for the destination stock location' do
253
+ subject
254
+ locations = assigns(:stock_movements).map(&:stock_item).flat_map(&:stock_location)
255
+ expect(locations).to match_array [destination, destination]
256
+ end
257
+
258
+ it 'creates the stock movements for the received quantities' do
259
+ subject
260
+ movement_for_transfer_item_1 = assigns(:stock_movements).find { |sm| sm.stock_item.variant == transfer_item_1.variant }
261
+ expect(movement_for_transfer_item_1.quantity).to eq 2
262
+ movement_for_transfer_item_2 = assigns(:stock_movements).find { |sm| sm.stock_item.variant == transfer_item_2.variant }
263
+ expect(movement_for_transfer_item_2.quantity).to eq 5
264
+ end
265
+ end
266
+ end
267
+
268
+ context "error closing the stock transfer" do
269
+ before do
270
+ transfer_with_items.update_columns(destination_location_id: nil)
271
+ end
272
+
273
+ it "redirects back to receive" do
274
+ subject
275
+ expect(response).to redirect_to(spree.receive_admin_stock_transfer_path(transfer_with_items))
276
+ end
277
+
278
+ it "displays a flash error message" do
279
+ subject
280
+ expect(flash[:error]).to eq "Destination location can't be blank"
281
+ end
282
+ end
283
+ end
284
+
285
+ context "#finish" do
286
+ let(:stock_transfer) { Spree::StockTransfer.create(source_location: warehouse, destination_location: ny_store, created_by: create(:admin_user))}
287
+ let(:transfer_variant) { create(:variant) }
288
+ let(:warehouse_stock_item) { warehouse.stock_items.find_by(variant: transfer_variant) }
289
+ let(:ny_stock_item) { ny_store.stock_items.find_by(variant: transfer_variant) }
290
+
291
+ before do
292
+ warehouse_stock_item.set_count_on_hand(1)
293
+ stock_transfer.transfer_items.create!(variant: transfer_variant, expected_quantity: 1)
294
+ end
295
+
296
+ context "with transferable items" do
297
+
298
+ it "marks the transfer shipped" do
299
+ spree_put :ship, :id => stock_transfer.number
300
+
301
+ expect(stock_transfer.reload.shipped_at).to_not be_nil
302
+ expect(flash[:success]).to be_present
303
+ end
304
+
305
+ it "makes stock movements for the transferred items" do
306
+ spree_put :ship, :id => stock_transfer.number
307
+
308
+ expect(Spree::StockMovement.count).to eq 1
309
+ expect(warehouse_stock_item.reload.count_on_hand).to eq 0
310
+ end
311
+ end
312
+
313
+ context "with non-transferable items" do
314
+ before { warehouse_stock_item.set_count_on_hand(0) }
315
+
316
+ it "does not mark the transfer shipped" do
317
+ spree_put :ship, :id => stock_transfer.number
318
+
319
+ expect(stock_transfer.reload.shipped_at).to be_nil
320
+ end
321
+
322
+ it "errors and redirects to tracking_info page" do
323
+ spree_put :ship, :id => stock_transfer.number
324
+
325
+ expect(flash[:error]).to match /not enough inventory/
326
+ expect(response).to redirect_to(spree.tracking_info_admin_stock_transfer_path(stock_transfer))
327
+ end
328
+ end
329
+ end
330
+ end
331
+ end