From 836970b61953232ff71296422a598bf98d331fe2 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 1 Nov 2012 20:29:40 +0000 Subject: [PATCH] Fixing tests --- app/controllers/my_profile/cms_controller.rb | 3 ++- app/helpers/content_viewer_helper.rb | 2 +- app/models/approve_article.rb | 2 +- app/models/article.rb | 8 ++++++-- app/views/tasks/_suggest_article_accept_details.rhtml | 2 +- test/functional/cms_controller_test.rb | 4 ++-- test/functional/content_viewer_controller_test.rb | 2 +- test/unit/approve_article_test.rb | 10 ++++++---- test/unit/article_test.rb | 23 +++++++---------------- test/unit/folder_helper_test.rb | 2 +- test/unit/forum_helper_test.rb | 7 +++---- 11 files changed, 31 insertions(+), 34 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index e95f70a..fd34d92 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -18,7 +18,8 @@ class CmsController < MyProfileController protect_if :only => :upload_files do |c, user, profile| article_id = c.params[:parent_id] - profile.articles.find(article_id).allow_create?(user) + (article_id && profile.articles.find(article_id).allow_create?(user)) || + (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) end protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files] do |c, user, profile| diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 5cbc420..f6ba368 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -26,7 +26,7 @@ module ContentViewerHelper end title << content_tag('span', content_tag('span', show_date(article.published_at), :class => 'date') + - content_tag('span', [_(", by %s") % link_to(article.author_name, article.author.url)], :class => 'author') + + content_tag('span', [_(", by %s") % link_to(article.author_name, article.author_url)], :class => 'author') + content_tag('span', comments, :class => 'comments'), :class => 'created-at' ) diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb index 627a210..0adc1c4 100644 --- a/app/models/approve_article.rb +++ b/app/models/approve_article.rb @@ -48,7 +48,7 @@ class ApproveArticle < Task end def perform - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source) + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :author => article.author) end def title diff --git a/app/models/article.rb b/app/models/article.rb index e3c3453..e4f9fd9 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -296,7 +296,7 @@ class Article < ActiveRecord::Base 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 ? author.url : nil} + {:date => updated_at, :author_name => author_name, :author_url => author_url} end end @@ -546,7 +546,11 @@ class Article < ActiveRecord::Base end def author_name - author ? author.name : setting[:author_name] + author ? author.name : (setting[:author_name] || _('Unknown')) + end + + def author_url + author ? author.url : nil end alias :active_record_cache_key :cache_key diff --git a/app/views/tasks/_suggest_article_accept_details.rhtml b/app/views/tasks/_suggest_article_accept_details.rhtml index dd4028b..759e165 100644 --- a/app/views/tasks/_suggest_article_accept_details.rhtml +++ b/app/views/tasks/_suggest_article_accept_details.rhtml @@ -6,7 +6,7 @@ <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> -<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task]", 'article_parent_id', task.target) %> +<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %> <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => f, :abstract_method => 'article_abstract', :body_method => 'article_body', :lead_id => task.id} %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 5a6210c..900d031 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1125,7 +1125,7 @@ class CmsControllerTest < ActionController::TestCase should 'not allow user edit article if he is owner but has no publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'bogus_permission', c) - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) + a = c.articles.create!(:name => 'test_article', :author => u) login_as :test_user get :edit, :profile => c.identifier, :id => a.id @@ -1136,7 +1136,7 @@ class CmsControllerTest < ActionController::TestCase should 'allow user edit article if he is owner and has publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'publish_content', c) - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) + a = c.articles.create!(:name => 'test_article', :author => u) login_as :test_user @controller.stubs(:user).returns(u) diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 2f66529..829d9eb 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -850,7 +850,7 @@ end c = Community.create!(:name => 'test_com') u = create_user_with_permission('test_user', 'publish_content', c) login_as u.identifier - a = c.articles.create!(:name => 'test-article', :last_changed_by => u, :published => false) + a = c.articles.create!(:name => 'test-article', :author => u, :published => false) get :view_page, :profile => c.identifier, :page => a.explode_path diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index 5279eb0..7ba9815 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -210,7 +210,8 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'use author from original article on published' do - article.stubs(:last_changed_by_id).returns(profile) + article.author = profile + article.save! a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) a.finish @@ -218,14 +219,15 @@ class ApproveArticleTest < ActiveSupport::TestCase assert_equal profile, article.class.last.author end - - should 'use owning profile as author when there is no referenced article' do + should 'use original article author even if article is destroyed' do + article.author = profile + article.save! a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) a.finish article.destroy - assert_equal community, article.class.last.author + assert_equal profile, article.class.last.author end should 'the published article have parent if defined' do diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index f5067d1..d661b94 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -783,18 +783,10 @@ class ArticleTest < ActiveSupport::TestCase assert_match(/-owner/, a.cache_key({}, c)) end - should 'have a creator method' do - c = fast_create(Community) - a = c.articles.create!(:name => 'a test article', :last_changed_by => profile) - p = create_user('other_user').person - a.update_attributes(:body => 'some content', :last_changed_by => p); a.save! - assert_equal profile, a.creator - end - - should 'allow creator to edit if is publisher' do + should 'allow author to edit if is publisher' do c = fast_create(Community) p = create_user_with_permission('test_user', 'publish_content', c) - a = c.articles.create!(:name => 'a test article', :last_changed_by => p) + a = c.articles.create!(:name => 'a test article', :author => p) assert a.allow_post_content?(p) end @@ -1365,18 +1357,17 @@ class ArticleTest < ActiveSupport::TestCase end should "the author_name returns the name of the article's author" do - author = mock() - author.expects(:name).returns('author name') - a = Article.new - a.expects(:author).returns(author) - assert_equal 'author name', a.author_name + author = fast_create(Person) + a = Article.new(:author => author) + assert_equal author.name, a.author_name + a.author = nil a.author_name = 'some name' assert_equal 'some name', a.author_name end should 'retrieve latest info from topic when has no comments' do forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) - post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now) + post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now, :author_id => profile.id) assert_equal post.updated_at, post.info_from_last_update[:date] assert_equal profile.name, post.info_from_last_update[:author_name] assert_equal profile.url, post.info_from_last_update[:author_url] diff --git a/test/unit/folder_helper_test.rb b/test/unit/folder_helper_test.rb index c2dc11e..c28aee1 100644 --- a/test/unit/folder_helper_test.rb +++ b/test/unit/folder_helper_test.rb @@ -33,7 +33,7 @@ class FolderHelperTest < ActiveSupport::TestCase should 'display icon for type of article' do Article.expects(:icon_name).returns('article') - assert_match /icon-newarticle/, icon_for_new_article('Article') + assert_match /icon-newarticle/, icon_for_new_article(Article) end should 'list all the folder\'s children to the owner' do diff --git a/test/unit/forum_helper_test.rb b/test/unit/forum_helper_test.rb index 0ccbf4c..378e28b 100644 --- a/test/unit/forum_helper_test.rb +++ b/test/unit/forum_helper_test.rb @@ -29,17 +29,16 @@ class ForumHelperTest < ActiveSupport::TestCase end should 'list posts with different classes' do - forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false) + forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :author => profile) one_month_later = Time.now + 1.month Time.stubs(:now).returns(one_month_later) - forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true) + forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :author => profile) assert_match /forum-post position-1 first odd-post.*forum-post position-2 last not-published even-post/, list_forum_posts(forum.posts) end should 'return post update if it has no comments' do author = create_user('forum test author').person - some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true) - some_post.expects(:author).returns(author).times(2) + some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) assert some_post.comments.empty? out = last_topic_update(some_post) assert_match some_post.updated_at.to_s, out -- libgit2 0.21.2