Commit 1e60d6cfe55c86011e1981bf14d81ce67a16dbdd

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 5f250899

ActionItem1002: adding select to choose destination folder when approving articles.

app/helpers/application_helper.rb
... ... @@ -493,6 +493,10 @@ module ApplicationHelper
493 493 content_tag('div', result)
494 494 end
495 495  
  496 + def select_folder(object, method, collection, html_options = {}, js_options = {})
  497 + 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))
  498 + end
  499 +
496 500 def theme_option(opt = nil)
497 501 conf = RAILS_ROOT.to_s() +
498 502 '/public' + theme_path +
... ...
app/helpers/cms_helper.rb
... ... @@ -15,10 +15,6 @@ module CmsHelper
15 15 end
16 16 end
17 17  
18   - def select_folder(object, method, collection, html_options, js_options)
19   - 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))
20   - end
21   -
22 18 def pagination_links(collection, options={})
23 19 options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options)
24 20 will_paginate(collection, options)
... ...
app/models/approve_article.rb
... ... @@ -35,8 +35,24 @@ class ApproveArticle < Task
35 35 data[:closing_statment] = value
36 36 end
37 37  
  38 + def article_parent_id= value
  39 + data[:parent_id] = value
  40 + end
  41 +
  42 + def article_parent_id
  43 + data[:parent_id]
  44 + end
  45 +
  46 + def article_parent
  47 + Article.find_by_id article_parent_id
  48 + end
  49 +
  50 + def article_parent= value
  51 + article_parent_id = value.id
  52 + end
  53 +
38 54 def perform
39   - PublishedArticle.create(:name => name, :profile => target, :reference_article => article)
  55 + PublishedArticle.create(:name => name, :profile => target, :reference_article => article, :parent => article_parent)
40 56 end
41 57  
42 58 def target_notification_message
... ...
app/models/profile.rb
... ... @@ -592,4 +592,7 @@ class Profile < ActiveRecord::Base
592 592 !environment.enabled?('disable_contact_' + self.class.name.downcase)
593 593 end
594 594  
  595 + def folders
  596 + self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']])
  597 + end
595 598 end
... ...
app/views/tasks/_approve_article.rhtml
... ... @@ -21,6 +21,7 @@
21 21  
22 22 <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %>
23 23  
  24 + <%= labelled_form_field(_('Select the folder where the article must be published'), select_folder('task', 'article_parent_id', task.target.folders)) %>
24 25 <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %>
25 26  
26 27 </div>
... ...
test/functional/cms_controller_test.rb
... ... @@ -941,10 +941,10 @@ class CmsControllerTest &lt; Test::Unit::TestCase
941 941 assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' }
942 942 end
943 943  
944   - should 'display iframe for media listing when it is TinyMceArticle' do
945   - env = Environment.default
946   - env.enable('media_panel')
947   - env.save!
  944 + should 'display iframe for media listing when it is TinyMceArticle and enabled on environment' do
  945 + e = Environment.default
  946 + e.enable('media_panel')
  947 + e.save!
948 948  
949 949 image_folder = Folder.create(:profile => profile, :name => 'Image folder')
950 950 non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder')
... ...
test/functional/tasks_controller_test.rb
... ... @@ -153,4 +153,28 @@ class TasksControllerTest &lt; Test::Unit::TestCase
153 153 assert_equal f, assigns(:ticket).target
154 154 end
155 155  
  156 + should 'create published article after finish approve article task' do
  157 + PublishedArticle.destroy_all
  158 + c = Community.create!(:name => 'test comm', :moderated_articles => false)
  159 + @controller.stubs(:profile).returns(c)
  160 + c.affiliate(profile, Profile::Roles.all_roles)
  161 + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
  162 + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
  163 +
  164 + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name'}
  165 + assert_equal article, PublishedArticle.find(:first).reference_article
  166 + end
  167 +
  168 + should 'create published article in folder after finish approve article task' do
  169 + PublishedArticle.destroy_all
  170 + c = Community.create!(:name => 'test comm', :moderated_articles => false)
  171 + @controller.stubs(:profile).returns(c)
  172 + folder = c.articles.create!(:name => 'test folder', :type => 'Folder')
  173 + c.affiliate(profile, Profile::Roles.all_roles)
  174 + article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
  175 + t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
  176 +
  177 + post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => folder.id}
  178 + assert_equal folder, PublishedArticle.find(:first).parent
  179 + end
156 180 end
... ...
test/unit/approve_article_test.rb
... ... @@ -32,4 +32,22 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
32 32 end
33 33 end
34 34  
  35 + should 'have parent if defined' do
  36 + profile = create_user('test_user').person
  37 + article = profile.articles.create!(:name => 'test article')
  38 + folder = profile.articles.create!(:name => 'test folder', :type => 'Folder')
  39 +
  40 + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id)
  41 +
  42 + assert_equal folder, a.article_parent
  43 + end
  44 +
  45 + should 'not have parent if not defined' do
  46 + profile = create_user('test_user').person
  47 + article = profile.articles.create!(:name => 'test article')
  48 +
  49 + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
  50 +
  51 + assert_nil a.article_parent
  52 + end
35 53 end
... ...
test/unit/profile_test.rb
... ... @@ -1296,6 +1296,21 @@ class ProfileTest &lt; Test::Unit::TestCase
1296 1296 assert_includes profile.possible_domains, domain2
1297 1297 end
1298 1298  
  1299 + should 'list folder articles' do
  1300 + profile = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting')
  1301 + Article.destroy_all
  1302 + p1 = Folder.create!(:name => 'parent1', :profile => profile)
  1303 + p2 = Blog.create!(:name => 'parent2', :profile => profile)
  1304 +
  1305 + assert p1.folder?
  1306 + assert p2.folder?
  1307 +
  1308 + child = profile.articles.create!(:name => 'child', :parent => p1)
  1309 + profile.reload
  1310 + assert_equivalent [p1, p2], profile.folders
  1311 + assert !profile.folders.include?(child)
  1312 + end
  1313 +
1299 1314 private
1300 1315  
1301 1316 def assert_invalid_identifier(id)
... ...
test/unit/published_article_test.rb
... ... @@ -84,4 +84,12 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase
84 84 assert_equal @profile, PublishedArticle.new(:profile => @profile).author
85 85 end
86 86  
  87 + should 'have parent if defined' do
  88 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  89 + folder = Folder.create(:name => 'folder test', :profile => prof)
  90 + p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder)
  91 +
  92 + assert p
  93 + assert_equal folder, p.parent
  94 + end
87 95 end
... ...