Commit a61b1b26f877fdce7301360560c92e7c6cbaf3b7
1 parent
deeae934
Exists in
master
and in
29 other branches
ActionItem51:
displaying recent articles/comments and most commented articles on the category "homepage" git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1588 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
98 additions
and
13 deletions
Show diff stats
app/controllers/public/category_controller.rb
... | ... | @@ -3,8 +3,13 @@ class CategoryController < PublicController |
3 | 3 | # view the summary of one category |
4 | 4 | def view |
5 | 5 | # TODO: load articles, documents, etc so the view can list them. |
6 | + @recent_articles = category.recent_articles | |
7 | + @recent_comments = category.recent_comments | |
8 | + @most_commented_articles = category.most_commented_articles | |
6 | 9 | end |
7 | 10 | |
11 | + attr_reader :category | |
12 | + | |
8 | 13 | before_filter :load_category, :only => [ :view ] |
9 | 14 | def load_category |
10 | 15 | path = params[:path].join('/') | ... | ... |
app/models/comment.rb
... | ... | @@ -15,4 +15,20 @@ class Comment < ActiveRecord::Base |
15 | 15 | end |
16 | 16 | end |
17 | 17 | |
18 | + def author_name | |
19 | + if author | |
20 | + author.name | |
21 | + else | |
22 | + name | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def url | |
27 | + article.url.merge(:anchor => anchor) | |
28 | + end | |
29 | + | |
30 | + def anchor | |
31 | + "comment-#{id}" | |
32 | + end | |
33 | + | |
18 | 34 | end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<li><%= _('"%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) ] %></li> | ... | ... |
app/views/category/_category.rhtml
1 | -<%# FIXME %> | |
2 | -<p> | |
3 | -This page will list everything (articles, documents, photos, etc) that is | |
4 | -related to <%= @category.full_name %>. Actually generating this content is not | |
5 | -implement yet, though. | |
6 | -</p> | |
1 | +<h2><%= _('Recent articles') %></h2> | |
2 | +<ul> | |
3 | + <%= render :partial => 'article', :collection => @recent_articles %> | |
4 | +</ul> | |
7 | 5 | |
8 | -<p> | |
9 | -And yes, this placeholder text is not translated. | |
10 | -</p> | |
6 | +<h2><%= _('Recent Comments') %></h2> | |
7 | +<ul> | |
8 | +<% @recent_comments.each do |comment| %> | |
9 | + <li><%= _('"%{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 } %></li> | |
10 | +<% end %> | |
11 | +</ul> | |
12 | + | |
13 | +<h2><%= _('Most commented articles') %></h2> | |
14 | +<ul> | |
15 | + <%= render :partial => 'article', :collection => @most_commented_articles %> | |
16 | +</ul> | ... | ... |
app/views/category/view.rhtml
... | ... | @@ -9,11 +9,11 @@ |
9 | 9 | <%= render :partial => @category.class.name.underscore %> |
10 | 10 | |
11 | 11 | <div id="category-childs"> |
12 | + <h2> <%= _('Sub-categories') %> </h2> | |
12 | 13 | |
13 | 14 | <% if @category.children.empty? %> |
14 | - <strong id="cat-no-child"><%= _('No children categories') %></strong> | |
15 | + <strong id="cat-no-child"><%= _('No sub-categories') %></strong> | |
15 | 16 | <% else %> |
16 | - <h4> <%= _('Child categories:') %> </h4> | |
17 | 17 | <ul> |
18 | 18 | <% @category.children.each do |c| %> |
19 | 19 | <li> <%= link_to_category(c) %> </li> | ... | ... |
app/views/content_viewer/_comment.rhtml
1 | +<%= tag('a', :name => comment.anchor) %> | |
1 | 2 | <div class="article-comment<%= ' comment-from-owner' if ( comment.author && (@page.profile.name == comment.author.name) ) %> comment-logged-<%= comment.author ? 'in' : 'out' %>"> |
2 | 3 | <% if logged_in? && (user == @page.profile || user == comment.author) %> |
3 | 4 | <% button_bar(:style => 'float: right; margin-top: 0;') do %> | ... | ... |
test/functional/category_controller_test.rb
... | ... | @@ -9,13 +9,45 @@ class CategoryControllerTest < Test::Unit::TestCase |
9 | 9 | @controller = CategoryController.new |
10 | 10 | @request = ActionController::TestRequest.new |
11 | 11 | @response = ActionController::TestResponse.new |
12 | + | |
13 | + @category = Category.create!(:name => 'my category', :environment => Environment.default) | |
12 | 14 | end |
13 | 15 | |
14 | 16 | def test_should_display_a_given_category |
15 | - category = Category.create!(:name => 'my category', :environment => Environment.default) | |
17 | + get :view, :path => [ 'my-category' ] | |
18 | + assert_equal @category, assigns(:category) | |
19 | + end | |
20 | + | |
21 | + should 'expose category in a method' do | |
22 | + get :view, :path => [ 'my-category' ] | |
23 | + assert_same assigns(:category), @controller.category | |
24 | + end | |
25 | + | |
26 | + should 'list recent articles in the category' do | |
27 | + @controller.expects(:category).returns(@category).at_least_once | |
28 | + recent = [] | |
29 | + @category.expects(:recent_articles).returns(recent) | |
30 | + | |
31 | + get :view, :path => [ 'my-category' ] | |
32 | + assert_same recent, assigns(:recent_articles) | |
33 | + end | |
34 | + | |
35 | + should 'list recent comments in the category' do | |
36 | + @controller.expects(:category).returns(@category).at_least_once | |
37 | + recent = [] | |
38 | + @category.expects(:recent_comments).returns(recent) | |
39 | + | |
40 | + get :view, :path => [ 'my-category' ] | |
41 | + assert_same recent, assigns(:recent_comments) | |
42 | + end | |
43 | + | |
44 | + should 'list most commented articles in the category' do | |
45 | + @controller.expects(:category).returns(@category).at_least_once | |
46 | + most_commented = [] | |
47 | + @category.expects(:most_commented_articles).returns(most_commented) | |
16 | 48 | |
17 | 49 | get :view, :path => [ 'my-category' ] |
18 | - assert_equal category, assigns(:category) | |
50 | + assert_same most_commented, assigns(:most_commented_articles) | |
19 | 51 | end |
20 | 52 | |
21 | 53 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -69,4 +69,28 @@ class CommentTest < Test::Unit::TestCase |
69 | 69 | assert_equal cc + 1, art.comments_count |
70 | 70 | end |
71 | 71 | |
72 | + should 'provide author name for authenticated authors' do | |
73 | + owner = create_user('testuser').person | |
74 | + assert_equal 'testuser', Comment.new(:author => owner).author_name | |
75 | + end | |
76 | + | |
77 | + should 'provide author name for unauthenticated author' do | |
78 | + assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name | |
79 | + end | |
80 | + | |
81 | + should 'provide url to comment' do | |
82 | + art = Article.new | |
83 | + art.expects(:url).returns({ :controller => 'lala', :action => 'something' }) | |
84 | + comment = Comment.new(:article => art) | |
85 | + comment.expects(:id).returns(9876) | |
86 | + | |
87 | + assert_equal({ :controller => 'lala', :action => 'something', :anchor => 'comment-9876'}, comment.url) | |
88 | + end | |
89 | + | |
90 | + should 'provide anchor' do | |
91 | + comment = Comment.new | |
92 | + comment.expects(:id).returns(4321) | |
93 | + assert_equal 'comment-4321', comment.anchor | |
94 | + end | |
95 | + | |
72 | 96 | end | ... | ... |