From ff2cbc07530d87132af09900b4d0c9ada9d3e716 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 28 Mar 2016 00:06:52 +0200 Subject: [PATCH] Remember me enabled by default --- app/controllers/auth/sessions_controller.rb | 8 +++++ app/models/user.rb | 4 --- .../auth/sessions_controller_spec.rb | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 spec/controllers/auth/sessions_controller_spec.rb diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 42b1d4ead..fe0adc9bb 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -1,3 +1,11 @@ class Auth::SessionsController < Devise::SessionsController + include Devise::Controllers::Rememberable + layout 'auth' + + def create + super do |resource| + remember_me(resource) + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 8b2cd22e0..a80efb50d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,8 +11,4 @@ class User < ActiveRecord::Base def admin? self.admin end - - def remember_me - (super == nil) ? '1' : super - end end diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb new file mode 100644 index 000000000..004a44fba --- /dev/null +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -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