Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Add methods for post login/registration redirects. #10

Merged
merged 2 commits into from Oct 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,7 +33,7 @@ def create
RegistrationsMailer.verification_token(@identity).deliver
flash[:notice] = "Check your email to verify your registration."
end
redirect_to main_app.root_url
redirect_to after_registration_path
end
end

Expand Down
Expand Up @@ -6,13 +6,13 @@ class SessionsController < ApplicationController
before_filter :authenticate!, only: [:authenticated]

def new
redirect_to main_app.root_url if logged_in?
redirect_to after_login_path if logged_in?
@identity = Identity.new
end

def destroy
logout
redirect_to main_app.root_url, notice: "You have been logged out."
redirect_to after_logout_path, notice: "You have been logged out."
end

def authenticated
Expand Down
21 changes: 21 additions & 0 deletions lib/thincloud/authentication/authenticatable_controller.rb
Expand Up @@ -58,6 +58,27 @@ def logout
reset_session
end

# Protected: Provides the URL to redirect to after logging in.
#
# Returns: A string.
def after_login_path
main_app.root_url
end

# Protected: Provides the URL to redirect to after logging out.
#
# Returns: A string.
def after_logout_path
main_app.root_url
end

# Protected: Provides the URL to redirect to after registering.
#
# Returns: A string.
def after_registration_path
main_app.root_url
end

end

end
Expand Down
Expand Up @@ -3,16 +3,28 @@
module Thincloud::Authentication
describe SessionsController do
describe "GET new" do
before { get :new }

it { assert_response :success }
it { assert_template :new }
describe "when not logged in" do
before { get :new }

it { assert_response :success }
it { assert_template :new }
end

describe "when logged in" do
before do
SessionsController.any_instance.stubs(:logged_in?).returns(true)
get :new
end

it { assert_redirected_to "/" }
end
end

describe "DELETE destroy" do
before { delete :destroy }

it { assert_response :redirect }
it { assert_redirected_to "/" }
it { flash[:notice].must_equal "You have been logged out." }
end

Expand Down