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.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Rakefile +15 -0
- data/script/rails +9 -0
- data/solidus_backend.gemspec +30 -0
- data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
- data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
- data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +460 -0
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
- data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
- data/spec/controllers/spree/admin/product_properties_controller_spec.rb +69 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +162 -0
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +124 -0
- data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
- data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +240 -0
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
- data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +351 -0
- data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
- data/spec/controllers/spree/admin/users_controller_spec.rb +257 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +50 -0
- data/spec/features/admin/configuration/countries_spec.rb +22 -0
- data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
- data/spec/features/admin/configuration/payment_methods_spec.rb +124 -0
- data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
- data/spec/features/admin/configuration/states_spec.rb +64 -0
- data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
- data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
- data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
- data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
- data/spec/features/admin/configuration/zones_spec.rb +39 -0
- data/spec/features/admin/homepage_spec.rb +78 -0
- data/spec/features/admin/locale_spec.rb +30 -0
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
- data/spec/features/admin/orders/adjustments_spec.rb +126 -0
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
- data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
- data/spec/features/admin/orders/customer_details_spec.rb +163 -0
- data/spec/features/admin/orders/line_items_spec.rb +50 -0
- data/spec/features/admin/orders/listing_spec.rb +130 -0
- data/spec/features/admin/orders/log_entries_spec.rb +55 -0
- data/spec/features/admin/orders/new_order_spec.rb +185 -0
- data/spec/features/admin/orders/order_details_spec.rb +533 -0
- data/spec/features/admin/orders/payments_spec.rb +234 -0
- data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
- data/spec/features/admin/orders/shipments_spec.rb +65 -0
- data/spec/features/admin/payments/store_credits_spec.rb +21 -0
- data/spec/features/admin/products/edit/images_spec.rb +87 -0
- data/spec/features/admin/products/edit/products_spec.rb +66 -0
- data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
- data/spec/features/admin/products/edit/variants_spec.rb +61 -0
- data/spec/features/admin/products/option_types_spec.rb +114 -0
- data/spec/features/admin/products/products_spec.rb +395 -0
- data/spec/features/admin/products/properties_spec.rb +139 -0
- data/spec/features/admin/products/prototypes_spec.rb +110 -0
- data/spec/features/admin/products/stock_management_spec.rb +82 -0
- data/spec/features/admin/products/variant_spec.rb +51 -0
- data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
- data/spec/features/admin/promotions/option_value_rule_spec.rb +65 -0
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
- data/spec/features/admin/reports_spec.rb +61 -0
- data/spec/features/admin/stock_transfer_spec.rb +104 -0
- data/spec/features/admin/store_credits_spec.rb +82 -0
- data/spec/features/admin/taxons_spec.rb +31 -0
- data/spec/features/admin/users_spec.rb +275 -0
- data/spec/helpers/admin/base_helper_spec.rb +18 -0
- data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
- data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
- data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
- data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
- data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/support/appear_before_matcher.rb +8 -0
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
- metadata +96 -6
@@ -0,0 +1,309 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples "update reason loader" do
|
4
|
+
it "sets the update_reasons variable to a list of categories sorted by category name " do
|
5
|
+
expect(assigns(:update_reasons)).to eq [update_reason]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Spree::Admin::StoreCreditsController do
|
10
|
+
stub_authorization!
|
11
|
+
|
12
|
+
let(:user) { create(:user) }
|
13
|
+
let(:admin_user) { create(:admin_user) }
|
14
|
+
|
15
|
+
let!(:b_credit_category) { create(:store_credit_category, name: "B category") }
|
16
|
+
let!(:a_credit_category) { create(:store_credit_category, name: "A category") }
|
17
|
+
let!(:update_reason) { create(:store_credit_update_reason) }
|
18
|
+
|
19
|
+
describe "#show" do
|
20
|
+
let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
|
21
|
+
let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
|
22
|
+
|
23
|
+
before { spree_get :show, user_id: user.id, id: store_credit.id }
|
24
|
+
|
25
|
+
it "sets the store_credit variable to a new store credit model" do
|
26
|
+
expect(assigns(:store_credit)).to eq store_credit
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets the store_credit_events variable to the store credit's events in chronological order" do
|
30
|
+
allocation_event = store_credit.store_credit_events.find_by(action: Spree::StoreCredit::ALLOCATION_ACTION)
|
31
|
+
expect(assigns(:store_credit_events)).to eq [event, allocation_event]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#new" do
|
36
|
+
before { spree_get :new, user_id: create(:user).id }
|
37
|
+
it { expect(assigns(:credit_categories)).to eq [a_credit_category, b_credit_category] }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#create" do
|
41
|
+
|
42
|
+
subject { spree_post :create, parameters }
|
43
|
+
|
44
|
+
before {
|
45
|
+
allow(controller).to receive_messages(try_spree_current_user: admin_user)
|
46
|
+
create(:primary_credit_type)
|
47
|
+
}
|
48
|
+
|
49
|
+
context "the passed parameters are valid" do
|
50
|
+
let(:parameters) do
|
51
|
+
{
|
52
|
+
user_id: user.id,
|
53
|
+
store_credit: {
|
54
|
+
amount: 1.00,
|
55
|
+
category_id: a_credit_category.id
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
it "creates a new store credit" do
|
61
|
+
expect { subject }.to change(Spree::StoreCredit, :count).by(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "associates the store credit with the user" do
|
65
|
+
subject
|
66
|
+
expect(user.reload.store_credits.count).to eq 1
|
67
|
+
end
|
68
|
+
|
69
|
+
it "assigns the store credit's created by to the current user" do
|
70
|
+
subject
|
71
|
+
expect(user.reload.store_credits.first.created_by).to eq admin_user
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'sets the admin as the store credit event originator' do
|
75
|
+
expect { subject }.to change { Spree::StoreCreditEvent.count }.by(1)
|
76
|
+
expect(Spree::StoreCreditEvent.last.originator).to eq admin_user
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "the passed parameters are invalid" do
|
81
|
+
let(:parameters) do
|
82
|
+
{
|
83
|
+
user_id: user.id,
|
84
|
+
store_credit: {
|
85
|
+
amount: -1.00,
|
86
|
+
category_id: a_credit_category.id
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
it { expect { subject }.not_to change(Spree::StoreCredit, :count) }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#edit_amount" do
|
96
|
+
let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
|
97
|
+
|
98
|
+
before { spree_get :edit_amount, user_id: user.id, id: store_credit.id }
|
99
|
+
|
100
|
+
it_behaves_like "update reason loader"
|
101
|
+
|
102
|
+
it "sets the store_credit variable to the persisted store credit" do
|
103
|
+
expect(assigns(:store_credit)).to eq store_credit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#edit_validity" do
|
108
|
+
let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
|
109
|
+
|
110
|
+
before { spree_get :edit_validity, user_id: user.id, id: store_credit.id }
|
111
|
+
|
112
|
+
it_behaves_like "update reason loader"
|
113
|
+
|
114
|
+
it "sets the store_credit variable to the persisted store credit" do
|
115
|
+
expect(assigns(:store_credit)).to eq store_credit
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#update" do
|
120
|
+
let(:memo) { "New memo" }
|
121
|
+
let!(:store_credit) { create(:store_credit, user: user) }
|
122
|
+
|
123
|
+
subject { spree_put :update, parameters.merge(format: :json) }
|
124
|
+
|
125
|
+
before { allow(controller).to receive_messages(try_spree_current_user: admin_user) }
|
126
|
+
|
127
|
+
context "the passed parameters are valid" do
|
128
|
+
let(:parameters) do
|
129
|
+
{
|
130
|
+
user_id: user.id,
|
131
|
+
id: store_credit.id,
|
132
|
+
store_credit: {
|
133
|
+
memo: memo
|
134
|
+
}
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
it "updates the memo to be the passed in value" do
|
139
|
+
expect { subject }.to change { store_credit.reload.memo }.to(memo)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "returns a success message" do
|
143
|
+
subject
|
144
|
+
expect(response).to have_http_status(:ok)
|
145
|
+
expect(JSON.parse(response.body)['message']).to match("Store credit has been successfully updated!")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "the passed parameters are invalid" do
|
150
|
+
let(:parameters) do
|
151
|
+
{
|
152
|
+
user_id: user.id,
|
153
|
+
id: store_credit.id,
|
154
|
+
store_credit: {
|
155
|
+
category_id: b_credit_category.id
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
it "doesn't update the store credit's category" do
|
160
|
+
expect { subject }.to_not change { store_credit.reload.category }
|
161
|
+
end
|
162
|
+
|
163
|
+
it "returns an error message" do
|
164
|
+
subject
|
165
|
+
expect(response).to have_http_status(:bad_request)
|
166
|
+
expect(JSON.parse(response.body)['message']).to match("Unable to update store credit")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#update_amount" do
|
172
|
+
let(:original_amount) { 100.0 }
|
173
|
+
let!(:store_credit) { create(:store_credit, user: user, amount: original_amount) }
|
174
|
+
let!(:update_reason) { create(:store_credit_update_reason) }
|
175
|
+
let(:parameters) do
|
176
|
+
{
|
177
|
+
user_id: user.id,
|
178
|
+
id: store_credit.id,
|
179
|
+
update_reason_id: update_reason.id,
|
180
|
+
store_credit: {
|
181
|
+
amount: updated_amount
|
182
|
+
}
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
subject { spree_put :update_amount, parameters }
|
187
|
+
|
188
|
+
before { allow(controller).to receive_messages(try_spree_current_user: admin_user) }
|
189
|
+
|
190
|
+
context "the passed parameters are valid" do
|
191
|
+
let(:updated_amount) { 300.0 }
|
192
|
+
|
193
|
+
context "the store credit has been partially used" do
|
194
|
+
before { store_credit.update_attributes(amount_used: 10.0) }
|
195
|
+
|
196
|
+
context "the new amount is greater than the used amount" do
|
197
|
+
let(:updated_amount) { 11.0 }
|
198
|
+
|
199
|
+
before { subject }
|
200
|
+
|
201
|
+
it "updates the amount to be the passed in amount" do
|
202
|
+
expect(store_credit.reload.amount).to eq updated_amount
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "the new amount is less than the used amount" do
|
207
|
+
let(:updated_amount) { 9.0 }
|
208
|
+
|
209
|
+
before { subject }
|
210
|
+
|
211
|
+
it "does not update the amount" do
|
212
|
+
expect(store_credit.reload.amount).to eq original_amount
|
213
|
+
end
|
214
|
+
|
215
|
+
it "renders the edit_amount template" do
|
216
|
+
expect(response).to render_template :edit_amount
|
217
|
+
end
|
218
|
+
|
219
|
+
it "adds an error message to the flash" do
|
220
|
+
expect(flash.now[:error]).to match "Unable to update"
|
221
|
+
end
|
222
|
+
|
223
|
+
it_behaves_like "update reason loader"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "the store credit has not been used" do
|
228
|
+
it "sets a success message in the flash" do
|
229
|
+
subject
|
230
|
+
expect(flash.now[:success]).to match "Store credit has been successfully updated!"
|
231
|
+
end
|
232
|
+
|
233
|
+
it "does not create a new store credit" do
|
234
|
+
expect { subject }.to_not change(Spree::StoreCredit, :count)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "updates passed amount" do
|
238
|
+
subject
|
239
|
+
expect(store_credit.reload.amount).to eq updated_amount
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "the passed parameters are invalid" do
|
245
|
+
let(:updated_amount) { -1.00 }
|
246
|
+
|
247
|
+
before { subject }
|
248
|
+
|
249
|
+
it "does not update the amount" do
|
250
|
+
expect(store_credit.reload.amount).to eq original_amount
|
251
|
+
end
|
252
|
+
|
253
|
+
it "renders the edit_amount template" do
|
254
|
+
expect(response).to render_template :edit_amount
|
255
|
+
end
|
256
|
+
|
257
|
+
it "adds an error message to the flash" do
|
258
|
+
expect(flash.now[:error]).to match "Unable to update"
|
259
|
+
end
|
260
|
+
|
261
|
+
it_behaves_like "update reason loader"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#invalidate" do
|
266
|
+
let!(:store_credit) { create(:store_credit, user: user, category: b_credit_category) }
|
267
|
+
|
268
|
+
let(:parameters) do
|
269
|
+
{
|
270
|
+
user_id: user.id,
|
271
|
+
id: store_credit.id,
|
272
|
+
update_reason_id: update_reason.id
|
273
|
+
}
|
274
|
+
end
|
275
|
+
|
276
|
+
subject { spree_put :invalidate, parameters }
|
277
|
+
|
278
|
+
it "attempts to invalidate the store credit" do
|
279
|
+
expect { subject }.to change { store_credit.reload.invalidated_at }.from(nil)
|
280
|
+
end
|
281
|
+
|
282
|
+
context "the invalidation is unsuccessful" do
|
283
|
+
before do
|
284
|
+
store_credit.authorize(5.0, "USD")
|
285
|
+
subject
|
286
|
+
end
|
287
|
+
|
288
|
+
it "doesn't invalidate the store credit" do
|
289
|
+
expect(store_credit.reload.invalidated_at).to be_nil
|
290
|
+
end
|
291
|
+
|
292
|
+
it "renders the edit_validity template" do
|
293
|
+
expect(response).to render_template :edit_validity
|
294
|
+
end
|
295
|
+
|
296
|
+
it "sets an error message in the flash" do
|
297
|
+
expect(flash.now[:error]).to match "Unable to invalidate store credit"
|
298
|
+
end
|
299
|
+
|
300
|
+
it_behaves_like "update reason loader"
|
301
|
+
end
|
302
|
+
|
303
|
+
context "the invalidation is successful" do
|
304
|
+
it "redirects to index" do
|
305
|
+
expect(subject).to redirect_to spree.admin_user_store_credit_path(user, store_credit)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spree/testing_support/bar_ability'
|
3
|
+
|
4
|
+
describe Spree::Admin::UsersController, :type => :controller do
|
5
|
+
let(:user) { create(:user) }
|
6
|
+
let(:mock_user) { mock_model Spree.user_class }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(controller).to receive_messages :spree_current_user => user
|
10
|
+
user.spree_roles.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
context "#show" do
|
14
|
+
before do
|
15
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "redirects to edit" do
|
19
|
+
spree_get :show, id: user.id
|
20
|
+
expect(response).to redirect_to spree.edit_admin_user_path(user)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#authorize_admin' do
|
25
|
+
before { use_mock_user }
|
26
|
+
|
27
|
+
it 'grant access to users with an admin role' do
|
28
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
29
|
+
spree_post :index
|
30
|
+
expect(response).to render_template :index
|
31
|
+
end
|
32
|
+
|
33
|
+
it "allows admins to update a user's API key" do
|
34
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
35
|
+
expect(mock_user).to receive(:generate_spree_api_key!).and_return(true)
|
36
|
+
spree_put :generate_api_key, id: mock_user.id
|
37
|
+
expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "allows admins to clear a user's API key" do
|
41
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
42
|
+
expect(mock_user).to receive(:clear_spree_api_key!).and_return(true)
|
43
|
+
spree_put :clear_api_key, id: mock_user.id
|
44
|
+
expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'deny access to users with an bar role' do
|
48
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
49
|
+
Spree::Ability.register_ability(BarAbility)
|
50
|
+
spree_post :index
|
51
|
+
expect(response).to redirect_to '/unauthorized'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'deny access to users with an bar role' do
|
55
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
56
|
+
Spree::Ability.register_ability(BarAbility)
|
57
|
+
spree_post :update, { id: '9' }
|
58
|
+
expect(response).to redirect_to '/unauthorized'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'deny access to users without an admin role' do
|
62
|
+
allow(user).to receive_messages :has_spree_role? => false
|
63
|
+
spree_post :index
|
64
|
+
expect(response).to redirect_to '/unauthorized'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#create" do
|
69
|
+
let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
|
70
|
+
|
71
|
+
before do
|
72
|
+
use_mock_user
|
73
|
+
allow(mock_user).to receive_messages(:spree_roles= => true, :stock_locations= => true)
|
74
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when the user can manage roles" do
|
78
|
+
it "can set roles" do
|
79
|
+
expect(mock_user).to receive(:spree_roles=).with([dummy_role])
|
80
|
+
spree_post :create, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can clear roles" do
|
84
|
+
expect(mock_user).to receive(:spree_roles=).with([])
|
85
|
+
spree_post :create, { id: mock_user.id, user: { first_name: "Bob"} }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when the user cannot manage roles" do
|
90
|
+
before do
|
91
|
+
user.spree_roles = [Spree::Role.find_or_create_by(name: "user_management")]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "cannot set roles" do
|
95
|
+
expect(mock_user).to_not receive(:spree_roles=)
|
96
|
+
spree_post :create, { user: { spree_role_ids: [dummy_role.id] } }
|
97
|
+
end
|
98
|
+
|
99
|
+
it "cannot set roles" do
|
100
|
+
expect(mock_user).to_not receive(:spree_roles=)
|
101
|
+
spree_post :create, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "cannot clear roles" do
|
105
|
+
expect(mock_user).to_not receive(:spree_roles=)
|
106
|
+
spree_post :create, { id: mock_user.id, user: { first_name: "Bob"} }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can create a shipping_address" do
|
111
|
+
expect(Spree.user_class).to receive(:new).with(hash_including(
|
112
|
+
"ship_address_attributes" => { "city" => "New York" }
|
113
|
+
))
|
114
|
+
spree_post :create, { :user => { :ship_address_attributes => { :city => "New York" } } }
|
115
|
+
end
|
116
|
+
|
117
|
+
it "can create a billing_address" do
|
118
|
+
expect(Spree.user_class).to receive(:new).with(hash_including(
|
119
|
+
"bill_address_attributes" => { "city" => "New York" }
|
120
|
+
))
|
121
|
+
spree_post :create, { :user => { :bill_address_attributes => { :city => "New York" } } }
|
122
|
+
end
|
123
|
+
|
124
|
+
it "can set stock locations" do
|
125
|
+
location = Spree::StockLocation.create(name: "my_location")
|
126
|
+
location_2 = Spree::StockLocation.create(name: "my_location_2")
|
127
|
+
expect(mock_user).to receive(:stock_locations=).with([location, location_2])
|
128
|
+
spree_post :create, { user: { stock_location_ids: [location.id, location_2.id] } }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#update" do
|
133
|
+
let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
|
134
|
+
let(:ability) { Spree::Ability.new(user) }
|
135
|
+
before do
|
136
|
+
use_mock_user
|
137
|
+
allow(mock_user).to receive_messages(:spree_roles= => true, :stock_locations= => true)
|
138
|
+
allow(controller).to receive(:current_ability) { ability }
|
139
|
+
Spree::PermissionSets::UserManagement.new(ability).activate!
|
140
|
+
end
|
141
|
+
|
142
|
+
context "as a superuser" do
|
143
|
+
before { Spree::PermissionSets::SuperUser.new(ability).activate! }
|
144
|
+
|
145
|
+
it "can set roles" do
|
146
|
+
expect(mock_user).to receive(:spree_roles=).with([dummy_role])
|
147
|
+
spree_put :update, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
|
148
|
+
end
|
149
|
+
|
150
|
+
it "can clear roles" do
|
151
|
+
expect(mock_user).to receive(:spree_roles=).with([])
|
152
|
+
spree_put :update, { id: mock_user.id, user: { first_name: "Bob" } }
|
153
|
+
end
|
154
|
+
|
155
|
+
it "can change email of a user with no roles" do
|
156
|
+
expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
|
157
|
+
spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
|
158
|
+
end
|
159
|
+
|
160
|
+
it "can change email of a user with roles" do
|
161
|
+
allow(mock_user).to receive(:spree_roles) { [dummy_role] }
|
162
|
+
expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
|
163
|
+
spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it "cannot set roles" do
|
168
|
+
expect(mock_user).to_not receive(:spree_roles=)
|
169
|
+
spree_put :update, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
|
170
|
+
end
|
171
|
+
|
172
|
+
it "cannot clear roles" do
|
173
|
+
expect(mock_user).to_not receive(:spree_roles=)
|
174
|
+
spree_put :update, { id: mock_user.id, user: { first_name: "Bob" } }
|
175
|
+
end
|
176
|
+
|
177
|
+
it "can change email of a user with no roles" do
|
178
|
+
expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
|
179
|
+
spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
|
180
|
+
end
|
181
|
+
|
182
|
+
it "cannot change email of a user with roles" do
|
183
|
+
allow(mock_user).to receive(:spree_roles) { [dummy_role] }
|
184
|
+
expect(mock_user).to receive(:update_attributes).with({})
|
185
|
+
spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
|
186
|
+
end
|
187
|
+
|
188
|
+
it "allows shipping address attributes through" do
|
189
|
+
expect(mock_user).to receive(:update_attributes).with(hash_including(
|
190
|
+
"ship_address_attributes" => { "city" => "New York" }
|
191
|
+
))
|
192
|
+
spree_put :update, { :id => mock_user.id, :user => { :ship_address_attributes => { :city => "New York" } } }
|
193
|
+
end
|
194
|
+
|
195
|
+
it "allows billing address attributes through" do
|
196
|
+
expect(mock_user).to receive(:update_attributes).with(hash_including(
|
197
|
+
"bill_address_attributes" => { "city" => "New York" }
|
198
|
+
))
|
199
|
+
spree_put :update, { :id => mock_user.id, :user => { :bill_address_attributes => { :city => "New York" } } }
|
200
|
+
end
|
201
|
+
|
202
|
+
it "can set stock locations" do
|
203
|
+
location = Spree::StockLocation.create(name: "my_location")
|
204
|
+
location_2 = Spree::StockLocation.create(name: "my_location_2")
|
205
|
+
expect(mock_user).to receive(:stock_locations=).with([location, location_2])
|
206
|
+
spree_put :update, { id: mock_user.id, user: { stock_location_ids: [location.id, location_2.id] } }
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "#orders" do
|
211
|
+
let(:order) { create(:order) }
|
212
|
+
before do
|
213
|
+
user.orders << order
|
214
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
215
|
+
end
|
216
|
+
|
217
|
+
it "assigns a list of the users orders" do
|
218
|
+
spree_get :orders, { :id => user.id }
|
219
|
+
expect(assigns[:orders].count).to eq 1
|
220
|
+
expect(assigns[:orders].first).to eq order
|
221
|
+
end
|
222
|
+
|
223
|
+
it "assigns a ransack search for Spree::Order" do
|
224
|
+
spree_get :orders, { :id => user.id }
|
225
|
+
expect(assigns[:search]).to be_a Ransack::Search
|
226
|
+
expect(assigns[:search].klass).to eq Spree::Order
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe "#items" do
|
231
|
+
let(:order) { create(:order) }
|
232
|
+
before do
|
233
|
+
user.orders << order
|
234
|
+
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
235
|
+
end
|
236
|
+
|
237
|
+
it "assigns a list of the users orders" do
|
238
|
+
spree_get :items, { :id => user.id }
|
239
|
+
expect(assigns[:orders].count).to eq 1
|
240
|
+
expect(assigns[:orders].first).to eq order
|
241
|
+
end
|
242
|
+
|
243
|
+
it "assigns a ransack search for Spree::Order" do
|
244
|
+
spree_get :items, { :id => user.id }
|
245
|
+
expect(assigns[:search]).to be_a Ransack::Search
|
246
|
+
expect(assigns[:search].klass).to eq Spree::Order
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def use_mock_user
|
252
|
+
allow(mock_user).to receive(:save).and_return(true)
|
253
|
+
allow(mock_user).to receive(:update_attributes).and_return(true)
|
254
|
+
allow(mock_user).to receive(:spree_roles).and_return([])
|
255
|
+
allow(Spree.user_class).to receive(:find).with(mock_user.id.to_s).and_return(mock_user)
|
256
|
+
allow(Spree.user_class).to receive(:new).and_return(mock_user)
|
257
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Admin
|
5
|
+
describe VariantsController, :type => :controller do
|
6
|
+
stub_authorization!
|
7
|
+
|
8
|
+
describe "#index" do
|
9
|
+
let(:product) { create(:product) }
|
10
|
+
let!(:variant_1) { create(:variant, product: product) }
|
11
|
+
let!(:variant_2) { create(:variant, product: product) }
|
12
|
+
|
13
|
+
context "deleted is not requested" do
|
14
|
+
it "assigns the variants for a requested product" do
|
15
|
+
spree_get :index, product_id: product.slug
|
16
|
+
expect(assigns(:collection)).to include variant_1
|
17
|
+
expect(assigns(:collection)).to include variant_2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "deleted is requested" do
|
22
|
+
before { variant_2.destroy }
|
23
|
+
it "assigns only deleted variants for a requested product" do
|
24
|
+
spree_get :index, product_id: product.slug, deleted: "on"
|
25
|
+
expect(assigns(:collection)).not_to include variant_1
|
26
|
+
expect(assigns(:collection)).to include variant_2
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Analytics Tracker", :type => :feature do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
context "index" do
|
7
|
+
before(:each) do
|
8
|
+
2.times { create(:tracker) }
|
9
|
+
visit spree.admin_path
|
10
|
+
click_link "Settings"
|
11
|
+
click_link "Analytics Tracker"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have the right content" do
|
15
|
+
expect(page).to have_content("Analytics Trackers")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have the right tabular values displayed" do
|
19
|
+
within_row(1) do
|
20
|
+
expect(column_text(1)).to eq("A100")
|
21
|
+
expect(column_text(2)).to eq("Yes")
|
22
|
+
end
|
23
|
+
|
24
|
+
within_row(2) do
|
25
|
+
expect(column_text(1)).to eq("A100")
|
26
|
+
expect(column_text(2)).to eq("Yes")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "create" do
|
32
|
+
before(:each) do
|
33
|
+
visit spree.admin_path
|
34
|
+
click_link "Settings"
|
35
|
+
click_link "Analytics Tracker"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to create a new analytics tracker" do
|
39
|
+
click_link "admin_new_tracker_link"
|
40
|
+
fill_in "tracker_analytics_id", :with => "A100"
|
41
|
+
click_button "Create"
|
42
|
+
|
43
|
+
expect(page).to have_content("successfully created!")
|
44
|
+
within_row(1) do
|
45
|
+
expect(column_text(1)).to eq("A100")
|
46
|
+
expect(column_text(2)).to eq("Yes")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe "Countries", type: :feature do
|
5
|
+
stub_authorization!
|
6
|
+
|
7
|
+
it "deletes a country", js: true do
|
8
|
+
visit spree.admin_countries_path
|
9
|
+
click_link "New Country"
|
10
|
+
|
11
|
+
fill_in "Name", with: "Brazil"
|
12
|
+
fill_in "Iso Name", with: "BRL"
|
13
|
+
click_button "Create"
|
14
|
+
|
15
|
+
accept_alert do
|
16
|
+
click_icon :trash
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(page).to have_content 'Country "Brazil" has been successfully removed!'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|