Fix login/register redirection for Turbolinks. Also disable unnecesary ujs
parent
a36729ec8b
commit
afc4a8248b
|
@ -1,4 +1,5 @@
|
|||
#= require active_admin/base
|
||||
#= require jquery_ujs
|
||||
|
||||
$ ->
|
||||
loading = false
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
||||
// about supported directives.
|
||||
//
|
||||
//= require jquery_ujs
|
||||
//= require cocoon
|
||||
//= require turbolinks
|
||||
//= require mods
|
|
@ -37,6 +37,8 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def after_sign_in_path_for(resource)
|
||||
begin
|
||||
# L params
|
||||
# L resource
|
||||
params[:redirect_to] ? URI(params[:redirect_to]).path : super
|
||||
rescue URI::InvalidURIError => e
|
||||
super
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module SessionHelper
|
||||
def redirect_to_input(f)
|
||||
f.input :redirect_to,
|
||||
as: :hidden,
|
||||
input_html: {
|
||||
name: :redirect_to,
|
||||
value: params[:redirect_to] || request.headers['X-XHR-Referer'] || request.referer
|
||||
}
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@
|
|||
- if user_signed_in?
|
||||
= link_to current_user.name, user_path(current_user)
|
||||
|
|
||||
= link_to 'Logout', destroy_user_session_path, method: :delete
|
||||
= link_to 'Logout', destroy_user_session_path
|
||||
- else
|
||||
= link_to 'Login', new_user_session_path
|
||||
|
|
||||
|
|
|
@ -224,7 +224,7 @@ Devise.setup do |config|
|
|||
# config.navigational_formats = ['*/*', :html]
|
||||
|
||||
# The default HTTP method used to sign out a resource. Default is :delete.
|
||||
config.sign_out_via = :delete
|
||||
config.sign_out_via = :get
|
||||
|
||||
# ==> OmniAuth
|
||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
require 'rails_helper'
|
||||
|
||||
include Warden::Test::Helpers
|
||||
|
||||
feature 'Redirect to the previous page the user was after login' do
|
||||
scenario 'user is viewing a mod, and clicks on login, then he submits the login form' do
|
||||
user = create :user, name: 'Potato', email: 'banana@split.com', password: 'rsarsarsa'
|
||||
mod = create :mod, name: 'Hey'
|
||||
visit '/mods/hey'
|
||||
click_link 'Login'
|
||||
expect(current_path).to eq '/users/login'
|
||||
fill_in 'Email', with: 'banana@split.com'
|
||||
fill_in 'Password', with: 'rsarsarsa'
|
||||
click_button 'Login'
|
||||
expect(current_path).to eq '/mods/hey'
|
||||
end
|
||||
|
||||
scenario 'user fails to login first, and then tries again' do
|
||||
user = create :user, name: 'Potato', email: 'banana@split.com', password: 'rsarsarsa'
|
||||
mod = create :mod, name: 'Hey'
|
||||
visit '/mods/hey'
|
||||
click_link 'Login'
|
||||
expect(current_path).to eq '/users/login'
|
||||
fill_in 'Email', with: 'banana@split.com'
|
||||
fill_in 'Password', with: 'nooooooooooooo'
|
||||
click_button 'Login'
|
||||
expect(current_path).to eq '/users/login'
|
||||
fill_in 'Email', with: 'banana@split.com'
|
||||
fill_in 'Password', with: 'rsarsarsa'
|
||||
click_button 'Login'
|
||||
expect(current_path).to eq '/mods/hey'
|
||||
end
|
||||
|
||||
scenario 'user is viewing a mod, and clicks on register, and then registers successfully' do
|
||||
mod = create :mod, name: 'Hey'
|
||||
visit '/mods/hey'
|
||||
click_link 'Register'
|
||||
expect(current_path).to eq '/users/register'
|
||||
find('#user_email').set 'banana@split.com'
|
||||
find('#user_name').set 'PotatoHead'
|
||||
find('#user_password').set 'rsarsarsa'
|
||||
find('#user_password_confirmation').set 'rsarsarsa'
|
||||
click_button 'Register'
|
||||
expect(current_path).to eq '/mods/hey'
|
||||
end
|
||||
|
||||
scenario 'user is viewing a mod, and clicks on register, and then fails, and then tries again' do
|
||||
mod = create :mod, name: 'Hey'
|
||||
visit '/mods/hey'
|
||||
click_link 'Register'
|
||||
expect(current_path).to eq '/users/register'
|
||||
find('#user_email').set 'banana@split.com'
|
||||
find('#user_name').set 'INVALID USERNAME!!!'
|
||||
find('#user_password').set 'rsarsarsa'
|
||||
find('#user_password_confirmation').set 'rsarsarsa'
|
||||
click_button 'Register'
|
||||
expect(current_path).to eq '/users'
|
||||
find('#user_email').set 'banana@split.com'
|
||||
find('#user_name').set 'PotatoHead'
|
||||
find('#user_password').set 'rsarsarsa'
|
||||
find('#user_password_confirmation').set 'rsarsarsa'
|
||||
click_button 'Register'
|
||||
expect(current_path).to eq '/mods/hey'
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue