solidus_backend 2.10.2 → 2.11.0

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 (233) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend.js +4 -1
  3. data/app/assets/javascripts/spree/backend/adjustments.js +1 -1
  4. data/app/assets/javascripts/spree/backend/admin.js +18 -29
  5. data/app/assets/javascripts/spree/backend/collections/states.js +1 -1
  6. data/app/assets/javascripts/spree/backend/components/selectable_table.js +5 -0
  7. data/app/assets/javascripts/spree/backend/components/selectable_table/return_items.js +5 -0
  8. data/app/assets/javascripts/spree/backend/components/selectable_table/summary.js +7 -0
  9. data/app/assets/javascripts/spree/backend/components/sortable_table.js +31 -25
  10. data/app/assets/javascripts/spree/backend/models/order.js +3 -3
  11. data/app/assets/javascripts/spree/backend/models/payment.js +1 -1
  12. data/app/assets/javascripts/spree/backend/models/shipment.js +1 -1
  13. data/app/assets/javascripts/spree/backend/models/stock_item.js +1 -1
  14. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +2 -2
  15. data/app/assets/javascripts/spree/backend/option_value_picker.js +2 -2
  16. data/app/assets/javascripts/spree/backend/product_picker.js +2 -2
  17. data/app/assets/javascripts/spree/backend/routes.js +40 -21
  18. data/app/assets/javascripts/spree/backend/shipments.js +5 -5
  19. data/app/assets/javascripts/spree/backend/shipping_methods/stock_locations_picker.js +18 -0
  20. data/app/assets/javascripts/spree/backend/stock_management.js +4 -2
  21. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +2 -2
  22. data/app/assets/javascripts/spree/backend/taxons.js +3 -3
  23. data/app/assets/javascripts/spree/backend/templates/index.js +2 -0
  24. data/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs +2 -2
  25. data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +5 -1
  26. data/app/assets/javascripts/spree/backend/templates/tables/return_item_sum_amount.hbs +7 -0
  27. data/app/assets/javascripts/spree/backend/templates/tables/selectable_label.hbs +6 -0
  28. data/app/assets/javascripts/spree/backend/user_picker.js +3 -4
  29. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +2 -2
  30. data/app/assets/javascripts/spree/backend/views/cart/empty_cart_button.js +2 -2
  31. data/app/assets/javascripts/spree/backend/views/index.js +4 -0
  32. data/app/assets/javascripts/spree/backend/views/order/address.js +1 -1
  33. data/app/assets/javascripts/spree/backend/views/order/customer_select.js +2 -3
  34. data/app/assets/javascripts/spree/backend/views/order/details_adjustments.js +4 -1
  35. data/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +4 -0
  36. data/app/assets/javascripts/spree/backend/views/tables/return_items.js +9 -0
  37. data/app/assets/javascripts/spree/backend/views/tables/selectable_table.js +70 -0
  38. data/app/assets/javascripts/spree/backend/views/tables/selectable_table/sum_return_item_amount.js +32 -0
  39. data/app/assets/javascripts/spree/backend/views/tables/selectable_table/summary.js +45 -0
  40. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +4 -5
  41. data/app/assets/stylesheets/spree/backend/sections/_orders.scss +5 -1
  42. data/app/assets/stylesheets/spree/backend/sections/_style_guide.scss +4 -0
  43. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +1 -0
  44. data/app/controllers/spree/admin/base_controller.rb +6 -0
  45. data/app/controllers/spree/admin/cancellations_controller.rb +2 -0
  46. data/app/controllers/spree/admin/customer_returns_controller.rb +4 -4
  47. data/app/controllers/spree/admin/images_controller.rb +2 -1
  48. data/app/controllers/spree/admin/orders/customer_details_controller.rb +2 -0
  49. data/app/controllers/spree/admin/orders_controller.rb +7 -2
  50. data/app/controllers/spree/admin/payments_controller.rb +3 -1
  51. data/app/controllers/spree/admin/product_properties_controller.rb +1 -1
  52. data/app/controllers/spree/admin/products_controller.rb +18 -24
  53. data/app/controllers/spree/admin/promotion_codes_controller.rb +9 -4
  54. data/app/controllers/spree/admin/refunds_controller.rb +19 -0
  55. data/app/controllers/spree/admin/resource_controller.rb +27 -7
  56. data/app/controllers/spree/admin/return_authorizations_controller.rb +1 -1
  57. data/app/controllers/spree/admin/root_controller.rb +1 -1
  58. data/app/controllers/spree/admin/search_controller.rb +1 -2
  59. data/app/controllers/spree/admin/stock_items_controller.rb +6 -5
  60. data/app/controllers/spree/admin/stock_locations_controller.rb +4 -0
  61. data/app/controllers/spree/admin/stock_movements_controller.rb +7 -0
  62. data/app/controllers/spree/admin/taxons_controller.rb +12 -1
  63. data/app/controllers/spree/admin/users/api_key_controller.rb +29 -0
  64. data/app/controllers/spree/admin/users_controller.rb +37 -20
  65. data/app/controllers/spree/admin/variants_controller.rb +4 -2
  66. data/app/controllers/spree/admin/zones_controller.rb +1 -1
  67. data/app/helpers/spree/admin/base_helper.rb +4 -0
  68. data/app/helpers/spree/admin/customer_returns_helper.rb +1 -1
  69. data/app/helpers/spree/admin/navigation_helper.rb +1 -1
  70. data/app/helpers/spree/admin/orders_helper.rb +8 -4
  71. data/app/helpers/spree/admin/stock_movements_helper.rb +8 -4
  72. data/app/views/spree/admin/customer_returns/_return_item_selection.html.erb +2 -3
  73. data/app/views/spree/admin/images/index.html.erb +25 -21
  74. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +8 -1
  75. data/app/views/spree/admin/option_types/edit.html.erb +3 -1
  76. data/app/views/spree/admin/orders/customer_details/_form.html.erb +13 -13
  77. data/app/views/spree/admin/orders/index.html.erb +23 -13
  78. data/app/views/spree/admin/payment_methods/_form.html.erb +7 -2
  79. data/app/views/spree/admin/payments/index.html.erb +3 -1
  80. data/app/views/spree/admin/prices/_master_variant_table.html.erb +3 -3
  81. data/app/views/spree/admin/prices/_table.html.erb +3 -3
  82. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +7 -2
  83. data/app/views/spree/admin/product_properties/index.html.erb +14 -2
  84. data/app/views/spree/admin/products/_form.html.erb +13 -2
  85. data/app/views/spree/admin/products/index.html.erb +1 -1
  86. data/app/views/spree/admin/promotion_codes/index.html.erb +1 -1
  87. data/app/views/spree/admin/promotions/_actions.html.erb +1 -1
  88. data/app/views/spree/admin/promotions/_activations_new.html.erb +1 -1
  89. data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
  90. data/app/views/spree/admin/promotions/edit.html.erb +2 -2
  91. data/app/views/spree/admin/promotions/index.html.erb +12 -5
  92. data/app/views/spree/admin/return_authorizations/_form.html.erb +3 -10
  93. data/app/views/spree/admin/return_authorizations/index.html.erb +1 -1
  94. data/app/views/spree/admin/search/users.json.jbuilder +15 -1
  95. data/app/views/spree/admin/shared/_address.html.erb +6 -6
  96. data/app/views/spree/admin/shared/_address_form.html.erb +15 -8
  97. data/app/views/spree/admin/shared/_order_submenu.html.erb +4 -4
  98. data/app/views/spree/admin/shared/_payments_tabs.html.erb +1 -1
  99. data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +5 -5
  100. data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +6 -6
  101. data/app/views/spree/admin/shared/_shipping_tabs.html.erb +3 -3
  102. data/app/views/spree/admin/shared/_taxes_tabs.html.erb +2 -2
  103. data/app/views/spree/admin/shared/preference_fields/_encrypted_string.html.erb +12 -0
  104. data/app/views/spree/admin/shipping_methods/_form.html.erb +18 -0
  105. data/app/views/spree/admin/stock_items/_stock_management.html.erb +1 -1
  106. data/app/views/spree/admin/stock_locations/edit.html.erb +1 -1
  107. data/app/views/spree/admin/stock_locations/index.html.erb +3 -1
  108. data/app/views/spree/admin/stock_movements/index.html.erb +30 -1
  109. data/app/views/spree/admin/stores/_form.html.erb +6 -0
  110. data/app/views/spree/admin/style_guide/topics/tables/_building_tables.html.erb +27 -3
  111. data/app/views/spree/admin/tax_categories/_form.html.erb +1 -0
  112. data/app/views/spree/admin/users/_form.html.erb +2 -2
  113. data/app/views/spree/admin/users/_tabs.html.erb +1 -1
  114. data/app/views/spree/admin/users/edit.html.erb +4 -4
  115. data/app/views/spree/admin/users/items.html.erb +5 -3
  116. data/app/views/spree/admin/users/orders.html.erb +5 -3
  117. data/app/views/spree/admin/variants/_table_filter.html.erb +1 -1
  118. data/app/views/spree/admin/variants/index.html.erb +2 -2
  119. data/config/initializers/form_builder.rb +2 -2
  120. data/lib/spree/backend/engine.rb +0 -2
  121. data/lib/spree/backend_configuration.rb +14 -1
  122. data/solidus_backend.gemspec +4 -4
  123. metadata +23 -122
  124. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +0 -35
  125. data/script/rails +0 -10
  126. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -26
  127. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +0 -83
  128. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -235
  129. data/spec/controllers/spree/admin/locale_controller_spec.rb +0 -45
  130. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
  131. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -128
  132. data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -408
  133. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -95
  134. data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -194
  135. data/spec/controllers/spree/admin/prices_controller_spec.rb +0 -45
  136. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +0 -71
  137. data/spec/controllers/spree/admin/products_controller_spec.rb +0 -270
  138. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -23
  139. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +0 -32
  140. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -36
  141. data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -122
  142. data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -35
  143. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -137
  144. data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -201
  145. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -291
  146. data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -29
  147. data/spec/controllers/spree/admin/root_controller_spec.rb +0 -43
  148. data/spec/controllers/spree/admin/search_controller_spec.rb +0 -106
  149. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -16
  150. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -52
  151. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -44
  152. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +0 -311
  153. data/spec/controllers/spree/admin/users_controller_spec.rb +0 -287
  154. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -71
  155. data/spec/features/admin/configuration/payment_methods_spec.rb +0 -176
  156. data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -126
  157. data/spec/features/admin/configuration/stock_locations_spec.rb +0 -54
  158. data/spec/features/admin/configuration/store_spec.rb +0 -62
  159. data/spec/features/admin/configuration/tax_categories_spec.rb +0 -58
  160. data/spec/features/admin/configuration/tax_rates_spec.rb +0 -31
  161. data/spec/features/admin/configuration/taxonomies_spec.rb +0 -61
  162. data/spec/features/admin/configuration/zones_spec.rb +0 -41
  163. data/spec/features/admin/homepage_spec.rb +0 -86
  164. data/spec/features/admin/javascript_format_money_spec.rb +0 -22
  165. data/spec/features/admin/locale_spec.rb +0 -34
  166. data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -55
  167. data/spec/features/admin/orders/adjustments_spec.rb +0 -130
  168. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -45
  169. data/spec/features/admin/orders/cancelling_inventory_spec.rb +0 -50
  170. data/spec/features/admin/orders/customer_details_spec.rb +0 -203
  171. data/spec/features/admin/orders/customer_returns_spec.rb +0 -41
  172. data/spec/features/admin/orders/line_items_spec.rb +0 -52
  173. data/spec/features/admin/orders/listing_spec.rb +0 -186
  174. data/spec/features/admin/orders/log_entries_spec.rb +0 -56
  175. data/spec/features/admin/orders/new_order_spec.rb +0 -379
  176. data/spec/features/admin/orders/new_refund_spec.rb +0 -35
  177. data/spec/features/admin/orders/order_details_spec.rb +0 -591
  178. data/spec/features/admin/orders/payments_spec.rb +0 -330
  179. data/spec/features/admin/orders/return_authorizations_spec.rb +0 -56
  180. data/spec/features/admin/orders/return_payment_state_spec.rb +0 -65
  181. data/spec/features/admin/orders/risk_analysis_spec.rb +0 -49
  182. data/spec/features/admin/orders/shipments_spec.rb +0 -145
  183. data/spec/features/admin/payments/store_credits_spec.rb +0 -23
  184. data/spec/features/admin/products/edit/images_spec.rb +0 -76
  185. data/spec/features/admin/products/edit/products_spec.rb +0 -92
  186. data/spec/features/admin/products/edit/taxons_spec.rb +0 -57
  187. data/spec/features/admin/products/edit/variants_spec.rb +0 -63
  188. data/spec/features/admin/products/option_types_spec.rb +0 -116
  189. data/spec/features/admin/products/pricing_spec.rb +0 -127
  190. data/spec/features/admin/products/products_spec.rb +0 -348
  191. data/spec/features/admin/products/properties_spec.rb +0 -141
  192. data/spec/features/admin/products/stock_management_spec.rb +0 -101
  193. data/spec/features/admin/products/variant_spec.rb +0 -89
  194. data/spec/features/admin/promotion_adjustments_spec.rb +0 -286
  195. data/spec/features/admin/promotions/option_value_rule_spec.rb +0 -90
  196. data/spec/features/admin/promotions/product_rule_spec.rb +0 -35
  197. data/spec/features/admin/promotions/promotion_categories_spec.rb +0 -83
  198. data/spec/features/admin/promotions/promotion_code_batches_spec.rb +0 -37
  199. data/spec/features/admin/promotions/promotion_code_spec.rb +0 -31
  200. data/spec/features/admin/promotions/promotion_spec.rb +0 -52
  201. data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -76
  202. data/spec/features/admin/promotions/user_rule_spec.rb +0 -42
  203. data/spec/features/admin/reimbursements_spec.rb +0 -18
  204. data/spec/features/admin/store_credits_spec.rb +0 -132
  205. data/spec/features/admin/stores_spec.rb +0 -37
  206. data/spec/features/admin/style_guide_spec.rb +0 -14
  207. data/spec/features/admin/taxons_spec.rb +0 -90
  208. data/spec/features/admin/users_spec.rb +0 -412
  209. data/spec/fixtures/files/ror_ringer.jpeg +0 -0
  210. data/spec/helpers/admin/base_helper_spec.rb +0 -49
  211. data/spec/helpers/admin/navigation_helper_spec.rb +0 -139
  212. data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -29
  213. data/spec/helpers/admin/store_credit_events_helper_spec.rb +0 -97
  214. data/spec/helpers/promotion_rules_helper_spec.rb +0 -14
  215. data/spec/javascripts/fixtures/_boot.html.erb +0 -8
  216. data/spec/javascripts/fixtures/number_with_currency/with_currency_select.html.erb +0 -3
  217. data/spec/javascripts/fixtures/number_with_currency/without_select.html.erb +0 -3
  218. data/spec/javascripts/format_money_spec.js +0 -48
  219. data/spec/javascripts/spec_helper.js +0 -13
  220. data/spec/javascripts/support/show_errors.js +0 -8
  221. data/spec/javascripts/support/with_translations.js +0 -11
  222. data/spec/javascripts/translation_spec.js +0 -58
  223. data/spec/javascripts/views/number_with_currency_spec.js +0 -72
  224. data/spec/lib/spree/backend_configuration/menu_item_spec.rb +0 -17
  225. data/spec/lib/spree/backend_configuration_spec.rb +0 -22
  226. data/spec/spec_helper.rb +0 -123
  227. data/spec/support/appear_before_matcher.rb +0 -10
  228. data/spec/support/feature/base_feature_helper.rb +0 -17
  229. data/spec/support/feature/order_feature_helper.rb +0 -27
  230. data/spec/teaspoon_env.rb +0 -51
  231. data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
  232. data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
  233. data/spec/views/spree/admin/shared/navigation_footer_spec.rb +0 -67
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Spree::Admin::ShippingMethodsController, type: :controller do
6
- stub_authorization!
7
-
8
- # Regression test for https://github.com/spree/spree/issues/1240
9
- it "should not hard-delete shipping methods" do
10
- shipping_method = stub_model(Spree::ShippingMethod)
11
- allow(Spree::ShippingMethod).to receive_messages find: shipping_method
12
- expect(shipping_method.deleted_at).to be_nil
13
- delete :destroy, params: { id: 1 }
14
- expect(shipping_method.reload.deleted_at).not_to be_nil
15
- end
16
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Spree
6
- module Admin
7
- describe StockItemsController, type: :controller do
8
- stub_authorization!
9
-
10
- describe "#create" do
11
- let!(:variant) { create(:variant) }
12
- let!(:stock_location) { variant.stock_locations.first }
13
- let(:stock_item) { variant.stock_items.first }
14
- let!(:user) { create :user }
15
-
16
- before { expect(controller).to receive(:try_spree_current_user).and_return(user) }
17
- before { request.env["HTTP_REFERER"] = "product_admin_page" }
18
-
19
- subject do
20
- post :create, params: { variant_id: variant, stock_location_id: stock_location, stock_movement: { quantity: 1, stock_item_id: stock_item.id } }
21
- end
22
-
23
- it "creates a stock movement with originator" do
24
- expect { subject }.to change { Spree::StockMovement.count }.by(1)
25
- stock_movement = Spree::StockMovement.last
26
- expect(stock_movement.originator_type).to eq "Spree::LegacyUser"
27
- end
28
- end
29
-
30
- describe "#index" do
31
- let!(:variant_1) { create(:variant) }
32
- let!(:variant_2) { create(:variant) }
33
-
34
- context "with product_slug param" do
35
- it "scopes the variants by the product" do
36
- get :index, params: { product_slug: variant_1.product.slug }
37
- expect(assigns(:variants)).to include variant_1
38
- expect(assigns(:variants)).not_to include variant_2
39
- end
40
- end
41
-
42
- context "without product_slug params" do
43
- it "allows all accessible variants to be returned" do
44
- get :index
45
- expect(assigns(:variants)).to include variant_1
46
- expect(assigns(:variants)).to include variant_2
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Spree
6
- module Admin
7
- describe StockLocationsController, type: :controller do
8
- stub_authorization!
9
-
10
- # Regression for https://github.com/spree/spree/issues/4272
11
- context "with no countries present" do
12
- it "cannot create a new stock location" do
13
- get :new
14
- expect(flash[:error]).to eq(I18n.t('spree.stock_locations_need_a_default_country'))
15
- expect(response).to redirect_to(spree.admin_stock_locations_path)
16
- end
17
- end
18
-
19
- context "with a default country other than the US present" do
20
- let(:country) { create :country, iso: "BR" }
21
-
22
- before do
23
- stub_spree_preferences(default_country_iso: country.iso)
24
- end
25
-
26
- it "can create a new stock location" do
27
- get :new
28
- expect(response).to be_successful
29
- end
30
- end
31
-
32
- context "with a country with the ISO code of 'US' existing" do
33
- before do
34
- FactoryBot.create(:country, iso: 'US')
35
- end
36
-
37
- it "can create a new stock location" do
38
- get :new
39
- expect(response).to be_successful
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,311 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- shared_examples "update reason loader" do
6
- it "sets the store_credit_reasons variable to a list of categories sorted by category name " do
7
- expect(assigns(:store_credit_reasons)).to eq [store_credit_reason]
8
- end
9
- end
10
-
11
- describe Spree::Admin::StoreCreditsController do
12
- stub_authorization!
13
-
14
- let(:user) { create(:user) }
15
- let(:admin_user) { create(:admin_user) }
16
-
17
- let!(:b_credit_category) { create(:store_credit_category, name: "B category") }
18
- let!(:a_credit_category) { create(:store_credit_category, name: "A category") }
19
- let!(:store_credit_reason) { create(:store_credit_reason) }
20
-
21
- describe "#show" do
22
- let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
23
- let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
24
-
25
- before { get :show, params: { user_id: user.id, id: store_credit.id } }
26
-
27
- it "sets the store_credit variable to a new store credit model" do
28
- expect(assigns(:store_credit)).to eq store_credit
29
- end
30
-
31
- it "sets the store_credit_events variable to the store credit's events in chronological order" do
32
- allocation_event = store_credit.store_credit_events.find_by(action: Spree::StoreCredit::ALLOCATION_ACTION)
33
- expect(assigns(:store_credit_events)).to eq [event, allocation_event]
34
- end
35
- end
36
-
37
- describe "#new" do
38
- before { get :new, params: { user_id: create(:user).id } }
39
- it { expect(assigns(:credit_categories)).to eq [a_credit_category, b_credit_category] }
40
- end
41
-
42
- describe "#create" do
43
- subject { post :create, params: parameters }
44
-
45
- before {
46
- allow(controller).to receive_messages(try_spree_current_user: admin_user)
47
- create(:primary_credit_type)
48
- }
49
-
50
- context "the passed parameters are valid" do
51
- let(:parameters) do
52
- {
53
- user_id: user.id,
54
- store_credit: {
55
- amount: 1.00,
56
- currency: "USD",
57
- category_id: a_credit_category.id
58
- }
59
- }
60
- end
61
-
62
- it "creates a new store credit" do
63
- expect { subject }.to change(Spree::StoreCredit, :count).by(1)
64
- end
65
-
66
- it "associates the store credit with the user" do
67
- subject
68
- expect(user.reload.store_credits.count).to eq 1
69
- end
70
-
71
- it "assigns the store credit's created by to the current user" do
72
- subject
73
- expect(user.reload.store_credits.first.created_by).to eq admin_user
74
- end
75
-
76
- it 'sets the admin as the store credit event originator' do
77
- expect { subject }.to change { Spree::StoreCreditEvent.count }.by(1)
78
- expect(Spree::StoreCreditEvent.last.originator).to eq admin_user
79
- end
80
- end
81
-
82
- context "the passed parameters are invalid" do
83
- let(:parameters) do
84
- {
85
- user_id: user.id,
86
- store_credit: {
87
- amount: -1.00,
88
- category_id: a_credit_category.id
89
- }
90
- }
91
- end
92
-
93
- it { expect { subject }.not_to change(Spree::StoreCredit, :count) }
94
- end
95
- end
96
-
97
- describe "#edit_amount" do
98
- let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
99
-
100
- before { get :edit_amount, params: { user_id: user.id, id: store_credit.id } }
101
-
102
- it_behaves_like "update reason loader"
103
-
104
- it "sets the store_credit variable to the persisted store credit" do
105
- expect(assigns(:store_credit)).to eq store_credit
106
- end
107
- end
108
-
109
- describe "#edit_validity" do
110
- let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
111
-
112
- before { get :edit_validity, params: { user_id: user.id, id: store_credit.id } }
113
-
114
- it_behaves_like "update reason loader"
115
-
116
- it "sets the store_credit variable to the persisted store credit" do
117
- expect(assigns(:store_credit)).to eq store_credit
118
- end
119
- end
120
-
121
- describe "#update" do
122
- let(:memo) { "New memo" }
123
- let!(:store_credit) { create(:store_credit, user: user) }
124
-
125
- subject { put :update, params: parameters.merge(format: :json) }
126
-
127
- before { allow(controller).to receive_messages(try_spree_current_user: admin_user) }
128
-
129
- context "the passed parameters are valid" do
130
- let(:parameters) do
131
- {
132
- user_id: user.id,
133
- id: store_credit.id,
134
- store_credit: {
135
- memo: memo
136
- }
137
- }
138
- end
139
-
140
- it "updates the memo to be the passed in value" do
141
- expect { subject }.to change { store_credit.reload.memo }.to(memo)
142
- end
143
-
144
- it "returns a success message" do
145
- subject
146
- expect(response).to have_http_status(:ok)
147
- expect(JSON.parse(response.body)['message']).to match("Store Credit has been successfully updated!")
148
- end
149
- end
150
-
151
- context "the passed parameters are invalid" do
152
- let(:parameters) do
153
- {
154
- user_id: user.id,
155
- id: store_credit.id,
156
- store_credit: {
157
- category_id: b_credit_category.id
158
- }
159
- }
160
- end
161
- it "doesn't update the store credit's category" do
162
- expect { subject }.to_not change { store_credit.reload.category }
163
- end
164
-
165
- it "returns an error message" do
166
- subject
167
- expect(response).to have_http_status(:bad_request)
168
- expect(JSON.parse(response.body)['message']).to match("Unable to update store credit")
169
- end
170
- end
171
- end
172
-
173
- describe "#update_amount" do
174
- let(:original_amount) { 100.0 }
175
- let!(:store_credit) { create(:store_credit, user: user, amount: original_amount) }
176
- let!(:store_credit_reason) { create(:store_credit_reason) }
177
- let(:parameters) do
178
- {
179
- user_id: user.id,
180
- id: store_credit.id,
181
- store_credit_reason_id: store_credit_reason.id,
182
- store_credit: {
183
- amount: updated_amount
184
- }
185
- }
186
- end
187
-
188
- subject { put :update_amount, params: parameters }
189
-
190
- before { allow(controller).to receive_messages(try_spree_current_user: admin_user) }
191
-
192
- context "the passed parameters are valid" do
193
- let(:updated_amount) { 300.0 }
194
-
195
- context "the store credit has been partially used" do
196
- before { store_credit.update(amount_used: 10.0) }
197
-
198
- context "the new amount is greater than the used amount" do
199
- let(:updated_amount) { 11.0 }
200
-
201
- before { subject }
202
-
203
- it "updates the amount to be the passed in amount" do
204
- expect(store_credit.reload.amount).to eq updated_amount
205
- end
206
- end
207
-
208
- context "the new amount is less than the used amount" do
209
- let(:updated_amount) { 9.0 }
210
-
211
- before { subject }
212
-
213
- it "does not update the amount" do
214
- expect(store_credit.reload.amount).to eq original_amount
215
- end
216
-
217
- it "renders the edit_amount template" do
218
- expect(response).to render_template :edit_amount
219
- end
220
-
221
- it "adds an error message to the flash" do
222
- expect(flash.now[:error]).to match "Unable to update"
223
- end
224
-
225
- it_behaves_like "update reason loader"
226
- end
227
- end
228
-
229
- context "the store credit has not been used" do
230
- it "sets a success message in the flash" do
231
- subject
232
- expect(flash.now[:success]).to match "Store Credit has been successfully updated!"
233
- end
234
-
235
- it "does not create a new store credit" do
236
- expect { subject }.to_not change(Spree::StoreCredit, :count)
237
- end
238
-
239
- it "updates passed amount" do
240
- subject
241
- expect(store_credit.reload.amount).to eq updated_amount
242
- end
243
- end
244
- end
245
-
246
- context "the passed parameters are invalid" do
247
- let(:updated_amount) { -1.00 }
248
-
249
- before { subject }
250
-
251
- it "does not update the amount" do
252
- expect(store_credit.reload.amount).to eq original_amount
253
- end
254
-
255
- it "renders the edit_amount template" do
256
- expect(response).to render_template :edit_amount
257
- end
258
-
259
- it "adds an error message to the flash" do
260
- expect(flash.now[:error]).to match "Unable to update"
261
- end
262
-
263
- it_behaves_like "update reason loader"
264
- end
265
- end
266
-
267
- describe "#invalidate" do
268
- let!(:store_credit) { create(:store_credit, user: user, category: b_credit_category) }
269
-
270
- let(:parameters) do
271
- {
272
- user_id: user.id,
273
- id: store_credit.id,
274
- store_credit_reason_id: store_credit_reason.id
275
- }
276
- end
277
-
278
- subject { put :invalidate, params: parameters }
279
-
280
- it "attempts to invalidate the store credit" do
281
- expect { subject }.to change { store_credit.reload.invalidated_at }.from(nil)
282
- end
283
-
284
- context "the invalidation is unsuccessful" do
285
- before do
286
- store_credit.authorize(5.0, "USD")
287
- subject
288
- end
289
-
290
- it "doesn't invalidate the store credit" do
291
- expect(store_credit.reload.invalidated_at).to be_nil
292
- end
293
-
294
- it "renders the edit_validity template" do
295
- expect(response).to render_template :edit_validity
296
- end
297
-
298
- it "sets an error message in the flash" do
299
- expect(flash.now[:error]).to match "Unable to invalidate store credit"
300
- end
301
-
302
- it_behaves_like "update reason loader"
303
- end
304
-
305
- context "the invalidation is successful" do
306
- it "redirects to index" do
307
- expect(subject).to redirect_to spree.admin_user_store_credit_path(user, store_credit)
308
- end
309
- end
310
- end
311
- end
@@ -1,287 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Spree::Admin::UsersController, type: :controller do
6
- let(:user) { create(:user) }
7
-
8
- let(:state) { create(:state, state_code: 'NY') }
9
- let(:valid_address_attributes) do
10
- {
11
- firstname: 'Foo',
12
- lastname: 'Bar',
13
- city: "New York",
14
- country_id: state.country.id,
15
- state_id: state.id,
16
- phone: '555-555-5555',
17
- address1: '123 Fake St.',
18
- zipcode: '10001',
19
- }
20
- end
21
-
22
- context "#show" do
23
- stub_authorization! do |_user|
24
- can [:admin, :manage], Spree.user_class
25
- end
26
-
27
- it "redirects to edit" do
28
- get :show, params: { id: user.id }
29
- expect(response).to redirect_to spree.edit_admin_user_path(user)
30
- end
31
- end
32
-
33
- context '#authorize_admin' do
34
- context "with ability to admin users" do
35
- stub_authorization! do |_user|
36
- can [:manage], Spree.user_class
37
- end
38
-
39
- it 'can visit index' do
40
- post :index
41
- expect(response).to be_successful
42
- end
43
-
44
- it "allows admins to update a user's API key" do
45
- expect {
46
- put :generate_api_key, params: { id: user.id }
47
- }.to change { user.reload.spree_api_key }
48
- expect(response).to redirect_to(spree.edit_admin_user_path(user))
49
- end
50
-
51
- it "allows admins to clear a user's API key" do
52
- user.generate_spree_api_key!
53
- expect {
54
- put :clear_api_key, params: { id: user.id }
55
- }.to change{ user.reload.spree_api_key }.to(nil)
56
- expect(response).to redirect_to(spree.edit_admin_user_path(user))
57
- end
58
- end
59
-
60
- context "without ability to admin users" do
61
- stub_authorization! do |_user|
62
- end
63
-
64
- it 'denies access' do
65
- post :index
66
- expect(response).to redirect_to '/unauthorized'
67
- end
68
- end
69
- end
70
-
71
- describe "#create" do
72
- let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
73
-
74
- # The created user
75
- def user
76
- Spree.user_class.last
77
- end
78
-
79
- stub_authorization! do |_user|
80
- can :manage, Spree.user_class
81
- end
82
-
83
- context "when the user can manage roles" do
84
- stub_authorization! do |_user|
85
- can :manage, Spree.user_class
86
- can :manage, Spree::Role
87
- end
88
-
89
- it "can create user with roles" do
90
- post :create, params: { user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
91
- expect(user.spree_roles).to eq([dummy_role])
92
- end
93
-
94
- it "can create user without roles" do
95
- post :create, params: { user: { first_name: "Bob" } }
96
- expect(user.spree_roles).to eq([])
97
- end
98
- end
99
-
100
- context "when the user cannot manage roles" do
101
- it "cannot assign users roles" do
102
- post :create, params: { user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
103
- expect(user.spree_roles).to eq([])
104
- end
105
-
106
- it "can create user without roles" do
107
- post :create, params: { user: { first_name: "Bob" } }
108
- expect(user.spree_roles).to eq([])
109
- end
110
- end
111
-
112
- it "can create a shipping_address" do
113
- post :create, params: { user: { ship_address_attributes: valid_address_attributes } }
114
- expect(user.reload.ship_address.city).to eq('New York')
115
- end
116
-
117
- it "can create a billing_address" do
118
- post :create, params: { user: { bill_address_attributes: valid_address_attributes } }
119
- expect(user.reload.bill_address.city).to eq('New York')
120
- end
121
-
122
- it "can set stock locations" do
123
- location = Spree::StockLocation.create(name: "my_location")
124
- location_2 = Spree::StockLocation.create(name: "my_location_2")
125
- post :create, params: { user: { stock_location_ids: [location.id, location_2.id] } }
126
- expect(user.stock_locations).to match_array([location, location_2])
127
- end
128
- end
129
-
130
- describe "#update" do
131
- let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
132
- let(:ability) { Spree::Ability.new(user) }
133
-
134
- stub_authorization! do |_user|
135
- can :manage, Spree.user_class
136
- end
137
-
138
- context "when the user can manage roles" do
139
- stub_authorization! do |_user|
140
- can :manage, Spree.user_class
141
- can :manage, Spree::Role
142
- end
143
-
144
- it "can set roles" do
145
- expect {
146
- put :update, params: { id: user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
147
- }.to change { user.reload.spree_roles.to_a }.to([dummy_role])
148
- end
149
-
150
- it "can clear roles" do
151
- user.spree_roles << dummy_role
152
- expect {
153
- put :update, params: { id: user.id, user: { first_name: "Bob", spree_role_ids: [""] } }
154
- }.to change { user.reload.spree_roles.to_a }.to([])
155
- end
156
-
157
- context 'when no role params are present' do
158
- it 'does not clear all present user roles' do
159
- user.spree_roles << dummy_role
160
- put :update, params: { id: user.id, user: { first_name: "Bob" } }
161
- expect(user.reload.spree_roles).to_not be_empty
162
- end
163
- end
164
- end
165
-
166
- context "when the user cannot manage roles" do
167
- it "cannot set roles" do
168
- expect {
169
- put :update, params: { id: user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
170
- }.not_to change { user.reload.spree_roles.to_a }
171
- end
172
-
173
- it "cannot clear roles" do
174
- user.spree_roles << dummy_role
175
- expect {
176
- put :update, params: { id: user.id, user: { first_name: "Bob" } }
177
- }.not_to change { user.reload.spree_roles.to_a }
178
- end
179
- end
180
-
181
- context "allowed to update email" do
182
- stub_authorization! do |_user|
183
- can [:admin, :update, :update_email], Spree.user_class
184
- end
185
-
186
- it "can change email of a user" do
187
- expect {
188
- put :update, params: { id: user.id, user: { email: "bob@example.com" } }
189
- }.to change { user.reload.email }.to("bob@example.com")
190
- end
191
- end
192
-
193
- context "not allowed to update email" do
194
- stub_authorization! do |_user|
195
- can [:admin, :update], Spree.user_class
196
- end
197
-
198
- it "cannot change email of a user" do
199
- expect {
200
- put :update, params: { id: user.id, user: { email: "bob@example.com" } }
201
- }.not_to change { user.reload.email }
202
- end
203
- end
204
-
205
- context "allowed to update passwords" do
206
- it "can change password of a user" do
207
- expect {
208
- put :update, params: { id: user.id, user: { password: "diff123", password_confirmation: "diff123" } }
209
- }.to_not raise_error
210
- end
211
- end
212
-
213
- context "not allowed to update passwords" do
214
- stub_authorization! do |_user|
215
- can [:admin, :update], Spree.user_class
216
- end
217
-
218
- it "cannot change password of a user" do
219
- allow(ActionController::Parameters).
220
- to receive(:action_on_unpermitted_parameters).and_return(:raise)
221
-
222
- expect {
223
- put :update, params: { id: user.id, user: { password: "diff123", password_confirmation: "diff123" } }
224
- }.to raise_error(ActionController::UnpermittedParameters)
225
- end
226
- end
227
-
228
- it "can update ship_address attributes" do
229
- post :update, params: { id: user.id, user: { ship_address_attributes: valid_address_attributes } }
230
- expect(user.reload.ship_address.city).to eq('New York')
231
- end
232
-
233
- it "can update bill_address attributes" do
234
- post :update, params: { id: user.id, user: { bill_address_attributes: valid_address_attributes } }
235
- expect(user.reload.bill_address.city).to eq('New York')
236
- end
237
-
238
- it "can set stock locations" do
239
- location = Spree::StockLocation.create(name: "my_location")
240
- location_2 = Spree::StockLocation.create(name: "my_location_2")
241
- post :update, params: { id: user.id, user: { stock_location_ids: [location.id, location_2.id] } }
242
- expect(user.stock_locations).to match_array([location, location_2])
243
- end
244
- end
245
-
246
- describe "#orders" do
247
- stub_authorization! do |_user|
248
- can :manage, Spree.user_class
249
- end
250
-
251
- let(:order) { create(:order) }
252
- before { user.orders << order }
253
-
254
- it "assigns a list of the users orders" do
255
- get :orders, params: { id: user.id }
256
- expect(assigns[:orders].count).to eq 1
257
- expect(assigns[:orders].first).to eq order
258
- end
259
-
260
- it "assigns a ransack search for Spree::Order" do
261
- get :orders, params: { id: user.id }
262
- expect(assigns[:search]).to be_a Ransack::Search
263
- expect(assigns[:search].klass).to eq Spree::Order
264
- end
265
- end
266
-
267
- describe "#items" do
268
- stub_authorization! do |_user|
269
- can :manage, Spree.user_class
270
- end
271
-
272
- let(:order) { create(:order) }
273
- before { user.orders << order }
274
-
275
- it "assigns a list of the users orders" do
276
- get :items, params: { id: user.id }
277
- expect(assigns[:orders].count).to eq 1
278
- expect(assigns[:orders].first).to eq order
279
- end
280
-
281
- it "assigns a ransack search for Spree::Order" do
282
- get :items, params: { id: user.id }
283
- expect(assigns[:search]).to be_a Ransack::Search
284
- expect(assigns[:search].klass).to eq Spree::Order
285
- end
286
- end
287
- end