diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 5fe2c78a3..bbab5371a 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -12,7 +12,7 @@ class Users::SessionsController < Devise::SessionsController def stored_path_allows_welcome_screen? stored_path = session[stored_location_key_for(resource)] - stored_path && stored_path[0..5] != "/email" + stored_path.nil? || stored_path[0..5] != "/email" end end diff --git a/spec/features/welcome_spec.rb b/spec/features/welcome_spec.rb index cef26e035..f75eadd0c 100644 --- a/spec/features/welcome_spec.rb +++ b/spec/features/welcome_spec.rb @@ -10,6 +10,24 @@ feature "Welcome screen" do expect(current_path).to eq(welcome_path) end + scenario 'a regular user does not see it when coing to /email' do + + plain, encrypted = Devise.token_generator.generate(User, :email_verification_token) + + user = create(:user, email_verification_token: plain) + + visit email_path(email_verification_token: encrypted) + + fill_in 'user_email', with: user.email + fill_in 'user_password', with: user.password + + click_button 'Log in' + + expect(page).to have_content("You are now a verified user") + + expect(current_path).to eq(account_path) + end + scenario 'it is not shown more than once' do user = create(:user, sign_in_count: 2) @@ -42,4 +60,12 @@ feature "Welcome screen" do expect(current_path).to eq(proposals_path) end + scenario 'is not shown to administrators' do + administrator = create(:administrator) + + login_through_form_as(administrator.user) + + expect(current_path).to eq(proposals_path) + end + end