mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add UserConfirmationsController spec
This commit is contained in:
committed by
Rob Harrington
parent
4f0b20e8ad
commit
7d971fc39d
@@ -8,9 +8,6 @@ class UserConfirmationsController < DeviseController
|
||||
|
||||
# POST /resource/confirmation
|
||||
def create
|
||||
self.resource = resource_class.find_by_unconfirmed_email_with_errors(resource_params)
|
||||
authorize! :resend_confirmation, resource
|
||||
|
||||
self.resource = resource_class.send_confirmation_instructions(resource_params)
|
||||
|
||||
if successfully_sent?(resource) && is_navigational_format?
|
||||
@@ -19,7 +16,7 @@ class UserConfirmationsController < DeviseController
|
||||
set_flash_message(:error, :confirmation_not_sent)
|
||||
end
|
||||
|
||||
respond_with_navigational(resource){ redirect_to spree.admin_path }
|
||||
respond_with_navigational(resource){ redirect_to login_path }
|
||||
end
|
||||
|
||||
# GET /resource/confirmation?confirmation_token=abcdef
|
||||
|
||||
56
spec/controllers/user_confirmations_controller_spec.rb
Normal file
56
spec/controllers/user_confirmations_controller_spec.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe UserConfirmationsController do
|
||||
include AuthenticationWorkflow
|
||||
let!(:user) { create_enterprise_user }
|
||||
let!(:confirmed_user) { create_enterprise_user(confirmed_at: nil) }
|
||||
let!(:unconfirmed_user) { create_enterprise_user(confirmed_at: nil) }
|
||||
let!(:confirmed_token) { confirmed_user.confirmation_token }
|
||||
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:spree_user]
|
||||
confirmed_user.confirm!
|
||||
end
|
||||
|
||||
context "confirming a user" do
|
||||
context "that has already been confirmed" do
|
||||
|
||||
before do
|
||||
spree_get :show, confirmation_token: confirmed_token
|
||||
end
|
||||
|
||||
it "redirects the user to login" do
|
||||
expect(response).to redirect_to login_path
|
||||
expect(flash[:error]).to eq I18n.t('devise.user_confirmations.spree_user.not_confirmed')
|
||||
end
|
||||
end
|
||||
|
||||
context "that has not been confirmed" do
|
||||
it "redirects the user to login" do
|
||||
spree_get :show, confirmation_token: unconfirmed_user.confirmation_token
|
||||
expect(response).to redirect_to login_path
|
||||
expect(flash[:success]).to eq I18n.t('devise.user_confirmations.spree_user.confirmed')
|
||||
end
|
||||
|
||||
it "confirms the user" do
|
||||
spree_get :show, confirmation_token: unconfirmed_user.confirmation_token
|
||||
expect(unconfirmed_user.reload.confirmed_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "requesting confirmation instructions to be resent" do
|
||||
it "redirects the user to login" do
|
||||
spree_post :create, { spree_user: { email: unconfirmed_user.email } }
|
||||
expect(response).to redirect_to login_path
|
||||
expect(flash[:success]).to eq I18n.t('devise.user_confirmations.spree_user.confirmation_sent')
|
||||
end
|
||||
|
||||
it "sends the confirmation email" do
|
||||
expect do
|
||||
spree_post :create, { spree_user: { email: unconfirmed_user.email } }
|
||||
end.to enqueue_job Delayed::PerformableMethod
|
||||
expect(Delayed::Job.last.payload_object.method_name).to eq(:send_confirmation_instructions_without_delay)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user