]> source.dussan.org Git - redmine.git/commitdiff
Fixed that sidebar with hook content only should not be hidden.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 May 2012 10:19:06 +0000 (10:19 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 May 2012 10:19:06 +0000 (10:19 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9598 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/views/layouts/base.html.erb
test/functional/projects_controller_test.rb
test/integration/lib/redmine/hook_test.rb [new file with mode: 0644]

index d40ae4dc43d911b45bdc1b955159935bb46ec2dd..7e528eb1abf8703d590c44574fe0eb1ae3555fa1 100644 (file)
@@ -1108,6 +1108,14 @@ module ApplicationHelper
     (@has_content && @has_content[name]) || false
   end
 
+  def sidebar_content?
+    has_content?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
+  end
+
+  def view_layouts_base_sidebar_hook_response
+    @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
+  end
+
   def email_delivery_enabled?
     !!ActionMailer::Base.perform_deliveries
   end
index fdb8aff7df0c724ee6c46b39399912ea49148ec8..57470c2c5dd634089d8646fdc88f90dcc711159f 100644 (file)
     <% end %>
 </div>
 
-<%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
+<%= tag('div', {:id => 'main', :class => (sidebar_content? ? '' : 'nosidebar')}, true) %>
     <div id="sidebar">
         <%= yield :sidebar %>
-        <%= call_hook :view_layouts_base_sidebar %>
+        <%= view_layouts_base_sidebar_hook_response %>
     </div>
 
     <div id="content">
index 8f2d56767fe04cf9cc018a160aa92146923ad492..f8a3b844de665d505a8f0e79b4f5cb2f4c66deab 100644 (file)
@@ -520,23 +520,4 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_response :success
     assert_template 'show'
   end
-
-  # A hook that is manually registered later
-  class ProjectBasedTemplate < Redmine::Hook::ViewListener
-    def view_layouts_base_html_head(context)
-      # Adds a project stylesheet
-      stylesheet_link_tag(context[:project].identifier) if context[:project]
-    end
-  end
-  # Don't use this hook now
-  Redmine::Hook.clear_listeners
-
-  def test_hook_response
-    Redmine::Hook.add_listener(ProjectBasedTemplate)
-    get :show, :id => 1
-    assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
-                               :parent => {:tag => 'head'}
-
-    Redmine::Hook.clear_listeners
-  end
 end
diff --git a/test/integration/lib/redmine/hook_test.rb b/test/integration/lib/redmine/hook_test.rb
new file mode 100644 (file)
index 0000000..bbea0e6
--- /dev/null
@@ -0,0 +1,67 @@
+# Redmine - project management software
+# Copyright (C) 2006-2012  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.expand_path('../../../../test_helper', __FILE__)
+
+class MenuManagerTest < ActionController::IntegrationTest
+
+  fixtures :users, :roles, :projects, :members, :member_roles
+
+  # Hooks that are manually registered later
+  class ProjectBasedTemplate < Redmine::Hook::ViewListener
+    def view_layouts_base_html_head(context)
+      # Adds a project stylesheet
+      stylesheet_link_tag(context[:project].identifier) if context[:project]
+    end
+  end
+
+  class SidebarContent < Redmine::Hook::ViewListener
+    def view_layouts_base_sidebar(context)
+      content_tag('p', 'Sidebar hook')
+    end
+  end
+
+  def setup
+    Redmine::Hook.clear_listeners
+  end
+
+  def teardown
+    Redmine::Hook.clear_listeners
+  end
+
+  def test_html_head_hook_response
+    Redmine::Hook.add_listener(ProjectBasedTemplate)
+
+    get '/projects/ecookbook'
+    assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
+                               :parent => {:tag => 'head'}
+  end
+
+  def test_empty_sidebar_should_be_hidden
+    get '/'
+    assert_select 'div#main.nosidebar'
+  end
+
+  def test_sidebar_with_hook_content_should_not_be_hidden
+    Redmine::Hook.add_listener(SidebarContent)
+
+    get '/'
+    assert_select 'div#sidebar p', :text => 'Sidebar hook'
+    assert_select 'div#main'
+    assert_select 'div#main.nosidebar', 0
+  end
+end