Commit 21a9339081c9f7fe9c4e271bccab808ab50e2f96
1 parent
067cda04
Exists in
master
and in
7 other branches
should not crash if em empty parent is passed as parameter
Showing
2 changed files
with
6 additions
and
1 deletions
Show diff stats
lib/proposals_discussion_plugin.rb
... | ... | @@ -16,7 +16,7 @@ class ProposalsDiscussionPlugin < Noosfero::Plugin |
16 | 16 | if context.respond_to?(:params) && context.params.kind_of?(Hash) && context.params[:controller] == 'cms' && context.params[:action] == 'new' |
17 | 17 | types = [] |
18 | 18 | parent_id = context.params[:parent_id] || (context.params[:article][:parent_id] unless context.params[:article].nil?) |
19 | - parent = parent_id ? context.profile.articles.find(parent_id) : 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/proposals_discussion_plugin_test.rb
... | ... | @@ -20,6 +20,11 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase |
20 | 20 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion |
21 | 21 | end |
22 | 22 | |
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 | + | |
23 | 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 | ... | ... |