solidus_backend 1.1.0 → 1.1.1

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/Rakefile +15 -0
  4. data/script/rails +9 -0
  5. data/solidus_backend.gemspec +30 -0
  6. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  7. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  8. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  9. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  10. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  11. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  12. data/spec/controllers/spree/admin/orders_controller_spec.rb +460 -0
  13. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  14. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  15. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +69 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +162 -0
  17. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  18. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
  19. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  20. data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
  21. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  22. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +124 -0
  23. data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
  24. data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
  25. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +240 -0
  26. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  27. data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
  28. data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
  29. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  30. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
  31. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  32. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +351 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +257 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +50 -0
  37. data/spec/features/admin/configuration/countries_spec.rb +22 -0
  38. data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
  39. data/spec/features/admin/configuration/payment_methods_spec.rb +124 -0
  40. data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
  41. data/spec/features/admin/configuration/states_spec.rb +64 -0
  42. data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
  43. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  44. data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
  45. data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
  46. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  47. data/spec/features/admin/homepage_spec.rb +78 -0
  48. data/spec/features/admin/locale_spec.rb +30 -0
  49. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  50. data/spec/features/admin/orders/adjustments_spec.rb +126 -0
  51. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
  52. data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
  53. data/spec/features/admin/orders/customer_details_spec.rb +163 -0
  54. data/spec/features/admin/orders/line_items_spec.rb +50 -0
  55. data/spec/features/admin/orders/listing_spec.rb +130 -0
  56. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  57. data/spec/features/admin/orders/new_order_spec.rb +185 -0
  58. data/spec/features/admin/orders/order_details_spec.rb +533 -0
  59. data/spec/features/admin/orders/payments_spec.rb +234 -0
  60. data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
  61. data/spec/features/admin/orders/shipments_spec.rb +65 -0
  62. data/spec/features/admin/payments/store_credits_spec.rb +21 -0
  63. data/spec/features/admin/products/edit/images_spec.rb +87 -0
  64. data/spec/features/admin/products/edit/products_spec.rb +66 -0
  65. data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
  66. data/spec/features/admin/products/edit/variants_spec.rb +61 -0
  67. data/spec/features/admin/products/option_types_spec.rb +114 -0
  68. data/spec/features/admin/products/products_spec.rb +395 -0
  69. data/spec/features/admin/products/properties_spec.rb +139 -0
  70. data/spec/features/admin/products/prototypes_spec.rb +110 -0
  71. data/spec/features/admin/products/stock_management_spec.rb +82 -0
  72. data/spec/features/admin/products/variant_spec.rb +51 -0
  73. data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
  74. data/spec/features/admin/promotions/option_value_rule_spec.rb +65 -0
  75. data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
  76. data/spec/features/admin/reports_spec.rb +61 -0
  77. data/spec/features/admin/stock_transfer_spec.rb +104 -0
  78. data/spec/features/admin/store_credits_spec.rb +82 -0
  79. data/spec/features/admin/taxons_spec.rb +31 -0
  80. data/spec/features/admin/users_spec.rb +275 -0
  81. data/spec/helpers/admin/base_helper_spec.rb +18 -0
  82. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  83. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  84. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  85. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  86. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  87. data/spec/spec_helper.rb +116 -0
  88. data/spec/support/appear_before_matcher.rb +8 -0
  89. data/spec/support/ror_ringer.jpeg +0 -0
  90. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  91. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  92. metadata +96 -6
@@ -0,0 +1,134 @@
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
@@ -0,0 +1,166 @@
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 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', scope: :all 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
@@ -0,0 +1,240 @@
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
+ describe "#load_stock_locations" do
135
+ let!(:active_stock_location) { create(:stock_location, active: true) }
136
+ let!(:inactive_stock_location) { create(:stock_location, active: false) }
137
+
138
+ before do
139
+ spree_get :new, order_id: order.to_param
140
+ end
141
+
142
+ it "loads all the active stock locations" do
143
+ expect(assigns(:stock_locations)).to include(active_stock_location)
144
+ expect(assigns(:stock_locations)).not_to include(inactive_stock_location)
145
+ end
146
+ end
147
+
148
+ context '#create' do
149
+ let(:stock_location) { create(:stock_location) }
150
+
151
+ subject { spree_post :create, params }
152
+
153
+ let(:params) do
154
+ {
155
+ order_id: order.to_param,
156
+ return_authorization: return_authorization_params,
157
+ }
158
+ end
159
+
160
+ let(:return_authorization_params) do
161
+ {
162
+ memo: "",
163
+ stock_location_id: stock_location.id,
164
+ return_reason_id: return_reason.id,
165
+ }
166
+ end
167
+
168
+ it "can create a return authorization" do
169
+ subject
170
+ expect(response).to redirect_to spree.admin_order_return_authorizations_path(order)
171
+ end
172
+ end
173
+
174
+ context '#update' do
175
+ let(:return_authorization) { create(:return_authorization, order: order) }
176
+
177
+ let(:params) do
178
+ {
179
+ id: return_authorization.to_param,
180
+ order_id: order.to_param,
181
+ return_authorization: return_authorization_params,
182
+ }
183
+ end
184
+ let(:return_authorization_params) do
185
+ {
186
+ memo: "",
187
+ return_items_attributes: return_items_params,
188
+ }
189
+ end
190
+
191
+ subject { spree_put :update, params }
192
+
193
+ context "adding an item" do
194
+ let(:return_items_params) do
195
+ {
196
+ '0' => {inventory_unit_id: inventory_unit_1.to_param}
197
+ }
198
+ end
199
+
200
+ context 'without existing items' do
201
+ it 'creates a new item' do
202
+ expect { subject }.to change { Spree::ReturnItem.count }.by(1)
203
+ end
204
+ end
205
+
206
+ context 'with existing completed items' do
207
+ let!(:completed_return_item) do
208
+ create(:return_item, {
209
+ return_authorization: return_authorization,
210
+ inventory_unit: inventory_unit_1,
211
+ reception_status: 'received',
212
+ })
213
+ end
214
+
215
+ it 'does not create new items' do
216
+ expect { subject }.to_not change { Spree::ReturnItem.count }
217
+ 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}"]
218
+ end
219
+ end
220
+ end
221
+
222
+ context "removing an item" do
223
+ let!(:return_item) do
224
+ create(:return_item, return_authorization: return_authorization, inventory_unit: inventory_unit_1)
225
+ end
226
+
227
+ let(:return_items_params) do
228
+ {
229
+ '0' => {id: return_item.to_param, _destroy: '1'}
230
+ }
231
+ end
232
+
233
+ context 'with existing items' do
234
+ it 'removes the item' do
235
+ expect { subject }.to change { Spree::ReturnItem.count }.by(-1)
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::ReturnItemsController, :type => :controller do
4
+ stub_authorization!
5
+
6
+ describe '#update' do
7
+ let(:customer_return) { create(:customer_return) }
8
+ let(:return_item) { customer_return.return_items.first }
9
+ let(:old_acceptance_status) { 'pending' }
10
+ let(:new_acceptance_status) { 'rejected' }
11
+
12
+ subject do
13
+ spree_put :update, id: return_item.to_param, return_item: {acceptance_status: new_acceptance_status}
14
+ end
15
+
16
+ it 'updates the return item' do
17
+ expect {
18
+ subject
19
+ }.to change { return_item.reload.acceptance_status }.from(old_acceptance_status).to(new_acceptance_status)
20
+ end
21
+
22
+ it 'redirects to the customer return' do
23
+ subject
24
+ expect(response).to redirect_to spree.edit_admin_order_customer_return_path(customer_return.order, customer_return)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::RootController do
4
+ describe "GET index" do
5
+ subject { get :index }
6
+
7
+ let(:user) { build(:user) }
8
+ let(:ability) { Spree::Ability.new(user) }
9
+
10
+ before do
11
+ allow_any_instance_of(Spree::Admin::RootController).to receive(:try_spree_current_user).and_return(user)
12
+ allow_any_instance_of(Spree::Admin::RootController).to receive(:current_ability).and_return(ability)
13
+ end
14
+
15
+ context "when a user can admin and display spree orders" do
16
+ before do
17
+ ability.can :admin, Spree::Order
18
+ ability.can :display, Spree::Order
19
+ end
20
+
21
+ it { is_expected.to redirect_to(spree.admin_orders_path) }
22
+ end
23
+
24
+ context "when a user cannot admin and display spree orders" do
25
+ context "when a user can admin and home dashboards" do
26
+ before do
27
+ ability.can :admin, :dashboards
28
+ ability.can :home, :dashboards
29
+ end
30
+
31
+ it { is_expected.to redirect_to(spree.home_admin_dashboards_path) }
32
+ end
33
+
34
+ context "when a user cannot admin and home dashboards" do
35
+ # The default exception handler redirects to /unauthorized.
36
+ # Extensions may change this.
37
+ it { is_expected.to redirect_to('/unauthorized') }
38
+ end
39
+ end
40
+ end
41
+ end