From 642c42c17697966191a276504ace873ff2d3362f Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 21 Dec 2015 10:50:19 -0300 Subject: [PATCH] Inherit categories from parent when save a proposal --- lib/proposals_discussion_plugin/proposal.rb | 7 +++++++ test/unit/proposal_task_test.rb | 8 ++++++++ test/unit/proposal_test.rb | 9 +++++++++ 3 files changed, 24 insertions(+), 0 deletions(-) diff --git a/lib/proposals_discussion_plugin/proposal.rb b/lib/proposals_discussion_plugin/proposal.rb index eaaa58a..0ce6182 100644 --- a/lib/proposals_discussion_plugin/proposal.rb +++ b/lib/proposals_discussion_plugin/proposal.rb @@ -9,6 +9,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle has_one :ranking_item + after_save :inherit_parent_categories + def self.short_description _("Proposal") end @@ -69,4 +71,9 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle false end + def inherit_parent_categories + return if parent.nil? + categories << parent.categories + end + end diff --git a/test/unit/proposal_task_test.rb b/test/unit/proposal_task_test.rb index fe9606b..7546691 100644 --- a/test/unit/proposal_task_test.rb +++ b/test/unit/proposal_task_test.rb @@ -83,4 +83,12 @@ class ProposalTaskTest < ActiveSupport::TestCase assert task.information.present? end + should 'create a proposal with category when accept a task' do + c1 = fast_create(Category) + discussion.categories << c1 + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article_parent_id => @discussion.id, :article => {:name => 'proposal 1', :abstract => 'proposal 1', :type => "ProposalsDiscussionPlugin::Proposal"}) + task.perform + assert_equal [c1], ProposalsDiscussionPlugin::Proposal.last.categories + end + end diff --git a/test/unit/proposal_test.rb b/test/unit/proposal_test.rb index 3491874..222928b 100644 --- a/test/unit/proposal_test.rb +++ b/test/unit/proposal_test.rb @@ -172,4 +172,13 @@ class ProposalTest < ActiveSupport::TestCase assert_match "Parent of Response needs be a Proposal", err.message end + should 'inherit categories from parent when save' do + c1 = fast_create(Category) + c2 = fast_create(Category) + proposal.categories << c1 + discussion.categories << c2 + proposal.save! + assert_equivalent [c1, c2], proposal.categories + end + end -- libgit2 0.21.2