Commit 3133df278c62e533376db76ca88020606bb28089
1 parent
4c91f481
Exists in
master
and in
28 other branches
Destroying forms when its profile is destroyed
Also added migration to remove existent forms without profile Signed-off-by: Ana Losnak <analosnak@gmail.com> (ActionItem3144)
Showing
4 changed files
with
30 additions
and
1 deletions
Show diff stats
plugins/custom_forms/db/migrate/20140619213950_remove_forms_without_profile.rb
0 → 100644
plugins/custom_forms/lib/custom_forms_plugin/form.rb
... | ... | @@ -19,7 +19,7 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
19 | 19 | end |
20 | 20 | |
21 | 21 | after_destroy do |form| |
22 | - tasks = CustomFormsPlugin::MembershipSurvey.from(form.profile).opened.select { |t| t.form_id == form.id } | |
22 | + tasks = CustomFormsPlugin::MembershipSurvey.opened.select { |t| t.form_id == form.id } | |
23 | 23 | tasks.each {|task| task.cancel} |
24 | 24 | end |
25 | 25 | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
... | ... | @@ -274,4 +274,15 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
274 | 274 | s2.reload |
275 | 275 | end |
276 | 276 | end |
277 | + | |
278 | + should 'destroy forms after profile is destroyed' do | |
279 | + profile = fast_create(Profile) | |
280 | + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') | |
281 | + profile.destroy | |
282 | + | |
283 | + assert_raise ActiveRecord::RecordNotFound do | |
284 | + CustomFormsPlugin::Form.find(form.id) | |
285 | + end | |
286 | + end | |
287 | + | |
277 | 288 | end | ... | ... |