Skip to content

Commit

Permalink
Adds Specs for UnlocksController
Browse files Browse the repository at this point in the history
  • Loading branch information
cesartalves committed Oct 18, 2022
1 parent a0d7c46 commit 33da025
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ RSpec/StubbedMock:
Exclude:
- 'spec/models/user_spec.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/features/confirmation_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/controllers/spree/admin/user_unlocks_controller_spec.rb'

# Offense count: 12
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand Down
39 changes: 39 additions & 0 deletions spec/controllers/spree/admin/user_unlocks_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

0 comments on commit 33da025

Please sign in to comment.