Merge pull request #787 from consul/devise-location

Devise location
This commit is contained in:
Juanjo Bazán
2015-12-22 12:21:04 +01:00
4 changed files with 45 additions and 9 deletions

View File

@@ -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

View File

@@ -1,15 +1,19 @@
class Users::SessionsController < Devise::SessionsController 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 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? def verifying_via_email?
return false unless resource.present? return false unless resource.present?
stored_path = session[stored_location_key_for(resource)] || "" stored_path = session[stored_location_key_for(resource)] || ""

View File

@@ -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
@@ -72,4 +74,4 @@ feature 'Moderate users' do
end end
end end
end end

View 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