diff --git a/app/helpers/forum_helper.rb b/app/helpers/forum_helper.rb index 82bd870..e37ab89 100644 --- a/app/helpers/forum_helper.rb +++ b/app/helpers/forum_helper.rb @@ -40,8 +40,12 @@ module ForumHelper end def last_topic_update(article) - last_update_at, last_update_by = (article.comments.count.zero? ? [article.updated_at, article.author] : [article.comments.last.created_at, article.comments.last.author]) - time_ago_as_sentence(last_update_at) + ' ' + _('ago') + ' ' + _('by') + ' ' + link_to(last_update_by.name, last_update_by.url) + info = article.info_from_last_update + if info[:author_url] + time_ago_as_sentence(info[:date]) + ' ' + _('ago') + ' ' + _('by') + ' ' + link_to(info[:author_name], info[:author_url]) + else + time_ago_as_sentence(info[:date]) + ' ' + _('ago') + ' ' + _('by') + ' ' + info[:author_name] + end end end diff --git a/app/models/article.rb b/app/models/article.rb index 2b87ca2..199791e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -232,6 +232,15 @@ class Article < ActiveRecord::Base self.parent and self.parent.blog? end + def info_from_last_update + last_comment = comments.last + if last_comment + {:date => last_comment.created_at, :author_name => last_comment.author_name, :author_url => last_comment.author_url} + else + {:date => updated_at, :author_name => author.name, :author_url => author.url} + end + end + def url @url ||= self.profile.url.merge(:page => path.split('/')) end diff --git a/app/models/comment.rb b/app/models/comment.rb index 1ef1bf6..e0385a2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -43,6 +43,10 @@ class Comment < ActiveRecord::Base author ? author.url : email end + def author_url + author ? author.url : nil + end + def url article.view_url.merge(:anchor => anchor) end diff --git a/features/forum.feature b/features/forum.feature index 2d69e24..4506669 100644 --- a/features/forum.feature +++ b/features/forum.feature @@ -67,3 +67,29 @@ Feature: forum And I go to /joaosilva/forum-one When I follow "Configure forum" Then I should be on edit "Forum One" by joaosilva + + Scenario: last topic update by unautenticated user should not link + Given the following forums + | owner | name | + | joaosilva | Forum | + And the following articles + | owner | name | parent | + | joaosilva | Post one | Forum | + And the following comments + | article | name | email | title | body | + | Post one | Joao | joao@example.com | Hi all | Hi all | + When I go to /joaosilva/forum + Then I should not see "Joao" link + + Scenario: last topic update by autenticated user should link to profile url + Given the following forums + | owner | name | + | joaosilva | Forum | + And the following articles + | owner | name | parent | + | joaosilva | Post one | Forum | + And the following comments + | article | author | title | body | + | Post one | joaosilva | Hi all | Hi all | + When I go to /joaosilva/forum + Then I should see "Joao" linking to "http:///joaosilva" diff --git a/features/step_definitions/custom_webrat_steps.rb b/features/step_definitions/custom_webrat_steps.rb index e890b6d..d4cf4ff 100644 --- a/features/step_definitions/custom_webrat_steps.rb +++ b/features/step_definitions/custom_webrat_steps.rb @@ -6,6 +6,11 @@ When /^I should not see "([^\"]+)" link$/ do |text| response.should_not have_selector("a:contains('#{text}')") end +When /^I should see "([^\"]+)" linking to "([^\"]+)"$/ do |text, href| + response.should have_selector("a:contains('#{text}')") + response.should have_selector("a[href='#{href}']") +end + Then /^I should be exactly on (.+)$/ do |page_name| URI.parse(current_url).request_uri.should == path_to(page_name) end diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 5c938d3..f2fda44 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -52,9 +52,14 @@ Given /^the following (articles|events|blogs|folders|forums|galleries)$/ do |con }[content] || raise("Don't know how to build %s" % content) table.hashes.map{|item| item.dup}.each do |item| owner_identifier = item.delete("owner") + parent = item.delete("parent") owner = Profile[owner_identifier] home = item.delete("homepage") - result = klass.create!(item.merge(:profile => owner)) + result = klass.new(item.merge(:profile => owner)) + if parent + result.parent = Article.find_by_name(parent) + end + result.save! if home owner.home_page = result owner.save! @@ -318,8 +323,11 @@ Given /^the following comments?$/ do |table| table.hashes.each do |item| data = item.dup article = Article.find_by_name(data.delete("article")) - author = Profile[data.delete("author")] - comment = article.comments.build(:author => author, :title => data.delete("title"), :body => data.delete("body")) + author = data.delete("author") + comment = article.comments.build(data) + if author + comment.author = Profile[author] + end comment.save! end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 29f669a..0a81ad6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -193,7 +193,8 @@ module NoosferoTestHelper end def content_tag(tag, content, options = {}) - "<#{tag}>#{content}#{tag}>" + tag_attr = options.blank? ? '' : ' ' + options.collect{ |o| "#{o[0]}=\"#{o[1]}\"" }.join(' ') + "<#{tag}#{tag_attr}>#{content}#{tag}>" end def submit_tag(content, options = {}) @@ -228,6 +229,8 @@ module NoosferoTestHelper icon end + def will_paginate(arg1, arg2) + end end class ActionController::IntegrationTest diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index 650e906..462a09a 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -89,7 +89,7 @@ class ArticleBlockTest < Test::Unit::TestCase block.expects(:title).returns('') block.stubs(:article).returns(article) - assert_equal "