Commit b4badb69daceb445d025ec9805dc96f2c9f9c30f
1 parent
562fa646
Exists in
master
and in
28 other branches
Validates there is at least one alternative
Showing
2 changed files
with
11 additions
and
0 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/select_field.rb
@@ -3,4 +3,6 @@ class CustomFormsPlugin::SelectField < CustomFormsPlugin::Field | @@ -3,4 +3,6 @@ class CustomFormsPlugin::SelectField < CustomFormsPlugin::Field | ||
3 | 3 | ||
4 | validates_length_of :select_field_type, :minimum => 1, :allow_nil => false | 4 | validates_length_of :select_field_type, :minimum => 1, :allow_nil => false |
5 | validates_inclusion_of :select_field_type, :in => %w(radio check_box select multiple_select) | 5 | validates_inclusion_of :select_field_type, :in => %w(radio check_box select multiple_select) |
6 | + | ||
7 | + validates_length_of :alternatives, :minimum => 1 | ||
6 | end | 8 | end |
plugins/custom_forms/test/unit/custom_forms_plugin/select_field_test.rb
1 | require File.dirname(__FILE__) + '/../../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../../test/test_helper' |
2 | 2 | ||
3 | class CustomFormsPlugin::SelectFieldTest < ActiveSupport::TestCase | 3 | class CustomFormsPlugin::SelectFieldTest < ActiveSupport::TestCase |
4 | + should 'have alternative' do | ||
5 | + select = CustomFormsPlugin::SelectField.new(:name => 'select_field001' ) | ||
6 | + assert !select.save | ||
7 | + | ||
8 | + select.alternatives << CustomFormsPlugin::Alternative.new(:label => 'option') | ||
9 | + assert select.save | ||
10 | + end | ||
11 | + | ||
4 | should 'validate type' do | 12 | should 'validate type' do |
5 | select = CustomFormsPlugin::SelectField.new(:name => 'select_field001' ) | 13 | select = CustomFormsPlugin::SelectField.new(:name => 'select_field001' ) |
14 | + select.alternatives << CustomFormsPlugin::Alternative.new(:label => 'option') | ||
6 | 15 | ||
7 | select.update_attribute(:select_field_type, 'random') | 16 | select.update_attribute(:select_field_type, 'random') |
8 | assert select.invalid? | 17 | assert select.invalid? |