spree_backend 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/spree/backend/admin.js +26 -0
  6. data/app/controllers/spree/admin/resource_controller.rb +4 -2
  7. data/app/helpers/spree/admin/navigation_helper.rb +10 -1
  8. data/app/views/spree/admin/images/new.html.erb +1 -1
  9. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  10. data/app/views/spree/admin/products/_form.html.erb +1 -1
  11. data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
  12. data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
  13. data/script/rails +9 -0
  14. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  15. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  16. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  17. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  18. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
  19. data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
  20. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  21. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  22. data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
  23. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  24. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  25. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  26. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  27. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  28. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  29. data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
  30. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  31. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  32. data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
  33. data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
  34. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  35. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  36. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  37. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  38. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  39. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  40. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  41. data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
  42. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  43. data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
  44. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  45. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  46. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  47. data/spec/features/admin/configuration/states_spec.rb +68 -0
  48. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  49. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  50. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  51. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  52. data/spec/features/admin/homepage_spec.rb +81 -0
  53. data/spec/features/admin/locale_spec.rb +31 -0
  54. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  55. data/spec/features/admin/orders/adjustments_spec.rb +129 -0
  56. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  57. data/spec/features/admin/orders/customer_details_spec.rb +182 -0
  58. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  59. data/spec/features/admin/orders/listing_spec.rb +225 -0
  60. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  61. data/spec/features/admin/orders/new_order_spec.rb +161 -0
  62. data/spec/features/admin/orders/order_details_spec.rb +620 -0
  63. data/spec/features/admin/orders/payments_spec.rb +229 -0
  64. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  65. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  66. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  67. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  68. data/spec/features/admin/products/edit/products_spec.rb +64 -0
  69. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  70. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  71. data/spec/features/admin/products/option_types_spec.rb +113 -0
  72. data/spec/features/admin/products/products_spec.rb +394 -0
  73. data/spec/features/admin/products/properties_spec.rb +140 -0
  74. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  75. data/spec/features/admin/products/stock_management_spec.rb +123 -0
  76. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  77. data/spec/features/admin/products/variant_spec.rb +50 -0
  78. data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
  79. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  80. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  81. data/spec/features/admin/reports_spec.rb +61 -0
  82. data/spec/features/admin/stock_transfer_spec.rb +75 -0
  83. data/spec/features/admin/taxons_spec.rb +47 -0
  84. data/spec/features/admin/users_spec.rb +284 -0
  85. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  86. data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
  87. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  88. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  89. data/spec/models/spree/resource_spec.rb +48 -0
  90. data/spec/spec_helper.rb +133 -0
  91. data/spec/support/appear_before_matcher.rb +8 -0
  92. data/spec/support/ror_ringer.jpeg +0 -0
  93. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  94. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  95. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  96. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  97. data/spree_backend.gemspec +29 -0
  98. metadata +101 -14
@@ -0,0 +1,225 @@
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_authorization_reason) { create(:return_authorization_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_authorization_reasons" do
14
+ let!(:inactive_rma_reason) { create(:return_authorization_reason, active: false) }
15
+
16
+ context "return authorization has an associated inactive reason" do
17
+ let!(:other_inactive_rma_reason) { create(:return_authorization_reason, active: false) }
18
+ let(:return_authorization) { create(:return_authorization, reason: inactive_rma_reason) }
19
+
20
+ it "loads all the active rma reasons" do
21
+ spree_get :edit, id: return_authorization.to_param, order_id: return_authorization.order.to_param
22
+ expect(assigns(:reasons)).to include(return_authorization_reason)
23
+ expect(assigns(:reasons)).to include(inactive_rma_reason)
24
+ expect(assigns(:reasons)).not_to include(other_inactive_rma_reason)
25
+ end
26
+ end
27
+
28
+ context "return authorization has an associated active reason" do
29
+ let(:return_authorization) { create(:return_authorization, reason: return_authorization_reason) }
30
+
31
+ it "loads all the active rma reasons" do
32
+ spree_get :edit, id: return_authorization.to_param, order_id: return_authorization.order.to_param
33
+ expect(assigns(:reasons)).to eq [return_authorization_reason]
34
+ end
35
+ end
36
+
37
+ context "return authorization doesn't have an associated reason" do
38
+ it "loads all the active rma reasons" do
39
+ spree_get :new, order_id: order.to_param
40
+ expect(assigns(:reasons)).to eq [return_authorization_reason]
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#load_return_items" do
46
+ shared_context 'without existing return items' do
47
+ context 'without existing return items' do
48
+ it 'has 3 new @form_return_items' do
49
+ subject
50
+ expect(assigns(:form_return_items).size).to eq 3
51
+ expect(assigns(:form_return_items).select(&:new_record?).size).to eq 3
52
+ end
53
+ end
54
+ end
55
+
56
+ shared_context 'with existing return items' do
57
+ context 'with existing return items' do
58
+ let!(:return_item_1) { create(:return_item, inventory_unit: inventory_unit_1, return_authorization: return_authorization) }
59
+
60
+ it 'has 1 existing return item and 2 new return items' do
61
+ subject
62
+ expect(assigns(:form_return_items).size).to eq 3
63
+ expect(assigns(:form_return_items).select(&:persisted?)).to eq [return_item_1]
64
+ expect(assigns(:form_return_items).select(&:new_record?).size).to eq 2
65
+ end
66
+ end
67
+ end
68
+
69
+ context '#new' do
70
+ subject { spree_get :new, order_id: order.to_param }
71
+
72
+ include_context 'without existing return items'
73
+ end
74
+
75
+ context '#edit' do
76
+ subject do
77
+ spree_get :edit, {
78
+ id: return_authorization.to_param,
79
+ order_id: order.to_param,
80
+ }
81
+ end
82
+
83
+ let(:return_authorization) { create(:return_authorization, order: order) }
84
+
85
+ include_context 'without existing return items'
86
+ include_context 'with existing return items'
87
+ end
88
+
89
+ context '#create failed' do
90
+ subject do
91
+ spree_post :create, {
92
+ return_authorization: {return_authorization_reason_id: -1}, # invalid reason_id
93
+ order_id: order.to_param,
94
+ }
95
+ end
96
+
97
+ include_context 'without existing return items'
98
+ end
99
+
100
+ context '#update failed' do
101
+ subject do
102
+ spree_put :update, {
103
+ return_authorization: {return_authorization_reason_id: -1}, # invalid reason_id
104
+ id: return_authorization.to_param,
105
+ order_id: order.to_param,
106
+ }
107
+ end
108
+
109
+ let(:return_authorization) { create(:return_authorization, order: order) }
110
+
111
+ include_context 'without existing return items'
112
+ include_context 'with existing return items'
113
+ end
114
+ end
115
+
116
+ describe "#load_reimbursement_types" do
117
+ let(:order) { create(:order) }
118
+ let!(:inactive_reimbursement_type) { create(:reimbursement_type, active: false) }
119
+ let!(:first_active_reimbursement_type) { create(:reimbursement_type) }
120
+ let!(:second_active_reimbursement_type) { create(:reimbursement_type) }
121
+
122
+ before do
123
+ spree_get :new, order_id: order.to_param
124
+ end
125
+
126
+ it "loads all the active reimbursement types" do
127
+ expect(assigns(:reimbursement_types)).to include(first_active_reimbursement_type)
128
+ expect(assigns(:reimbursement_types)).to include(second_active_reimbursement_type)
129
+ expect(assigns(:reimbursement_types)).not_to include(inactive_reimbursement_type)
130
+ end
131
+ end
132
+
133
+ context '#create' do
134
+ let(:stock_location) { create(:stock_location) }
135
+
136
+ subject { spree_post :create, params }
137
+
138
+ let(:params) do
139
+ {
140
+ order_id: order.to_param,
141
+ return_authorization: return_authorization_params,
142
+ }
143
+ end
144
+
145
+ let(:return_authorization_params) do
146
+ {
147
+ memo: "",
148
+ stock_location_id: stock_location.id,
149
+ return_authorization_reason_id: return_authorization_reason.id,
150
+ }
151
+ end
152
+
153
+ it "can create a return authorization" do
154
+ subject
155
+ expect(response).to redirect_to spree.admin_order_return_authorizations_path(order)
156
+ end
157
+ end
158
+
159
+ context '#update' do
160
+ let(:return_authorization) { create(:return_authorization, order: order) }
161
+
162
+ let(:params) do
163
+ {
164
+ id: return_authorization.to_param,
165
+ order_id: order.to_param,
166
+ return_authorization: return_authorization_params,
167
+ }
168
+ end
169
+ let(:return_authorization_params) do
170
+ {
171
+ memo: "",
172
+ return_items_attributes: return_items_params,
173
+ }
174
+ end
175
+
176
+ subject { spree_put :update, params }
177
+
178
+ context "adding an item" do
179
+ let(:return_items_params) do
180
+ {
181
+ '0' => {inventory_unit_id: inventory_unit_1.to_param}
182
+ }
183
+ end
184
+
185
+ context 'without existing items' do
186
+ it 'creates a new item' do
187
+ expect { subject }.to change { Spree::ReturnItem.count }.by(1)
188
+ end
189
+ end
190
+
191
+ context 'with existing completed items' do
192
+ let!(:completed_return_item) do
193
+ create(:return_item, {
194
+ return_authorization: return_authorization,
195
+ inventory_unit: inventory_unit_1,
196
+ reception_status: 'received',
197
+ })
198
+ end
199
+
200
+ it 'does not create new items' do
201
+ expect { subject }.to_not change { Spree::ReturnItem.count }
202
+ 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}"]
203
+ end
204
+ end
205
+ end
206
+
207
+ context "removing an item" do
208
+ let!(:return_item) do
209
+ create(:return_item, return_authorization: return_authorization, inventory_unit: inventory_unit_1)
210
+ end
211
+
212
+ let(:return_items_params) do
213
+ {
214
+ '0' => {id: return_item.to_param, _destroy: '1'}
215
+ }
216
+ end
217
+
218
+ context 'with existing items' do
219
+ it 'removes the item' do
220
+ expect { subject }.to change { Spree::ReturnItem.count }.by(-1)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ 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) { 'accepted' }
10
+ let(:new_acceptance_status) { 'rejected' }
11
+
12
+ subject do
13
+ spree_put :update, id: return_item.to_param, return_item: {acceptance_status: new_acceptance_status}
14
+ end
15
+
16
+ it 'updates the return item' do
17
+ expect {
18
+ subject
19
+ }.to change { return_item.reload.acceptance_status }.from(old_acceptance_status).to(new_acceptance_status)
20
+ end
21
+
22
+ it 'redirects to the custome return' do
23
+ subject
24
+ expect(response).to redirect_to spree.edit_admin_order_customer_return_path(customer_return.order, customer_return)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::RootController do
4
+
5
+ context "unauthorized request" do
6
+
7
+ before :each do
8
+ allow(controller).to receive(:spree_current_user).and_return(nil)
9
+ end
10
+
11
+ it "redirects to orders path by default" do
12
+ get :index
13
+
14
+ expect(response).to redirect_to '/admin/orders'
15
+ end
16
+ end
17
+
18
+ context "authorized request" do
19
+ stub_authorization!
20
+
21
+ it "redirects to orders path by default" do
22
+ get :index
23
+
24
+ expect(response).to redirect_to '/admin/orders'
25
+ end
26
+
27
+ it "redirects to wherever admin_root_redirects_path tells it to" do
28
+ expect(controller).to receive(:admin_root_redirect_path).and_return('/grooot')
29
+
30
+ get :index
31
+
32
+ expect(response).to redirect_to '/grooot'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::SearchController, :type => :controller do
4
+ stub_authorization!
5
+ # Regression test for ernie/ransack#176
6
+
7
+ describe "users" do
8
+ let(:user) { create(:user, :email => "spree_commerce@example.com") }
9
+
10
+ before do
11
+ user.ship_address = create(:address)
12
+ user.bill_address = create(:address)
13
+ user.save
14
+ end
15
+
16
+ it "can find a user by their email "do
17
+ spree_xhr_get :users, :q => user.email
18
+ expect(assigns[:users]).to include(user)
19
+ end
20
+
21
+ it "can find a user by their ship address's first name" do
22
+ spree_xhr_get :users, :q => user.ship_address.firstname
23
+ expect(assigns[:users]).to include(user)
24
+ end
25
+
26
+ it "can find a user by their ship address's last name" do
27
+ spree_xhr_get :users, :q => user.ship_address.lastname
28
+ expect(assigns[:users]).to include(user)
29
+ end
30
+
31
+ it "can find a user by their bill address's first name" do
32
+ spree_xhr_get :users, :q => user.bill_address.firstname
33
+ expect(assigns[:users]).to include(user)
34
+ end
35
+
36
+ it "can find a user by their bill address's last name" do
37
+ spree_xhr_get :users, :q => user.bill_address.lastname
38
+ expect(assigns[:users]).to include(user)
39
+ end
40
+ end
41
+
42
+ describe "products" do
43
+ let(:product) { create(:product, :name => "Example Product") }
44
+
45
+ it "can find a product by its name "do
46
+ spree_xhr_get :products, :q => product.name
47
+ expect(assigns[:products]).to include(product)
48
+ end
49
+
50
+ it "can find a product by its slug "do
51
+ spree_xhr_get :products, :q => product.slug
52
+ expect(assigns[:products]).to include(product)
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::ShippingMethodsController, :type => :controller do
4
+ stub_authorization!
5
+
6
+ # Regression test for #1240
7
+ it "should not hard-delete shipping methods" do
8
+ shipping_method = stub_model(Spree::ShippingMethod)
9
+ allow(Spree::ShippingMethod).to receive_messages :find => shipping_method
10
+ expect(shipping_method.deleted_at).to be_nil
11
+ spree_delete :destroy, :id => 1
12
+ expect(shipping_method.reload.deleted_at).not_to be_nil
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockItemsController, :type => :controller do
6
+ stub_authorization!
7
+
8
+ context "formats" do
9
+ let!(:stock_item) { create(:variant).stock_items.first }
10
+
11
+ it "destroy stock item via js" do
12
+ expect {
13
+ spree_delete :destroy, format: :js, id: stock_item
14
+ }.to change{ StockItem.count }.by(-1)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockLocationsController, :type => :controller do
6
+ stub_authorization!
7
+
8
+ # Regression for #4272
9
+ context "with no countries present" do
10
+ it "cannot create a new stock location" do
11
+ spree_get :new
12
+ expect(flash[:error]).to eq(Spree.t(:stock_locations_need_a_default_country))
13
+ expect(response).to redirect_to(spree.admin_stock_locations_path)
14
+ end
15
+ end
16
+
17
+ context "with a default country present" do
18
+ before do
19
+ country = FactoryGirl.create(:country)
20
+ Spree::Config[:default_country_id] = country.id
21
+ end
22
+
23
+ it "can create a new stock location" do
24
+ spree_get :new
25
+ expect(response).to be_success
26
+ end
27
+ end
28
+
29
+ context "with a country with the ISO code of 'US' existing" do
30
+ before do
31
+ FactoryGirl.create(:country, iso: 'US')
32
+ end
33
+
34
+ it "can create a new stock location" do
35
+ spree_get :new
36
+ expect(response).to be_success
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Admin::StockTransfersController, :type => :controller do
5
+ stub_authorization!
6
+
7
+ let!(:stock_transfer1) {
8
+ StockTransfer.create do |transfer|
9
+ transfer.source_location_id = 1
10
+ transfer.destination_location_id = 2
11
+ transfer.reference = 'PO 666'
12
+ end }
13
+
14
+ let!(:stock_transfer2) {
15
+ StockTransfer.create do |transfer|
16
+ transfer.source_location_id = 3
17
+ transfer.destination_location_id = 4
18
+ transfer.reference = 'PO 666'
19
+ end }
20
+
21
+
22
+ context "#index" do
23
+ it "gets all transfers without search criteria" do
24
+ spree_get :index
25
+ expect(assigns[:stock_transfers].count).to eq 2
26
+ end
27
+
28
+ it "searches by source location" do
29
+ spree_get :index, :q => { :source_location_id_eq => 1 }
30
+ expect(assigns[:stock_transfers].count).to eq 1
31
+ expect(assigns[:stock_transfers]).to include(stock_transfer1)
32
+ end
33
+
34
+ it "searches by destination location" do
35
+ spree_get :index, :q => { :destination_location_id_eq => 4 }
36
+ expect(assigns[:stock_transfers].count).to eq 1
37
+ expect(assigns[:stock_transfers]).to include(stock_transfer2)
38
+ end
39
+ end
40
+ end
41
+ end