From 1e60d6cfe55c86011e1981bf14d81ce67a16dbdd Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 23 Apr 2009 19:31:51 -0300 Subject: [PATCH] ActionItem1002: adding select to choose destination folder when approving articles. --- app/helpers/application_helper.rb | 4 ++++ app/helpers/cms_helper.rb | 4 ---- app/models/approve_article.rb | 18 +++++++++++++++++- app/models/profile.rb | 3 +++ app/views/tasks/_approve_article.rhtml | 1 + test/functional/cms_controller_test.rb | 8 ++++---- test/functional/tasks_controller_test.rb | 24 ++++++++++++++++++++++++ test/unit/approve_article_test.rb | 18 ++++++++++++++++++ test/unit/profile_test.rb | 15 +++++++++++++++ test/unit/published_article_test.rb | 8 ++++++++ 10 files changed, 94 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bfcccc2..f7b35bf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -493,6 +493,10 @@ module ApplicationHelper content_tag('div', result) end + def select_folder(object, method, collection, html_options = {}, js_options = {}) + labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options)) + end + def theme_option(opt = nil) conf = RAILS_ROOT.to_s() + '/public' + theme_path + diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 956b8cf..52a0708 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -15,10 +15,6 @@ module CmsHelper end end - def select_folder(object, method, collection, html_options, js_options) - labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options)) - end - def pagination_links(collection, options={}) options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options) will_paginate(collection, options) diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb index 960e906..4333320 100644 --- a/app/models/approve_article.rb +++ b/app/models/approve_article.rb @@ -35,8 +35,24 @@ class ApproveArticle < Task data[:closing_statment] = value end + def article_parent_id= value + data[:parent_id] = value + end + + def article_parent_id + data[:parent_id] + end + + def article_parent + Article.find_by_id article_parent_id + end + + def article_parent= value + article_parent_id = value.id + end + def perform - PublishedArticle.create(:name => name, :profile => target, :reference_article => article) + PublishedArticle.create(:name => name, :profile => target, :reference_article => article, :parent => article_parent) end def target_notification_message diff --git a/app/models/profile.rb b/app/models/profile.rb index ee3127a..902c290 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -592,4 +592,7 @@ class Profile < ActiveRecord::Base !environment.enabled?('disable_contact_' + self.class.name.downcase) end + def folders + self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']]) + end end diff --git a/app/views/tasks/_approve_article.rhtml b/app/views/tasks/_approve_article.rhtml index 6a6f804..6e5447a 100644 --- a/app/views/tasks/_approve_article.rhtml +++ b/app/views/tasks/_approve_article.rhtml @@ -21,6 +21,7 @@ <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %> + <%= labelled_form_field(_('Select the folder where the article must be published'), select_folder('task', 'article_parent_id', task.target.folders)) %> <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 37ca289..ec9286e 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -941,10 +941,10 @@ class CmsControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } end - should 'display iframe for media listing when it is TinyMceArticle' do - env = Environment.default - env.enable('media_panel') - env.save! + should 'display iframe for media listing when it is TinyMceArticle and enabled on environment' do + e = Environment.default + e.enable('media_panel') + e.save! image_folder = Folder.create(:profile => profile, :name => 'Image folder') non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 7da5cb8..bcd9ebc 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -153,4 +153,28 @@ class TasksControllerTest < Test::Unit::TestCase assert_equal f, assigns(:ticket).target end + should 'create published article after finish approve article task' do + PublishedArticle.destroy_all + c = Community.create!(:name => 'test comm', :moderated_articles => false) + @controller.stubs(:profile).returns(c) + c.affiliate(profile, Profile::Roles.all_roles) + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) + + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name'} + assert_equal article, PublishedArticle.find(:first).reference_article + end + + should 'create published article in folder after finish approve article task' do + PublishedArticle.destroy_all + c = Community.create!(:name => 'test comm', :moderated_articles => false) + @controller.stubs(:profile).returns(c) + folder = c.articles.create!(:name => 'test folder', :type => 'Folder') + c.affiliate(profile, Profile::Roles.all_roles) + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) + + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => folder.id} + assert_equal folder, PublishedArticle.find(:first).parent + end end diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index 386f7d0..ddbe486 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -32,4 +32,22 @@ class ApproveArticleTest < ActiveSupport::TestCase end end + should 'have parent if defined' do + profile = create_user('test_user').person + article = profile.articles.create!(:name => 'test article') + folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') + + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id) + + assert_equal folder, a.article_parent + end + + should 'not have parent if not defined' do + profile = create_user('test_user').person + article = profile.articles.create!(:name => 'test article') + + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) + + assert_nil a.article_parent + end end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index ad34754..3937c23 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1296,6 +1296,21 @@ class ProfileTest < Test::Unit::TestCase assert_includes profile.possible_domains, domain2 end + should 'list folder articles' do + profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') + Article.destroy_all + p1 = Folder.create!(:name => 'parent1', :profile => profile) + p2 = Blog.create!(:name => 'parent2', :profile => profile) + + assert p1.folder? + assert p2.folder? + + child = profile.articles.create!(:name => 'child', :parent => p1) + profile.reload + assert_equivalent [p1, p2], profile.folders + assert !profile.folders.include?(child) + end + private def assert_invalid_identifier(id) diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index c7d5f3f..edbcb0f 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -84,4 +84,12 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_equal @profile, PublishedArticle.new(:profile => @profile).author end + should 'have parent if defined' do + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + folder = Folder.create(:name => 'folder test', :profile => prof) + p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder) + + assert p + assert_equal folder, p.parent + end end -- libgit2 0.21.2