summaryrefslogtreecommitdiff
path: root/spec/controllers/confirmations_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/confirmations_controller_spec.rb')
-rw-r--r--spec/controllers/confirmations_controller_spec.rb64
1 files changed, 54 insertions, 10 deletions
diff --git a/spec/controllers/confirmations_controller_spec.rb b/spec/controllers/confirmations_controller_spec.rb
index 49a39f257fe..c9a0ae981fc 100644
--- a/spec/controllers/confirmations_controller_spec.rb
+++ b/spec/controllers/confirmations_controller_spec.rb
@@ -12,7 +12,9 @@ RSpec.describe ConfirmationsController do
describe '#show' do
render_views
- subject { get :show, params: { confirmation_token: confirmation_token } }
+ def perform_request
+ get :show, params: { confirmation_token: confirmation_token }
+ end
context 'user is already confirmed' do
let_it_be_with_reload(:user) { create(:user, :unconfirmed) }
@@ -20,20 +22,37 @@ RSpec.describe ConfirmationsController do
before do
user.confirm
- subject
end
it 'renders `new`' do
+ perform_request
+
expect(response).to render_template(:new)
end
it 'displays an error message' do
+ perform_request
+
expect(response.body).to include('Email was already confirmed, please try signing in')
end
it 'does not display the email of the user' do
+ perform_request
+
expect(response.body).not_to include(user.email)
end
+
+ it 'sets the username and caller_id in the context' do
+ expect(controller).to receive(:show).and_wrap_original do |m, *args|
+ m.call(*args)
+
+ expect(Gitlab::ApplicationContext.current)
+ .to include('meta.user' => user.username,
+ 'meta.caller_id' => 'ConfirmationsController#show')
+ end
+
+ perform_request
+ end
end
context 'user accesses the link after the expiry of confirmation token has passed' do
@@ -42,39 +61,64 @@ RSpec.describe ConfirmationsController do
before do
allow(Devise).to receive(:confirm_within).and_return(1.day)
-
- travel_to(3.days.from_now) do
- subject
- end
end
it 'renders `new`' do
+ travel_to(3.days.from_now) { perform_request }
+
expect(response).to render_template(:new)
end
it 'displays an error message' do
+ travel_to(3.days.from_now) { perform_request }
+
expect(response.body).to include('Email needs to be confirmed within 1 day, please request a new one below')
end
it 'does not display the email of the user' do
+ travel_to(3.days.from_now) { perform_request }
+
expect(response.body).not_to include(user.email)
end
+
+ it 'sets the username and caller_id in the context' do
+ expect(controller).to receive(:show).and_wrap_original do |m, *args|
+ m.call(*args)
+
+ expect(Gitlab::ApplicationContext.current)
+ .to include('meta.user' => user.username,
+ 'meta.caller_id' => 'ConfirmationsController#show')
+ end
+
+ travel_to(3.days.from_now) { perform_request }
+ end
end
context 'with an invalid confirmation token' do
let(:confirmation_token) { 'invalid_confirmation_token' }
- before do
- subject
- end
-
it 'renders `new`' do
+ perform_request
+
expect(response).to render_template(:new)
end
it 'displays an error message' do
+ perform_request
+
expect(response.body).to include('Confirmation token is invalid')
end
+
+ it 'sets the the caller_id in the context' do
+ expect(controller).to receive(:show).and_wrap_original do |m, *args|
+ expect(Gitlab::ApplicationContext.current)
+ .to include('meta.caller_id' => 'ConfirmationsController#show')
+
+ m.call(*args)
+ end
+
+ perform_request
+ end
end
end
end