Commit 3839e026bfb1e1434b66f089de6d9f7798247240
Exists in
avoid_duplicated_tasks
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
Showing
4 changed files
with
38 additions
and
8 deletions
Show diff stats
lib/proposals_discussion_plugin.rb
@@ -15,8 +15,8 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin | @@ -15,8 +15,8 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin | ||
15 | def content_types | 15 | def content_types |
16 | if context.respond_to?(:params) && context.params.kind_of?(Hash) && context.params[:controller] == 'cms' && context.params[:action] == 'new' | 16 | if context.respond_to?(:params) && context.params.kind_of?(Hash) && context.params[:controller] == 'cms' && context.params[:action] == 'new' |
17 | types = [] | 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 | types << ProposalsDiscussionPlugin::Discussion | 20 | types << ProposalsDiscussionPlugin::Discussion |
21 | types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) | 21 | types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) |
22 | if parent.kind_of?(ProposalsDiscussionPlugin::Topic) || ( parent.kind_of?(ProposalsDiscussionPlugin::Discussion) && !parent.allow_topics) | 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 < ActiveSupport::TestCase | @@ -36,8 +36,8 @@ class DiscussionTest < ActiveSupport::TestCase | ||
36 | topic4.add_category c2 | 36 | topic4.add_category c2 |
37 | 37 | ||
38 | random_topics = discussion.random_topics_one_by_category | 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 | assert_equal ["Category 1", "Category 2"],random_topics_categories | 42 | assert_equal ["Category 1", "Category 2"],random_topics_categories |
43 | end | 43 | end |
test/unit/proposals_discussion_plugin_test.rb
@@ -20,26 +20,54 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | @@ -20,26 +20,54 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | ||
20 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion | 20 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion |
21 | end | 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 | parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) | 29 | parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) |
25 | @params[:parent_id] = parent.id | 30 | @params[:parent_id] = parent.id |
26 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic | 31 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic |
27 | end | 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 | parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id) | 42 | parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id) |
31 | @params[:parent_id] = parent.id | 43 | @params[:parent_id] = parent.id |
32 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | 44 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
33 | end | 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 | parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false) | 55 | parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false) |
37 | @params[:parent_id] = parent.id | 56 | @params[:parent_id] = parent.id |
38 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | 57 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
39 | end | 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 | @params[:parent_id] = nil | 68 | @params[:parent_id] = nil |
69 | + @params[:article] = {} | ||
70 | + @params[:article][:parent_id] = nil | ||
43 | assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | 71 | assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
44 | end | 72 | end |
45 | 73 |
views/cms/proposals_discussion_plugin/_proposal.html.erb
@@ -23,6 +23,8 @@ | @@ -23,6 +23,8 @@ | ||
23 | <% editor_type = 'mceEditor' %> | 23 | <% editor_type = 'mceEditor' %> |
24 | <%= labelled_form_field(strip_tags(@article.discussion.custom_body_label), text_area(:article, :body, :class => editor_type)) %> | 24 | <%= labelled_form_field(strip_tags(@article.discussion.custom_body_label), text_area(:article, :body, :class => editor_type)) %> |
25 | </div> | 25 | </div> |
26 | + | ||
27 | + <%= hidden_field(:article, :parent_id) %> | ||
26 | </div> | 28 | </div> |
27 | 29 | ||
28 | <script> | 30 | <script> |