Skip to content

Commit

Permalink
Extracted WikiController#collection_title to WikiHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens committed Sep 24, 2008
1 parent 27d1e65 commit 1fd0f25
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
23 changes: 23 additions & 0 deletions spec/helpers/wiki_helper_spec.rb
Expand Up @@ -243,4 +243,27 @@ def controller
end
end
end

describe '#collection_title' do
before(:each) do
@category.stub!(:title).and_return('Category Title')
@tags = ['Tag 1', 'Tag 2']
end

it "should show the full collection title if all parameters are given" do
helper.collection_title(@category, @tags).should == "Pages about Category Title, tagged Tag 1 and Tag 2"
end

it "should show the collection title with category title if only category is given" do
helper.collection_title(@category, nil).should == "Pages about Category Title"
end

it "should show the collection title with tags if only tags are given" do
helper.collection_title(nil, @tags).should == "Pages tagged Tag 1 and Tag 2"
end

it "should show the default collection title if no parameters are given" do
helper.collection_title(nil, nil).should == "All pages"
end
end
end
9 changes: 0 additions & 9 deletions vendor/engines/adva_wiki/app/controllers/wiki_controller.rb
Expand Up @@ -14,8 +14,6 @@ class WikiController < BaseController
cache_sweeper :wikipage_sweeper, :category_sweeper, :tag_sweeper, :only => [:create, :update, :rollback, :destroy]
guards_permissions :wikipage, :except => [:index, :show, :diff]

helper_method :collection_title

def index
respond_to do |format|
format.html { render @section.render_options }
Expand Down Expand Up @@ -88,13 +86,6 @@ def destroy

private

def collection_title
title = []
title << "about #{@category.title}" if @category
title << "tagged #{@tags.to_sentence}" if @tags
title.empty? ? 'All pages' : 'Pages ' + title.join(', ')
end

def set_section
super
raise SectionRoutingError.new("Section must be a Wiki: #{@section.inspect}") unless @section.is_a? Wiki
Expand Down
6 changes: 6 additions & 0 deletions vendor/engines/adva_wiki/app/helpers/wiki_helper.rb
Expand Up @@ -84,4 +84,10 @@ def wiki_edit_links(wikipage, options = {})
content_tag :ul, links * "\n", :class => 'links'
end

def collection_title(category=nil, tags=nil)
title = []
title << "about #{category.title}" if category
title << "tagged #{tags.to_sentence}" if tags
title.empty? ? 'All pages' : 'Pages ' + title.join(', ')
end
end
2 changes: 1 addition & 1 deletion vendor/engines/adva_wiki/app/views/wiki/index.html.erb
@@ -1,4 +1,4 @@
<h2><%= collection_title %></h2>
<h2><%= collection_title(@category, @tags) %></h2>

<% if @wikipages.size > 0 -%>

Expand Down

0 comments on commit 1fd0f25

Please sign in to comment.