Commit 067cda04f5e1cf8201191563c03f28175c8b910d
1 parent
8c783480
Exists in
master
and in
7 other branches
fixing unit tests and put article[parent_id] parameter as an option
Showing
4 changed files
with
32 additions
and
7 deletions
Show diff stats
lib/proposals_discussion_plugin.rb
... | ... | @@ -15,7 +15,7 @@ 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] | |
18 | + parent_id = context.params[:parent_id] || (context.params[:article][:parent_id] unless context.params[:article].nil?) | |
19 | 19 | parent = parent_id ? context.profile.articles.find(parent_id) : nil |
20 | 20 | types << ProposalsDiscussionPlugin::Discussion |
21 | 21 | types << ProposalsDiscussionPlugin::Topic if parent.kind_of?(ProposalsDiscussionPlugin::Discussion) | ... | ... |
test/unit/discussion_test.rb
... | ... | @@ -36,8 +36,8 @@ class DiscussionTest < 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,49 @@ class ProposalsDiscussionPluginTest < 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 Topic as a content type if parent_id parameter is a Discussion' do | |
24 | 24 | parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) |
25 | 25 | @params[:parent_id] = parent.id |
26 | 26 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic |
27 | 27 | end |
28 | 28 | |
29 | - should 'return Proposal as a content type if parent is a Topic' do | |
29 | + should 'return Topic as a content type if article parent_id is a Discussion' do | |
30 | + parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) | |
31 | + @params[:article] = {} | |
32 | + @params[:article][:parent_id] = parent.id | |
33 | + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic | |
34 | + end | |
35 | + | |
36 | + should 'return Proposal as a content type if parent_id parameter is a Topic' do | |
30 | 37 | parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id) |
31 | 38 | @params[:parent_id] = parent.id |
32 | 39 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
33 | 40 | end |
34 | 41 | |
35 | - should 'return Proposal as a content type if parent is a Discussion and allow_topic is false' do | |
42 | + should 'return Proposal as a content type if article parent is a Topic' do | |
43 | + parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id) | |
44 | + @params[:article] = {} | |
45 | + @params[:article][:parent_id] = parent.id | |
46 | + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | |
47 | + end | |
48 | + | |
49 | + should 'return Proposal as a content type if parent_id parameter is a Discussion and allow_topic is false' do | |
36 | 50 | parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false) |
37 | 51 | @params[:parent_id] = parent.id |
38 | 52 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
39 | 53 | end |
40 | 54 | |
41 | - should 'do not return Proposal as a content type if parent is nil' do | |
55 | + should 'return Proposal as a content type if article parent is a Discussion and allow_topic is false' do | |
56 | + parent = ProposalsDiscussionPlugin::Discussion.create!(:profile => @profile, :name => 'discussion', :allow_topics => false) | |
57 | + @params[:article] = {} | |
58 | + @params[:article][:parent_id] = parent.id | |
59 | + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | |
60 | + end | |
61 | + | |
62 | + should 'do not return Proposal as a content type if parent and article parent is nil' do | |
42 | 63 | @params[:parent_id] = nil |
64 | + @params[:article] = {} | |
65 | + @params[:article][:parent_id] = nil | |
43 | 66 | assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
44 | 67 | end |
45 | 68 | ... | ... |
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> | ... | ... |