diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 933ef318..8e20db0b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,6 +1,6 @@ class SessionsController < ApplicationController - before_filter :authenticate!, :except => :new - before_filter :require_no_authentication, :only => :new + before_filter :authenticate!, :only => :destroy + before_filter :require_no_authentication, :except => :destroy # GET /session/new # @@ -10,12 +10,19 @@ class SessionsController < ApplicationController # POST /session # def create - redirect_to root_path if authenticated? + if authenticate + flash[:notice] = I18n.t(:signed_in, :scope => [:devise, :sessions], :default => 'Signed in successfully.') + redirect_to root_path + else + render :new + end end # DELETE /session # def destroy - redirect_to new_session_path if logout + logout + flash[:notice] = I18n.t(:signed_out, :scope => [:devise, :sessions], :default => 'Signed out successfully.') + redirect_to new_session_path end end diff --git a/config/locales/en.yml b/config/locales/en.yml index ca8be732..7c6c1364 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,8 @@ en: devise: sessions: authentication_failed: 'Invalid email or password.' + signed_in: 'Signed in successfully.' + signed_out: 'Signed out successfully.' new: title: 'Sign in' submit: 'Sign in' diff --git a/test/controllers/authenticable_test.rb b/test/controllers/authenticable_test.rb index 4827565d..134f1558 100644 --- a/test/controllers/authenticable_test.rb +++ b/test/controllers/authenticable_test.rb @@ -8,7 +8,7 @@ class MockController < ApplicationController end end -class AuthenticableTest < ActionController::TestCase +class ControllerAuthenticableTest < ActionController::TestCase def setup @controller = MockController.new diff --git a/test/integration/authentication_test.rb b/test/integration/authentication_test.rb index 0b64ec70..0fe101c5 100644 --- a/test/integration/authentication_test.rb +++ b/test/integration/authentication_test.rb @@ -42,6 +42,7 @@ class AuthenticationTest < ActionController::IntegrationTest assert_response :success assert_template 'home/index' + assert_contain 'Signed in successfully' assert_not_contain 'Sign In' assert warden.authenticated? end