From a07045349fdd3d3bad7be30a83153cce2e024e07 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 16 Mar 2009 12:12:32 -0300 Subject: [PATCH] ActionItem938: display author when available --- app/helpers/content_viewer_helper.rb | 2 +- app/models/article.rb | 5 +++++ app/models/published_article.rb | 9 +++++++++ test/unit/article_test.rb | 8 ++++++++ test/unit/content_viewer_helper_test.rb | 4 ++-- test/unit/published_article_test.rb | 10 ++++++++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 7d2155a..d336614 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -20,7 +20,7 @@ module ContentViewerHelper unless args[:no_link] title = content_tag('h3', link_to(article.name, article.url), :class => 'title') end - title << content_tag('span', _("%s, by %s") % [show_date(article.created_at), article.profile.name], :class => 'created-at') + title << content_tag('span', _("%s, by %s") % [show_date(article.created_at), link_to(article.author.name, article.author.url)], :class => 'created-at') end title end diff --git a/app/models/article.rb b/app/models/article.rb index bcddb18..604c5c1 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -249,6 +249,11 @@ class Article < ActiveRecord::Base false end + def author + last_changed_by || + profile + end + private def sanitize_tag_list diff --git a/app/models/published_article.rb b/app/models/published_article.rb index d0f8325..c993b6e 100644 --- a/app/models/published_article.rb +++ b/app/models/published_article.rb @@ -24,4 +24,13 @@ class PublishedArticle < Article def update_name self.name ||= self.reference_article.name end + + def author + if reference_article + reference_article.author + else + profile + end + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index e8d2352..ca37826 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -659,4 +659,12 @@ class ArticleTest < Test::Unit::TestCase assert_equal a.url, a.view_url end + should 'know its author' do + assert_equal profile, Article.new(:last_changed_by => profile).author + end + + should 'use owning profile as author when we dont know who did the last change' do + assert_equal profile, Article.new(:last_changed_by => nil, :profile => profile).author + end + end diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index 5d5de44..bff0db0 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -15,13 +15,13 @@ class ContentViewerHelperTest < Test::Unit::TestCase blog = Blog.create!(:name => 'Blog test', :profile => profile) post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) result = article_title(post) - assert_match /#{show_date(post.created_at)}, by #{profile.identifier}/, result + assert_match /#{show_date(post.created_at)}, by .*#{profile.identifier}/, result end should 'not display created-at for non-blog posts' do article = TextileArticle.create!(:name => 'article for test', :profile => profile) result = article_title(article) - assert_no_match /#{show_date(article.created_at)}, by #{profile.identifier}/, result + assert_no_match /#{show_date(article.created_at)}, by .*#{profile.identifier}/, result end should 'create link on title of blog posts' do diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index 70ee5de..2ca0889 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -73,5 +73,15 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_nil p.parent end + should "use author of original article as its author" do + original = Article.new(:last_changed_by => @profile) + community = Community.new + published = PublishedArticle.new(:reference_article => original, :profile => community) + assert_equal @profile, published.author + end + + should 'use owning profile as author when there is no referenced article yet' do + assert_equal @profile, PublishedArticle.new(:profile => @profile).author + end end -- libgit2 0.21.2