Commit cf9140ee2264b6cc90caf69b60a4404ff4cda7a2

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 44c42816

Redirecting logged users if tries to signup/login

(ActionItem1354)
app/controllers/public/account_controller.rb
... ... @@ -5,6 +5,7 @@ class AccountController < ApplicationController
5 5 require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ]
6 6  
7 7 before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise]
  8 + before_filter :redirect_if_logged_in, :only => [:login, :signup]
8 9  
9 10 # say something nice, you goof! something sweet.
10 11 def index
... ... @@ -291,4 +292,10 @@ class AccountController < ApplicationController
291 292 end
292 293 end
293 294  
  295 + def redirect_if_logged_in
  296 + if logged_in?
  297 + go_to_initial_page
  298 + end
  299 + end
  300 +
294 301 end
... ...
features/login.feature
... ... @@ -39,3 +39,8 @@ Feature: login
39 39 | Password | 123456 |
40 40 When I press "Log in"
41 41 Then I should be on Joao Silva's control panel
  42 +
  43 + Scenario: be redirected if user goes to login page and is logged
  44 + Given I am logged in as "joaosilva"
  45 + And I go to login page
  46 + Then I should be on Joao Silva's control panel
... ...
features/publish_article.feature
... ... @@ -40,6 +40,7 @@ Feature: publish article
40 40 And I follow "Spread"
41 41 And I check "Sample Community"
42 42 And I press "Publish"
  43 + And I am not logged in
43 44 And I am logged in as "mariasilva"
44 45 And "Maria Silva" is a member of "Sample Community"
45 46 And I am on Maria Silva's control panel
... ...
features/signup.feature
... ... @@ -15,3 +15,10 @@ Feature: signup
15 15 And I press "Sign up"
16 16 Then I should see "Thanks for signing up!"
17 17  
  18 + Scenario: be redirected if user goes to signup page and is logged
  19 + Given the following users
  20 + | login | name |
  21 + | joaosilva | Joao Silva |
  22 + Given I am logged in as "joaosilva"
  23 + And I go to signup page
  24 + Then I should be on Joao Silva's control panel
... ...
features/support/paths.rb
... ... @@ -29,6 +29,9 @@ module NavigationHelpers
29 29 when /^login page$/
30 30 '/account/login'
31 31  
  32 + when /^signup page$/
  33 + '/account/signup'
  34 +
32 35 when /^(.*)'s control panel$/
33 36 '/myprofile/%s' % Profile.find_by_name($1).identifier
34 37  
... ...
test/functional/account_controller_test.rb
... ... @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase
36 36 should 'redirect to where user was on login' do
37 37 @request.env["HTTP_REFERER"] = '/bli'
38 38 u = new_user
  39 + @controller.stubs(:logged_in?).returns(false)
39 40 post :login, :user => {:login => 'quire', :password => 'quire'}
40 41  
41 42 assert_redirected_to '/bli'
... ... @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase
283 284 assert_difference User, :count do
284 285 new_user(:login => 'user1', :email => 'user@example.com')
285 286 assert assigns(:user).valid?
  287 + @controller.stubs(:logged_in?).returns(false)
286 288 new_user(:login => 'user2', :email => 'user@example.com')
287 289 assert assigns(:user).errors.on(:email)
288 290 end
... ...
test/integration/enterprise_registration_test.rb
... ... @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest
44 44  
45 45 code = CreateEnterprise.find(:first, :order => 'id desc').code
46 46  
  47 + post '/account/logout'
  48 +
47 49 # steps done by the validator
48 50 validator = create_user_with_permission('validator', 'validate_enterprise', org)
49 51 login 'validator', 'validator'
50   -
  52 +
51 53 get "/myprofile/myorg/enterprise_validation"
52 54 assert_response :success
53 55 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" }
... ...