Commit f11c3f21347479d59bda2af52338d785d1bbaf66
1 parent
e69c983e
Exists in
master
and in
29 other branches
Keeping form after removing a field on CustomFormPlugin
Also destroying fields after removing a form (ActionItem2601)
Showing
4 changed files
with
24 additions
and
2 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/field.rb
| ... | ... | @@ -4,7 +4,7 @@ class CustomFormsPlugin::Field < ActiveRecord::Base |
| 4 | 4 | validates_presence_of :form, :name |
| 5 | 5 | validates_uniqueness_of :slug, :scope => :form_id |
| 6 | 6 | |
| 7 | - belongs_to :form, :class_name => 'CustomFormsPlugin::Form', :dependent => :destroy | |
| 7 | + belongs_to :form, :class_name => 'CustomFormsPlugin::Form' | |
| 8 | 8 | has_many :answers, :class_name => 'CustomFormsPlugin::Answer' |
| 9 | 9 | |
| 10 | 10 | serialize :choices, Hash | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/form.rb
| 1 | 1 | class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
| 2 | 2 | belongs_to :profile |
| 3 | 3 | |
| 4 | - has_many :fields, :class_name => 'CustomFormsPlugin::Field' | |
| 4 | + has_many :fields, :class_name => 'CustomFormsPlugin::Field', :dependent => :destroy | |
| 5 | 5 | has_many :submissions, :class_name => 'CustomFormsPlugin::Submission' |
| 6 | 6 | |
| 7 | 7 | serialize :access | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb
| ... | ... | @@ -60,5 +60,16 @@ class CustomFormsPlugin::FieldTest < ActiveSupport::TestCase |
| 60 | 60 | assert_equal 2, field.choices['Second'] |
| 61 | 61 | assert_equal 3, field.choices['Third'] |
| 62 | 62 | end |
| 63 | + | |
| 64 | + should 'not destroy form after removing a field' do | |
| 65 | + form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) | |
| 66 | + license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) | |
| 67 | + url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) | |
| 68 | + | |
| 69 | + assert_no_difference CustomFormsPlugin::Form, :count do | |
| 70 | + url_field.destroy | |
| 71 | + end | |
| 72 | + assert_equal form.fields, [license_field] | |
| 73 | + end | |
| 63 | 74 | end |
| 64 | 75 | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
| ... | ... | @@ -169,4 +169,15 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
| 169 | 169 | assert_includes scope, f2 |
| 170 | 170 | assert_not_includes scope, f3 |
| 171 | 171 | end |
| 172 | + | |
| 173 | + should 'destroy fields after removing a form' do | |
| 174 | + form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) | |
| 175 | + license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) | |
| 176 | + url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) | |
| 177 | + | |
| 178 | + assert_difference CustomFormsPlugin::Field, :count, -2 do | |
| 179 | + form.destroy | |
| 180 | + end | |
| 181 | + end | |
| 182 | + | |
| 172 | 183 | end | ... | ... |