Skip to content

Commit 33da025

Browse files
committed
Adds Specs for UnlocksController
1 parent a0d7c46 commit 33da025

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.rubocop_todo.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,13 @@ RSpec/StubbedMock:
294294
Exclude:
295295
- 'spec/models/user_spec.rb'
296296

297-
# Offense count: 2
297+
# Offense count: 3
298298
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
299299
RSpec/VerifiedDoubles:
300300
Exclude:
301301
- 'spec/features/confirmation_spec.rb'
302302
- 'spec/models/user_spec.rb'
303+
- 'spec/controllers/spree/admin/user_unlocks_controller_spec.rb'
303304

304305
# Offense count: 12
305306
# This cop supports unsafe autocorrection (--autocorrect-all).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Spree::Admin::UserUnlocksController, type: :controller do
4+
# rubocop:disable RSpec/InstanceVariable
5+
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
6+
7+
describe '#create' do
8+
let(:user) { create(:user, locked_at: Time.current) }
9+
10+
it 'sends unlock instructions to the user' do
11+
# rubocop:disable RSpec/StubbedMock
12+
expect(Spree::UserMailer).to receive(:unlock_instructions).and_return(double(deliver: true))
13+
# rubocop:enable RSpec/StubbedMock
14+
15+
post :create, params: { spree_user: { email: user.email } }
16+
17+
expect(assigns[:spree_user].email).to eq(user.email)
18+
expect(response.code).to eq('302')
19+
end
20+
end
21+
22+
describe '#show' do
23+
let(:user) { create(:user, locked_at: Time.current) }
24+
25+
before {
26+
@raw_token, encrypted_token = Devise.token_generator.generate(user.class, :unlock_token)
27+
user.update(unlock_token: encrypted_token)
28+
}
29+
30+
it 'unlocks a previously locked user' do
31+
get :show, params: { unlock_token: @raw_token }
32+
33+
expect(response.code).to eq '302'
34+
expect(user.reload.locked_at).to be_nil
35+
end
36+
end
37+
38+
# rubocop:enable RSpec/InstanceVariable
39+
end

0 commit comments

Comments
 (0)