middleman 2.0.16.1 → 3.0.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/CHANGELOG +16 -8
- data/features/builder.feature +2 -5
- data/features/cache_buster.feature +1 -1
- data/features/clean_build.feature +0 -1
- data/features/coffee-script.feature +3 -3
- data/features/custom_layout_engines.feature +10 -0
- data/features/directory_index.feature +0 -1
- data/features/dynamic_pages.feature +0 -1
- data/features/fonts.feature +0 -1
- data/features/{padrino_helpers.feature → former_padrino_helpers.feature} +1 -1
- data/features/sprockets.feature +34 -5
- data/features/sprockets_gems.feature +7 -4
- data/features/step_definitions/asset_host_steps.rb +7 -6
- data/features/step_definitions/builder_steps.rb +4 -0
- data/features/step_definitions/middleman_steps.rb +22 -16
- data/features/step_definitions/page_layout_steps.rb +10 -8
- data/fixtures/custom-layout-app/config.rb +1 -0
- data/fixtures/custom-layout-app/source/index.html.erb +1 -0
- data/fixtures/custom-layout-app/source/layout.haml +6 -0
- data/fixtures/sprockets-app/config.rb +2 -1
- data/fixtures/sprockets-app/source/library/css/bootstrap_include.css.scss +1 -0
- data/fixtures/sprockets-app/source/library/css/plain.css +3 -0
- data/fixtures/sprockets-app/source/library/css/sprockets_base1.css.scss +1 -0
- data/fixtures/sprockets-app/source/library/css/sprockets_base2.css.scss +1 -0
- data/fixtures/sprockets-app/source/library/css/sprockets_sub.css.scss +1 -0
- data/fixtures/sprockets-app/source/{jquery_include.js → library/js/jquery_include.js} +0 -0
- data/fixtures/sprockets-app/source/library/js/plain.js +3 -0
- data/fixtures/sprockets-app/source/library/{javascripts → js}/sprockets_base.js +0 -0
- data/fixtures/sprockets-app/source/library/{javascripts → js}/sprockets_sub.js +0 -0
- data/fixtures/test-app/config.rb +5 -4
- data/fixtures/test-app/source/{padrino_test.html.haml → former_padrino_test.html.haml} +0 -0
- data/fixtures/test-app/source/stylesheets/sprockets_base1.css.scss +1 -0
- data/fixtures/test-app/source/stylesheets/sprockets_base2.css.scss +1 -0
- data/fixtures/test-app/source/stylesheets/sprockets_sub.css.scss +1 -0
- data/lib/middleman.rb +27 -25
- data/lib/middleman/base.rb +408 -166
- data/lib/middleman/builder.rb +78 -162
- data/lib/middleman/cli.rb +61 -32
- data/lib/middleman/core_extensions/assets.rb +4 -44
- data/lib/middleman/core_extensions/builder.rb +12 -16
- data/lib/middleman/core_extensions/compass.rb +28 -57
- data/lib/middleman/core_extensions/data.rb +65 -49
- data/lib/middleman/core_extensions/default_helpers.rb +33 -18
- data/lib/middleman/core_extensions/features.rb +48 -26
- data/lib/middleman/core_extensions/file_watcher.rb +66 -0
- data/lib/middleman/core_extensions/front_matter.rb +91 -86
- data/lib/middleman/core_extensions/rendering.rb +9 -8
- data/lib/middleman/core_extensions/routing.rb +19 -53
- data/lib/middleman/core_extensions/sitemap.rb +229 -0
- data/lib/middleman/core_extensions/sprockets.rb +53 -37
- data/lib/middleman/features/asset_host.rb +20 -10
- data/lib/middleman/features/automatic_image_sizes.rb +12 -9
- data/lib/middleman/features/cache_buster.rb +38 -25
- data/lib/middleman/features/directory_indexes.rb +31 -28
- data/lib/middleman/features/minify_css.rb +3 -2
- data/lib/middleman/features/minify_css/cssmin.rb +55 -0
- data/lib/middleman/features/minify_javascript.rb +12 -5
- data/lib/middleman/features/relative_assets.rb +28 -25
- data/lib/middleman/features/sitemap_tree.rb +34 -0
- data/lib/middleman/guard.rb +57 -23
- data/lib/middleman/renderers/erb.rb +29 -0
- data/lib/middleman/renderers/liquid.rb +3 -12
- data/lib/middleman/renderers/markdown.rb +16 -15
- data/lib/middleman/renderers/sass.rb +34 -38
- data/lib/middleman/vendor/hooks-0.2.0/CHANGES.textile +9 -0
- data/lib/middleman/vendor/hooks-0.2.0/Gemfile +3 -0
- data/lib/middleman/vendor/hooks-0.2.0/README.rdoc +107 -0
- data/lib/middleman/vendor/hooks-0.2.0/Rakefile +12 -0
- data/lib/middleman/vendor/hooks-0.2.0/hooks.gemspec +22 -0
- data/lib/middleman/vendor/hooks-0.2.0/lib/hooks.rb +109 -0
- data/lib/middleman/vendor/hooks-0.2.0/lib/hooks/inheritable_attribute.rb +33 -0
- data/lib/middleman/vendor/hooks-0.2.0/test/hooks_test.rb +141 -0
- data/lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb +55 -0
- data/lib/middleman/vendor/hooks-0.2.0/test/test_helper.rb +10 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/.document +5 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/.gitignore +22 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/.yardopts +1 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/LICENSE.txt +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/README.rdoc +294 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/Rakefile +5 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/bin/padrino +9 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core.rb +167 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application.rb +270 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/rendering.rb +292 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/routing.rb +934 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/showexceptions.rb +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/caller.rb +53 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/adapter.rb +24 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/base.rb +151 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/console.rb +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/rake.rb +24 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/rake_tasks.rb +59 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/command.rb +38 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/images/404.png +0 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/images/500.png +0 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/loader.rb +210 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/cs.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/da.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/de.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/en.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/es.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/fr.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/hu.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/it.yml +40 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/ja.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/lv.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/nl.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/no.yml +35 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/pl.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/pt_br.yml +40 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/ru.yml +35 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/tr.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/uk.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/zh_cn.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/zh_tw.yml +34 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/logger.rb +345 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/mounter.rb +224 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/reloader.rb +254 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/router.rb +98 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/server.rb +79 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/support_lite.rb +199 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/tasks.rb +21 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/version.rb +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/padrino-core.gemspec +38 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/.components +6 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/.gitignore +7 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/complex.rb +32 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/simple.rb +33 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/a.rb +9 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/b.rb +4 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/c.rb +1 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/e.rb +13 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/f.rb +2 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/g.rb +2 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/d.rb +4 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/helper.rb +81 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/mini_shoulda.rb +45 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_application.rb +108 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_core.rb +79 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_dependencies.rb +44 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_filters.rb +278 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_locale.rb +21 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_logger.rb +100 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_mounter.rb +177 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_reloader_complex.rb +75 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_reloader_simple.rb +98 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_rendering.rb +461 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_restful_routing.rb +33 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_router.rb +146 -0
- data/lib/middleman/vendor/padrino-core-0.10.5/test/test_routing.rb +1673 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/.document +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/.gitignore +21 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/.yardopts +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/LICENSE.txt +20 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/README.rdoc +239 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/Rakefile +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers.rb +58 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/asset_tag_helpers.rb +420 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_builder/abstract_form_builder.rb +220 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_builder/standard_form_builder.rb +43 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_helpers.rb +602 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/format_helpers.rb +381 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/cs.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/da.yml +91 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/de.yml +81 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/en.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/es.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/fr.yml +80 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/hu.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/it.yml +89 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/ja.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/lv.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/nl.yml +82 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/no.yml +91 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/pl.yml +95 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/pt_br.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/ru.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/tr.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/uk.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/zh_cn.yml +104 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/zh_tw.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/number_helpers.rb +288 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers.rb +175 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/abstract_handler.rb +98 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/erb_handler.rb +79 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/haml_handler.rb +63 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/slim_handler.rb +81 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/render_helpers.rb +60 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/tag_helpers.rb +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/translation_helpers.rb +38 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/padrino-helpers.gemspec +27 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/app.rb +73 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.haml +12 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.slim +13 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.erb +14 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.haml +12 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.slim +12 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.slim +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.erb +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.slim +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.erb +20 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.haml +15 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.slim +15 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.slim +47 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.erb +56 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.slim +45 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.slim +4 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.slim +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.erb +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.haml +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.slim +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/app.rb +50 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/explicit_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/helper.rb +66 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_asset_tag_helpers.rb +320 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_form_builder.rb +996 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_form_helpers.rb +645 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_format_helpers.rb +227 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_locale.rb +20 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_number_helpers.rb +136 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_output_helpers.rb +153 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_render_helpers.rb +76 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_tag_helpers.rb +105 -0
- data/lib/middleman/version.rb +1 -1
- data/middleman-x86-mingw32.gemspec +16 -33
- data/middleman.gemspec +16 -31
- metadata +590 -349
- data/features/sinatra.feature +0 -6
- data/lib/middleman/core_extensions/rack_map.rb +0 -35
- data/lib/middleman/renderers/coffee_script.rb +0 -8
- data/lib/middleman/renderers/haml.rb +0 -31
- data/lib/middleman/renderers/slim.rb +0 -8
@@ -0,0 +1 @@
|
|
1
|
+
<span><%= current_engine %></span>
|
@@ -0,0 +1 @@
|
|
1
|
+
%span=current_engine
|
@@ -0,0 +1 @@
|
|
1
|
+
span=current_engine
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>This is a <%= @template %> template!</h1>
|
data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/haml/test.haml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template!
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template sent from render_template!
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path('../../../load_paths', __FILE__)
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda')
|
3
|
+
require 'rack/test'
|
4
|
+
require 'webrat'
|
5
|
+
require 'padrino-helpers'
|
6
|
+
require 'active_support/time'
|
7
|
+
|
8
|
+
class MiniTest::Spec
|
9
|
+
include Padrino::Helpers::OutputHelpers
|
10
|
+
include Padrino::Helpers::TagHelpers
|
11
|
+
include Padrino::Helpers::AssetTagHelpers
|
12
|
+
include Rack::Test::Methods
|
13
|
+
include Webrat::Methods
|
14
|
+
include Webrat::Matchers
|
15
|
+
|
16
|
+
Webrat.configure do |config|
|
17
|
+
config.mode = :rack
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop_time_for_test
|
21
|
+
time = Time.now
|
22
|
+
Time.stubs(:now).returns(time)
|
23
|
+
return time
|
24
|
+
end
|
25
|
+
|
26
|
+
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
27
|
+
# In this case, block is the html to evaluate
|
28
|
+
def assert_has_tag(name, attributes = {}, &block)
|
29
|
+
html = block && block.call
|
30
|
+
matcher = HaveSelector.new(name, attributes)
|
31
|
+
raise "Please specify a block!" if html.blank?
|
32
|
+
assert matcher.matches?(html), matcher.failure_message
|
33
|
+
end
|
34
|
+
|
35
|
+
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
36
|
+
# In this case, block is the html to evaluate
|
37
|
+
def assert_has_no_tag(name, attributes = {}, &block)
|
38
|
+
html = block && block.call
|
39
|
+
attributes.merge!(:count => 0)
|
40
|
+
matcher = HaveSelector.new(name, attributes)
|
41
|
+
raise "Please specify a block!" if html.blank?
|
42
|
+
assert matcher.matches?(html), matcher.failure_message
|
43
|
+
end
|
44
|
+
|
45
|
+
# Asserts that a file matches the pattern
|
46
|
+
def assert_match_in_file(pattern, file)
|
47
|
+
assert File.exist?(file), "File '#{file}' does not exist!"
|
48
|
+
assert_match pattern, File.read(file)
|
49
|
+
end
|
50
|
+
|
51
|
+
# mock_model("Business", :new_record? => true) => <Business>
|
52
|
+
def mock_model(klazz, options={})
|
53
|
+
options.reverse_merge!(:class => klazz, :new_record? => false, :id => 20, :errors => {})
|
54
|
+
record = stub(options)
|
55
|
+
record.stubs(:to_ary => [record])
|
56
|
+
record
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Webrat
|
61
|
+
module Logging
|
62
|
+
def logger # @private
|
63
|
+
@logger = nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
|
+
|
4
|
+
describe "AssetTagHelpers" do
|
5
|
+
include Padrino::Helpers::AssetTagHelpers
|
6
|
+
|
7
|
+
def app
|
8
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
9
|
+
end
|
10
|
+
|
11
|
+
def flash
|
12
|
+
{ :notice => "Demo notice" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for #flash_tag method' do
|
16
|
+
should "display flash with no given attributes" do
|
17
|
+
assert_has_tag('div.notice', :content => "Demo notice") { flash_tag(:notice) }
|
18
|
+
end
|
19
|
+
should "display flash with given attributes" do
|
20
|
+
actual_html = flash_tag(:notice, :class => 'notice', :id => 'notice-area')
|
21
|
+
assert_has_tag('div.notice#notice-area', :content => "Demo notice") { actual_html }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'for #link_to method' do
|
26
|
+
should "display link element with no given attributes" do
|
27
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register') { link_to('Sign up', '/register') }
|
28
|
+
end
|
29
|
+
|
30
|
+
should "display link element with given attributes" do
|
31
|
+
actual_html = link_to('Sign up', '/register', :class => 'first', :id => 'linky')
|
32
|
+
assert_has_tag('a#linky.first', :content => "Sign up", :href => '/register') { actual_html }
|
33
|
+
end
|
34
|
+
|
35
|
+
should "display link element with anchor attribute" do
|
36
|
+
actual_html = link_to("Anchor", "/anchor", :anchor => :foo)
|
37
|
+
assert_has_tag('a', :content => "Anchor", :href => '/anchor#foo') { actual_html }
|
38
|
+
end
|
39
|
+
|
40
|
+
should "display link element with void url and options" do
|
41
|
+
actual_link = link_to('Sign up', :class => "test")
|
42
|
+
assert_has_tag('a', :content => "Sign up", :href => 'javascript:void(0);', :class => 'test') { actual_link }
|
43
|
+
end
|
44
|
+
|
45
|
+
should "display link element with remote option" do
|
46
|
+
actual_link = link_to('Sign up', '/register', :remote => true)
|
47
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-remote' => 'true') { actual_link }
|
48
|
+
end
|
49
|
+
|
50
|
+
should "display link element with method option" do
|
51
|
+
actual_link = link_to('Sign up', '/register', :method => :delete)
|
52
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-method' => 'delete', :rel => 'nofollow') { actual_link }
|
53
|
+
end
|
54
|
+
|
55
|
+
should "display link element with confirm option" do
|
56
|
+
actual_link = link_to('Sign up', '/register', :confirm => "Are you sure?")
|
57
|
+
assert_has_tag('a', :content => "Sign up", :href => '/register', 'data-confirm' => 'Are you sure?') { actual_link }
|
58
|
+
end
|
59
|
+
|
60
|
+
should "display link element with ruby block" do
|
61
|
+
actual_link = link_to('/register', :class => 'first', :id => 'binky') { "Sign up" }
|
62
|
+
assert_has_tag('a#binky.first', :content => "Sign up", :href => '/register') { actual_link }
|
63
|
+
end
|
64
|
+
|
65
|
+
should "display link block element in haml" do
|
66
|
+
visit '/haml/link_to'
|
67
|
+
assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
|
68
|
+
assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
|
69
|
+
end
|
70
|
+
|
71
|
+
should "display link block element in erb" do
|
72
|
+
visit '/erb/link_to'
|
73
|
+
assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1'
|
74
|
+
assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'for #mail_to method' do
|
79
|
+
should "display link element for mail to no caption" do
|
80
|
+
actual_html = mail_to('test@demo.com')
|
81
|
+
assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'test@demo.com') { actual_html }
|
82
|
+
end
|
83
|
+
|
84
|
+
should "display link element for mail to with caption" do
|
85
|
+
actual_html = mail_to('test@demo.com', "My Email", :class => 'demo')
|
86
|
+
assert_has_tag(:a, :href => "mailto:test@demo.com", :content => 'My Email', :class => 'demo') { actual_html }
|
87
|
+
end
|
88
|
+
|
89
|
+
should "display link element for mail to with caption and mail options" do
|
90
|
+
actual_html = mail_to('test@demo.com', "My Email", :subject => 'demo test', :class => 'demo', :cc => 'foo@test.com')
|
91
|
+
assert_has_tag(:a, :class => 'demo') { actual_html }
|
92
|
+
assert_match %r{mailto\:test\@demo.com\?}, actual_html
|
93
|
+
assert_match %r{cc=foo\@test\.com}, actual_html
|
94
|
+
assert_match %r{subject\=demo\%20test}, actual_html
|
95
|
+
end
|
96
|
+
|
97
|
+
should "display mail link element in haml" do
|
98
|
+
visit '/haml/mail_to'
|
99
|
+
assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
|
100
|
+
assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
|
101
|
+
end
|
102
|
+
|
103
|
+
should "display mail link element in erb" do
|
104
|
+
visit '/erb/mail_to'
|
105
|
+
assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
|
106
|
+
assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
|
107
|
+
end
|
108
|
+
|
109
|
+
should "display mail link element in slim" do
|
110
|
+
visit '/slim/mail_to'
|
111
|
+
assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
|
112
|
+
assert_have_selector 'p.captioned a', :href => 'mailto:test@demo.com', :content => 'Click my Email'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'for #meta_tag method' do
|
117
|
+
should "display meta tag with given content and name" do
|
118
|
+
actual_html = meta_tag("weblog,news", :name => "keywords")
|
119
|
+
assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
|
120
|
+
end
|
121
|
+
|
122
|
+
should "display meta tag with given content and http-equiv" do
|
123
|
+
actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
|
124
|
+
assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
|
125
|
+
end
|
126
|
+
|
127
|
+
should "display meta tag element in haml" do
|
128
|
+
visit '/haml/meta_tag'
|
129
|
+
assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
|
130
|
+
assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
131
|
+
end
|
132
|
+
|
133
|
+
should "display meta tag element in erb" do
|
134
|
+
visit '/erb/meta_tag'
|
135
|
+
assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
|
136
|
+
assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
137
|
+
end
|
138
|
+
|
139
|
+
should "display meta tag element in slim" do
|
140
|
+
visit '/slim/meta_tag'
|
141
|
+
assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
|
142
|
+
assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'for #image_tag method' do
|
147
|
+
should "display image tag absolute link with no options" do
|
148
|
+
time = stop_time_for_test
|
149
|
+
assert_has_tag('img', :src => "/absolute/pic.gif?#{time.to_i}") { image_tag('/absolute/pic.gif') }
|
150
|
+
end
|
151
|
+
|
152
|
+
should "display image tag absolute link with specified uri root" do
|
153
|
+
time = stop_time_for_test
|
154
|
+
self.class.stubs(:uri_root).returns("/blog")
|
155
|
+
assert_has_tag('img', :src => "/blog/images/relative/pic.gif?#{time.to_i}") { image_tag('relative/pic.gif') }
|
156
|
+
end
|
157
|
+
|
158
|
+
should "display image tag relative link with options" do
|
159
|
+
time = stop_time_for_test
|
160
|
+
assert_has_tag('img.photo', :src => "/images/relative/pic.gif?#{time.to_i}") {
|
161
|
+
image_tag('relative/pic.gif', :class => 'photo') }
|
162
|
+
end
|
163
|
+
|
164
|
+
should "display image tag uri link with options" do
|
165
|
+
time = stop_time_for_test
|
166
|
+
assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
|
167
|
+
end
|
168
|
+
|
169
|
+
should "display image tag relative link with incorrect spacing" do
|
170
|
+
time = stop_time_for_test
|
171
|
+
assert_has_tag('img.photo', :src => "/images/%20relative/%20pic.gif%20%20?#{time.to_i}") {
|
172
|
+
image_tag(' relative/ pic.gif ', :class => 'photo') }
|
173
|
+
end
|
174
|
+
|
175
|
+
should "not use a timestamp if stamp setting is false" do
|
176
|
+
self.class.expects(:asset_stamp).returns(false)
|
177
|
+
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
|
178
|
+
end
|
179
|
+
|
180
|
+
should "have xhtml convention tag" do
|
181
|
+
self.class.expects(:asset_stamp).returns(false)
|
182
|
+
assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'for #stylesheet_link_tag method' do
|
187
|
+
should "display stylesheet link item" do
|
188
|
+
time = stop_time_for_test
|
189
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
190
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { stylesheet_link_tag('style') }
|
191
|
+
end
|
192
|
+
|
193
|
+
should "display stylesheet link item for long relative path" do
|
194
|
+
time = stop_time_for_test
|
195
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
196
|
+
actual_html = stylesheet_link_tag('example/demo/style')
|
197
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
|
198
|
+
end
|
199
|
+
|
200
|
+
should "display stylesheet link item with absolute path" do
|
201
|
+
time = stop_time_for_test
|
202
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
203
|
+
actual_html = stylesheet_link_tag('/css/style')
|
204
|
+
assert_has_tag('link', expected_options.merge(:href => "/css/style.css?#{time.to_i}")) { actual_html }
|
205
|
+
end
|
206
|
+
|
207
|
+
should "display stylesheet link item with uri root" do
|
208
|
+
self.class.stubs(:uri_root).returns("/blog")
|
209
|
+
time = stop_time_for_test
|
210
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
211
|
+
actual_html = stylesheet_link_tag('style')
|
212
|
+
assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
|
213
|
+
end
|
214
|
+
|
215
|
+
should "display stylesheet link items" do
|
216
|
+
time = stop_time_for_test
|
217
|
+
actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
|
218
|
+
assert_has_tag('link', :media => "screen", :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
|
219
|
+
assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
|
220
|
+
assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
|
221
|
+
assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
|
222
|
+
assert_equal actual_html, stylesheet_link_tag(['style', 'layout.css', 'http://google.com/style.css'])
|
223
|
+
end
|
224
|
+
|
225
|
+
should "not use a timestamp if stamp setting is false" do
|
226
|
+
self.class.expects(:asset_stamp).returns(false)
|
227
|
+
expected_options = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
228
|
+
assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css")) { stylesheet_link_tag('style') }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'for #javascript_include_tag method' do
|
233
|
+
should "display javascript item" do
|
234
|
+
time = stop_time_for_test
|
235
|
+
actual_html = javascript_include_tag('application')
|
236
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
237
|
+
end
|
238
|
+
|
239
|
+
should "display javascript item for long relative path" do
|
240
|
+
time = stop_time_for_test
|
241
|
+
actual_html = javascript_include_tag('example/demo/application')
|
242
|
+
assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
243
|
+
end
|
244
|
+
|
245
|
+
should "display javascript item for path containing js" do
|
246
|
+
time = stop_time_for_test
|
247
|
+
actual_html = javascript_include_tag 'test/jquery.json'
|
248
|
+
assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
|
249
|
+
end
|
250
|
+
|
251
|
+
should "display javascript item for path containing period" do
|
252
|
+
time = stop_time_for_test
|
253
|
+
actual_html = javascript_include_tag 'test/jquery.min'
|
254
|
+
assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
255
|
+
end
|
256
|
+
|
257
|
+
should "display javascript item with absolute path" do
|
258
|
+
time = stop_time_for_test
|
259
|
+
actual_html = javascript_include_tag('/js/application')
|
260
|
+
assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
261
|
+
end
|
262
|
+
|
263
|
+
should "display javascript item with uri root" do
|
264
|
+
self.class.stubs(:uri_root).returns("/blog")
|
265
|
+
time = stop_time_for_test
|
266
|
+
actual_html = javascript_include_tag('application')
|
267
|
+
assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
|
268
|
+
end
|
269
|
+
|
270
|
+
should "display javascript items" do
|
271
|
+
time = stop_time_for_test
|
272
|
+
actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
|
273
|
+
assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
|
274
|
+
assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
|
275
|
+
assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
|
276
|
+
assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
|
277
|
+
assert_equal actual_html, javascript_include_tag(['application', 'base.js', 'http://google.com/lib.js'])
|
278
|
+
end
|
279
|
+
|
280
|
+
should "not use a timestamp if stamp setting is false" do
|
281
|
+
self.class.expects(:asset_stamp).returns(false)
|
282
|
+
actual_html = javascript_include_tag('application')
|
283
|
+
assert_has_tag('script', :src => "/javascripts/application.js", :type => "text/javascript") { actual_html }
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context "for #favicon_tag method" do
|
288
|
+
should "display favicon" do
|
289
|
+
time = stop_time_for_test
|
290
|
+
actual_html = favicon_tag('icons/favicon.png')
|
291
|
+
assert_has_tag('link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}") { actual_html }
|
292
|
+
end
|
293
|
+
|
294
|
+
should "match type with file ext" do
|
295
|
+
time = stop_time_for_test
|
296
|
+
actual_html = favicon_tag('favicon.ico')
|
297
|
+
assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}") { actual_html }
|
298
|
+
end
|
299
|
+
|
300
|
+
should "allow option overrides" do
|
301
|
+
time = stop_time_for_test
|
302
|
+
actual_html = favicon_tag('favicon.png', :type => 'image/ico')
|
303
|
+
assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}") { actual_html }
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context 'for #feed_tag method' do
|
308
|
+
should "generate correctly link tag for rss" do
|
309
|
+
assert_has_tag('link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss') { feed_tag :rss, "/blog/post.rss" }
|
310
|
+
end
|
311
|
+
|
312
|
+
should "generate correctly link tag for atom" do
|
313
|
+
assert_has_tag('link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom') { feed_tag :atom, "/blog/post.atom" }
|
314
|
+
end
|
315
|
+
|
316
|
+
should "override options" do
|
317
|
+
assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" }
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
@@ -0,0 +1,996 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
|
+
|
4
|
+
describe "FormBuilder" do
|
5
|
+
include Padrino::Helpers::FormHelpers
|
6
|
+
|
7
|
+
# Dummy form builder for testing
|
8
|
+
module Padrino::Helpers::FormBuilder
|
9
|
+
class FakeFormBuilder < AbstractFormBuilder
|
10
|
+
def foo_field; @template.content_tag(:span, "bar"); end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def app
|
15
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
role_types = [mock_model('Role', :name => "Admin", :id => 1),
|
20
|
+
mock_model('Role', :name => 'Moderate', :id => 2), mock_model('Role', :name => 'Limited', :id => 3)]
|
21
|
+
@user = mock_model("User", :first_name => "Joe", :email => '', :session_id => 54)
|
22
|
+
@user.stubs(:errors => {:a => "must be present", :b => "must be valid", :email => "Must be valid", :first_name => []})
|
23
|
+
@user.stubs(:role_types => role_types, :role => "1")
|
24
|
+
@user_none = mock_model("User")
|
25
|
+
end
|
26
|
+
|
27
|
+
def standard_builder(object=@user)
|
28
|
+
Padrino::Helpers::FormBuilder::StandardFormBuilder.new(self, object)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'for #form_for method' do
|
32
|
+
should "display correct form html" do
|
33
|
+
actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { "Demo" }
|
34
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post', :content => "Demo") { actual_html }
|
35
|
+
assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
|
36
|
+
end
|
37
|
+
|
38
|
+
should "display correct form html with fake object" do
|
39
|
+
actual_html = form_for(:markup_user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
|
40
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post') { actual_html }
|
41
|
+
assert_has_tag('form input', :type => 'text', :name => 'markup_user[username]') { actual_html }
|
42
|
+
assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
|
43
|
+
end
|
44
|
+
|
45
|
+
should "display correct form html for namespaced object" do
|
46
|
+
actual_html = form_for(Outer::UserAccount.new, '/register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
|
47
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
|
48
|
+
assert_has_tag('form input', :type => 'text', :name => 'outer_user_account[username]') { actual_html }
|
49
|
+
end
|
50
|
+
|
51
|
+
should "display form specifying default builder setting" do
|
52
|
+
self.expects(:settings).returns(stub(:default_builder => 'FakeFormBuilder')).once
|
53
|
+
actual_html = ""
|
54
|
+
actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.foo_field }
|
55
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
|
56
|
+
assert_has_tag('span', :content => "bar") { actual_html }
|
57
|
+
end
|
58
|
+
|
59
|
+
should "display correct form html with remote option" do
|
60
|
+
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true) { "Demo" }
|
61
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
|
62
|
+
end
|
63
|
+
|
64
|
+
should "display correct form html with remote option and method put" do
|
65
|
+
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true, :method => 'put') { "Demo" }
|
66
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :method => 'post', "data-method" => 'put', "data-remote" => 'true') { actual_html }
|
67
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
|
68
|
+
end
|
69
|
+
|
70
|
+
should "display correct form html with method :put" do
|
71
|
+
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :method => 'put') { "Demo" }
|
72
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post') { actual_html }
|
73
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
|
74
|
+
end
|
75
|
+
|
76
|
+
should "display correct form html with method :delete" do
|
77
|
+
actual_html = form_for(@user, '/destroy', :"accept-charset" => "UTF-8", :method => 'delete') { "Demo" }
|
78
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/destroy', :method => 'post') { actual_html }
|
79
|
+
assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
|
80
|
+
end
|
81
|
+
|
82
|
+
should "display correct form html with multipart" do
|
83
|
+
actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
|
84
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
|
85
|
+
end
|
86
|
+
|
87
|
+
should "support changing form builder type" do
|
88
|
+
form_html = proc { form_for(@user, '/register', :"accept-charset" => "UTF-8", :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
|
89
|
+
assert_raises(NoMethodError) { form_html.call }
|
90
|
+
end
|
91
|
+
|
92
|
+
should "support using default standard builder" do
|
93
|
+
actual_html = form_for(@user, '/register') { |f| f.text_field_block(:name) }
|
94
|
+
assert_has_tag('form p input[type=text]') { actual_html }
|
95
|
+
end
|
96
|
+
|
97
|
+
should "display fail for form with nil object" do
|
98
|
+
assert_raises(RuntimeError) { form_for(@not_real, '/register', :id => 'register', :method => 'post') { "Demo" } }
|
99
|
+
end
|
100
|
+
|
101
|
+
should "display correct form in haml" do
|
102
|
+
visit '/haml/form_for'
|
103
|
+
assert_have_selector :form, :action => '/demo', :id => 'demo'
|
104
|
+
assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
|
105
|
+
assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
|
106
|
+
end
|
107
|
+
|
108
|
+
should "display correct form in erb" do
|
109
|
+
visit '/erb/form_for'
|
110
|
+
assert_have_selector :form, :action => '/demo', :id => 'demo'
|
111
|
+
assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
|
112
|
+
assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
|
113
|
+
end
|
114
|
+
|
115
|
+
should "display correct form in slim" do
|
116
|
+
visit '/slim/form_for'
|
117
|
+
assert_have_selector :form, :action => '/demo', :id => 'demo'
|
118
|
+
assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
|
119
|
+
assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
|
120
|
+
end
|
121
|
+
|
122
|
+
should "have a class of 'invalid' for fields with errors" do
|
123
|
+
actual_html = form_for(@user, '/register') {|f| f.text_field(:email) }
|
124
|
+
assert_has_tag(:input, :type => 'text', :name => 'user[email]', :id => 'user_email', :class => 'invalid') {actual_html }
|
125
|
+
end
|
126
|
+
|
127
|
+
should "not have a class of 'invalid' for fields with no errors" do
|
128
|
+
actual_html = form_for(@user, '/register') {|f| f.text_field(:first_name) }
|
129
|
+
assert_has_no_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name', :class => 'invalid') {actual_html }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'for #fields_for method' do
|
134
|
+
should 'display correct fields html' do
|
135
|
+
actual_html = fields_for(@user) { |f| f.text_field(:first_name) }
|
136
|
+
assert_has_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name') { actual_html }
|
137
|
+
end
|
138
|
+
|
139
|
+
should 'display correct fields html with symbol object' do
|
140
|
+
actual_html = fields_for(:markup_user) { |f| f.text_field(:first_name) }
|
141
|
+
assert_has_tag(:input, :type => 'text', :name => 'markup_user[first_name]', :id => 'markup_user_first_name') { actual_html }
|
142
|
+
end
|
143
|
+
|
144
|
+
should "display fail for nil object" do
|
145
|
+
assert_raises(RuntimeError) { fields_for(@not_real) { |f| "Demo" } }
|
146
|
+
end
|
147
|
+
|
148
|
+
should 'display correct simple fields in haml' do
|
149
|
+
visit '/haml/fields_for'
|
150
|
+
assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
|
151
|
+
assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
|
152
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
|
153
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
|
154
|
+
end
|
155
|
+
|
156
|
+
should "display correct simple fields in erb" do
|
157
|
+
visit '/erb/fields_for'
|
158
|
+
assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
|
159
|
+
assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
|
160
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
|
161
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
|
162
|
+
end
|
163
|
+
|
164
|
+
should "display correct simple fields in slim" do
|
165
|
+
visit '/slim/fields_for'
|
166
|
+
assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
|
167
|
+
assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
|
168
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
|
169
|
+
assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# ===========================
|
174
|
+
# AbstractFormBuilder
|
175
|
+
# ===========================
|
176
|
+
|
177
|
+
context 'for #error_messages method' do
|
178
|
+
should "display correct form html with no record" do
|
179
|
+
actual_html = standard_builder(@user_none).error_messages(:header_message => "Demo form cannot be saved")
|
180
|
+
assert actual_html.blank?
|
181
|
+
end
|
182
|
+
|
183
|
+
should "display correct form html with valid record" do
|
184
|
+
actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved", :style => "foo:bar", :class => "mine")
|
185
|
+
assert_has_tag('#field-errors h2', :content => "Demo form cannot be saved") { actual_html }
|
186
|
+
assert_has_tag('#field-errors ul li', :content => "B must be valid") { actual_html }
|
187
|
+
assert_has_tag('#field-errors ul li', :content => "A must be present") { actual_html }
|
188
|
+
assert_has_tag('#field-errors', :style => "foo:bar") { actual_html }
|
189
|
+
assert_has_tag('#field-errors', :class => "mine") { actual_html }
|
190
|
+
end
|
191
|
+
|
192
|
+
should "display correct form in haml" do
|
193
|
+
visit '/haml/form_for'
|
194
|
+
assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
195
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
|
196
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
|
197
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
|
198
|
+
assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
199
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
|
200
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
|
201
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
|
202
|
+
assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
|
203
|
+
end
|
204
|
+
|
205
|
+
should "display correct form in erb" do
|
206
|
+
visit '/erb/form_for'
|
207
|
+
assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
208
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
|
209
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
|
210
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
|
211
|
+
assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
212
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
|
213
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
|
214
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
|
215
|
+
assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
|
216
|
+
end
|
217
|
+
|
218
|
+
should "display correct form in slim" do
|
219
|
+
visit '/slim/form_for'
|
220
|
+
assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
221
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
|
222
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
|
223
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
|
224
|
+
assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
225
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
|
226
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
|
227
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
|
228
|
+
assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'for #error_message_on method' do
|
233
|
+
should "display correct form html with no record" do
|
234
|
+
actual_html = standard_builder(@user_none).error_message_on(:name)
|
235
|
+
assert actual_html.blank?
|
236
|
+
end
|
237
|
+
|
238
|
+
should "display error for specified invalid object" do
|
239
|
+
actual_html = standard_builder(@user).error_message_on(:a, :prepend => "foo", :append => "bar")
|
240
|
+
assert_has_tag('span.error', :content => "foo must be present bar") { actual_html }
|
241
|
+
end
|
242
|
+
|
243
|
+
should "display error for specified invalid object not matching class name" do
|
244
|
+
@bob = mock_model("User", :first_name => "Frank", :errors => { :foo => "must be bob" })
|
245
|
+
actual_html = standard_builder(@bob).error_message_on(:foo, :prepend => "foo", :append => "bar")
|
246
|
+
assert_has_tag('span.error', :content => "foo must be bob bar") { actual_html }
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'for #label method' do
|
251
|
+
should "display correct label html" do
|
252
|
+
actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name: ")
|
253
|
+
assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
|
254
|
+
end
|
255
|
+
|
256
|
+
should "display correct label in haml" do
|
257
|
+
visit '/haml/form_for'
|
258
|
+
assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
|
259
|
+
assert_have_selector '#demo label', :content => "About Me: "
|
260
|
+
assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
|
261
|
+
end
|
262
|
+
|
263
|
+
should "display correct label in erb" do
|
264
|
+
visit '/erb/form_for'
|
265
|
+
assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
|
266
|
+
assert_have_selector '#demo label', :content => "About Me: "
|
267
|
+
assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
|
268
|
+
end
|
269
|
+
|
270
|
+
should "display correct label in slim" do
|
271
|
+
visit '/slim/form_for'
|
272
|
+
assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
|
273
|
+
assert_have_selector '#demo label', :content => "About Me: "
|
274
|
+
assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context 'for #hidden_field method' do
|
279
|
+
should "display correct hidden field html" do
|
280
|
+
actual_html = standard_builder.hidden_field(:session_id, :class => 'hidden')
|
281
|
+
assert_has_tag('input.hidden[type=hidden]', :value => "54", :id => 'user_session_id', :name => 'user[session_id]') { actual_html }
|
282
|
+
end
|
283
|
+
|
284
|
+
should "display correct hidden field in haml" do
|
285
|
+
visit '/haml/form_for'
|
286
|
+
assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
|
287
|
+
assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
|
288
|
+
end
|
289
|
+
|
290
|
+
should "display correct hidden field in erb" do
|
291
|
+
visit '/erb/form_for'
|
292
|
+
assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
|
293
|
+
assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
|
294
|
+
end
|
295
|
+
|
296
|
+
should "display correct hidden field in slim" do
|
297
|
+
visit '/slim/form_for'
|
298
|
+
assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
|
299
|
+
assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context 'for #text_field method' do
|
304
|
+
should "display correct text field html" do
|
305
|
+
actual_html = standard_builder.text_field(:first_name, :class => 'large')
|
306
|
+
assert_has_tag('input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
|
307
|
+
end
|
308
|
+
|
309
|
+
should "display correct text field in haml" do
|
310
|
+
visit '/haml/form_for'
|
311
|
+
assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
|
312
|
+
assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
|
313
|
+
end
|
314
|
+
|
315
|
+
should "display correct text field in erb" do
|
316
|
+
visit '/erb/form_for'
|
317
|
+
assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
|
318
|
+
assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
|
319
|
+
end
|
320
|
+
|
321
|
+
should "display correct text field in slim" do
|
322
|
+
visit '/slim/form_for'
|
323
|
+
assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
|
324
|
+
assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'for #check_box method' do
|
329
|
+
should "display correct checkbox html" do
|
330
|
+
actual_html = standard_builder.check_box(:confirm_destroy, :class => 'large')
|
331
|
+
assert_has_tag('input.large[type=checkbox]', :id => 'user_confirm_destroy', :name => 'user[confirm_destroy]') { actual_html }
|
332
|
+
assert_has_tag('input[type=hidden]', :name => 'user[confirm_destroy]', :value => '0') { actual_html }
|
333
|
+
end
|
334
|
+
|
335
|
+
should "display correct checkbox html when checked" do
|
336
|
+
actual_html = standard_builder.check_box(:confirm_destroy, :checked => true)
|
337
|
+
assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[confirm_destroy]') { actual_html }
|
338
|
+
end
|
339
|
+
|
340
|
+
should "display correct checkbox html as checked when object value matches" do
|
341
|
+
@user.stubs(:show_favorites => 'human')
|
342
|
+
actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
|
343
|
+
assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
|
344
|
+
end
|
345
|
+
|
346
|
+
should "display correct checkbox html as checked when object value is true" do
|
347
|
+
@user.stubs(:show_favorites => true)
|
348
|
+
actual_html = standard_builder.check_box(:show_favorites, :value => '1')
|
349
|
+
assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
|
350
|
+
end
|
351
|
+
|
352
|
+
should "display correct checkbox html as unchecked when object value doesn't match" do
|
353
|
+
@user.stubs(:show_favorites => 'alien')
|
354
|
+
actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
|
355
|
+
assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
|
356
|
+
end
|
357
|
+
|
358
|
+
should "display correct checkbox html as unchecked when object value is false" do
|
359
|
+
@user.stubs(:show_favorites => false)
|
360
|
+
actual_html = standard_builder.check_box(:show_favorites, :value => '1')
|
361
|
+
assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
|
362
|
+
end
|
363
|
+
|
364
|
+
should "display correct unchecked hidden field when specified" do
|
365
|
+
actual_html = standard_builder.check_box(:show_favorites, :value => 'female', :uncheck_value => 'false')
|
366
|
+
assert_has_tag('input[type=hidden]', :name => 'user[show_favorites]', :value => 'false') { actual_html }
|
367
|
+
end
|
368
|
+
|
369
|
+
should "display correct checkbox in haml" do
|
370
|
+
visit '/haml/form_for'
|
371
|
+
assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
|
372
|
+
end
|
373
|
+
|
374
|
+
should "display correct checkbox in erb" do
|
375
|
+
visit '/erb/form_for'
|
376
|
+
assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
|
377
|
+
end
|
378
|
+
|
379
|
+
should "display correct checkbox in slim" do
|
380
|
+
visit '/slim/form_for'
|
381
|
+
assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context 'for #radio_button method' do
|
386
|
+
should "display correct radio button html" do
|
387
|
+
actual_html = standard_builder.radio_button(:gender, :value => 'male', :class => 'large')
|
388
|
+
assert_has_tag('input.large[type=radio]', :id => 'user_gender_male', :name => 'user[gender]', :value => 'male') { actual_html }
|
389
|
+
end
|
390
|
+
|
391
|
+
should "display correct radio button html when checked" do
|
392
|
+
actual_html = standard_builder.radio_button(:gender, :checked => true)
|
393
|
+
assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
|
394
|
+
end
|
395
|
+
|
396
|
+
should "display correct radio button html as checked when object value matches" do
|
397
|
+
@user.stubs(:gender => 'male')
|
398
|
+
actual_html = standard_builder.radio_button(:gender, :value => 'male')
|
399
|
+
assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
|
400
|
+
end
|
401
|
+
|
402
|
+
should "display correct radio button html as unchecked when object value doesn't match" do
|
403
|
+
@user.stubs(:gender => 'male')
|
404
|
+
actual_html = standard_builder.radio_button(:gender, :value => 'female')
|
405
|
+
assert_has_no_tag('input[type=radio]', :checked => 'checked') { actual_html }
|
406
|
+
end
|
407
|
+
|
408
|
+
should "display correct radio button in haml" do
|
409
|
+
visit '/haml/form_for'
|
410
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
|
411
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
|
412
|
+
assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
|
413
|
+
end
|
414
|
+
|
415
|
+
should "display correct radio button in erb" do
|
416
|
+
visit '/erb/form_for'
|
417
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
|
418
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
|
419
|
+
assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
|
420
|
+
end
|
421
|
+
|
422
|
+
should "display correct radio button in slim" do
|
423
|
+
visit '/slim/form_for'
|
424
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
|
425
|
+
assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
|
426
|
+
assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
context 'for #text_area method' do
|
431
|
+
should "display correct text_area html" do
|
432
|
+
actual_html = standard_builder.text_area(:about, :class => 'large')
|
433
|
+
assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]', :rows => '', :cols => '') { actual_html }
|
434
|
+
end
|
435
|
+
|
436
|
+
should "display correct text_area html and content" do
|
437
|
+
actual_html = standard_builder.text_area(:about, :value => "Demo", :rows => '5', :cols => '6')
|
438
|
+
assert_has_tag('textarea', :id => 'user_about', :content => 'Demo', :rows => '5', :cols => '6') { actual_html }
|
439
|
+
end
|
440
|
+
|
441
|
+
should "display correct text_area in haml" do
|
442
|
+
visit '/haml/form_for'
|
443
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
444
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
445
|
+
end
|
446
|
+
|
447
|
+
should "display correct text_area in erb" do
|
448
|
+
visit '/erb/form_for'
|
449
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
450
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
451
|
+
end
|
452
|
+
|
453
|
+
should "display correct text_area in slim" do
|
454
|
+
visit '/slim/form_for'
|
455
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
456
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context 'for #password_field method' do
|
461
|
+
should "display correct password_field html" do
|
462
|
+
actual_html = standard_builder.password_field(:code, :class => 'large')
|
463
|
+
assert_has_tag('input.large[type=password]', :id => 'user_code', :name => 'user[code]') { actual_html }
|
464
|
+
end
|
465
|
+
|
466
|
+
should "display correct password_field in haml" do
|
467
|
+
visit '/haml/form_for'
|
468
|
+
assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
|
469
|
+
assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
|
470
|
+
end
|
471
|
+
|
472
|
+
should "display correct password_field in erb" do
|
473
|
+
visit '/erb/form_for'
|
474
|
+
assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
|
475
|
+
assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
|
476
|
+
end
|
477
|
+
|
478
|
+
should "display correct password_field in slim" do
|
479
|
+
visit '/slim/form_for'
|
480
|
+
assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
|
481
|
+
assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
context 'for #file_field method' do
|
486
|
+
should "display correct file_field html" do
|
487
|
+
actual_html = standard_builder.file_field(:photo, :class => 'large')
|
488
|
+
assert_has_tag('input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
|
489
|
+
end
|
490
|
+
|
491
|
+
should "display correct file_field in haml" do
|
492
|
+
visit '/haml/form_for'
|
493
|
+
assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
494
|
+
assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
495
|
+
end
|
496
|
+
|
497
|
+
should "display correct file_field in erb" do
|
498
|
+
visit '/erb/form_for'
|
499
|
+
assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
500
|
+
assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
501
|
+
end
|
502
|
+
|
503
|
+
should "display correct file_field in slim" do
|
504
|
+
visit '/slim/form_for'
|
505
|
+
assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
506
|
+
assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
context 'for #select method' do
|
511
|
+
should "display correct select html" do
|
512
|
+
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :class => 'selecty')
|
513
|
+
assert_has_tag('select.selecty', :id => 'user_state', :name => 'user[state]') { actual_html }
|
514
|
+
assert_has_tag('select.selecty option', :count => 3) { actual_html }
|
515
|
+
assert_has_tag('select.selecty option', :value => 'California', :content => 'California') { actual_html }
|
516
|
+
assert_has_tag('select.selecty option', :value => 'Texas', :content => 'Texas') { actual_html }
|
517
|
+
assert_has_tag('select.selecty option', :value => 'Wyoming', :content => 'Wyoming') { actual_html }
|
518
|
+
end
|
519
|
+
|
520
|
+
should "display correct select html with selected item if it matches value" do
|
521
|
+
@user.stubs(:state => 'California')
|
522
|
+
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'])
|
523
|
+
assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
|
524
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
525
|
+
assert_has_tag('select option', :value => 'California', :selected => 'selected') { actual_html }
|
526
|
+
end
|
527
|
+
|
528
|
+
should "display correct select html with selected item if it matches full value" do
|
529
|
+
@user.stubs(:state => 'Cali')
|
530
|
+
actual_html = standard_builder.select(:state, :options => ['Cali', 'California', 'Texas', 'Wyoming'])
|
531
|
+
assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
|
532
|
+
assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
|
533
|
+
assert_has_tag('select option', :value => 'Cali', :selected => 'selected') { actual_html }
|
534
|
+
assert_has_tag('select option', :value => 'California') { actual_html }
|
535
|
+
end
|
536
|
+
|
537
|
+
should "display correct select html with multiple selected items" do
|
538
|
+
@user.stubs(:pickles => ['foo', 'bar'])
|
539
|
+
actual_html = standard_builder.select(
|
540
|
+
:pickles, :options => [ ['Foo', 'foo'], ['Bar', 'bar'], ['Baz', 'baz'], ['Bar Buz', 'bar buz'] ]
|
541
|
+
)
|
542
|
+
assert_has_tag('option', :value => 'foo', :content => 'Foo', :selected => 'selected') { actual_html }
|
543
|
+
assert_has_tag('option', :value => 'bar', :content => 'Bar', :selected => 'selected') { actual_html }
|
544
|
+
assert_has_tag('option', :value => 'baz', :content => 'Baz') { actual_html }
|
545
|
+
assert_has_tag('option', :value => 'bar buz', :content => 'Bar Buz') { actual_html }
|
546
|
+
end
|
547
|
+
|
548
|
+
should "display correct select html with include_blank" do
|
549
|
+
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => true)
|
550
|
+
assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
|
551
|
+
assert_has_tag('select option', :count => 4) { actual_html }
|
552
|
+
assert_has_tag('select option:first-child', :content => '') { actual_html }
|
553
|
+
assert_has_tag('select option:first-child', :value => '') { actual_html }
|
554
|
+
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => 'Select')
|
555
|
+
assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
|
556
|
+
assert_has_tag('select option', :count => 4) { actual_html }
|
557
|
+
assert_has_tag('select option:first-child', :content => 'Select') { actual_html }
|
558
|
+
assert_has_tag('select option:first-child', :value => '') { actual_html }
|
559
|
+
end
|
560
|
+
|
561
|
+
should "display correct select html with collection passed in" do
|
562
|
+
actual_html = standard_builder.select(:role, :collection => @user.role_types, :fields => [:name, :id])
|
563
|
+
assert_has_tag('select', :id => 'user_role', :name => 'user[role]') { actual_html }
|
564
|
+
assert_has_tag('select option', :count => 3) { actual_html }
|
565
|
+
assert_has_tag('select option', :value => '1', :content => 'Admin', :selected => 'selected') { actual_html }
|
566
|
+
assert_has_tag('select option', :value => '2', :content => 'Moderate') { actual_html }
|
567
|
+
assert_has_tag('select option', :value => '3', :content => 'Limited') { actual_html }
|
568
|
+
end
|
569
|
+
|
570
|
+
should "display correct select in haml" do
|
571
|
+
visit '/haml/form_for'
|
572
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
573
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
574
|
+
end
|
575
|
+
|
576
|
+
should "display correct select in erb" do
|
577
|
+
visit '/erb/form_for'
|
578
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
579
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
580
|
+
end
|
581
|
+
|
582
|
+
should "display correct select in slim" do
|
583
|
+
visit '/slim/form_for'
|
584
|
+
assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
|
585
|
+
assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
context 'for #submit method' do
|
590
|
+
should "display correct submit button html with no options" do
|
591
|
+
actual_html = standard_builder.submit
|
592
|
+
assert_has_tag('input[type=submit]', :value => "Submit") { actual_html }
|
593
|
+
end
|
594
|
+
|
595
|
+
should "display correct submit button html" do
|
596
|
+
actual_html = standard_builder.submit("Commit", :class => 'large')
|
597
|
+
assert_has_tag('input.large[type=submit]', :value => "Commit") { actual_html }
|
598
|
+
end
|
599
|
+
|
600
|
+
should "display correct submit button in haml" do
|
601
|
+
visit '/haml/form_for'
|
602
|
+
assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
|
603
|
+
assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
|
604
|
+
end
|
605
|
+
|
606
|
+
should "display correct submit button in erb" do
|
607
|
+
visit '/erb/form_for'
|
608
|
+
assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
|
609
|
+
assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
|
610
|
+
end
|
611
|
+
|
612
|
+
should "display correct submit button in slim" do
|
613
|
+
visit '/slim/form_for'
|
614
|
+
assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
|
615
|
+
assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
context 'for #image_submit method' do
|
620
|
+
setup do
|
621
|
+
@stamp = stop_time_for_test.to_i
|
622
|
+
end
|
623
|
+
|
624
|
+
should "display correct image submit button html with no options" do
|
625
|
+
actual_html = standard_builder.image_submit('buttons/ok.png')
|
626
|
+
assert_has_tag('input[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
|
627
|
+
end
|
628
|
+
|
629
|
+
should "display correct image submit button html" do
|
630
|
+
actual_html = standard_builder.image_submit('/system/ok.png', :class => 'large')
|
631
|
+
assert_has_tag('input.large[type=image]', :src => "/system/ok.png?#{@stamp}") { actual_html }
|
632
|
+
end
|
633
|
+
|
634
|
+
should "display correct image submit button in haml" do
|
635
|
+
visit '/haml/form_for'
|
636
|
+
assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
|
637
|
+
assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
638
|
+
end
|
639
|
+
|
640
|
+
should "display correct image submit button in erb" do
|
641
|
+
visit '/erb/form_for'
|
642
|
+
assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
|
643
|
+
assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
644
|
+
end
|
645
|
+
|
646
|
+
should "display correct image submit button in slim" do
|
647
|
+
visit '/slim/form_for'
|
648
|
+
assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
|
649
|
+
assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
context 'for #fields_for method' do
|
654
|
+
setup do
|
655
|
+
@telephone = mock_model("Telephone", :number => "4568769876")
|
656
|
+
@user.stubs(:telephone).returns(@telephone)
|
657
|
+
@businesses = [ mock_model("Business", :name => "Silver", :new_record? => false, :id => 20) ]
|
658
|
+
@businesses << mock_model("Business", :name => "Gold", :new_record? => true)
|
659
|
+
@addresses = [ mock_model("Address", :name => "Foo", :new_record? => false, :id => 20, :businesses => @businesses) ]
|
660
|
+
@addresses << mock_model("Address", :name => "Bar", :new_record? => true, :businesses => @businesses)
|
661
|
+
@user.stubs(:addresses).returns(@addresses)
|
662
|
+
end
|
663
|
+
|
664
|
+
should "display nested children fields one-to-one within form" do
|
665
|
+
actual_html = standard_builder.fields_for :telephone do |child_form|
|
666
|
+
child_form.label(:number) +
|
667
|
+
child_form.text_field(:number) +
|
668
|
+
child_form.check_box('_destroy')
|
669
|
+
end
|
670
|
+
assert_has_tag('label', :for => 'user_telephone_attributes_number') { actual_html }
|
671
|
+
assert_has_tag('input', :type => 'text', :id => 'user_telephone_attributes_number', :name => 'user[telephone_attributes][number]', :value => "4568769876") { actual_html }
|
672
|
+
assert_has_tag('input', :type => 'hidden', :name => 'user[telephone_attributes][_destroy]', :value => '0') { actual_html }
|
673
|
+
assert_has_tag('input', :type => 'checkbox', :id => 'user_telephone_attributes__destroy', :name => 'user[telephone_attributes][_destroy]', :value => '1') { actual_html }
|
674
|
+
end
|
675
|
+
|
676
|
+
should "display nested children fields one-to-many within form" do
|
677
|
+
actual_html = standard_builder.fields_for(:addresses) do |child_form|
|
678
|
+
html = child_form.label(:name)
|
679
|
+
html << child_form.check_box('_destroy') unless child_form.object.new_record?
|
680
|
+
html << child_form.text_field(:name)
|
681
|
+
end
|
682
|
+
# Address 1 (Saved)
|
683
|
+
assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
|
684
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
|
685
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]') { actual_html }
|
686
|
+
assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
|
687
|
+
# Address 2 (New)
|
688
|
+
assert_has_no_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_1_id') { actual_html }
|
689
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_1_name', :content => 'Name') { actual_html }
|
690
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_name', :name => 'user[addresses_attributes][1][name]') { actual_html }
|
691
|
+
assert_has_no_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_1__destroy') { actual_html }
|
692
|
+
end
|
693
|
+
|
694
|
+
should "display fields for explicit instance object" do
|
695
|
+
address = mock_model("Address", :name => "Page", :new_record? => false, :id => 40)
|
696
|
+
actual_html = standard_builder.fields_for(:addresses, address) do |child_form|
|
697
|
+
html = child_form.label(:name)
|
698
|
+
html << child_form.text_field(:name)
|
699
|
+
html << child_form.check_box('_destroy')
|
700
|
+
end
|
701
|
+
assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '40') { actual_html }
|
702
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
|
703
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Page") { actual_html }
|
704
|
+
assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]', :value => '1') { actual_html }
|
705
|
+
end
|
706
|
+
|
707
|
+
should "display fields for collection object" do
|
708
|
+
addresses = @addresses + [mock_model("Address", :name => "Walter", :new_record? => false, :id => 50)]
|
709
|
+
actual_html = standard_builder.fields_for(:addresses, addresses) do |child_form|
|
710
|
+
child_form.label(:name) +
|
711
|
+
child_form.text_field(:name) +
|
712
|
+
child_form.check_box('_destroy')
|
713
|
+
end
|
714
|
+
# Address 1
|
715
|
+
assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
|
716
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
|
717
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Foo") { actual_html }
|
718
|
+
assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
|
719
|
+
# Address 3
|
720
|
+
assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_2_id', :value => '50') { actual_html }
|
721
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_2_name', :content => 'Name') { actual_html }
|
722
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_2_name', :name => 'user[addresses_attributes][2][name]', :value => "Walter") { actual_html }
|
723
|
+
assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_2__destroy') { actual_html }
|
724
|
+
end
|
725
|
+
|
726
|
+
should "display fields for arbitrarily deep nested forms" do
|
727
|
+
actual_html = standard_builder.fields_for :addresses do |child_form|
|
728
|
+
child_form.fields_for(:businesses) do |second_child_form|
|
729
|
+
second_child_form.label(:name) +
|
730
|
+
second_child_form.text_field(:name) +
|
731
|
+
second_child_form.check_box('_destroy')
|
732
|
+
end
|
733
|
+
end
|
734
|
+
assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_0_name', :content => 'Name') { actual_html }
|
735
|
+
assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_0_name', :name => 'user[addresses_attributes][1][businesses_attributes][0][name]') { actual_html }
|
736
|
+
end
|
737
|
+
|
738
|
+
should "display nested children fields in erb" do
|
739
|
+
visit '/erb/fields_for'
|
740
|
+
# Telephone
|
741
|
+
assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
|
742
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
|
743
|
+
# Address 1 (Saved)
|
744
|
+
assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
|
745
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
|
746
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
|
747
|
+
assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
|
748
|
+
# Address 2 (New)
|
749
|
+
assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
|
750
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
|
751
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
|
752
|
+
assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
|
753
|
+
end
|
754
|
+
|
755
|
+
should "display nested children fields in haml" do
|
756
|
+
visit '/haml/fields_for'
|
757
|
+
# Telephone
|
758
|
+
assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
|
759
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
|
760
|
+
# Address 1 (Saved)
|
761
|
+
assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
|
762
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
|
763
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
|
764
|
+
assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
|
765
|
+
# Address 2 (New)
|
766
|
+
assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
|
767
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
|
768
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
|
769
|
+
assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
|
770
|
+
end
|
771
|
+
|
772
|
+
should "display nested children fields in slim" do
|
773
|
+
visit '/slim/fields_for'
|
774
|
+
# Telephone
|
775
|
+
assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
|
776
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
|
777
|
+
# Address 1 (Saved)
|
778
|
+
assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
|
779
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
|
780
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
|
781
|
+
assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
|
782
|
+
# Address 2 (New)
|
783
|
+
assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
|
784
|
+
assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
|
785
|
+
assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
|
786
|
+
assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
|
787
|
+
end
|
788
|
+
end
|
789
|
+
|
790
|
+
# ===========================
|
791
|
+
# StandardFormBuilder
|
792
|
+
# ===========================
|
793
|
+
|
794
|
+
context 'for #text_field_block method' do
|
795
|
+
should "display correct text field block html" do
|
796
|
+
actual_html = standard_builder.text_field_block(:first_name, :class => 'large', :caption => "FName")
|
797
|
+
assert_has_tag('p label', :for => 'user_first_name', :content => "FName") { actual_html }
|
798
|
+
assert_has_tag('p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
|
799
|
+
end
|
800
|
+
|
801
|
+
should "display correct text field block in haml" do
|
802
|
+
visit '/haml/form_for'
|
803
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
|
804
|
+
assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
|
805
|
+
end
|
806
|
+
|
807
|
+
should "display correct text field block in erb" do
|
808
|
+
visit '/erb/form_for'
|
809
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
|
810
|
+
assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
|
811
|
+
end
|
812
|
+
|
813
|
+
should "display correct text field block in slim" do
|
814
|
+
visit '/slim/form_for'
|
815
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
|
816
|
+
assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
|
817
|
+
end
|
818
|
+
end
|
819
|
+
|
820
|
+
context 'for #text_area_block method' do
|
821
|
+
should "display correct text area block html" do
|
822
|
+
actual_html = standard_builder.text_area_block(:about, :class => 'large', :caption => "About Me")
|
823
|
+
assert_has_tag('p label', :for => 'user_about', :content => "About Me") { actual_html }
|
824
|
+
assert_has_tag('p textarea', :id => 'user_about', :name => 'user[about]') { actual_html }
|
825
|
+
end
|
826
|
+
|
827
|
+
should "display correct text area block in haml" do
|
828
|
+
visit '/haml/form_for'
|
829
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
|
830
|
+
assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
|
831
|
+
end
|
832
|
+
|
833
|
+
should "display correct text area block in erb" do
|
834
|
+
visit '/erb/form_for'
|
835
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
|
836
|
+
assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
|
837
|
+
end
|
838
|
+
|
839
|
+
should "display correct text area block in slim" do
|
840
|
+
visit '/slim/form_for'
|
841
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
|
842
|
+
assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
context 'for #password_field_block method' do
|
847
|
+
should "display correct password field block html" do
|
848
|
+
actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code: ")
|
849
|
+
assert_has_tag('p label', :for => 'user_keycode', :content => "Code: ") { actual_html }
|
850
|
+
assert_has_tag('p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]') { actual_html }
|
851
|
+
end
|
852
|
+
|
853
|
+
should "display correct password field block in haml" do
|
854
|
+
visit '/haml/form_for'
|
855
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
|
856
|
+
assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
|
857
|
+
end
|
858
|
+
|
859
|
+
should "display correct password field block in erb" do
|
860
|
+
visit '/erb/form_for'
|
861
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
|
862
|
+
assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
|
863
|
+
end
|
864
|
+
|
865
|
+
should "display correct password field block in slim" do
|
866
|
+
visit '/slim/form_for'
|
867
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
|
868
|
+
assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
|
869
|
+
end
|
870
|
+
end
|
871
|
+
|
872
|
+
context 'for #file_field_block method' do
|
873
|
+
should "display correct file field block html" do
|
874
|
+
actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo: ")
|
875
|
+
assert_has_tag('p label', :for => 'user_photo', :content => "Photo: ") { actual_html }
|
876
|
+
assert_has_tag('p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
|
877
|
+
end
|
878
|
+
|
879
|
+
should "display correct file field block in haml" do
|
880
|
+
visit '/haml/form_for'
|
881
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
|
882
|
+
assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
883
|
+
end
|
884
|
+
|
885
|
+
should "display correct file field block in erb" do
|
886
|
+
visit '/erb/form_for'
|
887
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
|
888
|
+
assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
889
|
+
end
|
890
|
+
|
891
|
+
should "display correct file field block in slim" do
|
892
|
+
visit '/slim/form_for'
|
893
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
|
894
|
+
assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
|
895
|
+
end
|
896
|
+
end
|
897
|
+
|
898
|
+
context 'for #check_box_block method' do
|
899
|
+
should "display correct check box block html" do
|
900
|
+
actual_html = standard_builder.check_box_block(:remember_me, :class => 'large', :caption => "Remember session?")
|
901
|
+
assert_has_tag('p label', :for => 'user_remember_me', :content => "Remember session?") { actual_html }
|
902
|
+
assert_has_tag('p input.large[type=checkbox]', :id => 'user_remember_me', :name => 'user[remember_me]') { actual_html }
|
903
|
+
end
|
904
|
+
|
905
|
+
should "display correct check box block in haml" do
|
906
|
+
visit '/haml/form_for'
|
907
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
|
908
|
+
assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
|
909
|
+
end
|
910
|
+
|
911
|
+
should "display correct check box block in erb" do
|
912
|
+
visit '/erb/form_for'
|
913
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
|
914
|
+
assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
|
915
|
+
end
|
916
|
+
|
917
|
+
should "display correct check box block in slim" do
|
918
|
+
visit '/slim/form_for'
|
919
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
|
920
|
+
assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
|
921
|
+
end
|
922
|
+
end
|
923
|
+
|
924
|
+
context 'for #select_block method' do
|
925
|
+
should "display correct select_block block html" do
|
926
|
+
actual_html = standard_builder.select_block(:country, :options => ['USA', 'Canada'], :class => 'large', :caption => "Your country")
|
927
|
+
assert_has_tag('p label', :for => 'user_country', :content => "Your country") { actual_html }
|
928
|
+
assert_has_tag('p select', :id => 'user_country', :name => 'user[country]') { actual_html }
|
929
|
+
assert_has_tag('p select option', :content => 'USA') { actual_html }
|
930
|
+
assert_has_tag('p select option', :content => 'Canada') { actual_html }
|
931
|
+
end
|
932
|
+
|
933
|
+
should "display correct select_block block in haml" do
|
934
|
+
visit '/haml/form_for'
|
935
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
|
936
|
+
assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
|
937
|
+
assert_have_selector '#demo2 p select option', :content => 'California'
|
938
|
+
assert_have_selector '#demo2 p select option', :content => 'Texas'
|
939
|
+
end
|
940
|
+
|
941
|
+
should "display correct select_block block in erb" do
|
942
|
+
visit '/erb/form_for'
|
943
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
|
944
|
+
assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
|
945
|
+
end
|
946
|
+
|
947
|
+
should "display correct select_block block in slim" do
|
948
|
+
visit '/slim/form_for'
|
949
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
|
950
|
+
assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
|
951
|
+
end
|
952
|
+
end
|
953
|
+
|
954
|
+
context 'for #submit_block method' do
|
955
|
+
should "display correct submit block html" do
|
956
|
+
actual_html = standard_builder.submit_block("Update", :class => 'large')
|
957
|
+
assert_has_tag('p input.large[type=submit]', :value => 'Update') { actual_html }
|
958
|
+
end
|
959
|
+
|
960
|
+
should "display correct submit block in haml" do
|
961
|
+
visit '/haml/form_for'
|
962
|
+
assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
|
963
|
+
end
|
964
|
+
|
965
|
+
should "display correct submit block in erb" do
|
966
|
+
visit '/erb/form_for'
|
967
|
+
assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
|
968
|
+
end
|
969
|
+
|
970
|
+
should "display correct submit block in slim" do
|
971
|
+
visit '/slim/form_for'
|
972
|
+
assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
|
973
|
+
end
|
974
|
+
end
|
975
|
+
|
976
|
+
context 'for #image_submit_block method' do
|
977
|
+
setup do
|
978
|
+
@stamp = stop_time_for_test.to_i
|
979
|
+
end
|
980
|
+
|
981
|
+
should "display correct image submit block html" do
|
982
|
+
actual_html = standard_builder.image_submit_block("buttons/ok.png", :class => 'large')
|
983
|
+
assert_has_tag('p input.large[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
|
984
|
+
end
|
985
|
+
|
986
|
+
should "display correct image submit block in haml" do
|
987
|
+
visit '/haml/form_for'
|
988
|
+
assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
989
|
+
end
|
990
|
+
|
991
|
+
should "display correct image submit block in slim" do
|
992
|
+
visit '/slim/form_for'
|
993
|
+
assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
994
|
+
end
|
995
|
+
end
|
996
|
+
end
|