Commit 8a5479a33c669aad92b33ee0ec9d399cafa8e77c

Authored by AntonioTerceiro
1 parent 3d5ee0f6

ActionItem153: reworking login block; adding it to environments by default


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1296 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/account_controller.rb
... ... @@ -32,14 +32,6 @@ class AccountController < PublicController
32 32 render :action => 'login', :layout => false
33 33 end
34 34  
35   - def login_block
36   - if logged_in?
37   - render :action => 'user_info', :layout => 'block'
38   - else
39   - render :action => 'login_block', :layout => 'block'
40   - end
41   - end
42   -
43 35 # action to register an user to the application
44 36 def signup
45 37 begin
... ...
app/helpers/boxes_helper.rb
... ... @@ -51,6 +51,10 @@ module BoxesHelper
51 51 else
52 52 content
53 53 end
  54 + when Proc
  55 + self.instance_eval(&content)
  56 + else
  57 + raise "Unsupported content for block (#{content.class})"
54 58 end
55 59  
56 60 classes = ['block', block.css_class_name ].uniq.join(' ')
... ...
app/models/environment.rb
... ... @@ -36,6 +36,8 @@ class Environment < ActiveRecord::Base
36 36 env.boxes[1].blocks << EnvironmentStatisticsBlock.new
37 37 env.boxes[1].blocks << RecentDocumentsBlock.new
38 38  
  39 + env.boxes[2].blocks << LoginBlock.new
  40 +
39 41 end
40 42  
41 43 # One Environment can be reached by many domains
... ...
app/models/login_block.rb
... ... @@ -5,7 +5,13 @@ class LoginBlock &lt; Block
5 5 end
6 6  
7 7 def content
8   - { :controller => 'account', :action => 'login_block' }
  8 + lambda do
  9 + if logged_in?
  10 + render :file => 'account/user_info'
  11 + else
  12 + render :file => 'account/login_block'
  13 + end
  14 + end
9 15 end
10 16  
11 17 end
... ...
app/views/account/login_block.rhtml
... ... @@ -15,7 +15,7 @@
15 15 <%= link_to _("New user"), :controller => 'account', :action => 'signup' %>
16 16 </div>
17 17 <% else %>
18   - <h2><%= @profile.identifier %></h2>
  18 + <h2><%= user.identifier %></h2>
19 19 <% end %>
20 20  
21 21 </div><!-- end id="login-box" -->
... ...
app/views/account/user_info.rhtml
... ... @@ -4,3 +4,7 @@
4 4 <li><%= _('User since %d') % user.person_info.created_at.year %></li>
5 5 <li><%= link_to_homepage _('Homepage') %></li>
6 6 </ul>
  7 +
  8 +<ul>
  9 + <li><%= lightbox_link_to _('Logout'), :controller => 'account', :action => 'logout_popup' %></li>
  10 +</ul>
... ...
test/functional/account_controller_test.rb
... ... @@ -246,18 +246,6 @@ class AccountControllerTest &lt; Test::Unit::TestCase
246 246 assert_no_tag :tag => "body" # e.g. no layout
247 247 end
248 248  
249   - should 'provide login block' do
250   - get :login_block
251   - assert_template 'login_block'
252   - assert_tag :tag => 'body', :attributes => { :class => 'noosfero-block' }
253   - end
254   -
255   - should 'display user info in login block when logged in' do
256   - login_as('ze')
257   - get :login_block
258   - assert_template 'user_info'
259   - end
260   -
261 249 protected
262 250 def create_user(options = {})
263 251 post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
... ...
test/unit/login_block_test.rb
... ... @@ -12,7 +12,15 @@ class LoginBlockTest &lt; Test::Unit::TestCase
12 12 end
13 13  
14 14 should 'point to account/login_block' do
15   - assert_equal({ :controller => 'account', :action => 'login_block' }, block.content)
  15 + self.expects(:logged_in?).returns(false)
  16 + self.expects(:render).with(:file => 'account/login_block')
  17 + self.instance_eval(& block.content)
  18 + end
  19 +
  20 + should 'display user_info if not logged' do
  21 + self.expects(:logged_in?).returns(true)
  22 + self.expects(:render).with(:file => 'account/user_info')
  23 + self.instance_eval(& block.content)
16 24 end
17 25  
18 26 end
... ...