Commit 642c42c17697966191a276504ace873ff2d3362f
1 parent
42299045
Exists in
master
and in
3 other branches
Inherit categories from parent when save a proposal
Showing
3 changed files
with
24 additions
and
0 deletions
Show diff stats
lib/proposals_discussion_plugin/proposal.rb
@@ -9,6 +9,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | @@ -9,6 +9,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | ||
9 | 9 | ||
10 | has_one :ranking_item | 10 | has_one :ranking_item |
11 | 11 | ||
12 | + after_save :inherit_parent_categories | ||
13 | + | ||
12 | def self.short_description | 14 | def self.short_description |
13 | _("Proposal") | 15 | _("Proposal") |
14 | end | 16 | end |
@@ -69,4 +71,9 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | @@ -69,4 +71,9 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | ||
69 | false | 71 | false |
70 | end | 72 | end |
71 | 73 | ||
74 | + def inherit_parent_categories | ||
75 | + return if parent.nil? | ||
76 | + categories << parent.categories | ||
77 | + end | ||
78 | + | ||
72 | end | 79 | end |
test/unit/proposal_task_test.rb
@@ -83,4 +83,12 @@ class ProposalTaskTest < ActiveSupport::TestCase | @@ -83,4 +83,12 @@ class ProposalTaskTest < ActiveSupport::TestCase | ||
83 | assert task.information.present? | 83 | assert task.information.present? |
84 | end | 84 | end |
85 | 85 | ||
86 | + should 'create a proposal with category when accept a task' do | ||
87 | + c1 = fast_create(Category) | ||
88 | + discussion.categories << c1 | ||
89 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article_parent_id => @discussion.id, :article => {:name => 'proposal 1', :abstract => 'proposal 1', :type => "ProposalsDiscussionPlugin::Proposal"}) | ||
90 | + task.perform | ||
91 | + assert_equal [c1], ProposalsDiscussionPlugin::Proposal.last.categories | ||
92 | + end | ||
93 | + | ||
86 | end | 94 | end |
test/unit/proposal_test.rb
@@ -172,4 +172,13 @@ class ProposalTest < ActiveSupport::TestCase | @@ -172,4 +172,13 @@ class ProposalTest < ActiveSupport::TestCase | ||
172 | assert_match "Parent of Response needs be a Proposal", err.message | 172 | assert_match "Parent of Response needs be a Proposal", err.message |
173 | end | 173 | end |
174 | 174 | ||
175 | + should 'inherit categories from parent when save' do | ||
176 | + c1 = fast_create(Category) | ||
177 | + c2 = fast_create(Category) | ||
178 | + proposal.categories << c1 | ||
179 | + discussion.categories << c2 | ||
180 | + proposal.save! | ||
181 | + assert_equivalent [c1, c2], proposal.categories | ||
182 | + end | ||
183 | + | ||
175 | end | 184 | end |