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,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Admin::RefundsController do
4
- stub_authorization!
5
-
6
- describe "POST create" do
7
- context "a Spree::Core::GatewayError is raised" do
8
-
9
- let(:payment) { create(:payment) }
10
-
11
- subject do
12
- spree_post :create,
13
- refund: { amount: "50.0", refund_reason_id: "1" },
14
- order_id: payment.order_id,
15
- payment_id: payment.id
16
- end
17
-
18
- before(:each) do
19
- def controller.create
20
- raise Spree::Core::GatewayError.new('An error has occurred')
21
- end
22
- end
23
-
24
- it "sets an error message with the correct text" do
25
- subject
26
- expect(flash[:error]).to eq 'An error has occurred'
27
- end
28
-
29
- it { is_expected.to render_template(:new) }
30
- end
31
- end
32
- end
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Admin::ReimbursementsController, :type => :controller do
4
- stub_authorization!
5
-
6
- let!(:default_refund_reason) do
7
- Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
8
- end
9
-
10
- describe '#create' do
11
- let(:customer_return) { create(:customer_return, line_items_count: 1) }
12
- let(:order) { customer_return.order }
13
- let(:return_item) { customer_return.return_items.first }
14
- let(:payment) { order.payments.first }
15
- before { return_item.receive! }
16
-
17
- subject do
18
- spree_post :create, order_id: order.to_param, build_from_customer_return_id: customer_return.id
19
- end
20
-
21
- it 'creates the reimbursement' do
22
- expect { subject }.to change { order.reimbursements.count }.by(1)
23
- expect(assigns(:reimbursement).return_items.to_a).to eq customer_return.return_items.to_a
24
- end
25
-
26
- it 'redirects to the edit page' do
27
- subject
28
- expect(response).to redirect_to(spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement)))
29
- end
30
- end
31
-
32
- describe "#perform" do
33
- let(:reimbursement) { create(:reimbursement) }
34
- let(:customer_return) { reimbursement.customer_return }
35
- let(:order) { reimbursement.order }
36
- let(:return_items) { reimbursement.return_items }
37
- let(:payment) { order.payments.first }
38
-
39
- subject do
40
- spree_post :perform, order_id: order.to_param, id: reimbursement.to_param
41
- end
42
-
43
- it 'redirects to customer return page' do
44
- subject
45
- expect(response).to redirect_to spree.admin_order_reimbursement_path(order, reimbursement)
46
- end
47
-
48
- it 'performs the reimbursement' do
49
- expect {
50
- subject
51
- }.to change { payment.refunds.count }.by(1)
52
- expect(payment.refunds.last.amount).to be > 0
53
- expect(payment.refunds.last.amount).to eq return_items.to_a.sum(&:total)
54
- end
55
-
56
- context "a Spree::Core::GatewayError is raised" do
57
- before(:each) do
58
- def controller.perform
59
- raise Spree::Core::GatewayError.new('An error has occurred')
60
- end
61
- end
62
-
63
- it "sets an error message with the correct text" do
64
- subject
65
- expect(flash[:error]).to eq 'An error has occurred'
66
- end
67
-
68
- it 'redirects to the edit page' do
69
- subject
70
- redirect_path = spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement))
71
- expect(response).to redirect_to(redirect_path)
72
- end
73
- end
74
- end
75
- end
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Admin::ReportsController, :type => :controller do
4
- stub_authorization!
5
-
6
- describe 'ReportsController.available_reports' do
7
- it 'should contain sales_total' do
8
- expect(Spree::Admin::ReportsController.available_reports.keys.include?(:sales_total)).to be true
9
- end
10
-
11
- it 'should have the proper sales total report description' do
12
- expect(Spree::Admin::ReportsController.available_reports[:sales_total][:description]).to eql('Sales Total For All Orders')
13
- end
14
-
15
- end
16
-
17
- describe 'ReportsController.add_available_report!' do
18
- context 'when adding the report name' do
19
- it 'should contain the report' do
20
- Spree::Admin::ReportsController.add_available_report!(:some_report)
21
- expect(Spree::Admin::ReportsController.available_reports.keys.include?(:some_report)).to be true
22
- end
23
- end
24
- end
25
-
26
- describe 'GET sales_total' do
27
-
28
- let!(:order_complete_start_of_month) { create(:completed_order_with_totals) }
29
- let!(:order_complete_mid_month) { create(:completed_order_with_totals) }
30
- let!(:order_non_complete) { create(:order, completed_at: nil) }
31
-
32
- before do
33
- # can't set completed_at during factory creation
34
- order_complete_start_of_month.completed_at = Time.zone.now.beginning_of_month + 1.minute
35
- order_complete_start_of_month.save!
36
-
37
- order_complete_mid_month.completed_at = Time.zone.now.beginning_of_month + 15.days
38
- order_complete_mid_month.save!
39
- end
40
-
41
- subject { spree_get :sales_total, params }
42
-
43
- shared_examples 'sales total report' do
44
- it 'should respond with success' do
45
- expect(response).to be_success
46
- end
47
-
48
- it 'should set search to be a ransack search' do
49
- subject
50
- expect(assigns(:search)).to be_a Ransack::Search
51
- end
52
-
53
- it 'should set orders correctly for date parameters' do
54
- subject
55
- expect(assigns(:orders)).to eq expected_returned_orders
56
- end
57
-
58
- it 'does not include non-complete orders' do
59
- subject
60
- expect(assigns(:orders)).to_not include(order_non_complete)
61
- end
62
-
63
- it 'should correctly set the totals hash' do
64
- subject
65
- expect(assigns(:totals)).to eq expected_totals
66
- end
67
- end
68
-
69
- context 'when no dates are specified' do
70
- let(:params) { { } }
71
-
72
- it_behaves_like 'sales total report' do
73
- let(:expected_returned_orders) { [order_complete_mid_month, order_complete_start_of_month] }
74
- let(:expected_totals) {
75
- {
76
- 'USD' => {
77
- item_total: Money.new(2000, 'USD'),
78
- adjustment_total: Money.new(0, 'USD'),
79
- sales_total: Money.new(22000, 'USD')
80
- }
81
- }
82
- }
83
- end
84
- end
85
-
86
- context 'when params has a completed_at_gt' do
87
- let(:params) { { q: { completed_at_gt: Time.zone.now.beginning_of_month + 1.day } } }
88
-
89
- it_behaves_like 'sales total report' do
90
- let(:expected_returned_orders) { [order_complete_mid_month] }
91
- let(:expected_totals) {
92
- {
93
- 'USD' => {
94
- item_total: Money.new(1000, 'USD'),
95
- adjustment_total: Money.new(0, 'USD'),
96
- sales_total: Money.new(11000, 'USD')
97
- }
98
- }
99
- }
100
- end
101
- end
102
-
103
- context 'when params has a compeleted_at_lt' do
104
- let(:params) { { q: { completed_at_lt: Time.zone.now.beginning_of_month } } }
105
-
106
- it_behaves_like 'sales total report' do
107
- let(:expected_returned_orders) { [order_complete_start_of_month] }
108
- let(:expected_totals) {
109
- {
110
- 'USD' => {
111
- item_total: Money.new(1000, 'USD'),
112
- adjustment_total: Money.new(0, 'USD'),
113
- sales_total: Money.new(11000, 'USD')
114
- }
115
- }
116
- }
117
- end
118
- end
119
- end
120
-
121
- describe 'GET index' do
122
- it 'should be ok' do
123
- spree_get :index
124
- expect(response).to be_ok
125
- end
126
- end
127
-
128
- after(:each) do
129
- Spree::Admin::ReportsController.available_reports.delete_if do |key, value|
130
- key != :sales_total
131
- end
132
- end
133
-
134
- end
@@ -1,166 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Admin
5
- class WidgetsController < Spree::Admin::ResourceController
6
- prepend_view_path('spec/test_views')
7
-
8
- def model_class
9
- Widget
10
- end
11
- end
12
- end
13
- end
14
-
15
- describe Spree::Admin::WidgetsController, :type => :controller, :truncation => true do
16
- stub_authorization!
17
-
18
- after(:all) do
19
- # Spree::Core::Engine.routes.reload_routes!
20
- Rails.application.reload_routes!
21
- end
22
-
23
- with_model 'Widget' do
24
- table do |t|
25
- t.string :name
26
- t.integer :position
27
- t.timestamps null: false
28
- end
29
-
30
- model do
31
- acts_as_list
32
- validates :name, presence: true
33
- end
34
- end
35
-
36
- before do
37
- Spree::Core::Engine.routes.draw do
38
- namespace :admin do
39
- resources :widgets do
40
- post :update_positions, on: :member
41
- end
42
- end
43
- end
44
- end
45
-
46
- describe '#new' do
47
- subject do
48
- spree_get :new
49
- end
50
-
51
- it 'succeeds' do
52
- subject
53
- expect(response).to be_success
54
- end
55
- end
56
-
57
- describe '#edit' do
58
- let(:widget) { Widget.create!(name: 'a widget') }
59
-
60
- subject do
61
- spree_get :edit, id: widget.to_param
62
- end
63
-
64
- it 'succeeds' do
65
- subject
66
- expect(response).to be_success
67
- end
68
- end
69
-
70
- describe '#create' do
71
- let(:params) do
72
- {widget: {name: 'a widget'}}
73
- end
74
-
75
- subject { spree_post :create, params }
76
-
77
- it 'creates the resource' do
78
- expect { subject }.to change { Widget.count }.by(1)
79
- end
80
-
81
- context 'failure' do
82
- let(:params) do
83
- {widget: {name: ''}} # blank name generates an error
84
- end
85
-
86
- it 'sets a flash error' do
87
- subject
88
- expect(flash[:error]).to eq assigns(:widget).errors.full_messages.join(', ')
89
- end
90
- end
91
-
92
- context 'without any parameters' do
93
- let(:params) { {} }
94
-
95
- before do
96
- allow_any_instance_of(Widget).to receive(:name).and_return('some name')
97
- end
98
-
99
- it 'creates the resource' do
100
- expect { subject }.to change { Widget.count }.by(1)
101
- end
102
- end
103
- end
104
-
105
- describe '#update' do
106
- let(:widget) { Widget.create!(name: 'a widget') }
107
-
108
- let(:params) do
109
- {
110
- id: widget.to_param,
111
- widget: {name: 'widget renamed'},
112
- }
113
- end
114
-
115
- subject { spree_put :update, params }
116
-
117
- it 'updates the resource' do
118
- expect { subject }.to change { widget.reload.name }.from('a widget').to('widget renamed')
119
- end
120
-
121
- context 'failure' do
122
- let(:params) do
123
- {
124
- id: widget.to_param,
125
- widget: {name: ''}, # a blank name will trigger a validation error
126
- }
127
- end
128
-
129
- it 'sets a flash error' do
130
- subject
131
- expect(flash[:error]).to eq assigns(:widget).errors.full_messages.join(', ')
132
- end
133
- end
134
- end
135
-
136
- describe '#destroy' do
137
- let!(:widget) { Widget.create!(name: 'a widget') }
138
- let(:params) { {id: widget.id} }
139
-
140
- subject {
141
- spree_delete :destroy, params
142
- }
143
-
144
- it 'destroys the resource' do
145
- expect { subject }.to change { Widget.count }.from(1).to(0)
146
- end
147
- end
148
-
149
- describe '#update_positions' do
150
- let(:widget_1) { Widget.create!(name: 'widget 1', position: 1) }
151
- let(:widget_2) { Widget.create!(name: 'widget 2', position: 2) }
152
-
153
- subject do
154
- spree_post :update_positions, id: widget_1.to_param,
155
- positions: { widget_1.id => '2', widget_2.id => '1' }, format: 'js'
156
- end
157
-
158
- it 'updates the position of widget 1' do
159
- expect { subject }.to change { widget_1.reload.position }.from(1).to(2)
160
- end
161
-
162
- it 'updates the position of widget 2' do
163
- expect { subject }.to change { widget_2.reload.position }.from(2).to(1)
164
- end
165
- end
166
- end
@@ -1,226 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Admin::ReturnAuthorizationsController, :type => :controller do
4
- stub_authorization!
5
-
6
- # Regression test for #1370 #3
7
- let!(:order) { create(:shipped_order, line_items_count: 3) }
8
- let!(:return_reason) { create(:return_reason) }
9
- let(:inventory_unit_1) { order.inventory_units.order('id asc')[0] }
10
- let(:inventory_unit_2) { order.inventory_units.order('id asc')[1] }
11
- let(:inventory_unit_3) { order.inventory_units.order('id asc')[2] }
12
-
13
- describe "#load_return_reasons" do
14
- let!(:inactive_rma_reason) { create(:return_reason, active: false) }
15
-
16
- context "a return item in the return authorization has an associated inactive reason" do
17
- let!(:other_inactive_rma_reason) { create(:return_reason, active: false) }
18
- let(:return_item) { create(:return_item, return_reason: inactive_rma_reason) }
19
- let(:return_authorization) { return_item.return_authorization }
20
-
21
- it "loads all the active rma reasons" do
22
- spree_get :edit, id: return_authorization.to_param, order_id: return_authorization.order.to_param
23
- expect(assigns(:reasons)).to include(return_reason)
24
- expect(assigns(:reasons)).to include(inactive_rma_reason)
25
- expect(assigns(:reasons)).not_to include(other_inactive_rma_reason)
26
- end
27
- end
28
-
29
- context "return authorization has an associated active reason" do
30
- let(:return_authorization) { create(:return_authorization, reason: return_reason) }
31
-
32
- it "loads all the active rma reasons" do
33
- spree_get :edit, id: return_authorization.to_param, order_id: return_authorization.order.to_param
34
- expect(assigns(:reasons)).to eq [return_reason]
35
- end
36
- end
37
-
38
- context "return authorization doesn't have an associated reason" do
39
- it "loads all the active rma reasons" do
40
- spree_get :new, order_id: order.to_param
41
- expect(assigns(:reasons)).to eq [return_reason]
42
- end
43
- end
44
- end
45
-
46
- describe "#load_return_items" do
47
- shared_context 'without existing return items' do
48
- context 'without existing return items' do
49
- it 'has 3 new @form_return_items' do
50
- subject
51
- expect(assigns(:form_return_items).size).to eq 3
52
- expect(assigns(:form_return_items).select(&:new_record?).size).to eq 3
53
- end
54
- end
55
- end
56
-
57
- shared_context 'with existing return items' do
58
- context 'with existing return items' do
59
- let!(:return_item_1) { create(:return_item, inventory_unit: inventory_unit_1, return_authorization: return_authorization) }
60
-
61
- it 'has 1 existing return item and 2 new return items' do
62
- subject
63
- expect(assigns(:form_return_items).size).to eq 3
64
- expect(assigns(:form_return_items).select(&:persisted?)).to eq [return_item_1]
65
- expect(assigns(:form_return_items).select(&:new_record?).size).to eq 2
66
- end
67
- end
68
- end
69
-
70
- context '#new' do
71
- subject { spree_get :new, order_id: order.to_param }
72
-
73
- include_context 'without existing return items'
74
- end
75
-
76
- context '#edit' do
77
- subject do
78
- spree_get :edit, {
79
- id: return_authorization.to_param,
80
- order_id: order.to_param,
81
- }
82
- end
83
-
84
- let(:return_authorization) { create(:return_authorization, order: order) }
85
-
86
- include_context 'without existing return items'
87
- include_context 'with existing return items'
88
- end
89
-
90
- context '#create failed' do
91
- subject do
92
- spree_post :create, {
93
- return_authorization: {stock_location_id: nil}, # return authorization requires valid stock location, so this will fail
94
- order_id: order.to_param,
95
- }
96
- end
97
-
98
- include_context 'without existing return items'
99
- end
100
-
101
- context '#update failed' do
102
- subject do
103
- spree_put :update, {
104
- return_authorization: {stock_location_id: nil}, # return authorization requires valid stock location, so this will fail
105
- id: return_authorization.to_param,
106
- order_id: order.to_param,
107
- }
108
- end
109
-
110
- let(:return_authorization) { create(:return_authorization, order: order) }
111
-
112
- include_context 'without existing return items'
113
- include_context 'with existing return items'
114
- end
115
- end
116
-
117
- describe "#load_reimbursement_types" do
118
- let(:order) { create(:order) }
119
- let!(:inactive_reimbursement_type) { create(:reimbursement_type, active: false) }
120
- let!(:first_active_reimbursement_type) { create(:reimbursement_type) }
121
- let!(:second_active_reimbursement_type) { create(:reimbursement_type) }
122
-
123
- before do
124
- spree_get :new, order_id: order.to_param
125
- end
126
-
127
- it "loads all the active reimbursement types" do
128
- expect(assigns(:reimbursement_types)).to include(first_active_reimbursement_type)
129
- expect(assigns(:reimbursement_types)).to include(second_active_reimbursement_type)
130
- expect(assigns(:reimbursement_types)).not_to include(inactive_reimbursement_type)
131
- end
132
- end
133
-
134
- context '#create' do
135
- let(:stock_location) { create(:stock_location) }
136
-
137
- subject { spree_post :create, params }
138
-
139
- let(:params) do
140
- {
141
- order_id: order.to_param,
142
- return_authorization: return_authorization_params,
143
- }
144
- end
145
-
146
- let(:return_authorization_params) do
147
- {
148
- memo: "",
149
- stock_location_id: stock_location.id,
150
- return_reason_id: return_reason.id,
151
- }
152
- end
153
-
154
- it "can create a return authorization" do
155
- subject
156
- expect(response).to redirect_to spree.admin_order_return_authorizations_path(order)
157
- end
158
- end
159
-
160
- context '#update' do
161
- let(:return_authorization) { create(:return_authorization, order: order) }
162
-
163
- let(:params) do
164
- {
165
- id: return_authorization.to_param,
166
- order_id: order.to_param,
167
- return_authorization: return_authorization_params,
168
- }
169
- end
170
- let(:return_authorization_params) do
171
- {
172
- memo: "",
173
- return_items_attributes: return_items_params,
174
- }
175
- end
176
-
177
- subject { spree_put :update, params }
178
-
179
- context "adding an item" do
180
- let(:return_items_params) do
181
- {
182
- '0' => {inventory_unit_id: inventory_unit_1.to_param}
183
- }
184
- end
185
-
186
- context 'without existing items' do
187
- it 'creates a new item' do
188
- expect { subject }.to change { Spree::ReturnItem.count }.by(1)
189
- end
190
- end
191
-
192
- context 'with existing completed items' do
193
- let!(:completed_return_item) do
194
- create(:return_item, {
195
- return_authorization: return_authorization,
196
- inventory_unit: inventory_unit_1,
197
- reception_status: 'received',
198
- })
199
- end
200
-
201
- it 'does not create new items' do
202
- expect { subject }.to_not change { Spree::ReturnItem.count }
203
- expect(assigns[:return_authorization].errors['return_items.inventory_unit']).to eq ["#{inventory_unit_1.id} has already been taken by return item #{completed_return_item.id}"]
204
- end
205
- end
206
- end
207
-
208
- context "removing an item" do
209
- let!(:return_item) do
210
- create(:return_item, return_authorization: return_authorization, inventory_unit: inventory_unit_1)
211
- end
212
-
213
- let(:return_items_params) do
214
- {
215
- '0' => {id: return_item.to_param, _destroy: '1'}
216
- }
217
- end
218
-
219
- context 'with existing items' do
220
- it 'removes the item' do
221
- expect { subject }.to change { Spree::ReturnItem.count }.by(-1)
222
- end
223
- end
224
- end
225
- end
226
- end