@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
|
|||||||
before_action :ensure_signup_complete
|
before_action :ensure_signup_complete
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
before_action :track_email_campaign
|
before_action :track_email_campaign
|
||||||
|
before_action :set_return_url
|
||||||
|
|
||||||
check_authorization unless: :devise_controller?
|
check_authorization unless: :devise_controller?
|
||||||
self.responder = ApplicationResponder
|
self.responder = ApplicationResponder
|
||||||
@@ -101,4 +102,10 @@ class ApplicationController < ActionController::Base
|
|||||||
ahoy.track campaign.name if campaign.present?
|
ahoy.track campaign.name if campaign.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_return_url
|
||||||
|
if !devise_controller? && controller_name != 'welcome' && is_navigational_format?
|
||||||
|
store_location_for(:user, request.path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class Users::SessionsController < Devise::SessionsController
|
class Users::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
if !verifying_via_email? && resource.show_welcome_screen?
|
if !verifying_via_email? && resource.show_welcome_screen?
|
||||||
welcome_path
|
welcome_path
|
||||||
@@ -8,7 +10,9 @@ class Users::SessionsController < Devise::SessionsController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def after_sign_out_path_for(resource)
|
||||||
|
request.referrer.present? ? request.referrer : super
|
||||||
|
end
|
||||||
|
|
||||||
def verifying_via_email?
|
def verifying_via_email?
|
||||||
return false unless resource.present?
|
return false unless resource.present?
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ feature 'Moderate users' do
|
|||||||
|
|
||||||
click_link("Sign out")
|
click_link("Sign out")
|
||||||
|
|
||||||
|
visit root_path
|
||||||
|
|
||||||
click_link 'Sign in'
|
click_link 'Sign in'
|
||||||
fill_in 'user_email', with: citizen.email
|
fill_in 'user_email', with: citizen.email
|
||||||
fill_in 'user_password', with: citizen.password
|
fill_in 'user_password', with: citizen.password
|
||||||
|
|||||||
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