bureaucrat 0.0.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +120 -105
 - data/Rakefile +9 -0
 - data/bureaucrat.gemspec +32 -0
 - data/lib/bureaucrat.rb +26 -8
 - data/lib/bureaucrat/fields.rb +572 -336
 - data/lib/bureaucrat/forms.rb +296 -257
 - data/lib/bureaucrat/formsets.rb +235 -194
 - data/lib/bureaucrat/quickfields.rb +90 -62
 - data/lib/bureaucrat/temporary_uploaded_file.rb +14 -0
 - data/lib/bureaucrat/utils.rb +79 -62
 - data/lib/bureaucrat/validators.rb +163 -0
 - data/lib/bureaucrat/widgets.rb +459 -303
 - data/test/fields_test.rb +519 -380
 - data/test/forms_test.rb +78 -58
 - data/test/formsets_test.rb +48 -22
 - data/test/test_helper.rb +20 -12
 - data/test/widgets_test.rb +224 -204
 - metadata +27 -36
 - data/lib/bureaucrat/validation.rb +0 -130
 - data/lib/bureaucrat/validation_old.rb +0 -148
 - data/lib/bureaucrat/wizard.rb +0 -220
 
    
        data/test/fields_test.rb
    CHANGED
    
    | 
         @@ -1,577 +1,716 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
       6 
     | 
    
         
            -
                   
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                  end
         
     | 
| 
      
 3 
     | 
    
         
            +
            module FieldTests
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Test_with_empty_options < BureaucratTestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @field = Fields::Field.new
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                    end
         
     | 
| 
      
 9 
     | 
    
         
            +
                def test_be_required
         
     | 
| 
      
 10 
     | 
    
         
            +
                  blank_value = ''
         
     | 
| 
      
 11 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @field.clean(blank_value)
         
     | 
| 
       15 
13 
     | 
    
         
             
                  end
         
     | 
| 
       16 
14 
     | 
    
         
             
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              class Test_with_required_as_false < BureaucratTestCase
         
     | 
| 
      
 18 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @field = Fields::Field.new(required: false)
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
       22 
21 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                def test_not_be_required
         
     | 
| 
      
 23 
     | 
    
         
            +
                  blank_value = ''
         
     | 
| 
      
 24 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @field.clean(blank_value)
         
     | 
| 
       28 
26 
     | 
    
         
             
                  end
         
     | 
| 
       29 
27 
     | 
    
         
             
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
       30 
29 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 31 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @field = Fields::Field.new
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
       35 
34 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
                def test_return_the_original_value_if_valid
         
     | 
| 
      
 36 
     | 
    
         
            +
                  value = 'test'
         
     | 
| 
      
 37 
     | 
    
         
            +
                  assert_equal(value, @field.clean(value))
         
     | 
| 
       40 
38 
     | 
    
         
             
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
       41 
40 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
              class Test_when_copied < BureaucratTestCase
         
     | 
| 
      
 42 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @field = Fields::Field.new(initial: 'initial',
         
     | 
| 
      
 44 
     | 
    
         
            +
                                             label: 'label')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @field_copy = @field.dup
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
       48 
47 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                def test_have_its_own_copy_of_initial_value
         
     | 
| 
      
 49 
     | 
    
         
            +
                  assert_not_equal(@field.initial.object_id, @field_copy.initial.object_id)
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
       52 
51 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                def test_have_its_own_copy_of_the_label
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_not_equal(@field.label.object_id, @field_copy.label.object_id)
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
       56 
55 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                def test_have_its_own_copy_of_the_widget
         
     | 
| 
      
 57 
     | 
    
         
            +
                  assert_not_equal(@field.widget.object_id, @field_copy.widget.object_id)
         
     | 
| 
       60 
58 
     | 
    
         
             
                end
         
     | 
| 
       61 
     | 
    
         
            -
              end
         
     | 
| 
       62 
59 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                    @field = Fields::CharField.new
         
     | 
| 
       67 
     | 
    
         
            -
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
                def test_have_its_own_copy_of_validators
         
     | 
| 
      
 61 
     | 
    
         
            +
                  assert_not_equal(@field.validators.object_id, @field_copy.validators.object_id)
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
       68 
63 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                def test_have_its_own_copy_of_the_error_messaes
         
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_not_equal(@field.error_messages.object_id, @field_copy.error_messages.object_id)
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     | 
| 
       74 
69 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
            module CharFieldTests
         
     | 
| 
      
 71 
     | 
    
         
            +
              class Test_with_empty_options < BureaucratTestCase
         
     | 
| 
      
 72 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @field = Fields::CharField.new
         
     | 
| 
       80 
74 
     | 
    
         
             
                end
         
     | 
| 
       81 
75 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
                 
     | 
| 
       83 
     | 
    
         
            -
                   
     | 
| 
       84 
     | 
    
         
            -
                    @field 
     | 
| 
      
 76 
     | 
    
         
            +
                def test_not_validate_max_length
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 78 
     | 
    
         
            +
                    @field.clean("string" * 1000)
         
     | 
| 
       85 
79 
     | 
    
         
             
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
       86 
81 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                    end
         
     | 
| 
      
 82 
     | 
    
         
            +
                def test_not_validate_min_length
         
     | 
| 
      
 83 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 84 
     | 
    
         
            +
                    @field.clean("1")
         
     | 
| 
       91 
85 
     | 
    
         
             
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
       92 
88 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                    end
         
     | 
| 
       97 
     | 
    
         
            -
                  end
         
     | 
| 
      
 89 
     | 
    
         
            +
              class Test_with_max_length < BureaucratTestCase
         
     | 
| 
      
 90 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 91 
     | 
    
         
            +
                  @field = Fields::CharField.new(max_length: 10)
         
     | 
| 
       98 
92 
     | 
    
         
             
                end
         
     | 
| 
       99 
93 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
                 
     | 
| 
       101 
     | 
    
         
            -
                   
     | 
| 
       102 
     | 
    
         
            -
                    @field 
     | 
| 
      
 94 
     | 
    
         
            +
                def test_allow_values_with_length_less_than_or_equal_to_max_length
         
     | 
| 
      
 95 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 96 
     | 
    
         
            +
                    @field.clean('a' * 10)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    @field.clean('a' * 5)
         
     | 
| 
       103 
98 
     | 
    
         
             
                  end
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
       104 
100 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                    end
         
     | 
| 
      
 101 
     | 
    
         
            +
                def test_not_allow_values_with_length_greater_than_max_length
         
     | 
| 
      
 102 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 103 
     | 
    
         
            +
                    @field.clean('a' * 11)
         
     | 
| 
       109 
104 
     | 
    
         
             
                  end
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
              end
         
     | 
| 
       110 
107 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                    end
         
     | 
| 
       115 
     | 
    
         
            -
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
              class Test_with_min_length < BureaucratTestCase
         
     | 
| 
      
 109 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 110 
     | 
    
         
            +
                  @field = Fields::CharField.new(min_length: 10)
         
     | 
| 
       116 
111 
     | 
    
         
             
                end
         
     | 
| 
       117 
112 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
                 
     | 
| 
       119 
     | 
    
         
            -
                   
     | 
| 
       120 
     | 
    
         
            -
                    @field  
     | 
| 
      
 113 
     | 
    
         
            +
                def test_allow_values_with_length_greater_or_equal_to_min_length
         
     | 
| 
      
 114 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 115 
     | 
    
         
            +
                    @field.clean('a' * 10)
         
     | 
| 
      
 116 
     | 
    
         
            +
                    @field.clean('a' * 20)
         
     | 
| 
       121 
117 
     | 
    
         
             
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
       122 
119 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                     
     | 
| 
      
 120 
     | 
    
         
            +
                def test_not_allow_values_with_length_less_than_min_length
         
     | 
| 
      
 121 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 122 
     | 
    
         
            +
                    @field.clean('a' * 9)
         
     | 
| 
       126 
123 
     | 
    
         
             
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
       127 
126 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 128 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 129 
     | 
    
         
            +
                  @field = Fields::CharField.new
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
       133 
131 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                    assert_equal('', @field.clean(empty_value))
         
     | 
| 
       138 
     | 
    
         
            -
                  end
         
     | 
| 
      
 132 
     | 
    
         
            +
                def test_return_the_original_value_if_valid
         
     | 
| 
      
 133 
     | 
    
         
            +
                  valid_value = 'test'
         
     | 
| 
      
 134 
     | 
    
         
            +
                  assert_equal(valid_value, @field.clean(valid_value))
         
     | 
| 
       139 
135 
     | 
    
         
             
                end
         
     | 
| 
       140 
136 
     | 
    
         | 
| 
      
 137 
     | 
    
         
            +
                def test_return_a_blank_string_if_value_is_nil_and_required_is_false
         
     | 
| 
      
 138 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 139 
     | 
    
         
            +
                  nil_value = nil
         
     | 
| 
      
 140 
     | 
    
         
            +
                  assert_equal('', @field.clean(nil_value))
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                def test_return_a_blank_string_if_value_is_empty_and_required_is_false
         
     | 
| 
      
 144 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 145 
     | 
    
         
            +
                  empty_value = ''
         
     | 
| 
      
 146 
     | 
    
         
            +
                  assert_equal('', @field.clean(empty_value))
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
       141 
148 
     | 
    
         
             
              end
         
     | 
| 
       142 
149 
     | 
    
         | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
                describe 'with max value of 10' do
         
     | 
| 
       145 
     | 
    
         
            -
                  setup do
         
     | 
| 
       146 
     | 
    
         
            -
                    @field = Fields::IntegerField.new(:max_value => 10)
         
     | 
| 
       147 
     | 
    
         
            -
                  end
         
     | 
| 
      
 150 
     | 
    
         
            +
            end
         
     | 
| 
       148 
151 
     | 
    
         | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
      
 152 
     | 
    
         
            +
            module IntegerFieldTests
         
     | 
| 
      
 153 
     | 
    
         
            +
              class Test_with_max_value < BureaucratTestCase
         
     | 
| 
      
 154 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 155 
     | 
    
         
            +
                  @field = Fields::IntegerField.new(max_value: 10)
         
     | 
| 
      
 156 
     | 
    
         
            +
                end
         
     | 
| 
       154 
157 
     | 
    
         | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
                     
     | 
| 
      
 158 
     | 
    
         
            +
                def test_allow_values_less_or_equal_to_max_value
         
     | 
| 
      
 159 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 160 
     | 
    
         
            +
                    @field.clean('10')
         
     | 
| 
      
 161 
     | 
    
         
            +
                    @field.clean('4')
         
     | 
| 
       159 
162 
     | 
    
         
             
                  end
         
     | 
| 
       160 
163 
     | 
    
         
             
                end
         
     | 
| 
       161 
164 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
                 
     | 
| 
       163 
     | 
    
         
            -
                   
     | 
| 
       164 
     | 
    
         
            -
                    @field 
     | 
| 
      
 165 
     | 
    
         
            +
                def test_not_allow_values_greater_than_max_value
         
     | 
| 
      
 166 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 167 
     | 
    
         
            +
                    @field.clean('11')
         
     | 
| 
       165 
168 
     | 
    
         
             
                  end
         
     | 
| 
      
 169 
     | 
    
         
            +
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
              end
         
     | 
| 
       166 
171 
     | 
    
         | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
                  end
         
     | 
| 
      
 172 
     | 
    
         
            +
              class Test_with_min_value < BureaucratTestCase
         
     | 
| 
      
 173 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 174 
     | 
    
         
            +
                  @field = Fields::IntegerField.new(min_value: 10)
         
     | 
| 
      
 175 
     | 
    
         
            +
                end
         
     | 
| 
       172 
176 
     | 
    
         | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
                     
     | 
| 
      
 177 
     | 
    
         
            +
                def test_allow_values_greater_or_equal_to_min_value
         
     | 
| 
      
 178 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 179 
     | 
    
         
            +
                    @field.clean('10')
         
     | 
| 
      
 180 
     | 
    
         
            +
                    @field.clean('20')
         
     | 
| 
       177 
181 
     | 
    
         
             
                  end
         
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
182 
     | 
    
         
             
                end
         
     | 
| 
       180 
183 
     | 
    
         | 
| 
       181 
     | 
    
         
            -
                 
     | 
| 
       182 
     | 
    
         
            -
                   
     | 
| 
       183 
     | 
    
         
            -
                    @field 
     | 
| 
      
 184 
     | 
    
         
            +
                def test_not_allow_values_less_than_min_value
         
     | 
| 
      
 185 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 186 
     | 
    
         
            +
                    @field.clean('9')
         
     | 
| 
       184 
187 
     | 
    
         
             
                  end
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
       185 
189 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
                    valid_value = '123'
         
     | 
| 
       188 
     | 
    
         
            -
                    assert_equal(123, @field.clean(valid_value))
         
     | 
| 
       189 
     | 
    
         
            -
                  end
         
     | 
| 
      
 190 
     | 
    
         
            +
              end
         
     | 
| 
       190 
191 
     | 
    
         | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
      
 192 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 193 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 194 
     | 
    
         
            +
                  @field = Fields::IntegerField.new
         
     | 
| 
      
 195 
     | 
    
         
            +
                end
         
     | 
| 
       195 
196 
     | 
    
         | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
                def test_return_an_integer_if_valid
         
     | 
| 
      
 198 
     | 
    
         
            +
                  valid_value = '123'
         
     | 
| 
      
 199 
     | 
    
         
            +
                  assert_equal(123, @field.clean(valid_value))
         
     | 
| 
      
 200 
     | 
    
         
            +
                end
         
     | 
| 
       201 
201 
     | 
    
         | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 202 
     | 
    
         
            +
                def test_return_nil_if_value_is_nil_and_required_is_false
         
     | 
| 
      
 203 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 204 
     | 
    
         
            +
                  assert_nil(@field.clean(nil))
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
       206 
206 
     | 
    
         | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
                  end
         
     | 
| 
      
 207 
     | 
    
         
            +
                def test_return_nil_if_value_is_empty_and_required_is_false
         
     | 
| 
      
 208 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 209 
     | 
    
         
            +
                  empty_value = ''
         
     | 
| 
      
 210 
     | 
    
         
            +
                  assert_nil(@field.clean(empty_value))
         
     | 
| 
      
 211 
     | 
    
         
            +
                end
         
     | 
| 
       213 
212 
     | 
    
         | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
      
 213 
     | 
    
         
            +
                def test_not_validate_invalid_formats
         
     | 
| 
      
 214 
     | 
    
         
            +
                  invalid_formats = ['a', 'hello', '23eeee', '.', 'hi323',
         
     | 
| 
      
 215 
     | 
    
         
            +
                                     'joe@example.com', '___3232___323',
         
     | 
| 
      
 216 
     | 
    
         
            +
                                     '123.0', '123..4']
         
     | 
| 
       216 
217 
     | 
    
         | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
                      end
         
     | 
| 
      
 218 
     | 
    
         
            +
                  invalid_formats.each do |invalid|
         
     | 
| 
      
 219 
     | 
    
         
            +
                    assert_raises(ValidationError) do
         
     | 
| 
      
 220 
     | 
    
         
            +
                      @field.clean(invalid)
         
     | 
| 
       221 
221 
     | 
    
         
             
                    end
         
     | 
| 
       222 
222 
     | 
    
         
             
                  end
         
     | 
| 
      
 223 
     | 
    
         
            +
                end
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
                def test_validate_valid_formats
         
     | 
| 
      
 226 
     | 
    
         
            +
                  valid_formats = ['3', '100', '-100', '0', '-0']
         
     | 
| 
       223 
227 
     | 
    
         | 
| 
       224 
     | 
    
         
            -
                   
     | 
| 
       225 
     | 
    
         
            -
                     
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
      
 228 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 229 
     | 
    
         
            +
                    valid_formats.each do |valid|
         
     | 
| 
      
 230 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
      
 231 
     | 
    
         
            +
                    end
         
     | 
| 
       227 
232 
     | 
    
         
             
                  end
         
     | 
| 
       228 
233 
     | 
    
         
             
                end
         
     | 
| 
       229 
234 
     | 
    
         | 
| 
      
 235 
     | 
    
         
            +
                def test_return_an_instance_of_Integer_if_valid
         
     | 
| 
      
 236 
     | 
    
         
            +
                  result = @field.clean('7')
         
     | 
| 
      
 237 
     | 
    
         
            +
                  assert_kind_of(Integer, result)
         
     | 
| 
      
 238 
     | 
    
         
            +
                end
         
     | 
| 
       230 
239 
     | 
    
         
             
              end
         
     | 
| 
       231 
240 
     | 
    
         | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
                describe 'with max value of 10.5' do
         
     | 
| 
       234 
     | 
    
         
            -
                  setup do
         
     | 
| 
       235 
     | 
    
         
            -
                    @field = Fields::FloatField.new(:max_value => 10.5)
         
     | 
| 
       236 
     | 
    
         
            -
                  end
         
     | 
| 
      
 241 
     | 
    
         
            +
            end
         
     | 
| 
       237 
242 
     | 
    
         | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
             
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
             
     | 
| 
      
 243 
     | 
    
         
            +
            module FloatFieldTests
         
     | 
| 
      
 244 
     | 
    
         
            +
              class Test_with_max_value < BureaucratTestCase
         
     | 
| 
      
 245 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 246 
     | 
    
         
            +
                  @field = Fields::FloatField.new(max_value: 10.5)
         
     | 
| 
      
 247 
     | 
    
         
            +
                end
         
     | 
| 
       243 
248 
     | 
    
         | 
| 
       244 
     | 
    
         
            -
             
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
                     
     | 
| 
      
 249 
     | 
    
         
            +
                def test_allow_values_less_or_equal_to_max_value
         
     | 
| 
      
 250 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 251 
     | 
    
         
            +
                    @field.clean('10.5')
         
     | 
| 
      
 252 
     | 
    
         
            +
                    @field.clean('5')
         
     | 
| 
       248 
253 
     | 
    
         
             
                  end
         
     | 
| 
       249 
254 
     | 
    
         
             
                end
         
     | 
| 
       250 
255 
     | 
    
         | 
| 
       251 
     | 
    
         
            -
                 
     | 
| 
       252 
     | 
    
         
            -
                   
     | 
| 
       253 
     | 
    
         
            -
                    @field 
     | 
| 
      
 256 
     | 
    
         
            +
                def test_not_allow_values_greater_than_max_value
         
     | 
| 
      
 257 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 258 
     | 
    
         
            +
                    @field.clean('10.55')
         
     | 
| 
       254 
259 
     | 
    
         
             
                  end
         
     | 
| 
      
 260 
     | 
    
         
            +
                end
         
     | 
| 
      
 261 
     | 
    
         
            +
              end
         
     | 
| 
       255 
262 
     | 
    
         | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
             
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
             
     | 
| 
       260 
     | 
    
         
            -
                  end
         
     | 
| 
      
 263 
     | 
    
         
            +
              class Test_with_min_value < BureaucratTestCase
         
     | 
| 
      
 264 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 265 
     | 
    
         
            +
                  @field = Fields::FloatField.new(min_value: 10.5)
         
     | 
| 
      
 266 
     | 
    
         
            +
                end
         
     | 
| 
       261 
267 
     | 
    
         | 
| 
       262 
     | 
    
         
            -
             
     | 
| 
       263 
     | 
    
         
            -
             
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
                     
     | 
| 
      
 268 
     | 
    
         
            +
                def test_allow_values_greater_or_equal_than_min_value
         
     | 
| 
      
 269 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 270 
     | 
    
         
            +
                    @field.clean('10.5')
         
     | 
| 
      
 271 
     | 
    
         
            +
                    @field.clean('20.5')
         
     | 
| 
       266 
272 
     | 
    
         
             
                  end
         
     | 
| 
       267 
273 
     | 
    
         
             
                end
         
     | 
| 
       268 
274 
     | 
    
         | 
| 
       269 
     | 
    
         
            -
                 
     | 
| 
       270 
     | 
    
         
            -
                   
     | 
| 
       271 
     | 
    
         
            -
                    @field 
     | 
| 
      
 275 
     | 
    
         
            +
                def test_not_allow_values_less_than_min_value
         
     | 
| 
      
 276 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 277 
     | 
    
         
            +
                    @field.clean('10.49')
         
     | 
| 
       272 
278 
     | 
    
         
             
                  end
         
     | 
| 
      
 279 
     | 
    
         
            +
                end
         
     | 
| 
      
 280 
     | 
    
         
            +
              end
         
     | 
| 
       273 
281 
     | 
    
         | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
             
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
      
 282 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 283 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 284 
     | 
    
         
            +
                  @field = Fields::FloatField.new
         
     | 
| 
      
 285 
     | 
    
         
            +
                end
         
     | 
| 
       278 
286 
     | 
    
         | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
      
 287 
     | 
    
         
            +
                def test_return_nil_if_value_is_nil_and_required_is_false
         
     | 
| 
      
 288 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 289 
     | 
    
         
            +
                  assert_nil(@field.clean(nil))
         
     | 
| 
      
 290 
     | 
    
         
            +
                end
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
                def test_return_nil_if_value_is_empty_and_required_is_false
         
     | 
| 
      
 293 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 294 
     | 
    
         
            +
                  empty_value = ''
         
     | 
| 
      
 295 
     | 
    
         
            +
                  assert_nil(@field.clean(empty_value))
         
     | 
| 
      
 296 
     | 
    
         
            +
                end
         
     | 
| 
       284 
297 
     | 
    
         | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
      
 298 
     | 
    
         
            +
                def test_not_validate_invalid_formats
         
     | 
| 
      
 299 
     | 
    
         
            +
                  invalid_formats = ['a', 'hello', '23eeee', '.', 'hi323',
         
     | 
| 
      
 300 
     | 
    
         
            +
                                     'joe@example.com', '___3232___323',
         
     | 
| 
      
 301 
     | 
    
         
            +
                                     '123..', '123..4']
         
     | 
| 
       289 
302 
     | 
    
         | 
| 
       290 
     | 
    
         
            -
             
     | 
| 
       291 
     | 
    
         
            -
             
     | 
| 
       292 
     | 
    
         
            -
             
     | 
| 
       293 
     | 
    
         
            -
                      end
         
     | 
| 
      
 303 
     | 
    
         
            +
                  invalid_formats.each do |invalid|
         
     | 
| 
      
 304 
     | 
    
         
            +
                    assert_raises(ValidationError) do
         
     | 
| 
      
 305 
     | 
    
         
            +
                      @field.clean(invalid)
         
     | 
| 
       294 
306 
     | 
    
         
             
                    end
         
     | 
| 
       295 
307 
     | 
    
         
             
                  end
         
     | 
| 
      
 308 
     | 
    
         
            +
                end
         
     | 
| 
       296 
309 
     | 
    
         | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
      
 310 
     | 
    
         
            +
                def test_validate_valid_formats
         
     | 
| 
      
 311 
     | 
    
         
            +
                  valid_formats = ['3.14', "100", "1233.", ".3333", "0.434", "0.0"]
         
     | 
| 
       299 
312 
     | 
    
         | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
       301 
     | 
    
         
            -
             
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
                      end
         
     | 
| 
      
 313 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 314 
     | 
    
         
            +
                    valid_formats.each do |valid|
         
     | 
| 
      
 315 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
       304 
316 
     | 
    
         
             
                    end
         
     | 
| 
       305 
317 
     | 
    
         
             
                  end
         
     | 
| 
      
 318 
     | 
    
         
            +
                end
         
     | 
| 
       306 
319 
     | 
    
         | 
| 
       307 
     | 
    
         
            -
             
     | 
| 
       308 
     | 
    
         
            -
             
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
                  end
         
     | 
| 
      
 320 
     | 
    
         
            +
                def test_return_an_instance_of_Float_if_valid
         
     | 
| 
      
 321 
     | 
    
         
            +
                  result = @field.clean('3.14')
         
     | 
| 
      
 322 
     | 
    
         
            +
                  assert_instance_of(Float, result)
         
     | 
| 
       311 
323 
     | 
    
         
             
                end
         
     | 
| 
       312 
324 
     | 
    
         
             
              end
         
     | 
| 
      
 325 
     | 
    
         
            +
            end
         
     | 
| 
       313 
326 
     | 
    
         | 
| 
       314 
     | 
    
         
            -
             
     | 
| 
       315 
     | 
    
         
            -
             
     | 
| 
       316 
     | 
    
         
            -
             
     | 
| 
       317 
     | 
    
         
            -
             
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
      
 327 
     | 
    
         
            +
            module BigDecimalFieldTests
         
     | 
| 
      
 328 
     | 
    
         
            +
              class Test_with_max_value < BureaucratTestCase
         
     | 
| 
      
 329 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 330 
     | 
    
         
            +
                  @field = Fields::BigDecimalField.new(max_value: 10.5)
         
     | 
| 
      
 331 
     | 
    
         
            +
                end
         
     | 
| 
       319 
332 
     | 
    
         | 
| 
       320 
     | 
    
         
            -
             
     | 
| 
       321 
     | 
    
         
            -
             
     | 
| 
       322 
     | 
    
         
            -
             
     | 
| 
       323 
     | 
    
         
            -
                     
     | 
| 
      
 333 
     | 
    
         
            +
                def test_allow_values_less_or_equal_to_max_value
         
     | 
| 
      
 334 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 335 
     | 
    
         
            +
                    @field.clean('10.5')
         
     | 
| 
      
 336 
     | 
    
         
            +
                    @field.clean('5')
         
     | 
| 
       324 
337 
     | 
    
         
             
                  end
         
     | 
| 
      
 338 
     | 
    
         
            +
                end
         
     | 
| 
       325 
339 
     | 
    
         | 
| 
       326 
     | 
    
         
            -
             
     | 
| 
       327 
     | 
    
         
            -
             
     | 
| 
       328 
     | 
    
         
            -
             
     | 
| 
       329 
     | 
    
         
            -
                    end
         
     | 
| 
      
 340 
     | 
    
         
            +
                def test_not_allow_values_greater_than_max_value
         
     | 
| 
      
 341 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 342 
     | 
    
         
            +
                    @field.clean('10.55')
         
     | 
| 
       330 
343 
     | 
    
         
             
                  end
         
     | 
| 
       331 
344 
     | 
    
         
             
                end
         
     | 
| 
      
 345 
     | 
    
         
            +
              end
         
     | 
| 
       332 
346 
     | 
    
         | 
| 
       333 
     | 
    
         
            -
             
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
             
     | 
| 
       336 
     | 
    
         
            -
             
     | 
| 
      
 347 
     | 
    
         
            +
              class Test_with_min_value < BureaucratTestCase
         
     | 
| 
      
 348 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 349 
     | 
    
         
            +
                  @field = Fields::BigDecimalField.new(min_value: 10.5)
         
     | 
| 
      
 350 
     | 
    
         
            +
                end
         
     | 
| 
       337 
351 
     | 
    
         | 
| 
       338 
     | 
    
         
            -
             
     | 
| 
       339 
     | 
    
         
            -
             
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
       341 
     | 
    
         
            -
                     
     | 
| 
      
 352 
     | 
    
         
            +
                def test_allow_values_greater_or_equal_to_min_value
         
     | 
| 
      
 353 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 354 
     | 
    
         
            +
                    @field.clean('10.5')
         
     | 
| 
      
 355 
     | 
    
         
            +
                    @field.clean('20.5')
         
     | 
| 
       342 
356 
     | 
    
         
             
                  end
         
     | 
| 
      
 357 
     | 
    
         
            +
                end
         
     | 
| 
       343 
358 
     | 
    
         | 
| 
       344 
     | 
    
         
            -
             
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
             
     | 
| 
       347 
     | 
    
         
            -
                    end
         
     | 
| 
      
 359 
     | 
    
         
            +
                def test_not_allow_values_less_than_min_value
         
     | 
| 
      
 360 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 361 
     | 
    
         
            +
                    @field.clean('10.49')
         
     | 
| 
       348 
362 
     | 
    
         
             
                  end
         
     | 
| 
       349 
363 
     | 
    
         
             
                end
         
     | 
| 
      
 364 
     | 
    
         
            +
              end
         
     | 
| 
       350 
365 
     | 
    
         | 
| 
       351 
     | 
    
         
            -
             
     | 
| 
       352 
     | 
    
         
            -
             
     | 
| 
       353 
     | 
    
         
            -
             
     | 
| 
       354 
     | 
    
         
            -
             
     | 
| 
      
 366 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 367 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 368 
     | 
    
         
            +
                  @field = Fields::BigDecimalField.new
         
     | 
| 
      
 369 
     | 
    
         
            +
                end
         
     | 
| 
       355 
370 
     | 
    
         | 
| 
       356 
     | 
    
         
            -
             
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
             
     | 
| 
       359 
     | 
    
         
            -
             
     | 
| 
      
 371 
     | 
    
         
            +
                def test_return_nil_if_value_is_nil_and_required_is_false
         
     | 
| 
      
 372 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 373 
     | 
    
         
            +
                  assert_nil(@field.clean(nil))
         
     | 
| 
      
 374 
     | 
    
         
            +
                end
         
     | 
| 
       360 
375 
     | 
    
         | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
       363 
     | 
    
         
            -
             
     | 
| 
       364 
     | 
    
         
            -
             
     | 
| 
       365 
     | 
    
         
            -
             
     | 
| 
      
 376 
     | 
    
         
            +
                def test_return_nil_if_value_is_empty_and_required_is_false
         
     | 
| 
      
 377 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 378 
     | 
    
         
            +
                  empty_value = ''
         
     | 
| 
      
 379 
     | 
    
         
            +
                  assert_nil(@field.clean(empty_value))
         
     | 
| 
      
 380 
     | 
    
         
            +
                end
         
     | 
| 
       366 
381 
     | 
    
         | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
             
     | 
| 
       369 
     | 
    
         
            -
             
     | 
| 
       370 
     | 
    
         
            -
             
     | 
| 
      
 382 
     | 
    
         
            +
                def test_not_validate_invalid_formats
         
     | 
| 
      
 383 
     | 
    
         
            +
                  invalid_formats = ['a', 'hello', '23eeee', '.', 'hi323',
         
     | 
| 
      
 384 
     | 
    
         
            +
                                     'joe@example.com', '___3232___323',
         
     | 
| 
      
 385 
     | 
    
         
            +
                                     '123..', '123..4']
         
     | 
| 
       371 
386 
     | 
    
         | 
| 
       372 
     | 
    
         
            -
             
     | 
| 
       373 
     | 
    
         
            -
             
     | 
| 
       374 
     | 
    
         
            -
             
     | 
| 
       375 
     | 
    
         
            -
                      end
         
     | 
| 
      
 387 
     | 
    
         
            +
                  invalid_formats.each do |invalid|
         
     | 
| 
      
 388 
     | 
    
         
            +
                    assert_raises(ValidationError) do
         
     | 
| 
      
 389 
     | 
    
         
            +
                      @field.clean(invalid)
         
     | 
| 
       376 
390 
     | 
    
         
             
                    end
         
     | 
| 
       377 
391 
     | 
    
         
             
                  end
         
     | 
| 
      
 392 
     | 
    
         
            +
                end
         
     | 
| 
       378 
393 
     | 
    
         | 
| 
       379 
     | 
    
         
            -
             
     | 
| 
       380 
     | 
    
         
            -
             
     | 
| 
      
 394 
     | 
    
         
            +
                def test_validate_valid_formats
         
     | 
| 
      
 395 
     | 
    
         
            +
                  valid_formats = ['3.14', "100", "1233.", ".3333", "0.434", "0.0"]
         
     | 
| 
       381 
396 
     | 
    
         | 
| 
       382 
     | 
    
         
            -
             
     | 
| 
       383 
     | 
    
         
            -
             
     | 
| 
       384 
     | 
    
         
            -
             
     | 
| 
       385 
     | 
    
         
            -
                      end
         
     | 
| 
      
 397 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 398 
     | 
    
         
            +
                    valid_formats.each do |valid|
         
     | 
| 
      
 399 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
       386 
400 
     | 
    
         
             
                    end
         
     | 
| 
       387 
401 
     | 
    
         
             
                  end
         
     | 
| 
      
 402 
     | 
    
         
            +
                end
         
     | 
| 
       388 
403 
     | 
    
         | 
| 
       389 
     | 
    
         
            -
             
     | 
| 
       390 
     | 
    
         
            -
             
     | 
| 
       391 
     | 
    
         
            -
             
     | 
| 
       392 
     | 
    
         
            -
                  end
         
     | 
| 
      
 404 
     | 
    
         
            +
                def test_return_an_instance_of_BigDecimal_if_valid
         
     | 
| 
      
 405 
     | 
    
         
            +
                  result = @field.clean('3.14')
         
     | 
| 
      
 406 
     | 
    
         
            +
                  assert_instance_of(BigDecimal, result)
         
     | 
| 
       393 
407 
     | 
    
         
             
                end
         
     | 
| 
       394 
408 
     | 
    
         
             
              end
         
     | 
| 
      
 409 
     | 
    
         
            +
            end
         
     | 
| 
       395 
410 
     | 
    
         | 
| 
       396 
     | 
    
         
            -
             
     | 
| 
       397 
     | 
    
         
            -
             
     | 
| 
      
 411 
     | 
    
         
            +
            module RegexFieldTests
         
     | 
| 
      
 412 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 413 
     | 
    
         
            +
                def setup
         
     | 
| 
       398 
414 
     | 
    
         
             
                  @field = Fields::RegexField.new(/ba(na){2,}/)
         
     | 
| 
       399 
415 
     | 
    
         
             
                end
         
     | 
| 
       400 
416 
     | 
    
         | 
| 
       401 
     | 
    
         
            -
                 
     | 
| 
       402 
     | 
    
         
            -
                   
     | 
| 
       403 
     | 
    
         
            -
             
     | 
| 
       404 
     | 
    
         
            -
                     
     | 
| 
       405 
     | 
    
         
            -
                       
     | 
| 
       406 
     | 
    
         
            -
                        @field.clean(valid)
         
     | 
| 
       407 
     | 
    
         
            -
                      end
         
     | 
| 
      
 417 
     | 
    
         
            +
                def test_validate_matching_values
         
     | 
| 
      
 418 
     | 
    
         
            +
                  valid_values = ['banana', 'bananananana']
         
     | 
| 
      
 419 
     | 
    
         
            +
                  valid_values.each do |valid|
         
     | 
| 
      
 420 
     | 
    
         
            +
                    assert_nothing_raised do
         
     | 
| 
      
 421 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
       408 
422 
     | 
    
         
             
                    end
         
     | 
| 
       409 
423 
     | 
    
         
             
                  end
         
     | 
| 
      
 424 
     | 
    
         
            +
                end
         
     | 
| 
       410 
425 
     | 
    
         | 
| 
       411 
     | 
    
         
            -
             
     | 
| 
       412 
     | 
    
         
            -
             
     | 
| 
       413 
     | 
    
         
            -
             
     | 
| 
       414 
     | 
    
         
            -
             
     | 
| 
       415 
     | 
    
         
            -
             
     | 
| 
       416 
     | 
    
         
            -
                      end
         
     | 
| 
      
 426 
     | 
    
         
            +
                def test_not_validate_non_matching_values
         
     | 
| 
      
 427 
     | 
    
         
            +
                  invalid_values = ['bana', 'spoon']
         
     | 
| 
      
 428 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 429 
     | 
    
         
            +
                    invalid_values.each do |invalid|
         
     | 
| 
      
 430 
     | 
    
         
            +
                      @field.clean(invalid)
         
     | 
| 
       417 
431 
     | 
    
         
             
                    end
         
     | 
| 
       418 
432 
     | 
    
         
             
                  end
         
     | 
| 
      
 433 
     | 
    
         
            +
                end
         
     | 
| 
       419 
434 
     | 
    
         | 
| 
       420 
     | 
    
         
            -
             
     | 
| 
       421 
     | 
    
         
            -
             
     | 
| 
       422 
     | 
    
         
            -
             
     | 
| 
       423 
     | 
    
         
            -
             
     | 
| 
       424 
     | 
    
         
            -
                  end
         
     | 
| 
      
 435 
     | 
    
         
            +
                def test_return_a_blank_string_if_value_is_empty_and_required_is_false
         
     | 
| 
      
 436 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 437 
     | 
    
         
            +
                  empty_value = ''
         
     | 
| 
      
 438 
     | 
    
         
            +
                  assert_equal('', @field.clean(empty_value))
         
     | 
| 
       425 
439 
     | 
    
         
             
                end
         
     | 
| 
       426 
440 
     | 
    
         
             
              end
         
     | 
| 
      
 441 
     | 
    
         
            +
            end
         
     | 
| 
       427 
442 
     | 
    
         | 
| 
       428 
     | 
    
         
            -
             
     | 
| 
       429 
     | 
    
         
            -
             
     | 
| 
      
 443 
     | 
    
         
            +
            module EmailFieldTests
         
     | 
| 
      
 444 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 445 
     | 
    
         
            +
                def setup
         
     | 
| 
       430 
446 
     | 
    
         
             
                  @field = Fields::EmailField.new
         
     | 
| 
       431 
447 
     | 
    
         
             
                end
         
     | 
| 
       432 
448 
     | 
    
         | 
| 
       433 
     | 
    
         
            -
                 
     | 
| 
       434 
     | 
    
         
            -
                   
     | 
| 
       435 
     | 
    
         
            -
             
     | 
| 
       436 
     | 
    
         
            -
             
     | 
| 
       437 
     | 
    
         
            -
                     
     | 
| 
       438 
     | 
    
         
            -
                       
     | 
| 
       439 
     | 
    
         
            -
                        @field.clean(valid)
         
     | 
| 
       440 
     | 
    
         
            -
                      end
         
     | 
| 
      
 449 
     | 
    
         
            +
                def test_validate_email_matching_values
         
     | 
| 
      
 450 
     | 
    
         
            +
                  valid_values = ['email@domain.com', 'email+extra@domain.com',
         
     | 
| 
      
 451 
     | 
    
         
            +
                                  'email@domain.fm', 'email@domain.co.uk']
         
     | 
| 
      
 452 
     | 
    
         
            +
                  valid_values.each do |valid|
         
     | 
| 
      
 453 
     | 
    
         
            +
                    assert_nothing_raised do
         
     | 
| 
      
 454 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
       441 
455 
     | 
    
         
             
                    end
         
     | 
| 
       442 
456 
     | 
    
         
             
                  end
         
     | 
| 
      
 457 
     | 
    
         
            +
                end
         
     | 
| 
       443 
458 
     | 
    
         | 
| 
       444 
     | 
    
         
            -
             
     | 
| 
       445 
     | 
    
         
            -
             
     | 
| 
       446 
     | 
    
         
            -
             
     | 
| 
       447 
     | 
    
         
            -
             
     | 
| 
       448 
     | 
    
         
            -
             
     | 
| 
       449 
     | 
    
         
            -
             
     | 
| 
       450 
     | 
    
         
            -
             
     | 
| 
       451 
     | 
    
         
            -
                      end
         
     | 
| 
      
 459 
     | 
    
         
            +
                def test_not_validate_non_email_matching_values
         
     | 
| 
      
 460 
     | 
    
         
            +
                  invalid_values = ['banana', 'spoon', 'invalid@dom#ain.com',
         
     | 
| 
      
 461 
     | 
    
         
            +
                                    'invalid@@domain.com', 'invalid@domain',
         
     | 
| 
      
 462 
     | 
    
         
            +
                                    'invalid@.com']
         
     | 
| 
      
 463 
     | 
    
         
            +
                  invalid_values.each do |invalid|
         
     | 
| 
      
 464 
     | 
    
         
            +
                    assert_raises(ValidationError) do
         
     | 
| 
      
 465 
     | 
    
         
            +
                      @field.clean(invalid)
         
     | 
| 
       452 
466 
     | 
    
         
             
                    end
         
     | 
| 
       453 
467 
     | 
    
         
             
                  end
         
     | 
| 
       454 
468 
     | 
    
         
             
                end
         
     | 
| 
       455 
469 
     | 
    
         
             
              end
         
     | 
| 
      
 470 
     | 
    
         
            +
            end
         
     | 
| 
       456 
471 
     | 
    
         | 
| 
       457 
     | 
    
         
            -
             
     | 
| 
       458 
     | 
    
         
            -
             
     | 
| 
      
 472 
     | 
    
         
            +
            module BooleanFieldTests
         
     | 
| 
      
 473 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 474 
     | 
    
         
            +
                def setup
         
     | 
| 
       459 
475 
     | 
    
         
             
                  @true_values = [1, true, 'true', '1']
         
     | 
| 
       460 
476 
     | 
    
         
             
                  @false_values = [nil, 0, false, 'false', '0']
         
     | 
| 
       461 
477 
     | 
    
         
             
                  @field = Fields::BooleanField.new
         
     | 
| 
       462 
478 
     | 
    
         
             
                end
         
     | 
| 
       463 
479 
     | 
    
         | 
| 
       464 
     | 
    
         
            -
                 
     | 
| 
       465 
     | 
    
         
            -
                   
     | 
| 
       466 
     | 
    
         
            -
                    @ 
     | 
| 
       467 
     | 
    
         
            -
                      assert_equal(true, @field.clean(true_value))
         
     | 
| 
       468 
     | 
    
         
            -
                    end
         
     | 
| 
      
 480 
     | 
    
         
            +
                def test_return_true_for_true_values
         
     | 
| 
      
 481 
     | 
    
         
            +
                  @true_values.each do |true_value|
         
     | 
| 
      
 482 
     | 
    
         
            +
                    assert_equal(true, @field.clean(true_value))
         
     | 
| 
       469 
483 
     | 
    
         
             
                  end
         
     | 
| 
      
 484 
     | 
    
         
            +
                end
         
     | 
| 
       470 
485 
     | 
    
         | 
| 
       471 
     | 
    
         
            -
             
     | 
| 
       472 
     | 
    
         
            -
             
     | 
| 
       473 
     | 
    
         
            -
             
     | 
| 
       474 
     | 
    
         
            -
             
     | 
| 
       475 
     | 
    
         
            -
                    end
         
     | 
| 
      
 486 
     | 
    
         
            +
                def test_return_false_for_false_values
         
     | 
| 
      
 487 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 488 
     | 
    
         
            +
                  @false_values.each do |false_value|
         
     | 
| 
      
 489 
     | 
    
         
            +
                    assert_equal(false, @field.clean(false_value))
         
     | 
| 
       476 
490 
     | 
    
         
             
                  end
         
     | 
| 
      
 491 
     | 
    
         
            +
                end
         
     | 
| 
       477 
492 
     | 
    
         | 
| 
       478 
     | 
    
         
            -
             
     | 
| 
       479 
     | 
    
         
            -
             
     | 
| 
       480 
     | 
    
         
            -
             
     | 
| 
       481 
     | 
    
         
            -
             
     | 
| 
       482 
     | 
    
         
            -
                      end
         
     | 
| 
      
 493 
     | 
    
         
            +
                def test_validate_on_true_values_when_required
         
     | 
| 
      
 494 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 495 
     | 
    
         
            +
                    @true_values.each do |true_value|
         
     | 
| 
      
 496 
     | 
    
         
            +
                      @field.clean(true_value)
         
     | 
| 
       483 
497 
     | 
    
         
             
                    end
         
     | 
| 
       484 
498 
     | 
    
         
             
                  end
         
     | 
| 
      
 499 
     | 
    
         
            +
                end
         
     | 
| 
       485 
500 
     | 
    
         | 
| 
       486 
     | 
    
         
            -
             
     | 
| 
       487 
     | 
    
         
            -
             
     | 
| 
       488 
     | 
    
         
            -
             
     | 
| 
       489 
     | 
    
         
            -
             
     | 
| 
       490 
     | 
    
         
            -
                      end
         
     | 
| 
      
 501 
     | 
    
         
            +
                def test_not_validate_on_false_values_when_required
         
     | 
| 
      
 502 
     | 
    
         
            +
                  @false_values.each do |false_value|
         
     | 
| 
      
 503 
     | 
    
         
            +
                    assert_raises(ValidationError) do
         
     | 
| 
      
 504 
     | 
    
         
            +
                      @field.clean(false_value)
         
     | 
| 
       491 
505 
     | 
    
         
             
                    end
         
     | 
| 
       492 
506 
     | 
    
         
             
                  end
         
     | 
| 
      
 507 
     | 
    
         
            +
                end
         
     | 
| 
       493 
508 
     | 
    
         | 
| 
       494 
     | 
    
         
            -
             
     | 
| 
       495 
     | 
    
         
            -
             
     | 
| 
       496 
     | 
    
         
            -
             
     | 
| 
       497 
     | 
    
         
            -
             
     | 
| 
       498 
     | 
    
         
            -
             
     | 
| 
       499 
     | 
    
         
            -
                      end
         
     | 
| 
      
 509 
     | 
    
         
            +
                def test_validate_on_false_values_when_not_required
         
     | 
| 
      
 510 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 511 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 512 
     | 
    
         
            +
                    @false_values.each do |false_value|
         
     | 
| 
      
 513 
     | 
    
         
            +
                      @field.clean(false_value)
         
     | 
| 
       500 
514 
     | 
    
         
             
                    end
         
     | 
| 
       501 
515 
     | 
    
         
             
                  end
         
     | 
| 
       502 
516 
     | 
    
         
             
                end
         
     | 
| 
       503 
517 
     | 
    
         
             
              end
         
     | 
| 
      
 518 
     | 
    
         
            +
            end
         
     | 
| 
       504 
519 
     | 
    
         | 
| 
       505 
     | 
    
         
            -
             
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
      
 520 
     | 
    
         
            +
            module NullBooleanFieldTests
         
     | 
| 
      
 521 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 522 
     | 
    
         
            +
                def setup
         
     | 
| 
       507 
523 
     | 
    
         
             
                  @true_values = [true, 'true', '1']
         
     | 
| 
       508 
524 
     | 
    
         
             
                  @false_values = [false, 'false', '0']
         
     | 
| 
       509 
525 
     | 
    
         
             
                  @null_values = [nil, '', 'banana']
         
     | 
| 
       510 
526 
     | 
    
         
             
                  @field = Fields::NullBooleanField.new
         
     | 
| 
       511 
527 
     | 
    
         
             
                end
         
     | 
| 
       512 
528 
     | 
    
         | 
| 
       513 
     | 
    
         
            -
                 
     | 
| 
       514 
     | 
    
         
            -
                   
     | 
| 
       515 
     | 
    
         
            -
                    @ 
     | 
| 
       516 
     | 
    
         
            -
                      assert_equal(true, @field.clean(true_value))
         
     | 
| 
       517 
     | 
    
         
            -
                    end
         
     | 
| 
      
 529 
     | 
    
         
            +
                def test_return_true_for_true_values
         
     | 
| 
      
 530 
     | 
    
         
            +
                  @true_values.each do |true_value|
         
     | 
| 
      
 531 
     | 
    
         
            +
                    assert_equal(true, @field.clean(true_value))
         
     | 
| 
       518 
532 
     | 
    
         
             
                  end
         
     | 
| 
      
 533 
     | 
    
         
            +
                end
         
     | 
| 
       519 
534 
     | 
    
         | 
| 
       520 
     | 
    
         
            -
             
     | 
| 
       521 
     | 
    
         
            -
             
     | 
| 
       522 
     | 
    
         
            -
             
     | 
| 
       523 
     | 
    
         
            -
                    end
         
     | 
| 
      
 535 
     | 
    
         
            +
                def test_return_false_for_false_values
         
     | 
| 
      
 536 
     | 
    
         
            +
                  @false_values.each do |false_value|
         
     | 
| 
      
 537 
     | 
    
         
            +
                    assert_equal(false, @field.clean(false_value))
         
     | 
| 
       524 
538 
     | 
    
         
             
                  end
         
     | 
| 
      
 539 
     | 
    
         
            +
                end
         
     | 
| 
       525 
540 
     | 
    
         | 
| 
       526 
     | 
    
         
            -
             
     | 
| 
       527 
     | 
    
         
            -
             
     | 
| 
       528 
     | 
    
         
            -
             
     | 
| 
       529 
     | 
    
         
            -
                    end
         
     | 
| 
      
 541 
     | 
    
         
            +
                def test_return_nil_for_null_values
         
     | 
| 
      
 542 
     | 
    
         
            +
                  @null_values.each do |null_value|
         
     | 
| 
      
 543 
     | 
    
         
            +
                    assert_equal(nil, @field.clean(null_value))
         
     | 
| 
       530 
544 
     | 
    
         
             
                  end
         
     | 
| 
      
 545 
     | 
    
         
            +
                end
         
     | 
| 
       531 
546 
     | 
    
         | 
| 
       532 
     | 
    
         
            -
             
     | 
| 
       533 
     | 
    
         
            -
             
     | 
| 
       534 
     | 
    
         
            -
             
     | 
| 
       535 
     | 
    
         
            -
             
     | 
| 
       536 
     | 
    
         
            -
             
     | 
| 
       537 
     | 
    
         
            -
                      end
         
     | 
| 
      
 547 
     | 
    
         
            +
                def test_validate_on_all_values
         
     | 
| 
      
 548 
     | 
    
         
            +
                  all_values = @true_values + @false_values + @null_values
         
     | 
| 
      
 549 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 550 
     | 
    
         
            +
                    all_values.each do |value|
         
     | 
| 
      
 551 
     | 
    
         
            +
                      @field.clean(value)
         
     | 
| 
       538 
552 
     | 
    
         
             
                    end
         
     | 
| 
       539 
553 
     | 
    
         
             
                  end
         
     | 
| 
       540 
554 
     | 
    
         
             
                end
         
     | 
| 
       541 
555 
     | 
    
         
             
              end
         
     | 
| 
      
 556 
     | 
    
         
            +
            end
         
     | 
| 
       542 
557 
     | 
    
         | 
| 
       543 
     | 
    
         
            -
             
     | 
| 
       544 
     | 
    
         
            -
             
     | 
| 
      
 558 
     | 
    
         
            +
            module ChoiceFieldTests
         
     | 
| 
      
 559 
     | 
    
         
            +
              class Test_when_copied < BureaucratTestCase
         
     | 
| 
      
 560 
     | 
    
         
            +
                def setup
         
     | 
| 
       545 
561 
     | 
    
         
             
                  @choices = [['tea', 'Tea'], ['milk', 'Milk']]
         
     | 
| 
       546 
562 
     | 
    
         
             
                  @field = Fields::ChoiceField.new(@choices)
         
     | 
| 
      
 563 
     | 
    
         
            +
                  @field_copy = @field.dup
         
     | 
| 
       547 
564 
     | 
    
         
             
                end
         
     | 
| 
       548 
565 
     | 
    
         | 
| 
       549 
     | 
    
         
            -
                 
     | 
| 
       550 
     | 
    
         
            -
                   
     | 
| 
       551 
     | 
    
         
            -
             
     | 
| 
       552 
     | 
    
         
            -
             
     | 
| 
       553 
     | 
    
         
            -
             
     | 
| 
       554 
     | 
    
         
            -
             
     | 
| 
      
 566 
     | 
    
         
            +
                def test_have_its_own_copy_of_choices
         
     | 
| 
      
 567 
     | 
    
         
            +
                  assert_not_equal(@field.choices.object_id, @field_copy.choices.object_id)
         
     | 
| 
      
 568 
     | 
    
         
            +
                end
         
     | 
| 
      
 569 
     | 
    
         
            +
              end
         
     | 
| 
      
 570 
     | 
    
         
            +
             
     | 
| 
      
 571 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 572 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 573 
     | 
    
         
            +
                  @choices = [['tea', 'Tea'], ['milk', 'Milk']]
         
     | 
| 
      
 574 
     | 
    
         
            +
                  @choices_hash = [[{ value: "able" }, "able"], [{ value: "baker" }, "Baker"]]
         
     | 
| 
      
 575 
     | 
    
         
            +
                  @field = Fields::ChoiceField.new(@choices)
         
     | 
| 
      
 576 
     | 
    
         
            +
                  @field_hash = Fields::ChoiceField.new(@choices_hash)
         
     | 
| 
      
 577 
     | 
    
         
            +
                end
         
     | 
| 
      
 578 
     | 
    
         
            +
             
     | 
| 
      
 579 
     | 
    
         
            +
                def test_validate_all_values_in_choices_list
         
     | 
| 
      
 580 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 581 
     | 
    
         
            +
                    @choices.collect(&:first).each do |valid|
         
     | 
| 
      
 582 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
      
 583 
     | 
    
         
            +
                    end
         
     | 
| 
      
 584 
     | 
    
         
            +
                  end
         
     | 
| 
      
 585 
     | 
    
         
            +
                end
         
     | 
| 
      
 586 
     | 
    
         
            +
             
     | 
| 
      
 587 
     | 
    
         
            +
                def test_validate_all_values_in_a_hash_choices_list
         
     | 
| 
      
 588 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 589 
     | 
    
         
            +
                    @choices_hash.collect(&:first).each do |valid|
         
     | 
| 
      
 590 
     | 
    
         
            +
                      @field_hash.clean(valid[:value])
         
     | 
| 
      
 591 
     | 
    
         
            +
                    end
         
     | 
| 
      
 592 
     | 
    
         
            +
                  end
         
     | 
| 
      
 593 
     | 
    
         
            +
                end
         
     | 
| 
      
 594 
     | 
    
         
            +
             
     | 
| 
      
 595 
     | 
    
         
            +
                def test_not_validate_a_value_not_in_choices_list
         
     | 
| 
      
 596 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 597 
     | 
    
         
            +
                    @field.clean('not_in_choices')
         
     | 
| 
      
 598 
     | 
    
         
            +
                  end
         
     | 
| 
      
 599 
     | 
    
         
            +
                end
         
     | 
| 
      
 600 
     | 
    
         
            +
             
     | 
| 
      
 601 
     | 
    
         
            +
                def test_not_validate_a_value_not_in_a_hash_choices_list
         
     | 
| 
      
 602 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 603 
     | 
    
         
            +
                    @field_hash.clean('not_in_choices')
         
     | 
| 
      
 604 
     | 
    
         
            +
                  end
         
     | 
| 
      
 605 
     | 
    
         
            +
                end
         
     | 
| 
      
 606 
     | 
    
         
            +
             
     | 
| 
      
 607 
     | 
    
         
            +
                def test_return_the_original_value_if_valid
         
     | 
| 
      
 608 
     | 
    
         
            +
                  value = 'tea'
         
     | 
| 
      
 609 
     | 
    
         
            +
                  result = @field.clean(value)
         
     | 
| 
      
 610 
     | 
    
         
            +
                  assert_equal(value, result)
         
     | 
| 
      
 611 
     | 
    
         
            +
                end
         
     | 
| 
      
 612 
     | 
    
         
            +
             
     | 
| 
      
 613 
     | 
    
         
            +
                def test_return_the_original_value_if_valid_from_a_hash_choices_list
         
     | 
| 
      
 614 
     | 
    
         
            +
                  value = 'baker'
         
     | 
| 
      
 615 
     | 
    
         
            +
                  result = @field_hash.clean(value)
         
     | 
| 
      
 616 
     | 
    
         
            +
                  assert_equal(value, result)
         
     | 
| 
      
 617 
     | 
    
         
            +
                end
         
     | 
| 
      
 618 
     | 
    
         
            +
             
     | 
| 
      
 619 
     | 
    
         
            +
                def test_return_an_empty_string_if_value_is_empty_and_not_required
         
     | 
| 
      
 620 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 621 
     | 
    
         
            +
                  result = @field.clean('')
         
     | 
| 
      
 622 
     | 
    
         
            +
                  assert_equal('', result)
         
     | 
| 
      
 623 
     | 
    
         
            +
                end
         
     | 
| 
      
 624 
     | 
    
         
            +
             
     | 
| 
      
 625 
     | 
    
         
            +
                def test_return_an_empty_string_if_value_is_empty_and_not_required_from_a_hash_choices_list
         
     | 
| 
      
 626 
     | 
    
         
            +
                  @field_hash.required = false
         
     | 
| 
      
 627 
     | 
    
         
            +
                  result = @field_hash.clean('')
         
     | 
| 
      
 628 
     | 
    
         
            +
                  assert_equal('', result)
         
     | 
| 
      
 629 
     | 
    
         
            +
                end
         
     | 
| 
      
 630 
     | 
    
         
            +
              end
         
     | 
| 
      
 631 
     | 
    
         
            +
            end
         
     | 
| 
      
 632 
     | 
    
         
            +
             
     | 
| 
      
 633 
     | 
    
         
            +
            module TypedChoiceFieldTests
         
     | 
| 
      
 634 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 635 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 636 
     | 
    
         
            +
                  @choices = [[1, 'One'], [2, 'Two'], ['3', 'Three']]
         
     | 
| 
      
 637 
     | 
    
         
            +
                  to_int = lambda{|val| Integer(val)}
         
     | 
| 
      
 638 
     | 
    
         
            +
                  @field = Fields::TypedChoiceField.new(@choices,
         
     | 
| 
      
 639 
     | 
    
         
            +
                                                        coerce: to_int)
         
     | 
| 
      
 640 
     | 
    
         
            +
                end
         
     | 
| 
      
 641 
     | 
    
         
            +
             
     | 
| 
      
 642 
     | 
    
         
            +
                def test_validate_all_values_in_choices_list
         
     | 
| 
      
 643 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 644 
     | 
    
         
            +
                    @choices.collect(&:first).each do |valid|
         
     | 
| 
      
 645 
     | 
    
         
            +
                      @field.clean(valid)
         
     | 
| 
       555 
646 
     | 
    
         
             
                    end
         
     | 
| 
       556 
647 
     | 
    
         
             
                  end
         
     | 
| 
      
 648 
     | 
    
         
            +
                end
         
     | 
| 
      
 649 
     | 
    
         
            +
             
     | 
| 
      
 650 
     | 
    
         
            +
                def test_not_validate_a_value_not_in_choices_list
         
     | 
| 
      
 651 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 652 
     | 
    
         
            +
                    @field.clean('four')
         
     | 
| 
      
 653 
     | 
    
         
            +
                  end
         
     | 
| 
      
 654 
     | 
    
         
            +
                end
         
     | 
| 
      
 655 
     | 
    
         
            +
             
     | 
| 
      
 656 
     | 
    
         
            +
                def test_return_the_original_value_if_valid
         
     | 
| 
      
 657 
     | 
    
         
            +
                  value = 1
         
     | 
| 
      
 658 
     | 
    
         
            +
                  result = @field.clean(value)
         
     | 
| 
      
 659 
     | 
    
         
            +
                  assert_equal(value, result)
         
     | 
| 
      
 660 
     | 
    
         
            +
                end
         
     | 
| 
       557 
661 
     | 
    
         | 
| 
       558 
     | 
    
         
            -
             
     | 
| 
       559 
     | 
    
         
            -
             
     | 
| 
       560 
     | 
    
         
            -
             
     | 
| 
      
 662 
     | 
    
         
            +
                def test_return_a_coerced_version_of_the_original_value_if_valid_but_of_different_type
         
     | 
| 
      
 663 
     | 
    
         
            +
                  value = 2
         
     | 
| 
      
 664 
     | 
    
         
            +
                  result = @field.clean(value.to_s)
         
     | 
| 
      
 665 
     | 
    
         
            +
                  assert_equal(value, result)
         
     | 
| 
      
 666 
     | 
    
         
            +
                end
         
     | 
| 
      
 667 
     | 
    
         
            +
             
     | 
| 
      
 668 
     | 
    
         
            +
                def test_return_an_empty_string_if_value_is_empty_and_not_required
         
     | 
| 
      
 669 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 670 
     | 
    
         
            +
                  result = @field.clean('')
         
     | 
| 
      
 671 
     | 
    
         
            +
                  assert_equal('', result)
         
     | 
| 
      
 672 
     | 
    
         
            +
                end
         
     | 
| 
      
 673 
     | 
    
         
            +
              end
         
     | 
| 
      
 674 
     | 
    
         
            +
            end
         
     | 
| 
      
 675 
     | 
    
         
            +
             
     | 
| 
      
 676 
     | 
    
         
            +
            module MultipleChoiceFieldTests
         
     | 
| 
      
 677 
     | 
    
         
            +
              class Test_on_clean < BureaucratTestCase
         
     | 
| 
      
 678 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 679 
     | 
    
         
            +
                  @choices = [['tea', 'Tea'], ['milk', 'Milk'], ['coffee', 'Coffee']]
         
     | 
| 
      
 680 
     | 
    
         
            +
                  @field = Fields::MultipleChoiceField.new(@choices)
         
     | 
| 
      
 681 
     | 
    
         
            +
                end
         
     | 
| 
      
 682 
     | 
    
         
            +
             
     | 
| 
      
 683 
     | 
    
         
            +
                def test_validate_all_single_values_in_choices_list
         
     | 
| 
      
 684 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 685 
     | 
    
         
            +
                    @choices.collect(&:first).each do |valid|
         
     | 
| 
      
 686 
     | 
    
         
            +
                      @field.clean([valid])
         
     | 
| 
       561 
687 
     | 
    
         
             
                    end
         
     | 
| 
       562 
688 
     | 
    
         
             
                  end
         
     | 
| 
      
 689 
     | 
    
         
            +
                end
         
     | 
| 
       563 
690 
     | 
    
         | 
| 
       564 
     | 
    
         
            -
             
     | 
| 
       565 
     | 
    
         
            -
             
     | 
| 
       566 
     | 
    
         
            -
             
     | 
| 
       567 
     | 
    
         
            -
                     
     | 
| 
      
 691 
     | 
    
         
            +
                def test_validate_multiple_values
         
     | 
| 
      
 692 
     | 
    
         
            +
                  values = ['tea', 'coffee']
         
     | 
| 
      
 693 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 694 
     | 
    
         
            +
                    @field.clean(values)
         
     | 
| 
       568 
695 
     | 
    
         
             
                  end
         
     | 
| 
      
 696 
     | 
    
         
            +
                end
         
     | 
| 
       569 
697 
     | 
    
         | 
| 
       570 
     | 
    
         
            -
             
     | 
| 
       571 
     | 
    
         
            -
             
     | 
| 
       572 
     | 
    
         
            -
                     
     | 
| 
       573 
     | 
    
         
            -
                    assert_equal('', result)
         
     | 
| 
      
 698 
     | 
    
         
            +
                def test_not_validate_a_value_not_in_choices_list
         
     | 
| 
      
 699 
     | 
    
         
            +
                  assert_raises(ValidationError) do
         
     | 
| 
      
 700 
     | 
    
         
            +
                    @field.clean(['tea', 'not_in_choices'])
         
     | 
| 
       574 
701 
     | 
    
         
             
                  end
         
     | 
| 
       575 
702 
     | 
    
         
             
                end
         
     | 
| 
      
 703 
     | 
    
         
            +
             
     | 
| 
      
 704 
     | 
    
         
            +
                def test_return_the_original_value_if_valid
         
     | 
| 
      
 705 
     | 
    
         
            +
                  value = 'tea'
         
     | 
| 
      
 706 
     | 
    
         
            +
                  result = @field.clean([value])
         
     | 
| 
      
 707 
     | 
    
         
            +
                  assert_equal([value], result)
         
     | 
| 
      
 708 
     | 
    
         
            +
                end
         
     | 
| 
      
 709 
     | 
    
         
            +
             
     | 
| 
      
 710 
     | 
    
         
            +
                def test_return_an_empty_list_if_value_is_empty_and_not_required
         
     | 
| 
      
 711 
     | 
    
         
            +
                  @field.required = false
         
     | 
| 
      
 712 
     | 
    
         
            +
                  result = @field.clean([])
         
     | 
| 
      
 713 
     | 
    
         
            +
                  assert_equal([], result)
         
     | 
| 
      
 714 
     | 
    
         
            +
                end
         
     | 
| 
       576 
715 
     | 
    
         
             
              end
         
     | 
| 
       577 
716 
     | 
    
         
             
            end
         
     |