Commit a07045349fdd3d3bad7be30a83153cce2e024e07
1 parent
7ea7efc5
Exists in
master
and in
29 other branches
ActionItem938: display author when available
When we know who is the author, use it instead of just using the profile owning the article. This is rather limited, though, since the history is not queried to get all the authors; only the last author is displayed.
Showing
6 changed files
with
35 additions
and
3 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
@@ -20,7 +20,7 @@ module ContentViewerHelper | @@ -20,7 +20,7 @@ module ContentViewerHelper | ||
20 | unless args[:no_link] | 20 | unless args[:no_link] |
21 | title = content_tag('h3', link_to(article.name, article.url), :class => 'title') | 21 | title = content_tag('h3', link_to(article.name, article.url), :class => 'title') |
22 | end | 22 | end |
23 | - title << content_tag('span', _("%s, by %s") % [show_date(article.created_at), article.profile.name], :class => 'created-at') | 23 | + title << content_tag('span', _("%s, by %s") % [show_date(article.created_at), link_to(article.author.name, article.author.url)], :class => 'created-at') |
24 | end | 24 | end |
25 | title | 25 | title |
26 | end | 26 | end |
app/models/article.rb
@@ -249,6 +249,11 @@ class Article < ActiveRecord::Base | @@ -249,6 +249,11 @@ class Article < ActiveRecord::Base | ||
249 | false | 249 | false |
250 | end | 250 | end |
251 | 251 | ||
252 | + def author | ||
253 | + last_changed_by || | ||
254 | + profile | ||
255 | + end | ||
256 | + | ||
252 | private | 257 | private |
253 | 258 | ||
254 | def sanitize_tag_list | 259 | def sanitize_tag_list |
app/models/published_article.rb
@@ -24,4 +24,13 @@ class PublishedArticle < Article | @@ -24,4 +24,13 @@ class PublishedArticle < Article | ||
24 | def update_name | 24 | def update_name |
25 | self.name ||= self.reference_article.name | 25 | self.name ||= self.reference_article.name |
26 | end | 26 | end |
27 | + | ||
28 | + def author | ||
29 | + if reference_article | ||
30 | + reference_article.author | ||
31 | + else | ||
32 | + profile | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
27 | end | 36 | end |
test/unit/article_test.rb
@@ -659,4 +659,12 @@ class ArticleTest < Test::Unit::TestCase | @@ -659,4 +659,12 @@ class ArticleTest < Test::Unit::TestCase | ||
659 | assert_equal a.url, a.view_url | 659 | assert_equal a.url, a.view_url |
660 | end | 660 | end |
661 | 661 | ||
662 | + should 'know its author' do | ||
663 | + assert_equal profile, Article.new(:last_changed_by => profile).author | ||
664 | + end | ||
665 | + | ||
666 | + should 'use owning profile as author when we dont know who did the last change' do | ||
667 | + assert_equal profile, Article.new(:last_changed_by => nil, :profile => profile).author | ||
668 | + end | ||
669 | + | ||
662 | end | 670 | end |
test/unit/content_viewer_helper_test.rb
@@ -15,13 +15,13 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -15,13 +15,13 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
15 | blog = Blog.create!(:name => 'Blog test', :profile => profile) | 15 | blog = Blog.create!(:name => 'Blog test', :profile => profile) |
16 | post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) | 16 | post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) |
17 | result = article_title(post) | 17 | result = article_title(post) |
18 | - assert_match /#{show_date(post.created_at)}, by #{profile.identifier}/, result | 18 | + assert_match /#{show_date(post.created_at)}, by .*#{profile.identifier}/, result |
19 | end | 19 | end |
20 | 20 | ||
21 | should 'not display created-at for non-blog posts' do | 21 | should 'not display created-at for non-blog posts' do |
22 | article = TextileArticle.create!(:name => 'article for test', :profile => profile) | 22 | article = TextileArticle.create!(:name => 'article for test', :profile => profile) |
23 | result = article_title(article) | 23 | result = article_title(article) |
24 | - assert_no_match /#{show_date(article.created_at)}, by #{profile.identifier}/, result | 24 | + assert_no_match /#{show_date(article.created_at)}, by .*#{profile.identifier}/, result |
25 | end | 25 | end |
26 | 26 | ||
27 | should 'create link on title of blog posts' do | 27 | should 'create link on title of blog posts' do |
test/unit/published_article_test.rb
@@ -73,5 +73,15 @@ class PublishedArticleTest < ActiveSupport::TestCase | @@ -73,5 +73,15 @@ class PublishedArticleTest < ActiveSupport::TestCase | ||
73 | assert_nil p.parent | 73 | assert_nil p.parent |
74 | end | 74 | end |
75 | 75 | ||
76 | + should "use author of original article as its author" do | ||
77 | + original = Article.new(:last_changed_by => @profile) | ||
78 | + community = Community.new | ||
79 | + published = PublishedArticle.new(:reference_article => original, :profile => community) | ||
80 | + assert_equal @profile, published.author | ||
81 | + end | ||
82 | + | ||
83 | + should 'use owning profile as author when there is no referenced article yet' do | ||
84 | + assert_equal @profile, PublishedArticle.new(:profile => @profile).author | ||
85 | + end | ||
76 | 86 | ||
77 | end | 87 | end |