From d5678672f051154e2e1d03d8de96851557a8913e Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 27 Jul 2007 19:16:18 +0000 Subject: [PATCH] ActionItem9: adding tests and minor refactoring in account_controller --- app/controllers/account_controller.rb | 18 ++++++++++-------- app/helpers/application_helper.rb | 18 +++++++++++++++++- test/integration/enable_disable_features_test.rb | 2 +- test/integration/login_to_the_application_test.rb | 14 +++++++++++++- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index e8b18ef..2820893 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -23,14 +23,16 @@ class AccountController < ApplicationController end def signup - @user = User.new(params[:user]) - return unless request.post? - @user.save! - self.current_user = @user - redirect_back_or_default(:controller => '/account', :action => 'index') - flash[:notice] = _("Thanks for signing up!") - rescue ActiveRecord::RecordInvalid - render :action => 'signup' + begin + @user = User.new(params[:user]) + return unless request.post? + @user.save! + self.current_user = @user + redirect_back_or_default(:controller => '/account', :action => 'index') + flash[:notice] = _("Thanks for signing up!") + rescue ActiveRecord::RecordInvalid + render :action => 'signup' + end end def logout diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c287ff7..c146d32 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -92,13 +92,29 @@ module ApplicationHelper end def header - virtual_community_identification + (logged_in? ? user_links : login_box) + virtual_community_identification + login_or_register_or_logout + end + + def login_or_register_or_logout + if logged_in? + user_links + logout_box + else + login_box + register_box + end end def login_box content_tag('div', (link_to _('Login'), :controller => 'account', :action => 'login'), :id => 'login_box') end + def register_box + content_tag('div', (link_to _('Not a user yet? Register now!'), :controller => 'account', :action => 'signup'), :id => 'register_box') + end + + def logout_box + content_tag('div', (link_to _('Logout'), { :controller => 'account', :action => 'logout'}, :method => 'post'), :id => 'logout_box') + end + # FIXME def footer 'nothing in the footer yet' diff --git a/test/integration/enable_disable_features_test.rb b/test/integration/enable_disable_features_test.rb index 1d23b2f..cf87e6c 100644 --- a/test/integration/enable_disable_features_test.rb +++ b/test/integration/enable_disable_features_test.rb @@ -1,7 +1,7 @@ require "#{File.dirname(__FILE__)}/../test_helper" class EnableDisableFeaturesTest < ActionController::IntegrationTest - fixtures :virtual_communities, :users, :profiles + fixtures :domains, :virtual_communities, :users, :profiles def test_enable_features uses_host 'anhetegua.net' diff --git a/test/integration/login_to_the_application_test.rb b/test/integration/login_to_the_application_test.rb index c6e730c..e003645 100644 --- a/test/integration/login_to_the_application_test.rb +++ b/test/integration/login_to_the_application_test.rb @@ -3,17 +3,29 @@ require "#{File.dirname(__FILE__)}/../test_helper" class LoginToTheApplicationTest < ActionController::IntegrationTest fixtures :users, :virtual_communities, :profiles - def test_anonymous_sees_login_box + def test_anonymous_user_logins_to_application get '/' assert_tag :tag => 'div', :attributes => { :id => 'login_box' } assert_no_tag :tag => 'div', :attributes => { :id => 'user_links' } + assert_no_tag :tag => 'div', :attributes => { :id => 'logout_box' } + + get '/account/login' + assert_response :success + + login('ze', 'test') + + assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' } + assert_tag :tag => 'div', :attributes => { :id => 'user_links' } + assert_tag :tag => 'div', :attributes => { :id => 'logout_box' } end def test_logged_in_does_not_see_login_box login('ze', 'test') get '/' assert_no_tag :tag => 'div', :attributes => { :id => 'login_box' } + assert_no_tag :tag => 'div', :attributes => { :id => 'register_box' } assert_tag :tag => 'div', :attributes => { :id => 'user_links' } + assert_tag :tag => 'div', :attributes => { :id => 'logout_box' } end end -- libgit2 0.21.2