case_form 0.0.3
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/CHANGELOG.rdoc +1 -0
- data/MIT-LICENSE.rdoc +20 -0
- data/Manifest +86 -0
- data/README.rdoc +0 -0
- data/Rakefile +30 -0
- data/TODO.rdoc +7 -0
- data/case_form.gemspec +31 -0
- data/lib/case_form.rb +88 -0
- data/lib/case_form/associations.rb +50 -0
- data/lib/case_form/buttons.rb +175 -0
- data/lib/case_form/core_ext/form_helper.rb +54 -0
- data/lib/case_form/core_ext/layout_helper.rb +16 -0
- data/lib/case_form/core_ext/sentence_error.rb +38 -0
- data/lib/case_form/element.rb +40 -0
- data/lib/case_form/element/base.rb +95 -0
- data/lib/case_form/element/button.rb +64 -0
- data/lib/case_form/element/error.rb +54 -0
- data/lib/case_form/element/errors/complex_error.rb +107 -0
- data/lib/case_form/element/errors/simple_error.rb +76 -0
- data/lib/case_form/element/fieldset.rb +35 -0
- data/lib/case_form/element/hint.rb +54 -0
- data/lib/case_form/element/input.rb +106 -0
- data/lib/case_form/element/inputs/collection/checkbox_input.rb +36 -0
- data/lib/case_form/element/inputs/collection/radio_input.rb +27 -0
- data/lib/case_form/element/inputs/collection/select_input.rb +22 -0
- data/lib/case_form/element/inputs/collection_input.rb +89 -0
- data/lib/case_form/element/inputs/datetime/date_input.rb +45 -0
- data/lib/case_form/element/inputs/datetime/date_time_input.rb +50 -0
- data/lib/case_form/element/inputs/datetime/time_input.rb +34 -0
- data/lib/case_form/element/inputs/datetime/time_zone_input.rb +24 -0
- data/lib/case_form/element/inputs/file_input.rb +13 -0
- data/lib/case_form/element/inputs/hidden_input.rb +17 -0
- data/lib/case_form/element/inputs/number_input.rb +42 -0
- data/lib/case_form/element/inputs/search_input.rb +32 -0
- data/lib/case_form/element/inputs/string_input.rb +18 -0
- data/lib/case_form/element/inputs/text_input.rb +19 -0
- data/lib/case_form/element/label.rb +52 -0
- data/lib/case_form/element/nested_model.rb +105 -0
- data/lib/case_form/element/nested_models/handle.rb +18 -0
- data/lib/case_form/element/nested_models/handles/destructor_handle.rb +47 -0
- data/lib/case_form/element/nested_models/handles/generator_handle.rb +55 -0
- data/lib/case_form/element_ext/associationable.rb +54 -0
- data/lib/case_form/element_ext/columnable.rb +21 -0
- data/lib/case_form/element_ext/naming.rb +17 -0
- data/lib/case_form/element_ext/validationable.rb +13 -0
- data/lib/case_form/errors.rb +189 -0
- data/lib/case_form/form_builder.rb +11 -0
- data/lib/case_form/inputs.rb +1095 -0
- data/lib/case_form/labels.rb +102 -0
- data/lib/case_form/version.rb +6 -0
- data/lib/generators/case_form/install_generator.rb +33 -0
- data/lib/generators/case_form/templates/case_form.rb +63 -0
- data/lib/generators/case_form/templates/javascripts/jquery.case_form.js +10 -0
- data/lib/generators/case_form/templates/javascripts/prototype.case_form.js +0 -0
- data/lib/generators/case_form/templates/locales/en.yml +28 -0
- data/lib/generators/case_form/templates/locales/pl.yml +28 -0
- data/lib/generators/case_form/templates/stylesheets/stylesheet.css +93 -0
- data/lib/generators/case_form/templates/stylesheets/stylesheet_changes.css +1 -0
- data/lib/generators/case_form/uninstall_generator.rb +30 -0
- data/rails/init.rb +1 -0
- data/test/element/button_test.rb +85 -0
- data/test/element/errors/complex_error_test.rb +140 -0
- data/test/element/errors/simple_error_test.rb +92 -0
- data/test/element/fieldset_test.rb +28 -0
- data/test/element/hint_test.rb +81 -0
- data/test/element/input_test.rb +197 -0
- data/test/element/inputs/collection/checkbox_input_test.rb +176 -0
- data/test/element/inputs/collection/radio_input_test.rb +156 -0
- data/test/element/inputs/collection/select_input_test.rb +152 -0
- data/test/element/inputs/datetime/date_input_test.rb +160 -0
- data/test/element/inputs/datetime/datetime_input_test.rb +227 -0
- data/test/element/inputs/datetime/time_input_test.rb +72 -0
- data/test/element/inputs/datetime/time_zone_input_test.rb +42 -0
- data/test/element/inputs/file_input_test.rb +13 -0
- data/test/element/inputs/hidden_input_test.rb +13 -0
- data/test/element/inputs/number_input_test.rb +50 -0
- data/test/element/inputs/search_input_test.rb +13 -0
- data/test/element/inputs/string_input_test.rb +33 -0
- data/test/element/inputs/text_input_test.rb +13 -0
- data/test/element/label_test.rb +62 -0
- data/test/element/nested_model_test.rb +163 -0
- data/test/element/nested_models/handles/destructor_handle_test.rb +35 -0
- data/test/element/nested_models/handles/generator_handle_test.rb +27 -0
- data/test/form_builder_test.rb +25 -0
- data/test/form_helper_test.rb +15 -0
- data/test/lib/models.rb +268 -0
- data/test/test_helper.rb +74 -0
- metadata +235 -0
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class TimeZoneInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def time_zone_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.time_zone(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate time zone input" do
         | 
| 10 | 
            +
                time_zone_case_form_for(@user, :firstname)
         | 
| 11 | 
            +
                assert_select "select", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              test "should generate time zone without blank" do
         | 
| 15 | 
            +
                time_zone_case_form_for(@user, :firstname, :blank => false)
         | 
| 16 | 
            +
                assert_select("select") { assert_select "option", :count => 0 , :text => "" }
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              test "should generate time zone with blank" do
         | 
| 20 | 
            +
                time_zone_case_form_for(@user, :firstname, :blank => true)
         | 
| 21 | 
            +
                assert_select("select") { assert_select "option", :count => 1 , :text => "" }
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              # TODO fixit
         | 
| 25 | 
            +
              # test "should generate time zone with selected zone" do
         | 
| 26 | 
            +
              #   zone = "Warsaw"
         | 
| 27 | 
            +
              #   time_zone_case_form_for(@user, :firstname, :time_zone => zone)
         | 
| 28 | 
            +
              #   assert_select("select") { assert_select "option[selected=selected]", 1 }
         | 
| 29 | 
            +
              # end
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
              test "should generate time zone with priority zones" do
         | 
| 32 | 
            +
                zones = [::ActiveSupport::TimeZone['Warsaw'], ::ActiveSupport::TimeZone['London']]
         | 
| 33 | 
            +
                time_zone_case_form_for(@user, :firstname, :priority_zones => zones)
         | 
| 34 | 
            +
                assert_select("select") { assert_select "option[disabled=disabled]", 1 }
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
              test "should generate time zone with html class" do
         | 
| 38 | 
            +
                html_class = "Warsaw"
         | 
| 39 | 
            +
                time_zone_case_form_for(@user, :firstname, :class => html_class)
         | 
| 40 | 
            +
                assert_select("select.#{html_class}")
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class FileInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def file_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.file(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate file input" do
         | 
| 10 | 
            +
                file_case_form_for(@user, :firstname)
         | 
| 11 | 
            +
                assert_select "input[type=file]", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class HiddenInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def hidden_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.hidden(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate hidden input" do
         | 
| 10 | 
            +
                hidden_case_form_for(@user, :firstname)
         | 
| 11 | 
            +
                assert_select "input[type=hidden]", 3 # +1 _utf and _method
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class NumberInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def number_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.number(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate number input" do
         | 
| 10 | 
            +
                number_case_form_for(@valid_user, :height)
         | 
| 11 | 
            +
                assert_select "input[type=number]", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              test "should generate range input" do
         | 
| 15 | 
            +
                concat(case_form_for(@valid_user) { |f| f.range(:height) } )
         | 
| 16 | 
            +
                assert_select "input[type=range]", 1
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              test "should generate number input with min and max from column attribute" do
         | 
| 20 | 
            +
                number_case_form_for(@valid_user, :height)
         | 
| 21 | 
            +
                assert_select "input[type=number][min=-99.999][max=99.999]", 1
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              test "should generate number input with min and max from validation" do
         | 
| 25 | 
            +
                number_case_form_for(@valid_user, :valid_height)
         | 
| 26 | 
            +
                assert_select "input[type=number][min=0][max=280]", 1
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              test "should generate number input with min from validation" do
         | 
| 30 | 
            +
                number_case_form_for(@valid_user, :min_height)
         | 
| 31 | 
            +
                assert_select "input[type=number][min=0]", 1
         | 
| 32 | 
            +
                assert_select "input[type=number][max]", 0
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
              
         | 
| 35 | 
            +
              test "should generate number input with max from validation" do
         | 
| 36 | 
            +
                number_case_form_for(@valid_user, :max_height)
         | 
| 37 | 
            +
                assert_select "input[type=number][min]", 0
         | 
| 38 | 
            +
                assert_select "input[type=number][max=280]", 1
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
              
         | 
| 41 | 
            +
              test "should generate number input with step from column attribute" do
         | 
| 42 | 
            +
                number_case_form_for(@valid_user, :height)
         | 
| 43 | 
            +
                assert_select "input[type=number][step=0.001]", 1
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
              
         | 
| 46 | 
            +
              test "should generate number input with default step from validation" do
         | 
| 47 | 
            +
                number_case_form_for(@valid_user, :valid_height)
         | 
| 48 | 
            +
                assert_select "input[type=number][step=1]", 1
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class SearchInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def search_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.search(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate search input" do
         | 
| 10 | 
            +
                search_case_form_for(@user, :firstname)
         | 
| 11 | 
            +
                assert_select "input[type=search]", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class StringInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def string_case_form_for(object, method, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.send(method, attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate string input" do
         | 
| 10 | 
            +
                string_case_form_for(@user, :string, :firstname)
         | 
| 11 | 
            +
                assert_select "input[type=text]", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              test "should generate email input" do
         | 
| 15 | 
            +
                string_case_form_for(@user, :email, :firstname)
         | 
| 16 | 
            +
                assert_select "input[type=email]", 1
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              test "should generate password input" do
         | 
| 20 | 
            +
                string_case_form_for(@user, :password, :firstname)
         | 
| 21 | 
            +
                assert_select "input[type=password]", 1
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              test "should generate telephone input" do
         | 
| 25 | 
            +
                string_case_form_for(@user, :telephone, :firstname)
         | 
| 26 | 
            +
                assert_select "input[type=tel]", 1
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              test "should generate url input" do
         | 
| 30 | 
            +
                string_case_form_for(@user, :url, :firstname)
         | 
| 31 | 
            +
                assert_select "input[type=url]", 1
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class SearchInputTest < ActionView::TestCase
         | 
| 5 | 
            +
              def text_case_form_for(object, attribute, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| f.text(attribute, options) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate text input" do
         | 
| 10 | 
            +
                text_case_form_for(@user, :description)
         | 
| 11 | 
            +
                assert_select "textarea", 1
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,62 @@ | |
| 1 | 
            +
            require 'test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class LabelTest < ActionView::TestCase
         | 
| 4 | 
            +
              def label_case_form_for(object, attribute, options={})
         | 
| 5 | 
            +
                concat(case_form_for(object) { |f| f.label(attribute, options) })
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              test "should generate label" do
         | 
| 9 | 
            +
                label_case_form_for(@user, :firstname)
         | 
| 10 | 
            +
                assert_select "label[for=user_firstname]"
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              test "should generate label with text" do
         | 
| 14 | 
            +
                label_case_form_for(@user, :firstname, :text => "Enter firstname")
         | 
| 15 | 
            +
                assert_select "label[for=user_firstname]", "Enter firstname"
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              test "should generate label with default HTML class" do
         | 
| 19 | 
            +
                label_case_form_for(@user, :firstname)
         | 
| 20 | 
            +
                assert_select "label[for=user_firstname].label"
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              
         | 
| 23 | 
            +
              test "should generate label with specific HTML class" do
         | 
| 24 | 
            +
                specific_class = "some_class"
         | 
| 25 | 
            +
                label_case_form_for(@user, :firstname, :class => specific_class)
         | 
| 26 | 
            +
                assert_select "label[for=user_firstname].#{specific_class}"
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              test "should generate label with default HTML id" do
         | 
| 30 | 
            +
                label_case_form_for(@user, :firstname)
         | 
| 31 | 
            +
                assert_select "label[for=user_firstname]#user_firstname_label"
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              test "should generate label with specific HTML id" do
         | 
| 35 | 
            +
                specific_id = "some_id"
         | 
| 36 | 
            +
                label_case_form_for(@user, :firstname, :id => specific_id)
         | 
| 37 | 
            +
                assert_select "label[for=user_firstname]##{specific_id}"
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
              test "should generate label with wrong options" do
         | 
| 41 | 
            +
                assert_raise(ArgumentError) { label_case_form_for(@user, :firstname, :foo => :bar) }
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
              test "should generate label with custom data (HTML attribute)" do
         | 
| 45 | 
            +
                label_case_form_for(@user, :firstname, :custom => { :foo => :bar })
         | 
| 46 | 
            +
                assert_select "label[for=user_firstname][data-foo=bar]", 1
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              
         | 
| 49 | 
            +
              test "should generate label with invalid custom data (HTML attribute)" do
         | 
| 50 | 
            +
                assert_raise(ArgumentError) { label_case_form_for(@user, :firstname, :custom => :foo) }
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
              
         | 
| 53 | 
            +
              test "should generate label as required" do
         | 
| 54 | 
            +
                label_case_form_for(@user, :firstname, :required => true)
         | 
| 55 | 
            +
                assert_select "label[for=user_firstname]", "Firstname*"
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
              
         | 
| 58 | 
            +
              test "should generate label as not required" do
         | 
| 59 | 
            +
                label_case_form_for(@user, :firstname, :required => false)
         | 
| 60 | 
            +
                assert_select "label[for=user_firstname]", "Firstname"
         | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
            end
         | 
| @@ -0,0 +1,163 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class NestedModelTest < ActionView::TestCase
         | 
| 5 | 
            +
              # non association
         | 
| 6 | 
            +
              test "shouldn't generate association input for non association method" do
         | 
| 7 | 
            +
                assert_raise(ArgumentError) { concat(case_form_for(@user) { |f| f.belongs_to(:non_association) }) }
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
              
         | 
| 10 | 
            +
              # :belongs_to association
         | 
| 11 | 
            +
              test "should generate association input for :belongs_to association" do
         | 
| 12 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:special_country)) })
         | 
| 13 | 
            +
                assert_select "select", 1
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              test "should generate association input for :belongs_to association with specified input" do
         | 
| 17 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country, :as => :radio)) })
         | 
| 18 | 
            +
                assert_select "input[type=radio]", 5
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              test "should generate nasted inputs for :belongs_to association with block" do
         | 
| 22 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country) { |c| concat(c.attribute(:name)) }) })
         | 
| 23 | 
            +
                assert_select "fieldset", 1
         | 
| 24 | 
            +
                assert_select("div.country_association_inputs", 1) { assert_select "input[type=text]", 1 }
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              
         | 
| 27 | 
            +
              test "should generate nasted inputs for :belongs_to association without block and defined :accept_* method" do
         | 
| 28 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country)) })
         | 
| 29 | 
            +
                assert_select "fieldset", 1
         | 
| 30 | 
            +
                assert_select("div.country_association_inputs", 1) { assert_select "input[type=text]", 2 }
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
              test "should generate nasted inputs for :belongs_to association without block and defined :fields option" do
         | 
| 34 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country, :fields => :name)) })
         | 
| 35 | 
            +
                assert_select("div.country_association_inputs", 1) { assert_select "input[type=text]", 1 }
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
              test "shouldn't generate nested inputs for :belongs_to association without defined :accept_* method" do
         | 
| 39 | 
            +
                assert_raise(NoMethodError) { concat(case_form_for(@user) { |f| f.belongs_to(:special_country) { |c| c.attribute(:name) } }) }
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              
         | 
| 42 | 
            +
              test "should generate nasted inputs for :belongs_to association with empty object and block" do
         | 
| 43 | 
            +
                @user.country = nil
         | 
| 44 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country) { |c| concat(c.attribute(:name)) }) })
         | 
| 45 | 
            +
                assert_select("div.country_association_inputs", 1) { assert_select "input[type=text]", 1 }
         | 
| 46 | 
            +
                @user.country = @country
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              
         | 
| 49 | 
            +
              test "should generate nasted inputs for :belongs_to association with empty object and without block" do
         | 
| 50 | 
            +
                @user.country = nil
         | 
| 51 | 
            +
                concat(case_form_for(@user) { |f| concat(f.belongs_to(:country)) })
         | 
| 52 | 
            +
                assert_select("div.country_association_inputs", 1) { assert_select "input[type=text]", 2 }
         | 
| 53 | 
            +
                @user.country = @country
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
              
         | 
| 56 | 
            +
              # :has_one association
         | 
| 57 | 
            +
              test "should generate nasted inputs for :has_one association" do
         | 
| 58 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_one(:profile)) })
         | 
| 59 | 
            +
                assert_select "fieldset", 1
         | 
| 60 | 
            +
                assert_select "div.profile_association_inputs", 1 do
         | 
| 61 | 
            +
                  assert_select "input[type=email]", 1
         | 
| 62 | 
            +
                  assert_select "input[type=text]", 1
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
              
         | 
| 66 | 
            +
              test "should generate nasted inputs for :has_one association with block" do
         | 
| 67 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_one(:profile) { |p| concat(p.attribute(:email)) }) })
         | 
| 68 | 
            +
                assert_select "fieldset", 1
         | 
| 69 | 
            +
                assert_select("div.profile_association_inputs", 1) { assert_select "input[type=email]", 1 }
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
              
         | 
| 72 | 
            +
              test "should generate nasted inputs for :has_one association without block and with defined :fields option" do
         | 
| 73 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_one(:profile, :fields => :twitter)) })
         | 
| 74 | 
            +
                assert_select "div.profile_association_inputs", 1 do
         | 
| 75 | 
            +
                  assert_select "input[type=email]", 0
         | 
| 76 | 
            +
                  assert_select "input[type=text]", 1
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
              
         | 
| 80 | 
            +
              test "shouldn't generate nested inputs for :has_one association without defined :accept_* method" do
         | 
| 81 | 
            +
                assert_raise(NoMethodError) { concat(case_form_for(@user) { |f| f.has_one(:special_profile) { |c| c.attribute(:email) } }) }
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
              
         | 
| 84 | 
            +
              test "shouldn't generate association input for :has_one association" do
         | 
| 85 | 
            +
                assert_raise(ArgumentError) { concat(case_form_for(@user) { |f| f.has_one(:profile, :as => :select) }) }
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
              
         | 
| 88 | 
            +
              test "should generate nasted inputs for :has_one association with empty object and block" do
         | 
| 89 | 
            +
                @user.profile = nil
         | 
| 90 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_one(:profile) { |p| concat(p.attribute(:email)) }) })
         | 
| 91 | 
            +
                assert_select("div.profile_association_inputs", 1) { assert_select "input[type=email]", 1 }
         | 
| 92 | 
            +
                @user.profile = @profile
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
              
         | 
| 95 | 
            +
              test "should generate nasted inputs for :has_one association with empty object and without block" do
         | 
| 96 | 
            +
                @user.profile = nil
         | 
| 97 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_one(:profile)) })
         | 
| 98 | 
            +
                assert_select("div.profile_association_inputs", 1) { assert_select "input[type=email]", 1 }
         | 
| 99 | 
            +
                @user.profile = @profile
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
              
         | 
| 102 | 
            +
              # :has_many association
         | 
| 103 | 
            +
              test "should generate association input for :has_many association" do
         | 
| 104 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:special_projects)) })
         | 
| 105 | 
            +
                assert_select "input[type=checkbox]", 5
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
              
         | 
| 108 | 
            +
              test "should generate association input for :has_many association with specified input" do
         | 
| 109 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects, :as => :radio)) })
         | 
| 110 | 
            +
                assert_select "input[type=radio]", 5
         | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
              
         | 
| 113 | 
            +
              test "should generate nasted inputs for :has_many association with block" do
         | 
| 114 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects) { |c| concat(c.attribute(:name)) }) })
         | 
| 115 | 
            +
                assert_select "fieldset", 1 # 2 Projects in collection 
         | 
| 116 | 
            +
                assert_select("div.projects_association_inputs", 2) { assert_select "input[type=text]", 2 }
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
              
         | 
| 119 | 
            +
              test "should generate nasted inputs for :has_many association without block and defined :accept_* method" do
         | 
| 120 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects)) })
         | 
| 121 | 
            +
                assert_select "fieldset", 2 # 2 Projects in collection + 1 new
         | 
| 122 | 
            +
                assert_select("div.projects_association_inputs", 3) { assert_select "input[type=text]", 6 }
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
              
         | 
| 125 | 
            +
              test "should generate nasted inputs for :has_many association without block and with defined :fields option" do
         | 
| 126 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects, :fields => :name)) })
         | 
| 127 | 
            +
                assert_select "fieldset", 2 # 2 Projects in collection + 1 new
         | 
| 128 | 
            +
                assert_select("div.projects_association_inputs", 3) { assert_select "input[type=text]", 3 }
         | 
| 129 | 
            +
              end
         | 
| 130 | 
            +
              
         | 
| 131 | 
            +
              test "shouldn't generate nested inputs for :has_many association without defined :accept_* method" do
         | 
| 132 | 
            +
                assert_raise(NoMethodError) { concat(case_form_for(@user) { |f| f.has_many(:special_projects) { |c| c.attribute(:name) } }) }
         | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
              
         | 
| 135 | 
            +
              test "should generate nasted inputs for :has_many association with specified collection" do
         | 
| 136 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects, :collection => Project.extra)) })
         | 
| 137 | 
            +
                assert_select("div.projects_association_inputs", 4) { assert_select "input[type=text]", 8 }
         | 
| 138 | 
            +
              end
         | 
| 139 | 
            +
              
         | 
| 140 | 
            +
              test "shouldn't generate nasted inputs for :has_many association with empty object and block" do
         | 
| 141 | 
            +
                @user.projects = nil
         | 
| 142 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects) { |a| concat(a.attribute(:name)) }) })
         | 
| 143 | 
            +
                assert_select("div.projects_association_inputs", 0)
         | 
| 144 | 
            +
                @user.projects = @projects
         | 
| 145 | 
            +
              end
         | 
| 146 | 
            +
              
         | 
| 147 | 
            +
              test "should generate nasted inputs for :has_many association with empty object and without block" do
         | 
| 148 | 
            +
                @user.projects = nil
         | 
| 149 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects)) })
         | 
| 150 | 
            +
                assert_select("div.projects_association_inputs", 1) { assert_select "input[type=text]", 2 }
         | 
| 151 | 
            +
                @user.projects = @projects
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
              
         | 
| 154 | 
            +
              test "should generate nasted inputs for :has_many association without :generator" do
         | 
| 155 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects, :generator => false)) })
         | 
| 156 | 
            +
                assert_select "a[data-action=new]", 0
         | 
| 157 | 
            +
              end
         | 
| 158 | 
            +
              
         | 
| 159 | 
            +
              test "should generate nasted inputs for :has_many association without :destructor" do
         | 
| 160 | 
            +
                concat(case_form_for(@user) { |f| concat(f.has_many(:projects, :destructor => false)) })
         | 
| 161 | 
            +
                assert_select "input[type=checkbox]", 2
         | 
| 162 | 
            +
              end
         | 
| 163 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            require 'test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class DestructorHandleTest < ActionView::TestCase
         | 
| 5 | 
            +
              def destructor_case_form_for(object, association, options={})
         | 
| 6 | 
            +
                concat(case_form_for(object) { |f| concat(f.association(association) { |d| concat(d.destroy_object(options)) }) })
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              test "should generate destructor" do
         | 
| 10 | 
            +
                destructor_case_form_for(@user, :projects)
         | 
| 11 | 
            +
                assert_select "fieldset", 1 # 2x Project object
         | 
| 12 | 
            +
                assert_select "input[type=checkbox]", 2
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              test "should generate destructor as link" do
         | 
| 16 | 
            +
                destructor_case_form_for(@user, :projects, :as => :link)
         | 
| 17 | 
            +
                assert_select "fieldset", 1 # 2x Project object
         | 
| 18 | 
            +
                assert_select "a[data-action=destroy]", 2
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              test "should generate destructor with text" do
         | 
| 22 | 
            +
                text = "Usun"
         | 
| 23 | 
            +
                destructor_case_form_for(@user, :projects, :text => text)
         | 
| 24 | 
            +
                assert_select "fieldset", 1 # 2x Project object
         | 
| 25 | 
            +
                assert_select "input[type=checkbox]", 2
         | 
| 26 | 
            +
                assert_select "label", :count => 2, :text => text
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              test "should generate destructor as link with text" do
         | 
| 30 | 
            +
                text = "Usun"
         | 
| 31 | 
            +
                destructor_case_form_for(@user, :projects, :as => :link, :text => text)
         | 
| 32 | 
            +
                assert_select "fieldset", 1 # 2x Project object
         | 
| 33 | 
            +
                assert_select "a[data-action=destroy]", :count => 2, :text => text
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         |