added tests

This commit is contained in:
Hauke Klement
2015-02-23 15:51:01 +01:00
parent cbca0c0c1e
commit dafeb3a706

View File

@ -163,6 +163,49 @@ describe InternalUsersController do
expect_template(:edit) expect_template(:edit)
end end
describe 'GET #forgot_password' do
context 'when no user is logged in' do
before(:each) do
expect(controller).to receive(:current_user).and_return(nil)
get :forgot_password
end
expect_status(200)
expect_template(:forgot_password)
end
context 'when a user is already logged in' do
before(:each) do
expect(controller).to receive(:current_user).and_return(user)
get :forgot_password
end
expect_redirect(:root)
end
end
describe 'POST #forgot_password' do
context 'with an email address' do
let(:request) { proc { post :forgot_password, email: user.email } }
before(:each) { request.call }
it 'delivers instructions to reset the password' do
expect(InternalUser).to receive(:find_by).and_return(user)
expect(user).to receive(:deliver_reset_password_instructions!)
request.call
end
expect_redirect(:root)
end
context 'without an email address' do
before(:each) { post :forgot_password }
expect_status(200)
expect_template(:forgot_password)
end
end
describe 'GET #index' do describe 'GET #index' do
before(:each) do before(:each) do
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
@ -185,6 +228,65 @@ describe InternalUsersController do
expect_template(:new) expect_template(:new)
end end
describe 'GET #reset_password' do
let(:user) { users.first }
context 'without a valid password reset token' do
before(:each) { get :reset_password, id: user.id }
expect_redirect
end
context 'with a valid password reset token' do
before(:each) do
user.deliver_reset_password_instructions!
get :reset_password, id: user.id, token: user.reset_password_token
end
expect_assigns(user: :user)
expect_status(200)
expect_template(:reset_password)
end
end
describe 'PUT #reset_password' do
let(:user) { users.first }
before(:each) { user.deliver_reset_password_instructions! }
context 'without a valid password reset token' do
before(:each) { put :reset_password, id: user.id }
expect_redirect(:root)
end
context 'with a valid password reset token' do
let(:password) { 'foo' }
context 'with a matching password confirmation' do
let(:request) { proc { put :reset_password, internal_user: {password: password, password_confirmation: password}, id: user.id, token: user.reset_password_token } }
before(:each) { request.call }
expect_assigns(user: :user)
it 'changes the password' do
expect(InternalUser.authenticate(user.email, password)).to eq(user)
end
expect_redirect { Rails.application.routes.url_helpers.send(:sign_in_path) }
end
context 'without a matching password confirmation' do
before(:each) do
put :reset_password, internal_user: {password: password, password_confirmation: ''}, id: users.first.id, token: user.reset_password_token
end
expect_assigns(user: :user)
expect_status(200)
expect_template(:reset_password)
end
end
end
describe 'GET #show' do describe 'GET #show' do
before(:each) do before(:each) do
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)