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,14 +23,16 @@ class AccountController < ApplicationController
23 end 23 end
24 24
25 def signup 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 end 36 end
35 37
36 def logout 38 def logout
app/helpers/application_helper.rb
@@ -92,13 +92,29 @@ module ApplicationHelper @@ -92,13 +92,29 @@ module ApplicationHelper
92 end 92 end
93 93
94 def header 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 end 104 end
97 105
98 def login_box 106 def login_box
99 content_tag('div', (link_to _('Login'), :controller => 'account', :action => 'login'), :id => 'login_box') 107 content_tag('div', (link_to _('Login'), :controller => 'account', :action => 'login'), :id => 'login_box')
100 end 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 # FIXME 118 # FIXME
103 def footer 119 def footer
104 'nothing in the footer yet' 120 'nothing in the footer yet'
test/integration/enable_disable_features_test.rb
1 require "#{File.dirname(__FILE__)}/../test_helper" 1 require "#{File.dirname(__FILE__)}/../test_helper"
2 2
3 class EnableDisableFeaturesTest < ActionController::IntegrationTest 3 class EnableDisableFeaturesTest < ActionController::IntegrationTest
4 - fixtures :virtual_communities, :users, :profiles 4 + fixtures :domains, :virtual_communities, :users, :profiles
5 5
6 def test_enable_features 6 def test_enable_features
7 uses_host 'anhetegua.net' 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,17 +3,29 @@ require &quot;#{File.dirname(__FILE__)}/../test_helper&quot;
3 class LoginToTheApplicationTest < ActionController::IntegrationTest 3 class LoginToTheApplicationTest < ActionController::IntegrationTest
4 fixtures :users, :virtual_communities, :profiles 4 fixtures :users, :virtual_communities, :profiles
5 5
6 - def test_anonymous_sees_login_box 6 + def test_anonymous_user_logins_to_application
7 get '/' 7 get '/'
8 assert_tag :tag => 'div', :attributes => { :id => 'login_box' } 8 assert_tag :tag => 'div', :attributes => { :id => 'login_box' }
9 assert_no_tag :tag => 'div', :attributes => { :id => 'user_links' } 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 end 20 end
11 21
12 def test_logged_in_does_not_see_login_box 22 def test_logged_in_does_not_see_login_box
13 login('ze', 'test') 23 login('ze', 'test')
14 get '/' 24 get '/'
15 assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' } 25 assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' }
  26 + assert_no_tag :tag => 'div', :attributes => { :id => 'register_box' }
16 assert_tag :tag => 'div', :attributes => { :id => 'user_links' } 27 assert_tag :tag => 'div', :attributes => { :id => 'user_links' }
  28 + assert_tag :tag => 'div', :attributes => { :id => 'logout_box' }
17 end 29 end
18 30
19 end 31 end