Remember me enabled by default

This commit is contained in:
Eugen Rochko 2016-03-28 00:06:52 +02:00
parent c38ad208c3
commit ff2cbc0753
3 changed files with 39 additions and 4 deletions

View file

@ -1,3 +1,11 @@
class Auth::SessionsController < Devise::SessionsController class Auth::SessionsController < Devise::SessionsController
include Devise::Controllers::Rememberable
layout 'auth' layout 'auth'
def create
super do |resource|
remember_me(resource)
end
end
end end

View file

@ -11,8 +11,4 @@ class User < ActiveRecord::Base
def admin? def admin?
self.admin self.admin
end end
def remember_me
(super == nil) ? '1' : super
end
end end

View file

@ -0,0 +1,31 @@
require 'rails_helper'
RSpec.describe Auth::SessionsController, type: :controller do
describe 'GET #new' do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
end
it 'returns http success' do
get :new
expect(response).to have_http_status(:success)
end
end
describe 'POST #create' do
let(:user) { Fabricate(:user, email: 'foo@bar.com', password: 'abcdefgh') }
before do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create, user: { email: user.email, password: user.password }
end
it 'redirects to home page' do
expect(response).to redirect_to(root_path)
end
it 'logs the user in' do
expect(controller.current_user).to eq user
end
end
end