solidus_backend 1.0.7 → 1.1.0.beta1

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 (201) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend.js +3 -0
  3. data/app/assets/javascripts/spree/backend/admin.js.erb +17 -24
  4. data/app/assets/javascripts/spree/backend/checkouts/edit.js +3 -5
  5. data/app/assets/javascripts/spree/backend/flash.coffee +17 -0
  6. data/app/assets/javascripts/spree/backend/handlebars_extensions.coffee +9 -0
  7. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js.erb +6 -6
  8. data/app/assets/javascripts/spree/backend/option_value_picker.js +43 -0
  9. data/app/assets/javascripts/spree/backend/product_picker.js +10 -8
  10. data/app/assets/javascripts/spree/backend/promotions.js.coffee +101 -0
  11. data/app/assets/javascripts/spree/backend/routes.js +2 -1
  12. data/app/assets/javascripts/spree/backend/shipments.js.erb +1 -1
  13. data/app/assets/javascripts/spree/backend/stock_management/index_add_forms.coffee +1 -1
  14. data/app/assets/javascripts/spree/backend/stock_movement.js.coffee +2 -2
  15. data/app/assets/javascripts/spree/backend/stock_transfers/variant_form.coffee +1 -1
  16. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb +6 -6
  17. data/app/assets/javascripts/spree/backend/taxons.js.coffee +6 -7
  18. data/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs +17 -0
  19. data/app/assets/javascripts/spree/backend/templates/products/sortable.hbs +5 -0
  20. data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_flat_rate.hbs +17 -0
  21. data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_percent.hbs +17 -0
  22. data/app/assets/javascripts/spree/backend/templates/promotions/rules/option_values.hbs +10 -0
  23. data/app/assets/javascripts/spree/backend/templates/promotions/rules/option_values_select.hbs +1 -0
  24. data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +19 -0
  25. data/app/assets/javascripts/spree/backend/templates/stock_transfers/transfer_item.hbs.erb +52 -0
  26. data/app/assets/javascripts/spree/backend/templates/variants/autocomplete.hbs.erb +23 -0
  27. data/app/assets/javascripts/spree/backend/templates/variants/autocomplete_stock.hbs +51 -0
  28. data/app/assets/javascripts/spree/backend/templates/variants/line_items_autocomplete_stock.hbs +67 -0
  29. data/app/assets/javascripts/spree/backend/templates/variants/split.hbs +27 -0
  30. data/app/assets/javascripts/spree/backend/user_picker.js +8 -8
  31. data/app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb +6 -8
  32. data/app/assets/stylesheets/spree/backend/components/_messages.scss +6 -3
  33. data/app/assets/stylesheets/spree/backend/sections/_promotions.scss +16 -0
  34. data/app/controllers/spree/admin/base_controller.rb +1 -1
  35. data/app/controllers/spree/admin/option_types_controller.rb +1 -3
  36. data/app/controllers/spree/admin/orders/customer_details_controller.rb +1 -1
  37. data/app/controllers/spree/admin/orders_controller.rb +6 -11
  38. data/app/controllers/spree/admin/product_properties_controller.rb +9 -0
  39. data/app/controllers/spree/admin/products_controller.rb +20 -5
  40. data/app/controllers/spree/admin/promotions_controller.rb +2 -1
  41. data/app/controllers/spree/admin/reimbursements_controller.rb +20 -0
  42. data/app/controllers/spree/admin/resource_controller.rb +1 -1
  43. data/app/controllers/spree/admin/return_authorizations_controller.rb +5 -0
  44. data/app/controllers/spree/admin/root_controller.rb +1 -1
  45. data/app/controllers/spree/admin/search_controller.rb +2 -4
  46. data/app/controllers/spree/admin/states_controller.rb +1 -1
  47. data/app/controllers/spree/admin/stock_items_controller.rb +1 -1
  48. data/app/controllers/spree/admin/stock_transfers_controller.rb +3 -14
  49. data/app/controllers/spree/admin/users_controller.rb +2 -3
  50. data/app/controllers/spree/admin/variant_property_rule_values_controller.rb +7 -0
  51. data/app/controllers/spree/admin/variants_controller.rb +1 -1
  52. data/app/controllers/spree/admin/zones_controller.rb +1 -1
  53. data/app/helpers/spree/admin/adjustments_helper.rb +4 -9
  54. data/app/helpers/spree/admin/base_helper.rb +7 -6
  55. data/app/helpers/spree/admin/navigation_helper.rb +8 -2
  56. data/app/helpers/spree/admin/orders_helper.rb +1 -1
  57. data/app/helpers/spree/admin/products_helper.rb +2 -4
  58. data/app/helpers/spree/admin/stock_movements_helper.rb +3 -3
  59. data/app/views/spree/admin/adjustments/_adjustment.html.erb +1 -1
  60. data/app/views/spree/admin/orders/_add_line_item.html.erb +0 -5
  61. data/app/views/spree/admin/orders/_add_product.html.erb +0 -3
  62. data/app/views/spree/admin/orders/_carton.html.erb +0 -1
  63. data/app/views/spree/admin/orders/_shipment.html.erb +0 -1
  64. data/app/views/spree/admin/orders/confirm/_shipment.html.erb +0 -1
  65. data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
  66. data/app/views/spree/admin/orders/customer_details/edit.html.erb +0 -1
  67. data/app/views/spree/admin/orders/index.html.erb +1 -2
  68. data/app/views/spree/admin/payment_methods/_form.html.erb +0 -4
  69. data/app/views/spree/admin/payment_methods/index.html.erb +0 -2
  70. data/app/views/spree/admin/payments/source_views/_gateway.html.erb +3 -0
  71. data/app/views/spree/admin/product_properties/index.html.erb +52 -2
  72. data/app/views/spree/admin/promotions/_actions.html.erb +14 -10
  73. data/app/views/spree/admin/promotions/_promotion_action.html.erb +5 -3
  74. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +5 -3
  75. data/app/views/spree/admin/promotions/_rules.html.erb +18 -14
  76. data/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +5 -28
  77. data/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +5 -27
  78. data/app/views/spree/admin/promotions/edit.html.erb +6 -4
  79. data/app/views/spree/admin/promotions/index.html.erb +1 -1
  80. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +13 -0
  81. data/app/views/spree/admin/refund_reasons/index.html.erb +2 -2
  82. data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
  83. data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
  84. data/app/views/spree/admin/search/users.rabl +1 -1
  85. data/app/views/spree/admin/shared/_order_summary.html.erb +6 -0
  86. data/app/views/spree/admin/shared/_tabs.html.erb +2 -2
  87. data/app/views/spree/admin/shared/_translations.html.erb +16 -46
  88. data/app/views/spree/admin/shared/named_types/_index.html.erb +2 -2
  89. data/app/views/spree/admin/stock_items/_stock_management.html.erb +0 -2
  90. data/app/views/spree/admin/stock_movements/_form.html.erb +0 -2
  91. data/app/views/spree/admin/stock_transfers/edit.html.erb +0 -3
  92. data/app/views/spree/admin/stock_transfers/receive.html.erb +0 -2
  93. data/app/views/spree/admin/stock_transfers/show.html.erb +1 -1
  94. data/app/views/spree/admin/taxons/index.html.erb +0 -1
  95. data/app/views/spree/admin/users/_addresses_form.html.erb +4 -4
  96. data/app/views/spree/layouts/admin.html.erb +11 -9
  97. data/config/routes.rb +5 -0
  98. data/lib/spree/backend.rb +1 -2
  99. metadata +41 -139
  100. data/CHANGELOG.md +0 -1
  101. data/Gemfile +0 -6
  102. data/Rakefile +0 -15
  103. data/app/assets/javascripts/spree/backend/handlebar_extensions.js +0 -9
  104. data/app/assets/javascripts/spree/backend/promotions.js +0 -73
  105. data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +0 -196
  106. data/app/views/spree/admin/products/_autocomplete.js.erb +0 -14
  107. data/app/views/spree/admin/products/_sortable.html +0 -7
  108. data/app/views/spree/admin/stock_items/_stock_location_stock_item_template.html.erb +0 -21
  109. data/app/views/spree/admin/stock_transfers/_transfer_item_template.html.erb +0 -54
  110. data/app/views/spree/admin/variants/_autocomplete.js.erb +0 -25
  111. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +0 -69
  112. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +0 -53
  113. data/app/views/spree/admin/variants/_split.js.erb +0 -29
  114. data/script/rails +0 -9
  115. data/solidus_backend.gemspec +0 -30
  116. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -24
  117. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +0 -77
  118. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -234
  119. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +0 -41
  120. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
  121. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -80
  122. data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -472
  123. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -49
  124. data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -175
  125. data/spec/controllers/spree/admin/products_controller_spec.rb +0 -45
  126. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -21
  127. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +0 -18
  128. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -21
  129. data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -122
  130. data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -32
  131. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -75
  132. data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -134
  133. data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -166
  134. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -226
  135. data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -27
  136. data/spec/controllers/spree/admin/root_controller_spec.rb +0 -41
  137. data/spec/controllers/spree/admin/search_controller_spec.rb +0 -104
  138. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -14
  139. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -50
  140. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -41
  141. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +0 -331
  142. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +0 -309
  143. data/spec/controllers/spree/admin/users_controller_spec.rb +0 -236
  144. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -32
  145. data/spec/features/admin/configuration/analytics_tracker_spec.rb +0 -54
  146. data/spec/features/admin/configuration/countries_spec.rb +0 -22
  147. data/spec/features/admin/configuration/general_settings_spec.rb +0 -45
  148. data/spec/features/admin/configuration/payment_methods_spec.rb +0 -125
  149. data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -64
  150. data/spec/features/admin/configuration/states_spec.rb +0 -64
  151. data/spec/features/admin/configuration/stock_locations_spec.rb +0 -50
  152. data/spec/features/admin/configuration/tax_categories_spec.rb +0 -56
  153. data/spec/features/admin/configuration/tax_rates_spec.rb +0 -30
  154. data/spec/features/admin/configuration/taxonomies_spec.rb +0 -52
  155. data/spec/features/admin/configuration/zones_spec.rb +0 -39
  156. data/spec/features/admin/homepage_spec.rb +0 -78
  157. data/spec/features/admin/locale_spec.rb +0 -30
  158. data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -53
  159. data/spec/features/admin/orders/adjustments_spec.rb +0 -126
  160. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -48
  161. data/spec/features/admin/orders/cancelling_inventory_spec.rb +0 -48
  162. data/spec/features/admin/orders/customer_details_spec.rb +0 -163
  163. data/spec/features/admin/orders/line_items_spec.rb +0 -50
  164. data/spec/features/admin/orders/listing_spec.rb +0 -130
  165. data/spec/features/admin/orders/log_entries_spec.rb +0 -55
  166. data/spec/features/admin/orders/new_order_spec.rb +0 -197
  167. data/spec/features/admin/orders/order_details_spec.rb +0 -533
  168. data/spec/features/admin/orders/payments_spec.rb +0 -228
  169. data/spec/features/admin/orders/risk_analysis_spec.rb +0 -47
  170. data/spec/features/admin/orders/shipments_spec.rb +0 -65
  171. data/spec/features/admin/payments/store_credits_spec.rb +0 -21
  172. data/spec/features/admin/products/edit/images_spec.rb +0 -87
  173. data/spec/features/admin/products/edit/products_spec.rb +0 -66
  174. data/spec/features/admin/products/edit/taxons_spec.rb +0 -56
  175. data/spec/features/admin/products/edit/variants_spec.rb +0 -61
  176. data/spec/features/admin/products/option_types_spec.rb +0 -114
  177. data/spec/features/admin/products/products_spec.rb +0 -392
  178. data/spec/features/admin/products/properties_spec.rb +0 -139
  179. data/spec/features/admin/products/prototypes_spec.rb +0 -110
  180. data/spec/features/admin/products/stock_management_spec.rb +0 -82
  181. data/spec/features/admin/products/variant_spec.rb +0 -51
  182. data/spec/features/admin/promotion_adjustments_spec.rb +0 -220
  183. data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -69
  184. data/spec/features/admin/promotions/user_rule_spec.rb +0 -25
  185. data/spec/features/admin/reports_spec.rb +0 -61
  186. data/spec/features/admin/stock_transfer_spec.rb +0 -86
  187. data/spec/features/admin/store_credits_spec.rb +0 -82
  188. data/spec/features/admin/taxons_spec.rb +0 -31
  189. data/spec/features/admin/users_spec.rb +0 -270
  190. data/spec/helpers/admin/base_helper_spec.rb +0 -24
  191. data/spec/helpers/admin/navigation_helper_spec.rb +0 -73
  192. data/spec/helpers/admin/reimbursements_helper_spec.rb +0 -34
  193. data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -29
  194. data/spec/helpers/admin/store_credit_events_helper_spec.rb +0 -95
  195. data/spec/helpers/promotion_rules_helper_spec.rb +0 -12
  196. data/spec/spec_helper.rb +0 -108
  197. data/spec/support/appear_before_matcher.rb +0 -8
  198. data/spec/support/ror_ringer.jpeg +0 -0
  199. data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
  200. data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
  201. data/vendor/assets/javascripts/handlebars.js +0 -2746
@@ -1,27 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,104 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,50 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,331 +0,0 @@
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