Skip to content

Commit 483a40c

Browse files
committed
Adds Specs for UnlocksController
1 parent a0d7c46 commit 483a40c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
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(instance_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)