solidus_backend 2.7.4 → 2.9.2

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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -8
  3. data/app/assets/images/favicon.ico +0 -0
  4. data/app/assets/javascripts/spree/backend.js +0 -2
  5. data/app/assets/javascripts/spree/backend/adjustments.js +1 -1
  6. data/app/assets/javascripts/spree/backend/components/sortable_table.js +1 -0
  7. data/app/assets/javascripts/spree/backend/components/tabs.js +1 -0
  8. data/app/assets/javascripts/spree/backend/components/tooltips.js +21 -17
  9. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +1 -1
  10. data/app/assets/javascripts/spree/backend/product_picker.js +1 -1
  11. data/app/assets/javascripts/spree/backend/shipments.js +7 -1
  12. data/app/assets/javascripts/spree/backend/stock_management.js +18 -0
  13. data/app/assets/javascripts/spree/backend/store_credits.js +18 -2
  14. data/app/assets/javascripts/spree/backend/taxons.js +1 -1
  15. data/app/assets/javascripts/spree/backend/templates/orders/line_item.hbs +1 -1
  16. data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +24 -25
  17. data/app/assets/javascripts/spree/backend/user_picker.js +1 -1
  18. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +1 -1
  19. data/app/assets/javascripts/spree/backend/views/order/customer_select.js +1 -1
  20. data/app/assets/javascripts/spree/backend/views/order/summary.js +2 -2
  21. data/app/assets/javascripts/spree/backend/views/stock/add_stock_item.js +15 -4
  22. data/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +46 -10
  23. data/app/assets/stylesheets/spree/backend/_bootstrap_custom.scss +24 -16
  24. data/app/assets/stylesheets/spree/backend/components/_breadcrumb.scss +12 -0
  25. data/app/assets/stylesheets/spree/backend/components/_buttons.scss +18 -0
  26. data/app/assets/stylesheets/spree/backend/components/_image_placeholder.scss +2 -2
  27. data/app/assets/stylesheets/spree/backend/components/_list_group.scss +2 -2
  28. data/app/assets/stylesheets/spree/backend/components/_messages.scss +20 -12
  29. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +45 -11
  30. data/app/assets/stylesheets/spree/backend/components/_progress.scss +3 -3
  31. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +1 -2
  32. data/app/assets/stylesheets/spree/backend/components/_tabs.scss +14 -13
  33. data/app/assets/stylesheets/spree/backend/globals/_deprecated_variables.scss +24 -0
  34. data/app/assets/stylesheets/spree/backend/globals/_deprecation.scss +10 -1
  35. data/app/assets/stylesheets/spree/backend/globals/_functions.scss +2 -0
  36. data/app/assets/stylesheets/spree/backend/globals/_variables.scss +88 -57
  37. data/app/assets/stylesheets/spree/backend/globals/_variables_override.scss +1 -0
  38. data/app/assets/stylesheets/spree/backend/globals/mixins/_caret.scss +1 -1
  39. data/app/assets/stylesheets/spree/backend/globals/mixins/_line_through.scss +1 -1
  40. data/app/assets/stylesheets/spree/backend/sections/_log_entries.scss +8 -2
  41. data/app/assets/stylesheets/spree/backend/sections/_orders.scss +25 -6
  42. data/app/assets/stylesheets/spree/backend/sections/_products.scss +3 -1
  43. data/app/assets/stylesheets/spree/backend/sections/_promotions.scss +5 -5
  44. data/app/assets/stylesheets/spree/backend/sections/_stock_management.scss +77 -2
  45. data/app/assets/stylesheets/spree/backend/sections/_style_guide.scss +4 -4
  46. data/app/assets/stylesheets/spree/backend/sections/_taxonomies.scss +1 -1
  47. data/app/assets/stylesheets/spree/backend/shared/_fonts.scss +15 -0
  48. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +27 -7
  49. data/app/assets/stylesheets/spree/backend/shared/_header.scss +2 -2
  50. data/app/assets/stylesheets/spree/backend/shared/_icons.scss +5 -1
  51. data/app/assets/stylesheets/spree/backend/shared/_layout.scss +5 -4
  52. data/app/assets/stylesheets/spree/backend/shared/_tables.scss +11 -6
  53. data/app/assets/stylesheets/spree/backend/shared/_typography.scss +10 -6
  54. data/app/assets/stylesheets/spree/backend/spree_admin.scss +3 -1
  55. data/app/controllers/spree/admin/cancellations_controller.rb +2 -2
  56. data/app/controllers/spree/admin/customer_returns_controller.rb +8 -1
  57. data/app/controllers/spree/admin/locale_controller.rb +1 -1
  58. data/app/controllers/spree/admin/log_entries_controller.rb +3 -0
  59. data/app/controllers/spree/admin/orders/customer_details_controller.rb +8 -1
  60. data/app/controllers/spree/admin/orders_controller.rb +1 -12
  61. data/app/controllers/spree/admin/products_controller.rb +10 -6
  62. data/app/controllers/spree/admin/promotion_codes_controller.rb +19 -1
  63. data/app/controllers/spree/admin/promotions_controller.rb +1 -1
  64. data/app/controllers/spree/admin/reimbursements_controller.rb +7 -2
  65. data/app/controllers/spree/admin/resource_controller.rb +1 -0
  66. data/app/controllers/spree/admin/store_credit_reasons_controller.rb +8 -0
  67. data/app/controllers/spree/admin/store_credits_controller.rb +11 -11
  68. data/app/controllers/spree/admin/users_controller.rb +4 -2
  69. data/app/helpers/spree/admin/base_helper.rb +9 -3
  70. data/app/helpers/spree/admin/navigation_helper.rb +1 -1
  71. data/app/helpers/spree/admin/promotions_helper.rb +15 -0
  72. data/app/models/spree/backend_configuration.rb +38 -21
  73. data/app/views/spree/admin/cancellations/index.html.erb +3 -1
  74. data/app/views/spree/admin/images/_image_row.html.erb +1 -1
  75. data/app/views/spree/admin/images/edit.html.erb +3 -3
  76. data/app/views/spree/admin/images/index.html.erb +3 -3
  77. data/app/views/spree/admin/log_entries/index.html.erb +1 -19
  78. data/app/views/spree/admin/option_types/edit.html.erb +1 -1
  79. data/app/views/spree/admin/orders/_carton_manifest.html.erb +3 -1
  80. data/app/views/spree/admin/orders/_line_items_edit_form.html.erb +1 -1
  81. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +3 -1
  82. data/app/views/spree/admin/orders/confirm/_line_items.html.erb +3 -2
  83. data/app/views/spree/admin/orders/confirm/_shipment_manifest.html.erb +3 -1
  84. data/app/views/spree/admin/orders/index.html.erb +1 -1
  85. data/app/views/spree/admin/payments/_capture_events.html.erb +15 -18
  86. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  87. data/app/views/spree/admin/payments/_log_entries.html.erb +29 -0
  88. data/app/views/spree/admin/payments/show.html.erb +13 -6
  89. data/app/views/spree/admin/payments/source_forms/{_storecredit.html.erb → _store_credit.html.erb} +0 -0
  90. data/app/views/spree/admin/payments/source_views/{_storecredit.html.erb → _store_credit.html.erb} +0 -0
  91. data/app/views/spree/admin/prices/_form.html.erb +1 -1
  92. data/app/views/spree/admin/product_properties/index.html.erb +1 -1
  93. data/app/views/spree/admin/products/_form.html.erb +23 -12
  94. data/app/views/spree/admin/products/edit.html.erb +5 -0
  95. data/app/views/spree/admin/products/index.html.erb +3 -1
  96. data/app/views/spree/admin/promotion_categories/index.html.erb +1 -1
  97. data/app/views/spree/admin/promotion_code_batches/index.html.erb +1 -1
  98. data/app/views/spree/admin/promotion_codes/index.html.erb +5 -1
  99. data/app/views/spree/admin/promotion_codes/new.html.erb +31 -0
  100. data/app/views/spree/admin/promotions/_actions.html.erb +1 -1
  101. data/app/views/spree/admin/promotions/_activations_edit.html.erb +1 -1
  102. data/app/views/spree/admin/promotions/_form.html.erb +6 -5
  103. data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
  104. data/app/views/spree/admin/promotions/edit.html.erb +3 -1
  105. data/app/views/spree/admin/promotions/index.html.erb +4 -4
  106. data/app/views/spree/admin/refunds/new.html.erb +1 -1
  107. data/app/views/spree/admin/reimbursements/edit.html.erb +2 -2
  108. data/app/views/spree/admin/shared/_address_form.html.erb +10 -3
  109. data/app/views/spree/admin/shared/_edit_resource_links.html.erb +1 -1
  110. data/app/views/spree/admin/shared/_head.html.erb +1 -3
  111. data/app/views/spree/admin/shared/_image.html.erb +2 -2
  112. data/app/views/spree/admin/shared/_modal.html.erb +1 -1
  113. data/app/views/spree/admin/shared/_product_sub_menu.html.erb +1 -1
  114. data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +4 -0
  115. data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +3 -3
  116. data/app/views/spree/admin/shared/_tabs.html.erb +3 -2
  117. data/app/views/spree/admin/shared/_variant_search.html.erb +1 -1
  118. data/app/views/spree/admin/shipping_methods/_form.html.erb +10 -10
  119. data/app/views/spree/admin/stock_items/_stock_management.html.erb +56 -38
  120. data/app/views/spree/admin/stock_locations/_form.html.erb +133 -121
  121. data/app/views/spree/admin/stock_locations/edit.html.erb +4 -2
  122. data/app/views/spree/admin/store_credit_reasons/edit.html.erb +15 -0
  123. data/app/views/spree/admin/store_credit_reasons/index.html.erb +56 -0
  124. data/app/views/spree/admin/store_credit_reasons/new.html.erb +18 -0
  125. data/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb +15 -0
  126. data/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb +7 -0
  127. data/app/views/spree/admin/store_credits/edit_amount.html.erb +1 -1
  128. data/app/views/spree/admin/store_credits/edit_validity.html.erb +2 -2
  129. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  130. data/app/views/spree/admin/store_credits/show.html.erb +3 -3
  131. data/app/views/spree/admin/stores/_form.html.erb +1 -0
  132. data/app/views/spree/admin/style_guide/topics/typography/_colors.html.erb +30 -20
  133. data/app/views/spree/admin/style_guide/topics/typography/_fonts.html.erb +1 -1
  134. data/app/views/spree/admin/taxonomies/edit.html.erb +1 -1
  135. data/app/views/spree/admin/taxons/_form.html.erb +1 -1
  136. data/app/views/spree/admin/taxons/edit.html.erb +2 -2
  137. data/app/views/spree/admin/users/edit.html.erb +2 -2
  138. data/app/views/spree/admin/users/index.html.erb +2 -2
  139. data/app/views/spree/admin/users/items.html.erb +3 -1
  140. data/app/views/spree/admin/users/orders.html.erb +1 -1
  141. data/app/views/spree/admin/variants/_form.html.erb +1 -1
  142. data/app/views/spree/admin/variants/index.html.erb +1 -1
  143. data/app/views/spree/admin/zones/_state_members.html.erb +1 -1
  144. data/config/routes.rb +2 -8
  145. data/lib/spree/backend.rb +1 -1
  146. data/solidus_backend.gemspec +3 -4
  147. data/spec/controllers/spree/admin/base_controller_spec.rb +1 -1
  148. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +7 -3
  149. data/spec/controllers/spree/admin/locale_controller_spec.rb +45 -0
  150. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +50 -2
  151. data/spec/controllers/spree/admin/orders_controller_spec.rb +25 -13
  152. data/spec/controllers/spree/admin/payments_controller_spec.rb +1 -1
  153. data/spec/controllers/spree/admin/products_controller_spec.rb +72 -0
  154. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +13 -1
  155. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +11 -0
  156. data/spec/controllers/spree/admin/resource_controller_spec.rb +22 -0
  157. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +1 -1
  158. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +1 -1
  159. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +7 -7
  160. data/spec/features/admin/configuration/payment_methods_spec.rb +2 -2
  161. data/spec/features/admin/configuration/shipping_methods_spec.rb +2 -2
  162. data/spec/features/admin/homepage_spec.rb +1 -6
  163. data/spec/features/admin/locale_spec.rb +1 -2
  164. data/spec/features/admin/orders/adjustments_spec.rb +1 -1
  165. data/spec/features/admin/orders/customer_details_spec.rb +5 -7
  166. data/spec/features/admin/orders/customer_returns_spec.rb +28 -0
  167. data/spec/features/admin/orders/listing_spec.rb +2 -7
  168. data/spec/features/admin/orders/log_entries_spec.rb +2 -2
  169. data/spec/features/admin/orders/new_order_spec.rb +117 -0
  170. data/spec/features/admin/orders/new_refund_spec.rb +35 -0
  171. data/spec/features/admin/orders/order_details_spec.rb +10 -5
  172. data/spec/features/admin/orders/payments_spec.rb +82 -41
  173. data/spec/features/admin/orders/return_payment_state_spec.rb +3 -0
  174. data/spec/features/admin/orders/shipments_spec.rb +28 -0
  175. data/spec/features/admin/products/edit/products_spec.rb +25 -0
  176. data/spec/features/admin/products/edit/taxons_spec.rb +4 -0
  177. data/spec/features/admin/products/pricing_spec.rb +24 -6
  178. data/spec/features/admin/products/products_spec.rb +5 -5
  179. data/spec/features/admin/products/stock_management_spec.rb +27 -13
  180. data/spec/features/admin/products/variant_spec.rb +1 -1
  181. data/spec/features/admin/promotion_adjustments_spec.rb +12 -12
  182. data/spec/features/admin/promotions/option_value_rule_spec.rb +2 -2
  183. data/spec/features/admin/promotions/product_rule_spec.rb +1 -1
  184. data/spec/features/admin/promotions/promotion_spec.rb +52 -0
  185. data/spec/features/admin/promotions/tiered_calculator_spec.rb +1 -1
  186. data/spec/features/admin/promotions/user_rule_spec.rb +2 -2
  187. data/spec/features/admin/reimbursements_spec.rb +1 -1
  188. data/spec/features/admin/store_credits_spec.rb +51 -2
  189. data/spec/features/admin/taxons_spec.rb +35 -0
  190. data/spec/features/admin/users_spec.rb +44 -11
  191. data/spec/helpers/admin/navigation_helper_spec.rb +4 -2
  192. data/spec/helpers/admin/store_credit_events_helper_spec.rb +2 -2
  193. data/spec/javascripts/spec_helper.js +2 -0
  194. data/spec/models/spree/backend_configuration/menu_item_spec.rb +17 -0
  195. data/spec/models/spree/backend_configuration_spec.rb +22 -0
  196. data/spec/spec_helper.rb +2 -2
  197. data/spec/support/appear_before_matcher.rb +1 -1
  198. data/spec/support/feature/order_feature_helper.rb +1 -1
  199. data/spec/views/spree/admin/shared/navigation_footer_spec.rb +1 -1
  200. data/vendor/assets/fonts/inter/Inter-Regular.woff +0 -0
  201. data/vendor/assets/fonts/inter/Inter-Regular.woff2 +0 -0
  202. data/vendor/assets/fonts/inter/Inter-SemiBold.woff +0 -0
  203. data/vendor/assets/fonts/inter/Inter-SemiBold.woff2 +0 -0
  204. data/vendor/assets/javascripts/solidus_admin/select2_locales/select2_locale_en-US.js +10 -0
  205. data/vendor/assets/stylesheets/solidus_admin/bootstrap/_pagination.scss +4 -0
  206. metadata +38 -36
  207. data/.eslintrc +0 -21
  208. data/app/controllers/spree/admin/reports_controller.rb +0 -82
  209. data/app/views/spree/admin/reports/index.html.erb +0 -19
  210. data/app/views/spree/admin/reports/sales_total.html.erb +0 -35
  211. data/app/views/spree/admin/shared/_report_order_criteria.html.erb +0 -19
  212. data/app/views/spree/admin/store_credits/_update_reason_field.html.erb +0 -7
  213. data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -133
  214. data/spec/features/admin/reports_spec.rb +0 -63
@@ -26,12 +26,11 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.add_dependency 'coffee-rails'
28
28
  s.add_dependency 'font-awesome-rails', '~> 4.0'
29
- s.add_dependency 'jbuilder', '~> 2.6'
29
+ s.add_dependency 'jbuilder', '~> 2.8'
30
30
  s.add_dependency 'jquery-rails'
31
31
  s.add_dependency 'kaminari', '~> 1.1'
32
- s.add_dependency 'sass-rails'
33
- s.add_dependency 'sass', '>= 3.5.2'
32
+ s.add_dependency 'sassc-rails'
34
33
 
35
- s.add_dependency 'autoprefixer-rails', '~> 7.1'
34
+ s.add_dependency 'autoprefixer-rails'
36
35
  s.add_dependency 'handlebars_assets', '~> 0.23'
37
36
  end
@@ -15,7 +15,7 @@ describe Spree::Admin::BaseController, type: :controller do
15
15
 
16
16
  context "unauthorized request" do
17
17
  before do
18
- allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(nil)
18
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(nil)
19
19
  end
20
20
 
21
21
  it "redirects to unauthorized" do
@@ -22,7 +22,7 @@ describe Spree::Admin::CancellationsController do
22
22
  describe "#cancel" do
23
23
  subject { post :short_ship, params: { order_id: order.number, inventory_unit_ids: inventory_units.map(&:id) } }
24
24
 
25
- let(:order) { create(:order_ready_to_ship, number: "R100", state: "complete", line_items_count: 1) }
25
+ let(:order) { create(:order_with_line_items, line_items_attributes: [{ quantity: 4 }]) }
26
26
  let(:referer) { "order_admin_page" }
27
27
 
28
28
  context "no inventory unit ids are provided" do
@@ -67,12 +67,16 @@ describe Spree::Admin::CancellationsController do
67
67
  end
68
68
 
69
69
  it "creates a unit cancel" do
70
- expect { subject }.to change { Spree::UnitCancel.count }.by(1)
70
+ expect { subject }.to change { Spree::UnitCancel.count }.by(4)
71
71
  end
72
72
 
73
73
  it "cancels the inventory" do
74
74
  subject
75
- expect(order.inventory_units.map(&:state).uniq).to match_array(['canceled'])
75
+ expect(order.reload.inventory_units.map(&:state).uniq).to match_array(['canceled'])
76
+ end
77
+
78
+ it "adjusts the order" do
79
+ expect { subject }.to change { order.reload.total }.by(-40.0)
76
80
  end
77
81
  end
78
82
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Spree::Admin::LocaleController, type: :controller do
6
+ stub_authorization!
7
+
8
+ before { I18n.backend.store_translations(:fr, {}) }
9
+
10
+ after do
11
+ I18n.locale = :en
12
+ I18n.reload!
13
+ end
14
+
15
+ context 'switch_to_locale specified' do
16
+ let(:json_response) { JSON.parse(response.body, symbolize_names: true) }
17
+
18
+ before do
19
+ get :set, params: { switch_to_locale: switch_to_locale, format: :json }
20
+ end
21
+
22
+ context 'available locale' do
23
+ let(:switch_to_locale) { 'fr' }
24
+
25
+ it 'sets locale and returns the location for the redirect' do
26
+ expect(I18n.locale).to eq :fr
27
+ expect(session[:admin_locale]).to eq(switch_to_locale)
28
+ expect(json_response).
29
+ to eq({ locale: switch_to_locale,
30
+ location: spree.admin_url(host: 'test.host') })
31
+ expect(response).to have_http_status(:ok)
32
+ end
33
+ end
34
+
35
+ context 'unavailable locale' do
36
+ let(:switch_to_locale) { 'klingon' }
37
+
38
+ it 'does not change locale and returns 404' do
39
+ expect(I18n.locale).to eq :en
40
+ expect(json_response).to eq({ locale: 'en', })
41
+ expect(response).to have_http_status(:not_found)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -7,11 +7,59 @@ describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
7
7
  context "with authorization" do
8
8
  stub_authorization!
9
9
 
10
- let(:order) { create(:order, number: "R123456789") }
10
+ context '#edit' do
11
+ context 'when order has no shipping nor billing address' do
12
+ let(:order) { create(:order, number: "R123456789", ship_address: nil, bill_address: nil) }
11
13
 
12
- before { allow(Spree::Order).to receive_message_chain(:includes, :find_by!) { order } }
14
+ context "with a checkout_zone set as the country of Canada" do
15
+ let!(:united_states) { create(:country, iso: 'US', states_required: true) }
16
+ let!(:canada) { create(:country, iso: 'CA', states_required: true) }
17
+ let!(:checkout_zone) { create(:zone, name: "Checkout Zone", countries: [canada]) }
18
+
19
+ before do
20
+ stub_spree_preferences(checkout_zone: checkout_zone.name)
21
+ end
22
+
23
+ context "and default_country_iso of the Canada" do
24
+ before do
25
+ stub_spree_preferences(default_country_iso: Spree::Country.find_by!(iso: "CA").iso)
26
+ end
27
+
28
+ it 'defaults the shipping address country to Canada' do
29
+ get :edit, params: { order_id: order.number }
30
+ expect(assigns(:order).shipping_address.country_id).to eq canada.id
31
+ end
32
+
33
+ it 'defaults the billing address country to Canada' do
34
+ get :edit, params: { order_id: order.number }
35
+ expect(assigns(:order).billing_address.country_id).to eq canada.id
36
+ end
37
+ end
38
+
39
+ context "and default_country_iso of the United States" do
40
+ before do
41
+ stub_spree_preferences(default_country_iso: Spree::Country.find_by!(iso: "US").iso)
42
+ end
43
+
44
+ it 'defaults the shipping address country to nil' do
45
+ get :edit, params: { order_id: order.number }
46
+ expect(assigns(:order).shipping_address.country_id).to be_nil
47
+ end
48
+
49
+ it 'defaults the billing address country to nil' do
50
+ get :edit, params: { order_id: order.number }
51
+ expect(assigns(:order).billing_address.country_id).to be_nil
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
13
57
 
14
58
  context "#update" do
59
+ let(:order) { create(:order, number: "R123456789") }
60
+
61
+ before { allow(Spree::Order).to receive_message_chain(:includes, :find_by!) { order } }
62
+
15
63
  it "updates + progresses the order" do
16
64
  expect(order).to receive(:update_attributes) { true }
17
65
  expect(order).to receive(:next) { false }
@@ -69,7 +69,7 @@ describe Spree::Admin::OrdersController, type: :controller do
69
69
  it "can page through the orders" do
70
70
  get :index, params: { page: 2, per_page: 10 }
71
71
  expect(assigns[:orders].offset_value).to eq(10)
72
- expect(assigns[:orders].current_per_page).to eq(10)
72
+ expect(assigns[:orders].limit_value).to eq(10)
73
73
  end
74
74
  end
75
75
 
@@ -77,7 +77,7 @@ describe Spree::Admin::OrdersController, type: :controller do
77
77
  context "#new" do
78
78
  let(:user) { create(:user) }
79
79
  before do
80
- allow(controller).to receive_messages spree_current_user: user
80
+ allow(controller).to receive_messages try_spree_current_user: user
81
81
  end
82
82
 
83
83
  it "imports a new order and sets the current user as a creator" do
@@ -140,7 +140,7 @@ describe Spree::Admin::OrdersController, type: :controller do
140
140
  end
141
141
 
142
142
  context 'when order_bill_address_used is true' do
143
- before { Spree::Config[:order_bill_address_used] = true }
143
+ before { stub_spree_preferences(order_bill_address_used: true) }
144
144
 
145
145
  it "should redirect to the customer details page" do
146
146
  get :edit, params: { id: order.number }
@@ -149,7 +149,7 @@ describe Spree::Admin::OrdersController, type: :controller do
149
149
  end
150
150
 
151
151
  context 'when order_bill_address_used is false' do
152
- before { Spree::Config[:order_bill_address_used] = false }
152
+ before { stub_spree_preferences(order_bill_address_used: false) }
153
153
 
154
154
  it "should redirect to the customer details page" do
155
155
  get :edit, params: { id: order.number }
@@ -288,18 +288,30 @@ describe Spree::Admin::OrdersController, type: :controller do
288
288
  let(:user) { create(:user) }
289
289
 
290
290
  before do
291
- allow(controller).to receive_messages spree_current_user: user
291
+ allow(controller).to receive_messages try_spree_current_user: user
292
292
  user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
293
293
 
294
- create(:completed_order_with_totals)
295
- expect(Spree::Order.count).to eq 1
294
+ create_list(:completed_order_with_totals, 2)
295
+ expect(Spree::Order.count).to eq 2
296
296
  end
297
297
 
298
- it "does not display duplicated results" do
299
- get :index, params: { q: {
300
- line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
301
- } }
302
- expect(assigns[:orders].map(&:number).count).to eq 1
298
+ context 'by line_items_variant_id_in' do
299
+ it "does not display duplicated results" do
300
+ get :index, params: { q: {
301
+ line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
302
+ } }
303
+ expect(assigns[:orders].size).to eq 1
304
+ end
305
+ end
306
+
307
+ context 'by email' do
308
+ it "does not display duplicated results" do
309
+ get :index, params: { q: {
310
+ email_start: Spree::Order.first.email
311
+ } }
312
+ expect(assigns[:orders].size).to eq 1
313
+ expect(assigns[:orders][0].email).to eq(Spree::Order.first.email)
314
+ end
303
315
  end
304
316
  end
305
317
 
@@ -349,7 +361,7 @@ describe Spree::Admin::OrdersController, type: :controller do
349
361
  let!(:order) { create(:completed_order_with_totals, number: 'R987654321') }
350
362
 
351
363
  before do
352
- allow(controller).to receive_messages spree_current_user: user
364
+ allow(controller).to receive_messages try_spree_current_user: user
353
365
  end
354
366
 
355
367
  it 'should grant access to users with an admin role' do
@@ -6,7 +6,7 @@ module Spree
6
6
  module Admin
7
7
  describe PaymentsController, type: :controller do
8
8
  before do
9
- allow(controller).to receive_messages spree_current_user: user
9
+ allow(controller).to receive_messages try_spree_current_user: user
10
10
  end
11
11
 
12
12
  let(:user) { create(:admin_user) }
@@ -50,6 +50,78 @@ describe Spree::Admin::ProductsController, type: :controller do
50
50
  end
51
51
  end
52
52
 
53
+ # regression test for https://github.com/solidusio/solidus/issues/2791
54
+ context "creating a product" do
55
+ before(:all) do
56
+ create(:shipping_category)
57
+ end
58
+
59
+ it "creates a product" do
60
+ post :create, params: {
61
+ product: {
62
+ name: "Product #1 - 9632",
63
+ description: "As seen on TV!",
64
+ price: 19.99,
65
+ shipping_category_id: Spree::ShippingCategory.first.id,
66
+ }
67
+ }
68
+ expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!")
69
+ end
70
+
71
+ context "when there is a taxon" do
72
+ let(:first_taxon) { create(:taxon) }
73
+
74
+ it "creates a product with a taxon" do
75
+ post :create, params: {
76
+ product: {
77
+ name: "Product #1 - 9632",
78
+ description: "As seen on TV!",
79
+ price: 19.99,
80
+ shipping_category_id: Spree::ShippingCategory.first.id,
81
+ taxon_ids: first_taxon.id.to_s
82
+ }
83
+ }
84
+ expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!")
85
+ end
86
+
87
+ context "when their are multiple taxons" do
88
+ let(:second_taxon) { create(:taxon) }
89
+
90
+ it "creates a product with multiple taxons" do
91
+ post :create, params: {
92
+ product: {
93
+ name: "Product #1 - 9632",
94
+ description: "As seen on TV!",
95
+ price: 19.99,
96
+ shipping_category_id: Spree::ShippingCategory.first.id,
97
+ taxon_ids: "#{first_taxon.id}, #{second_taxon.id}"
98
+ }
99
+ }
100
+ expect(flash[:success]).to eq("Product \"Product #1 - 9632\" has been successfully created!")
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ context "adding taxons to a product" do
107
+ let(:product) { create(:product) }
108
+ let(:first_taxon) { create(:taxon) }
109
+
110
+ it "adds a single taxon to a product" do
111
+ put :update, params: { id: product.to_param, product: { taxon_ids: first_taxon.id.to_s } }
112
+ expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!")
113
+ end
114
+
115
+ context "when there are mulitple taxons" do
116
+ let(:second_taxon) { create(:taxon) }
117
+
118
+ it "adds multiple taxons to a product" do
119
+ put :update, params: { id: product.to_param, product: { taxon_ids: "#{first_taxon.id}, #{second_taxon.id}" } }
120
+ expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!")
121
+ end
122
+ end
123
+ end
124
+
53
125
  describe "creating variant property rules" do
54
126
  let(:first_property) { create(:property) }
55
127
  let(:second_property) { create(:property) }
@@ -11,10 +11,22 @@ describe Spree::Admin::PromotionCodesController do
11
11
  let!(:code2) { create(:promotion_code, promotion: promotion) }
12
12
  let!(:code3) { create(:promotion_code, promotion: promotion) }
13
13
 
14
- it "can create a promotion rule of a valid type" do
14
+ it "can create a CSV file with all promotion codes" do
15
15
  get :index, params: { promotion_id: promotion.id, format: 'csv' }
16
16
  expect(response).to be_successful
17
17
  parsed = CSV.parse(response.body, headers: true)
18
18
  expect(parsed.entries.map(&:to_h)).to eq([{ "Code" => code1.value }, { "Code" => code2.value }, { "Code" => code3.value }])
19
19
  end
20
+
21
+ it "can create a new code" do
22
+ post :create, params: { promotion_id: promotion.id, promotion_code: { value: "new_code" } }
23
+ expect(response).to redirect_to(spree.admin_promotion_promotion_codes_path(promotion))
24
+ expect(Spree::PromotionCode.where(promotion: promotion).count).to eql(4)
25
+ end
26
+
27
+ it "cannot create an existing code" do
28
+ post :create, params: { promotion_id: promotion.id, promotion_code: { value: code1.value } }
29
+ expect(flash[:error]).not_to be_nil
30
+ expect(Spree::PromotionCode.where(promotion: promotion).count).to eql(3)
31
+ end
20
32
  end
@@ -9,6 +9,13 @@ describe Spree::Admin::ReimbursementsController, type: :controller do
9
9
  Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
10
10
  end
11
11
 
12
+ let(:user) { stub_model(Spree::LegacyUser, has_spree_role?: true, id: 1) }
13
+
14
+ before do
15
+ allow_any_instance_of(described_class).to receive(:try_spree_current_user).
16
+ and_return(user)
17
+ end
18
+
12
19
  describe '#edit' do
13
20
  let(:reimbursement) { create(:reimbursement) }
14
21
  let(:order) { reimbursement.order }
@@ -42,6 +49,10 @@ describe Spree::Admin::ReimbursementsController, type: :controller do
42
49
  expect(assigns(:reimbursement).return_items.to_a).to eq customer_return.return_items.to_a
43
50
  end
44
51
 
52
+ it 'order is recalculated' do
53
+ expect { subject }.to change { order.reload.payment_state }.from('paid').to('credit_owed')
54
+ end
55
+
45
56
  it 'redirects to the edit page' do
46
57
  subject
47
58
  expect(response).to redirect_to(spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement)))
@@ -32,6 +32,13 @@ describe Spree::Admin::WidgetsController, type: :controller do
32
32
  model do
33
33
  acts_as_list
34
34
  validates :name, presence: true
35
+ before_destroy :check_destroy_constraints
36
+
37
+ def check_destroy_constraints
38
+ return unless name == 'undestroyable'
39
+ errors.add :base, "You can't destroy undestroyable things!"
40
+ throw(:abort)
41
+ end
35
42
  end
36
43
  end
37
44
 
@@ -146,6 +153,21 @@ describe Spree::Admin::WidgetsController, type: :controller do
146
153
  it 'destroys the resource' do
147
154
  expect { subject }.to change { Widget.count }.from(1).to(0)
148
155
  end
156
+
157
+ context 'failure' do
158
+ let(:widget) { Widget.create!(name: 'undestroyable') }
159
+ let(:params) { { id: widget.id } }
160
+
161
+ context 'js format' do
162
+ subject { delete :destroy, params: params, format: 'js' }
163
+
164
+ it 'responds with error message' do
165
+ subject
166
+ expect(response).to be_unprocessable
167
+ expect(response.body).to eq assigns(:widget).errors.full_messages.join(', ')
168
+ end
169
+ end
170
+ end
149
171
  end
150
172
 
151
173
  describe '#update_positions' do
@@ -13,7 +13,7 @@ module Spree
13
13
  let(:stock_item) { variant.stock_items.first }
14
14
  let!(:user) { create :user }
15
15
 
16
- before { expect(controller).to receive(:spree_current_user).and_return(user) }
16
+ before { expect(controller).to receive(:try_spree_current_user).and_return(user) }
17
17
  before { request.env["HTTP_REFERER"] = "product_admin_page" }
18
18
 
19
19
  subject do
@@ -20,7 +20,7 @@ module Spree
20
20
  let(:country) { create :country, iso: "BR" }
21
21
 
22
22
  before do
23
- Spree::Config[:default_country_iso] = country.iso
23
+ stub_spree_preferences(default_country_iso: country.iso)
24
24
  end
25
25
 
26
26
  it "can create a new stock location" do
@@ -3,8 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  shared_examples "update reason loader" do
6
- it "sets the update_reasons variable to a list of categories sorted by category name " do
7
- expect(assigns(:update_reasons)).to eq [update_reason]
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
8
  end
9
9
  end
10
10
 
@@ -16,11 +16,11 @@ describe Spree::Admin::StoreCreditsController do
16
16
 
17
17
  let!(:b_credit_category) { create(:store_credit_category, name: "B category") }
18
18
  let!(:a_credit_category) { create(:store_credit_category, name: "A category") }
19
- let!(:update_reason) { create(:store_credit_update_reason) }
19
+ let!(:store_credit_reason) { create(:store_credit_reason) }
20
20
 
21
21
  describe "#show" do
22
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) }
23
+ let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
24
24
 
25
25
  before { get :show, params: { user_id: user.id, id: store_credit.id } }
26
26
 
@@ -173,12 +173,12 @@ describe Spree::Admin::StoreCreditsController do
173
173
  describe "#update_amount" do
174
174
  let(:original_amount) { 100.0 }
175
175
  let!(:store_credit) { create(:store_credit, user: user, amount: original_amount) }
176
- let!(:update_reason) { create(:store_credit_update_reason) }
176
+ let!(:store_credit_reason) { create(:store_credit_reason) }
177
177
  let(:parameters) do
178
178
  {
179
179
  user_id: user.id,
180
180
  id: store_credit.id,
181
- update_reason_id: update_reason.id,
181
+ store_credit_reason_id: store_credit_reason.id,
182
182
  store_credit: {
183
183
  amount: updated_amount
184
184
  }
@@ -271,7 +271,7 @@ describe Spree::Admin::StoreCreditsController do
271
271
  {
272
272
  user_id: user.id,
273
273
  id: store_credit.id,
274
- update_reason_id: update_reason.id
274
+ store_credit_reason_id: store_credit_reason.id
275
275
  }
276
276
  end
277
277