diff options
-rw-r--r-- | app/views/sidebar_modules/_sidebar_module.html.erb | 2 | ||||
-rw-r--r-- | test/unit/helper/sidebar_helper_test.rb | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/app/views/sidebar_modules/_sidebar_module.html.erb b/app/views/sidebar_modules/_sidebar_module.html.erb index c7a24e9..2fb989c 100644 --- a/app/views/sidebar_modules/_sidebar_module.html.erb +++ b/app/views/sidebar_modules/_sidebar_module.html.erb @@ -1,4 +1,4 @@ -<div id="sidebar_module_<%= sidebar_module.title %>" class="sidebar_module"> +<div id="sidebar_module_<%= sidebar_module.title.parameterize %>" class="sidebar_module"> <h1><%= sidebar_module.title %></h1> <div><%= content_for "sidebar_module_#{sidebar_module.title}_body" %></div> </div> diff --git a/test/unit/helper/sidebar_helper_test.rb b/test/unit/helper/sidebar_helper_test.rb new file mode 100644 index 0000000..10ae63f --- /dev/null +++ b/test/unit/helper/sidebar_helper_test.rb @@ -0,0 +1,50 @@ +require File.dirname(__FILE__) + '/../../test_helper' +require 'action_view/test_case' + +class SidebarHelperTest < ActionView::TestCase + def setup + setup_with_controller + end + + test "should not render anything if no modules" do + result = render_sidebar_modules [] + assert_select ".sidebar_module", :count => 0 + end + + test "should only render modules with matching position" do + modules = [ + SidebarModule.new("Module 1", "Module 1 body", 1), + SidebarModule.new("Module 2", "Module 2 body", 2) + ] + + result = render_sidebar_modules(modules, :position => 2) + assert_select ".sidebar_module", :count => 1 + assert_select "#sidebar_module_module-1", :count => 0 + assert_select "#sidebar_module_module-2", :count => 1 + end + + test "should render all modules if no position given" do + modules = [ + SidebarModule.new("Module 1", "Module 1 body", 1), + SidebarModule.new("Module 2", "Module 2 body", 2) + ] + + result = render_sidebar_modules(modules) + assert_select ".sidebar_module", :count => 2 + assert_select "#sidebar_module_module-1", :count => 1 + assert_select "#sidebar_module_module-2", :count => 1 + end + + test "should not render modules with empty body" do + modules = [ + SidebarModule.new("Module 1", "", 1), + SidebarModule.new("Module 2", "Module 2 body", 1) + ] + + result = render_sidebar_modules(modules) + assert_select ".sidebar_module", :count => 1 + assert_select "#sidebar_module_module-1", :count => 0 + assert_select "#sidebar_module_module-2", :count => 1 + end +end + |