From 8a5479a33c669aad92b33ee0ec9d399cafa8e77c Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 6 Feb 2008 14:56:31 +0000 Subject: [PATCH] ActionItem153: reworking login block; adding it to environments by default --- app/controllers/public/account_controller.rb | 8 -------- app/helpers/boxes_helper.rb | 4 ++++ app/models/environment.rb | 2 ++ app/models/login_block.rb | 8 +++++++- app/views/account/login_block.rhtml | 2 +- app/views/account/user_info.rhtml | 4 ++++ test/functional/account_controller_test.rb | 12 ------------ test/unit/login_block_test.rb | 10 +++++++++- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 14fc0c7..06a19a8 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -32,14 +32,6 @@ class AccountController < PublicController render :action => 'login', :layout => false end - def login_block - if logged_in? - render :action => 'user_info', :layout => 'block' - else - render :action => 'login_block', :layout => 'block' - end - end - # action to register an user to the application def signup begin diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 3953f7b..4f72a9a 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -51,6 +51,10 @@ module BoxesHelper else content end + when Proc + self.instance_eval(&content) + else + raise "Unsupported content for block (#{content.class})" end classes = ['block', block.css_class_name ].uniq.join(' ') diff --git a/app/models/environment.rb b/app/models/environment.rb index f435e2a..2401708 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -36,6 +36,8 @@ class Environment < ActiveRecord::Base env.boxes[1].blocks << EnvironmentStatisticsBlock.new env.boxes[1].blocks << RecentDocumentsBlock.new + env.boxes[2].blocks << LoginBlock.new + end # One Environment can be reached by many domains diff --git a/app/models/login_block.rb b/app/models/login_block.rb index 5b33a4f..2ba0f24 100644 --- a/app/models/login_block.rb +++ b/app/models/login_block.rb @@ -5,7 +5,13 @@ class LoginBlock < Block end def content - { :controller => 'account', :action => 'login_block' } + lambda do + if logged_in? + render :file => 'account/user_info' + else + render :file => 'account/login_block' + end + end end end diff --git a/app/views/account/login_block.rhtml b/app/views/account/login_block.rhtml index 09c89d8..4d9ed77 100644 --- a/app/views/account/login_block.rhtml +++ b/app/views/account/login_block.rhtml @@ -15,7 +15,7 @@ <%= link_to _("New user"), :controller => 'account', :action => 'signup' %> <% else %> -

<%= @profile.identifier %>

+

<%= user.identifier %>

<% end %> diff --git a/app/views/account/user_info.rhtml b/app/views/account/user_info.rhtml index 71685af..99fb7af 100644 --- a/app/views/account/user_info.rhtml +++ b/app/views/account/user_info.rhtml @@ -4,3 +4,7 @@
  • <%= _('User since %d') % user.person_info.created_at.year %>
  • <%= link_to_homepage _('Homepage') %>
  • + + diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index c4123df..7f56572 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -246,18 +246,6 @@ class AccountControllerTest < Test::Unit::TestCase assert_no_tag :tag => "body" # e.g. no layout end - should 'provide login block' do - get :login_block - assert_template 'login_block' - assert_tag :tag => 'body', :attributes => { :class => 'noosfero-block' } - end - - should 'display user info in login block when logged in' do - login_as('ze') - get :login_block - assert_template 'user_info' - end - protected def create_user(options = {}) post :signup, :user => { :login => 'quire', :email => 'quire@example.com', diff --git a/test/unit/login_block_test.rb b/test/unit/login_block_test.rb index 06ade83..43cdd1a 100644 --- a/test/unit/login_block_test.rb +++ b/test/unit/login_block_test.rb @@ -12,7 +12,15 @@ class LoginBlockTest < Test::Unit::TestCase end should 'point to account/login_block' do - assert_equal({ :controller => 'account', :action => 'login_block' }, block.content) + self.expects(:logged_in?).returns(false) + self.expects(:render).with(:file => 'account/login_block') + self.instance_eval(& block.content) + end + + should 'display user_info if not logged' do + self.expects(:logged_in?).returns(true) + self.expects(:render).with(:file => 'account/user_info') + self.instance_eval(& block.content) end end -- libgit2 0.21.2