-
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathuser_unlocks_controller_spec.rb
More file actions
39 lines (29 loc) · 1.18 KB
/
user_unlocks_controller_spec.rb
File metadata and controls
39 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
RSpec.describe Spree::Admin::UserUnlocksController, type: :controller do
# rubocop:disable RSpec/InstanceVariable
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
describe '#create' do
let(:user) { create(:user, locked_at: Time.current) }
it 'sends unlock instructions to the user' do
# rubocop:disable RSpec/StubbedMock
expect(Spree::UserMailer).to receive(:unlock_instructions).and_return(double(deliver: true))
# rubocop:enable RSpec/StubbedMock
post :create, params: { spree_user: { email: user.email } }
expect(assigns[:spree_user].email).to eq(user.email)
expect(response.code).to eq('302')
end
end
describe '#show' do
let(:user) { create(:user, locked_at: Time.current) }
before {
@raw_token, encrypted_token = Devise.token_generator.generate(user.class, :unlock_token)
user.update(unlock_token: encrypted_token)
}
it 'unlocks a previously locked user' do
get :show, params: { unlock_token: @raw_token }
expect(response.code).to eq '302'
expect(user.reload.locked_at).to be_nil
end
end
# rubocop:enable RSpec/InstanceVariable
end