[Git][noosfero/noosfero][stable-1.7] Merge branch 'article_authors' into 'master'
Rodrigo Souto
gitlab at mg.gitlab.com
Thu Mar 23 11:04:27 BRT 2017
Rodrigo Souto pushed to branch stable-1.7 at Noosfero / noosfero
Commits:
592741c3 by Rodrigo Souto at 2017-03-23T14:04:16+00:00
Merge branch 'article_authors' into 'master'
Shows the author of the version in article versions list
See merge request !1145
- - - - -
5 changed files:
- app/models/article.rb
- app/views/content_viewer/versioned_article.html.erb
- test/functional/cms_controller_test.rb
- test/functional/content_viewer_controller_test.rb
- test/unit/article_test.rb
Changes:
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -739,7 +739,9 @@ class Article < ApplicationRecord
end
def author_by_version(version_number = nil)
- if version_number then profile.environment.people.where(id: get_version(version_number).author_id).first else author end
+ return author unless version_number
+ author_id = get_version(version_number).last_changed_by_id
+ profile.environment.people.where(id: author_id).first
end
def author_name(version_number = nil)
=====================================
app/views/content_viewer/versioned_article.html.erb
=====================================
--- a/app/views/content_viewer/versioned_article.html.erb
+++ b/app/views/content_viewer/versioned_article.html.erb
@@ -13,7 +13,7 @@
<%= expirable_button @page, :undo, content, url, :id => 'article-revert-version-link' %>
<% end %>
- <%= button(:forward, _('Go to latest version'), {:action => 'view_page'}) %>
+ <%= button(:forward, _('Go to latest version'), @page.url) %>
</div>
<div id="article-header">
<h1 class='title'><%= @versioned_article.name %></h1>
=====================================
test/functional/cms_controller_test.rb
=====================================
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -2038,6 +2038,26 @@ class CmsControllerTest < ActionController::TestCase
end
end
+ should 'save and display correct authors for article versions' do
+ community = fast_create(Community)
+ author1 = create_user('test1').person
+ author2 = create_user('test2').person
+
+ community.add_admin(author1)
+ community.add_admin(author2)
+ login_as(author1.identifier)
+ post :new, :type => 'TextArticle', :profile => community.identifier,
+ :article => { :name => 'Main Article', :body => 'some content' }
+
+ article = community.articles.last
+ @controller.stubs(:user).returns(author2)
+ post :edit, :id => article.id, :profile => community.identifier,
+ :article => { :name => 'Main Article', :body => 'edited' }
+
+ assert_equal 2, article.versions.count
+ assert_equivalent [author1.id, author2.id], article.versions.map(&:last_changed_by_id)
+ end
+
protected
# FIXME this is to avoid adding an extra dependency for a proper JSON parser.
=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -396,6 +396,24 @@ class ContentViewerControllerTest < ActionController::TestCase
assert_select "ul#article-versions a[href=http://#{profile.environment.default_hostname}/#{profile.identifier}/#{page.path}?version=1]"
end
+ should "display correct author for each article versions" do
+ community = fast_create(Community)
+ author1 = create_user.person
+ author2 = create_user.person
+ article = create(TextArticle, :name => 'article', :body => 'first version', :display_versions => true,
+ :profile => community, :author => author1, :last_changed_by => author1)
+
+ article.body = 'second version'
+ article.last_changed_by = author2
+ article.save
+
+ get :article_versions, :profile => community.identifier, :page => article.path
+ assert_tag :tag => 'span', :attributes => { :class => 'updated-by' },
+ :child => { :tag => 'a', :content => author1.name }
+ assert_tag :tag => 'span', :attributes => { :class => 'updated-by' },
+ :child => { :tag => 'a', :content => author2.name }
+ end
+
should "fetch correct article version" do
page = TextArticle.create!(:name => 'myarticle', :body => 'original article', :display_versions => true, :profile => profile)
page.body = 'edited article'; page.save
=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -1781,9 +1781,9 @@ class ArticleTest < ActiveSupport::TestCase
should "return the author_name of a specific version" do
author1 = fast_create(Person)
author2 = fast_create(Person)
- article = create(Article, :name => 'first version', :profile => profile, :author => author1)
+ article = create(Article, :name => 'first version', :profile => profile, :author => author1, :last_changed_by => author1)
article.name = 'second version'
- article.author = author2
+ article.last_changed_by = author2
article.save
assert_equal author1.name, article.author_name(1)
assert_equal author2.name, article.author_name(2)
@@ -1854,13 +1854,13 @@ class ArticleTest < ActiveSupport::TestCase
p1 = fast_create(Person)
p2 = fast_create(Person)
p3 = fast_create(Person)
- article = create(Article, :name => 'first version', :profile => profile, :author => p1)
+ article = create(Article, :name => 'first version', :profile => profile, :author => p1, :last_changed_by => p1)
article.name = 'second version'
- article.author = p2
+ article.last_changed_by = p2
article.save!
- article.author = p3
+ article.last_changed_by = p3
article.name = 'third version'
article.save!
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/592741c3cef1798e46fed0f2584677343319b976
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170323/835d6473/attachment-0001.html>
More information about the Noosfero-dev
mailing list