Commit 8d3bc89247caf944faeee7ef7d6b6d50dfd4142c
1 parent
49fc73d7
Exists in
staging
and in
42 other branches
Cancels survey tasks after removing a form
Showing
2 changed files
with
24 additions
and
0 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/form.rb
... | ... | @@ -17,6 +17,11 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
17 | 17 | form.access = nil if form.access.blank? |
18 | 18 | end |
19 | 19 | |
20 | + after_destroy do |form| | |
21 | + tasks = CustomFormsPlugin::MembershipSurvey.from(form.profile).opened.select { |t| t.form_id == form.id } | |
22 | + tasks.each {|task| task.cancel} | |
23 | + end | |
24 | + | |
20 | 25 | named_scope :from, lambda {|profile| {:conditions => {:profile_id => profile.id}}} |
21 | 26 | named_scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}} |
22 | 27 | named_scope :for_admissions, {:conditions => {:for_admission => true}} | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
... | ... | @@ -211,4 +211,23 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
211 | 211 | assert_includes scope, f1 |
212 | 212 | assert_not_includes scope, f2 |
213 | 213 | end |
214 | + | |
215 | + should 'cancel survey tasks after removing a form' do | |
216 | + profile = fast_create(Profile) | |
217 | + person = fast_create(Person) | |
218 | + | |
219 | + form1 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => profile) | |
220 | + form2 = CustomFormsPlugin::Form.create!(:name => 'Operation System', :profile => profile) | |
221 | + | |
222 | + task1 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form1.id, :target => person, :requestor => profile) | |
223 | + task2 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form2.id, :target => person, :requestor => profile) | |
224 | + | |
225 | + assert_includes Task.opened, task1 | |
226 | + assert_includes Task.opened, task2 | |
227 | + form1.destroy | |
228 | + assert_includes Task.canceled, task1 | |
229 | + assert_includes Task.opened, task2 | |
230 | + form2.destroy | |
231 | + assert_includes Task.canceled, task2 | |
232 | + end | |
214 | 233 | end | ... | ... |