Commit 836970b61953232ff71296422a598bf98d331fe2
1 parent
45e5189b
Exists in
staging
and in
42 other branches
Fixing tests
Features: * Move Article * Language Selection * Work Assignment Plugin
Showing
11 changed files
with
31 additions
and
34 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -18,7 +18,8 @@ class CmsController < MyProfileController |
18 | 18 | |
19 | 19 | protect_if :only => :upload_files do |c, user, profile| |
20 | 20 | article_id = c.params[:parent_id] |
21 | - profile.articles.find(article_id).allow_create?(user) | |
21 | + (article_id && profile.articles.find(article_id).allow_create?(user)) || | |
22 | + (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) | |
22 | 23 | end |
23 | 24 | |
24 | 25 | protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files] do |c, user, profile| | ... | ... |
app/helpers/content_viewer_helper.rb
... | ... | @@ -26,7 +26,7 @@ module ContentViewerHelper |
26 | 26 | end |
27 | 27 | title << content_tag('span', |
28 | 28 | content_tag('span', show_date(article.published_at), :class => 'date') + |
29 | - content_tag('span', [_(", by %s") % link_to(article.author_name, article.author.url)], :class => 'author') + | |
29 | + content_tag('span', [_(", by %s") % link_to(article.author_name, article.author_url)], :class => 'author') + | |
30 | 30 | content_tag('span', comments, :class => 'comments'), |
31 | 31 | :class => 'created-at' |
32 | 32 | ) | ... | ... |
app/models/approve_article.rb
... | ... | @@ -48,7 +48,7 @@ class ApproveArticle < Task |
48 | 48 | end |
49 | 49 | |
50 | 50 | def perform |
51 | - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source) | |
51 | + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :author => article.author) | |
52 | 52 | end |
53 | 53 | |
54 | 54 | def title | ... | ... |
app/models/article.rb
... | ... | @@ -296,7 +296,7 @@ class Article < ActiveRecord::Base |
296 | 296 | if last_comment |
297 | 297 | {:date => last_comment.created_at, :author_name => last_comment.author_name, :author_url => last_comment.author_url} |
298 | 298 | else |
299 | - {:date => updated_at, :author_name => author_name, :author_url => author ? author.url : nil} | |
299 | + {:date => updated_at, :author_name => author_name, :author_url => author_url} | |
300 | 300 | end |
301 | 301 | end |
302 | 302 | |
... | ... | @@ -546,7 +546,11 @@ class Article < ActiveRecord::Base |
546 | 546 | end |
547 | 547 | |
548 | 548 | def author_name |
549 | - author ? author.name : setting[:author_name] | |
549 | + author ? author.name : (setting[:author_name] || _('Unknown')) | |
550 | + end | |
551 | + | |
552 | + def author_url | |
553 | + author ? author.url : nil | |
550 | 554 | end |
551 | 555 | |
552 | 556 | alias :active_record_cache_key :cache_key | ... | ... |
app/views/tasks/_suggest_article_accept_details.rhtml
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> |
7 | 7 | <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> |
8 | 8 | |
9 | -<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %> | |
9 | +<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %> | |
10 | 10 | <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> |
11 | 11 | |
12 | 12 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => f, :abstract_method => 'article_abstract', :body_method => 'article_body', :lead_id => task.id} %> | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -1125,7 +1125,7 @@ class CmsControllerTest < ActionController::TestCase |
1125 | 1125 | should 'not allow user edit article if he is owner but has no publish permission' do |
1126 | 1126 | c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') |
1127 | 1127 | u = create_user_with_permission('test_user', 'bogus_permission', c) |
1128 | - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) | |
1128 | + a = c.articles.create!(:name => 'test_article', :author => u) | |
1129 | 1129 | login_as :test_user |
1130 | 1130 | |
1131 | 1131 | get :edit, :profile => c.identifier, :id => a.id |
... | ... | @@ -1136,7 +1136,7 @@ class CmsControllerTest < ActionController::TestCase |
1136 | 1136 | should 'allow user edit article if he is owner and has publish permission' do |
1137 | 1137 | c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') |
1138 | 1138 | u = create_user_with_permission('test_user', 'publish_content', c) |
1139 | - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) | |
1139 | + a = c.articles.create!(:name => 'test_article', :author => u) | |
1140 | 1140 | login_as :test_user |
1141 | 1141 | @controller.stubs(:user).returns(u) |
1142 | 1142 | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -850,7 +850,7 @@ end |
850 | 850 | c = Community.create!(:name => 'test_com') |
851 | 851 | u = create_user_with_permission('test_user', 'publish_content', c) |
852 | 852 | login_as u.identifier |
853 | - a = c.articles.create!(:name => 'test-article', :last_changed_by => u, :published => false) | |
853 | + a = c.articles.create!(:name => 'test-article', :author => u, :published => false) | |
854 | 854 | |
855 | 855 | get :view_page, :profile => c.identifier, :page => a.explode_path |
856 | 856 | ... | ... |
test/unit/approve_article_test.rb
... | ... | @@ -210,7 +210,8 @@ class ApproveArticleTest < ActiveSupport::TestCase |
210 | 210 | end |
211 | 211 | |
212 | 212 | should 'use author from original article on published' do |
213 | - article.stubs(:last_changed_by_id).returns(profile) | |
213 | + article.author = profile | |
214 | + article.save! | |
214 | 215 | |
215 | 216 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) |
216 | 217 | a.finish |
... | ... | @@ -218,14 +219,15 @@ class ApproveArticleTest < ActiveSupport::TestCase |
218 | 219 | assert_equal profile, article.class.last.author |
219 | 220 | end |
220 | 221 | |
221 | - | |
222 | - should 'use owning profile as author when there is no referenced article' do | |
222 | + should 'use original article author even if article is destroyed' do | |
223 | + article.author = profile | |
224 | + article.save! | |
223 | 225 | a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) |
224 | 226 | a.finish |
225 | 227 | |
226 | 228 | article.destroy |
227 | 229 | |
228 | - assert_equal community, article.class.last.author | |
230 | + assert_equal profile, article.class.last.author | |
229 | 231 | end |
230 | 232 | |
231 | 233 | should 'the published article have parent if defined' do | ... | ... |
test/unit/article_test.rb
... | ... | @@ -783,18 +783,10 @@ class ArticleTest < ActiveSupport::TestCase |
783 | 783 | assert_match(/-owner/, a.cache_key({}, c)) |
784 | 784 | end |
785 | 785 | |
786 | - should 'have a creator method' do | |
787 | - c = fast_create(Community) | |
788 | - a = c.articles.create!(:name => 'a test article', :last_changed_by => profile) | |
789 | - p = create_user('other_user').person | |
790 | - a.update_attributes(:body => 'some content', :last_changed_by => p); a.save! | |
791 | - assert_equal profile, a.creator | |
792 | - end | |
793 | - | |
794 | - should 'allow creator to edit if is publisher' do | |
786 | + should 'allow author to edit if is publisher' do | |
795 | 787 | c = fast_create(Community) |
796 | 788 | p = create_user_with_permission('test_user', 'publish_content', c) |
797 | - a = c.articles.create!(:name => 'a test article', :last_changed_by => p) | |
789 | + a = c.articles.create!(:name => 'a test article', :author => p) | |
798 | 790 | |
799 | 791 | assert a.allow_post_content?(p) |
800 | 792 | end |
... | ... | @@ -1365,18 +1357,17 @@ class ArticleTest < ActiveSupport::TestCase |
1365 | 1357 | end |
1366 | 1358 | |
1367 | 1359 | should "the author_name returns the name of the article's author" do |
1368 | - author = mock() | |
1369 | - author.expects(:name).returns('author name') | |
1370 | - a = Article.new | |
1371 | - a.expects(:author).returns(author) | |
1372 | - assert_equal 'author name', a.author_name | |
1360 | + author = fast_create(Person) | |
1361 | + a = Article.new(:author => author) | |
1362 | + assert_equal author.name, a.author_name | |
1363 | + a.author = nil | |
1373 | 1364 | a.author_name = 'some name' |
1374 | 1365 | assert_equal 'some name', a.author_name |
1375 | 1366 | end |
1376 | 1367 | |
1377 | 1368 | should 'retrieve latest info from topic when has no comments' do |
1378 | 1369 | forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) |
1379 | - post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now) | |
1370 | + post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now, :author_id => profile.id) | |
1380 | 1371 | assert_equal post.updated_at, post.info_from_last_update[:date] |
1381 | 1372 | assert_equal profile.name, post.info_from_last_update[:author_name] |
1382 | 1373 | assert_equal profile.url, post.info_from_last_update[:author_url] | ... | ... |
test/unit/folder_helper_test.rb
... | ... | @@ -33,7 +33,7 @@ class FolderHelperTest < ActiveSupport::TestCase |
33 | 33 | |
34 | 34 | should 'display icon for type of article' do |
35 | 35 | Article.expects(:icon_name).returns('article') |
36 | - assert_match /icon-newarticle/, icon_for_new_article('Article') | |
36 | + assert_match /icon-newarticle/, icon_for_new_article(Article) | |
37 | 37 | end |
38 | 38 | |
39 | 39 | should 'list all the folder\'s children to the owner' do | ... | ... |
test/unit/forum_helper_test.rb
... | ... | @@ -29,17 +29,16 @@ class ForumHelperTest < ActiveSupport::TestCase |
29 | 29 | end |
30 | 30 | |
31 | 31 | should 'list posts with different classes' do |
32 | - forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false) | |
32 | + forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :author => profile) | |
33 | 33 | one_month_later = Time.now + 1.month |
34 | 34 | Time.stubs(:now).returns(one_month_later) |
35 | - forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true) | |
35 | + forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :author => profile) | |
36 | 36 | assert_match /forum-post position-1 first odd-post.*forum-post position-2 last not-published even-post/, list_forum_posts(forum.posts) |
37 | 37 | end |
38 | 38 | |
39 | 39 | should 'return post update if it has no comments' do |
40 | 40 | author = create_user('forum test author').person |
41 | - some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true) | |
42 | - some_post.expects(:author).returns(author).times(2) | |
41 | + some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) | |
43 | 42 | assert some_post.comments.empty? |
44 | 43 | out = last_topic_update(some_post) |
45 | 44 | assert_match some_post.updated_at.to_s, out | ... | ... |