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