diff --git a/app/controllers/public/category_controller.rb b/app/controllers/public/category_controller.rb
index e2d8a92..6b394d0 100644
--- a/app/controllers/public/category_controller.rb
+++ b/app/controllers/public/category_controller.rb
@@ -3,8 +3,13 @@ class CategoryController < PublicController
# view the summary of one category
def view
# TODO: load articles, documents, etc so the view can list them.
+ @recent_articles = category.recent_articles
+ @recent_comments = category.recent_comments
+ @most_commented_articles = category.most_commented_articles
end
+ attr_reader :category
+
before_filter :load_category, :only => [ :view ]
def load_category
path = params[:path].join('/')
diff --git a/app/models/comment.rb b/app/models/comment.rb
index e99f35d..d9f7d32 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -15,4 +15,20 @@ class Comment < ActiveRecord::Base
end
end
+ def author_name
+ if author
+ author.name
+ else
+ name
+ end
+ end
+
+ def url
+ article.url.merge(:anchor => anchor)
+ end
+
+ def anchor
+ "comment-#{id}"
+ end
+
end
diff --git a/app/views/category/_article.rhtml b/app/views/category/_article.rhtml
new file mode 100644
index 0000000..83ee999
--- /dev/null
+++ b/app/views/category/_article.rhtml
@@ -0,0 +1 @@
+
<%= _('"%s", by %s. Last update: %s.') % [link_to(article.title, article.url), link_to(article.last_changed_by.name, article.last_changed_by.url), show_date(article.updated_on) ] %>
diff --git a/app/views/category/_category.rhtml b/app/views/category/_category.rhtml
index 76f9d00..de35a9d 100644
--- a/app/views/category/_category.rhtml
+++ b/app/views/category/_category.rhtml
@@ -1,10 +1,16 @@
-<%# FIXME %>
-
-This page will list everything (articles, documents, photos, etc) that is
-related to <%= @category.full_name %>. Actually generating this content is not
-implement yet, though.
-
+<%= _('Recent articles') %>
+
+ <%= render :partial => 'article', :collection => @recent_articles %>
+
-
-And yes, this placeholder text is not translated.
-
+<%= _('Recent Comments') %>
+
+<% @recent_comments.each do |comment| %>
+ - <%= _('"%{comment}" by %{author} on "%{article}"') % { :comment => link_to(comment.title, comment.url), :article => link_to(comment.article.title, comment.article.url), :author => comment.author_name } %>
+<% end %>
+
+
+<%= _('Most commented articles') %>
+
+ <%= render :partial => 'article', :collection => @most_commented_articles %>
+
diff --git a/app/views/category/view.rhtml b/app/views/category/view.rhtml
index 8cdf450..1931932 100644
--- a/app/views/category/view.rhtml
+++ b/app/views/category/view.rhtml
@@ -9,11 +9,11 @@
<%= render :partial => @category.class.name.underscore %>
+
<%= _('Sub-categories') %>
<% if @category.children.empty? %>
-
<%= _('No children categories') %>
+
<%= _('No sub-categories') %>
<% else %>
-
<%= _('Child categories:') %>
<% @category.children.each do |c| %>
- <%= link_to_category(c) %>
diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml
index 48615c5..374f50a 100644
--- a/app/views/content_viewer/_comment.rhtml
+++ b/app/views/content_viewer/_comment.rhtml
@@ -1,3 +1,4 @@
+<%= tag('a', :name => comment.anchor) %>
<% if logged_in? && (user == @page.profile || user == comment.author) %>
<% button_bar(:style => 'float: right; margin-top: 0;') do %>
diff --git a/test/functional/category_controller_test.rb b/test/functional/category_controller_test.rb
index 784bd2d..f7bcac2 100644
--- a/test/functional/category_controller_test.rb
+++ b/test/functional/category_controller_test.rb
@@ -9,13 +9,45 @@ class CategoryControllerTest < Test::Unit::TestCase
@controller = CategoryController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+
+ @category = Category.create!(:name => 'my category', :environment => Environment.default)
end
def test_should_display_a_given_category
- category = Category.create!(:name => 'my category', :environment => Environment.default)
+ get :view, :path => [ 'my-category' ]
+ assert_equal @category, assigns(:category)
+ end
+
+ should 'expose category in a method' do
+ get :view, :path => [ 'my-category' ]
+ assert_same assigns(:category), @controller.category
+ end
+
+ should 'list recent articles in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ recent = []
+ @category.expects(:recent_articles).returns(recent)
+
+ get :view, :path => [ 'my-category' ]
+ assert_same recent, assigns(:recent_articles)
+ end
+
+ should 'list recent comments in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ recent = []
+ @category.expects(:recent_comments).returns(recent)
+
+ get :view, :path => [ 'my-category' ]
+ assert_same recent, assigns(:recent_comments)
+ end
+
+ should 'list most commented articles in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ most_commented = []
+ @category.expects(:most_commented_articles).returns(most_commented)
get :view, :path => [ 'my-category' ]
- assert_equal category, assigns(:category)
+ assert_same most_commented, assigns(:most_commented_articles)
end
end
diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index 40618d3..85134c7 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -69,4 +69,28 @@ class CommentTest < Test::Unit::TestCase
assert_equal cc + 1, art.comments_count
end
+ should 'provide author name for authenticated authors' do
+ owner = create_user('testuser').person
+ assert_equal 'testuser', Comment.new(:author => owner).author_name
+ end
+
+ should 'provide author name for unauthenticated author' do
+ assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name
+ end
+
+ should 'provide url to comment' do
+ art = Article.new
+ art.expects(:url).returns({ :controller => 'lala', :action => 'something' })
+ comment = Comment.new(:article => art)
+ comment.expects(:id).returns(9876)
+
+ assert_equal({ :controller => 'lala', :action => 'something', :anchor => 'comment-9876'}, comment.url)
+ end
+
+ should 'provide anchor' do
+ comment = Comment.new
+ comment.expects(:id).returns(4321)
+ assert_equal 'comment-4321', comment.anchor
+ end
+
end
--
libgit2 0.21.2