@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
|
||||
before_action :ensure_signup_complete
|
||||
before_action :set_locale
|
||||
before_action :track_email_campaign
|
||||
before_action :set_return_url
|
||||
|
||||
check_authorization unless: :devise_controller?
|
||||
self.responder = ApplicationResponder
|
||||
@@ -101,4 +102,10 @@ class ApplicationController < ActionController::Base
|
||||
ahoy.track campaign.name if campaign.present?
|
||||
end
|
||||
end
|
||||
|
||||
def set_return_url
|
||||
if !devise_controller? && controller_name != 'welcome' && is_navigational_format?
|
||||
store_location_for(:user, request.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
class Users::SessionsController < Devise::SessionsController
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
if !verifying_via_email? && resource.show_welcome_screen?
|
||||
welcome_path
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
if !verifying_via_email? && resource.show_welcome_screen?
|
||||
welcome_path
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def after_sign_out_path_for(resource)
|
||||
request.referrer.present? ? request.referrer : super
|
||||
end
|
||||
|
||||
def verifying_via_email?
|
||||
return false unless resource.present?
|
||||
stored_path = session[stored_location_key_for(resource)] || ""
|
||||
|
||||
@@ -39,6 +39,8 @@ feature 'Moderate users' do
|
||||
|
||||
click_link("Sign out")
|
||||
|
||||
visit root_path
|
||||
|
||||
click_link 'Sign in'
|
||||
fill_in 'user_email', with: citizen.email
|
||||
fill_in 'user_password', with: citizen.password
|
||||
@@ -72,4 +74,4 @@ feature 'Moderate users' do
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
23
spec/features/sessions_spec.rb
Normal file
23
spec/features/sessions_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Sessions' do
|
||||
|
||||
scenario 'Staying in the same page after doing login/logout' do
|
||||
user = create(:user, sign_in_count: 10)
|
||||
debate = create(:debate)
|
||||
|
||||
visit debate_path(debate)
|
||||
|
||||
login_through_form_as(user)
|
||||
|
||||
expect(page).to have_content('You have been signed in successfully')
|
||||
expect(current_path).to eq(debate_path(debate))
|
||||
|
||||
click_link 'Sign out'
|
||||
|
||||
expect(page).to have_content('You have been signed out successfully')
|
||||
expect(current_path).to eq(debate_path(debate))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user