Commit d5678672f051154e2e1d03d8de96851557a8913e

Authored by AntonioTerceiro
1 parent a0b41878

ActionItem9: adding tests and minor refactoring in account_controller

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@192 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/account_controller.rb
... ... @@ -23,14 +23,16 @@ class AccountController < ApplicationController
23 23 end
24 24  
25 25 def signup
26   - @user = User.new(params[:user])
27   - return unless request.post?
28   - @user.save!
29   - self.current_user = @user
30   - redirect_back_or_default(:controller => '/account', :action => 'index')
31   - flash[:notice] = _("Thanks for signing up!")
32   - rescue ActiveRecord::RecordInvalid
33   - render :action => 'signup'
  26 + begin
  27 + @user = User.new(params[:user])
  28 + return unless request.post?
  29 + @user.save!
  30 + self.current_user = @user
  31 + redirect_back_or_default(:controller => '/account', :action => 'index')
  32 + flash[:notice] = _("Thanks for signing up!")
  33 + rescue ActiveRecord::RecordInvalid
  34 + render :action => 'signup'
  35 + end
34 36 end
35 37  
36 38 def logout
... ...
app/helpers/application_helper.rb
... ... @@ -92,13 +92,29 @@ module ApplicationHelper
92 92 end
93 93  
94 94 def header
95   - virtual_community_identification + (logged_in? ? user_links : login_box)
  95 + virtual_community_identification + login_or_register_or_logout
  96 + end
  97 +
  98 + def login_or_register_or_logout
  99 + if logged_in?
  100 + user_links + logout_box
  101 + else
  102 + login_box + register_box
  103 + end
96 104 end
97 105  
98 106 def login_box
99 107 content_tag('div', (link_to _('Login'), :controller => 'account', :action => 'login'), :id => 'login_box')
100 108 end
101 109  
  110 + def register_box
  111 + content_tag('div', (link_to _('Not a user yet? Register now!'), :controller => 'account', :action => 'signup'), :id => 'register_box')
  112 + end
  113 +
  114 + def logout_box
  115 + content_tag('div', (link_to _('Logout'), { :controller => 'account', :action => 'logout'}, :method => 'post'), :id => 'logout_box')
  116 + end
  117 +
102 118 # FIXME
103 119 def footer
104 120 'nothing in the footer yet'
... ...
test/integration/enable_disable_features_test.rb
1 1 require "#{File.dirname(__FILE__)}/../test_helper"
2 2  
3 3 class EnableDisableFeaturesTest < ActionController::IntegrationTest
4   - fixtures :virtual_communities, :users, :profiles
  4 + fixtures :domains, :virtual_communities, :users, :profiles
5 5  
6 6 def test_enable_features
7 7 uses_host 'anhetegua.net'
... ...
test/integration/login_to_the_application_test.rb
... ... @@ -3,17 +3,29 @@ require &quot;#{File.dirname(__FILE__)}/../test_helper&quot;
3 3 class LoginToTheApplicationTest < ActionController::IntegrationTest
4 4 fixtures :users, :virtual_communities, :profiles
5 5  
6   - def test_anonymous_sees_login_box
  6 + def test_anonymous_user_logins_to_application
7 7 get '/'
8 8 assert_tag :tag => 'div', :attributes => { :id => 'login_box' }
9 9 assert_no_tag :tag => 'div', :attributes => { :id => 'user_links' }
  10 + assert_no_tag :tag => 'div', :attributes => { :id => 'logout_box' }
  11 +
  12 + get '/account/login'
  13 + assert_response :success
  14 +
  15 + login('ze', 'test')
  16 +
  17 + assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' }
  18 + assert_tag :tag => 'div', :attributes => { :id => 'user_links' }
  19 + assert_tag :tag => 'div', :attributes => { :id => 'logout_box' }
10 20 end
11 21  
12 22 def test_logged_in_does_not_see_login_box
13 23 login('ze', 'test')
14 24 get '/'
15 25 assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' }
  26 + assert_no_tag :tag => 'div', :attributes => { :id => 'register_box' }
16 27 assert_tag :tag => 'div', :attributes => { :id => 'user_links' }
  28 + assert_tag :tag => 'div', :attributes => { :id => 'logout_box' }
17 29 end
18 30  
19 31 end
... ...