Commit 3839e026bfb1e1434b66f089de6d9f7798247240

Authored by Evandro Junior
2 parents 5f68bfb4 21a93390

Merge branch 'master' into avoid_duplicated_tasks

* master:
  should not crash if em empty parent is passed as parameter
  fixing unit tests and put article[parent_id] parameter as an option
  sorry - revert last 3 commits. Merge request is needed
  forcing commit
  fix avoid repeated tasks
  Avoid duplicated tasks
lib/proposals_discussion_plugin.rb
... ... @@ -15,8 +15,8 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin
15 15 def content_types
16 16 if context.respond_to?(:params) && context.params.kind_of?(Hash) && context.params[:controller] == 'cms' && context.params[:action] == 'new'
17 17 types = []
18   - parent_id = context.params[:parent_id]
19   - parent = parent_id ? context.profile.articles.find(parent_id) : nil
  18 + parent_id = context.params[:parent_id] || (context.params[:article][:parent_id] unless context.params[:article].nil?)
  19 + parent = parent_id.present? ? context.profile.articles.find(parent_id) : nil
20 20 types << ProposalsDiscussionPlugin::Discussion
21 21 types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion)
22 22 if parent.kind_of?(ProposalsDiscussionPlugin::Topic) || ( parent.kind_of?(ProposalsDiscussionPlugin::Discussion) && !parent.allow_topics)
... ...
test/unit/discussion_test.rb
... ... @@ -36,8 +36,8 @@ class DiscussionTest &lt; ActiveSupport::TestCase
36 36 topic4.add_category c2
37 37  
38 38 random_topics = discussion.random_topics_one_by_category
39   -
40   - random_topics_categories = random_topics.map {|t| t.category.name }
  39 +
  40 + random_topics_categories = random_topics.map {|t| t.categories.map{|c|c.name}}.flatten
41 41  
42 42 assert_equal ["Category 1", "Category 2"],random_topics_categories
43 43 end
... ...
test/unit/proposals_discussion_plugin_test.rb
... ... @@ -20,26 +20,54 @@ class ProposalsDiscussionPluginTest &lt; ActiveSupport::TestCase
20 20 assert_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion
21 21 end
22 22  
23   - should 'return Topic as a content type if parent is a Discussion' do
  23 + should 'return Discussion as a content type if parent is empty' do
  24 + @params[:parent_id] = ''
  25 + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion
  26 + end
  27 +
  28 + should 'return Topic as a content type if parent_id parameter is a Discussion' do
24 29 parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id)
25 30 @params[:parent_id] = parent.id
26 31 assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic
27 32 end
28 33  
29   - should 'return Proposal as a content type if parent is a Topic' do
  34 + should 'return Topic as a content type if article parent_id is a Discussion' do
  35 + parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id)
  36 + @params[:article] = {}
  37 + @params[:article][:parent_id] = parent.id
  38 + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic
  39 + end
  40 +
  41 + should 'return Proposal as a content type if parent_id parameter is a Topic' do
30 42 parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id)
31 43 @params[:parent_id] = parent.id
32 44 assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal
33 45 end
34 46  
35   - should 'return Proposal as a content type if parent is a Discussion and allow_topic is false' do
  47 + should 'return Proposal as a content type if article parent is a Topic' do
  48 + parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id)
  49 + @params[:article] = {}
  50 + @params[:article][:parent_id] = parent.id
  51 + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal
  52 + end
  53 +
  54 + should 'return Proposal as a content type if parent_id parameter is a Discussion and allow_topic is false' do
36 55 parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false)
37 56 @params[:parent_id] = parent.id
38 57 assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal
39 58 end
40 59  
41   - should 'do not return Proposal as a content type if parent is nil' do
  60 + should 'return Proposal as a content type if article parent is a Discussion and allow_topic is false' do
  61 + parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false)
  62 + @params[:article] = {}
  63 + @params[:article][:parent_id] = parent.id
  64 + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal
  65 + end
  66 +
  67 + should 'do not return Proposal as a content type if parent and article parent is nil' do
42 68 @params[:parent_id] = nil
  69 + @params[:article] = {}
  70 + @params[:article][:parent_id] = nil
43 71 assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal
44 72 end
45 73  
... ...
views/cms/proposals_discussion_plugin/_proposal.html.erb
... ... @@ -23,6 +23,8 @@
23 23 <% editor_type = 'mceEditor' %>
24 24 <%= labelled_form_field(strip_tags(@article.discussion.custom_body_label), text_area(:article, :body, :class => editor_type)) %>
25 25 </div>
  26 +
  27 + <%= hidden_field(:article, :parent_id) %>
26 28 </div>
27 29  
28 30 <script>
... ...