padrino-helpers 0.16.0.pre4 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +29 -29
- data/Rakefile +1 -1
- data/lib/padrino/rendering/erb_template.rb +7 -7
- data/lib/padrino/rendering/erubi_template.rb +4 -4
- data/lib/padrino/rendering/erubis_template.rb +4 -4
- data/lib/padrino/rendering/haml_template.rb +1 -1
- data/lib/padrino/rendering/hamlit_template.rb +4 -4
- data/lib/padrino/rendering/slim_template.rb +5 -5
- data/lib/padrino/rendering.rb +54 -45
- data/lib/padrino/safe_buffer.rb +31 -36
- data/lib/padrino-helpers/asset_tag_helpers.rb +48 -48
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +74 -70
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +20 -20
- data/lib/padrino-helpers/form_helpers/errors.rb +14 -14
- data/lib/padrino-helpers/form_helpers/options.rb +25 -24
- data/lib/padrino-helpers/form_helpers/security.rb +5 -5
- data/lib/padrino-helpers/form_helpers.rb +133 -133
- data/lib/padrino-helpers/format_helpers.rb +61 -63
- data/lib/padrino-helpers/number_helpers.rb +82 -78
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +5 -3
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +2 -2
- data/lib/padrino-helpers/output_helpers/haml_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers.rb +16 -17
- data/lib/padrino-helpers/render_helpers.rb +28 -27
- data/lib/padrino-helpers/tag_helpers.rb +62 -58
- data/lib/padrino-helpers/translation_helpers.rb +2 -2
- data/lib/padrino-helpers.rb +1 -2
- data/padrino-helpers.gemspec +17 -17
- data/test/fixtures/apps/render.rb +2 -2
- data/test/fixtures/markup_app/app.rb +9 -8
- data/test/fixtures/markup_app/views/button_to.erb +3 -3
- data/test/fixtures/markup_app/views/button_to.haml +2 -2
- data/test/fixtures/markup_app/views/button_to.slim +3 -3
- data/test/fixtures/markup_app/views/content_for.erb +4 -4
- data/test/fixtures/markup_app/views/content_for.haml +4 -4
- data/test/fixtures/markup_app/views/content_for.slim +2 -2
- data/test/fixtures/markup_app/views/content_tag.erb +3 -3
- data/test/fixtures/markup_app/views/content_tag.haml +3 -3
- data/test/fixtures/markup_app/views/content_tag.slim +3 -3
- data/test/fixtures/markup_app/views/fields_for.erb +2 -2
- data/test/fixtures/markup_app/views/fields_for.haml +2 -2
- data/test/fixtures/markup_app/views/fields_for.slim +2 -2
- data/test/fixtures/markup_app/views/form_for.erb +41 -41
- data/test/fixtures/markup_app/views/form_for.haml +41 -41
- data/test/fixtures/markup_app/views/form_for.slim +41 -42
- data/test/fixtures/markup_app/views/form_tag.erb +47 -47
- data/test/fixtures/markup_app/views/form_tag.haml +48 -48
- data/test/fixtures/markup_app/views/form_tag.slim +49 -49
- data/test/fixtures/markup_app/views/link_to.erb +2 -2
- data/test/fixtures/markup_app/views/link_to.haml +2 -2
- data/test/fixtures/markup_app/views/link_to.slim +2 -2
- data/test/fixtures/markup_app/views/meta_tag.erb +2 -2
- data/test/fixtures/markup_app/views/meta_tag.haml +2 -2
- data/test/fixtures/markup_app/views/meta_tag.slim +2 -2
- data/test/fixtures/markup_app/views/simple_partial.erb +1 -1
- data/test/fixtures/markup_app/views/simple_partial.haml +1 -1
- data/test/fixtures/markup_app/views/simple_partial.slim +1 -1
- data/test/fixtures/render_app/app.rb +13 -12
- data/test/fixtures/render_app/views/_unsafe.html.builder +1 -1
- data/test/fixtures/render_app/views/_unsafe_object.html.builder +1 -1
- data/test/fixtures/render_app/views/explicit_engine.haml +3 -3
- data/test/helper.rb +19 -19
- data/test/test_asset_tag_helpers.rb +133 -133
- data/test/test_form_builder.rb +629 -628
- data/test/test_form_helpers.rb +610 -610
- data/test/test_format_helpers.rb +66 -63
- data/test/test_helpers.rb +2 -2
- data/test/test_locale.rb +13 -11
- data/test/test_number_helpers.rb +65 -65
- data/test/test_output_helpers.rb +76 -76
- data/test/test_render_helpers.rb +101 -101
- data/test/test_rendering.rb +329 -326
- data/test/test_rendering_extensions.rb +4 -4
- data/test/test_tag_helpers.rb +55 -55
- metadata +6 -6
data/test/test_form_builder.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/markup_app/app'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe 'FormBuilder' do
|
|
5
5
|
include Padrino::Helpers::FormHelpers
|
|
6
6
|
|
|
7
7
|
def app
|
|
@@ -11,100 +11,104 @@ describe "FormBuilder" do
|
|
|
11
11
|
# Dummy form builder for testing
|
|
12
12
|
module Padrino::Helpers::FormBuilder
|
|
13
13
|
class FakeFormBuilder < AbstractFormBuilder
|
|
14
|
-
def foo_field; @template.content_tag(:span,
|
|
14
|
+
def foo_field; @template.content_tag(:span, 'bar'); end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def setup
|
|
19
|
-
role_types = [
|
|
20
|
-
mock_model('Role', :
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
role_types = [
|
|
20
|
+
mock_model('Role', name: 'Admin', id: 1),
|
|
21
|
+
mock_model('Role', name: 'Moderate', id: 2),
|
|
22
|
+
mock_model('Role', name: 'Limited', id: 3)
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
@user = mock_model('User', first_name: 'Joe', email: '', session_id: 54)
|
|
26
|
+
@user.stubs(errors: { a: 'must be present', b: 'must be valid', email: 'Must be valid', first_name: [] })
|
|
27
|
+
@user.stubs(role_types: role_types, role: '1', roles: [1, 3])
|
|
28
|
+
@user_none = mock_model('User')
|
|
25
29
|
end
|
|
26
30
|
|
|
27
|
-
def standard_builder(object
|
|
31
|
+
def standard_builder(object = @user)
|
|
28
32
|
Padrino::Helpers::FormBuilder::StandardFormBuilder.new(self, object)
|
|
29
33
|
end
|
|
30
34
|
|
|
31
35
|
describe 'for #form_for method' do
|
|
32
36
|
it 'should display correct form html' do
|
|
33
|
-
actual_html = form_for(@user, '/register', :
|
|
34
|
-
assert_html_has_tag(actual_html, 'form',
|
|
35
|
-
assert_html_has_tag(actual_html, 'form input[type=hidden]', :
|
|
37
|
+
actual_html = form_for(@user, '/register', id: 'register', "accept-charset": 'UTF-8', method: 'post') { 'Demo' }
|
|
38
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', id: 'register', method: 'post', content: 'Demo')
|
|
39
|
+
assert_html_has_tag(actual_html, 'form input[type=hidden]', name: '_method', count: 0) # no method action field
|
|
36
40
|
end
|
|
37
41
|
|
|
38
42
|
it 'should display correct form html with fake object' do
|
|
39
|
-
actual_html = form_for(:markup_user, '/register', :
|
|
40
|
-
assert_html_has_tag(actual_html, 'form',
|
|
41
|
-
assert_html_has_tag(actual_html, 'form input', :
|
|
42
|
-
assert_html_has_tag(actual_html, 'form input[type=hidden]', :
|
|
43
|
+
actual_html = form_for(:markup_user, '/register', id: 'register', "accept-charset": 'UTF-8', method: 'post') { |f| f.text_field :username }
|
|
44
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', id: 'register', method: 'post')
|
|
45
|
+
assert_html_has_tag(actual_html, 'form input', type: 'text', name: 'markup_user[username]')
|
|
46
|
+
assert_html_has_tag(actual_html, 'form input[type=hidden]', name: '_method', count: 0) # no method action field
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
it 'should display correct form html for namespaced object' do
|
|
46
|
-
actual_html = form_for(Outer::UserAccount.new, '/register',
|
|
47
|
-
assert_html_has_tag(actual_html, 'form',
|
|
48
|
-
assert_html_has_tag(actual_html, 'form input', :
|
|
50
|
+
actual_html = form_for(Outer::UserAccount.new, '/register', "accept-charset": 'UTF-8', method: 'post') { |f| f.text_field :username }
|
|
51
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', method: 'post')
|
|
52
|
+
assert_html_has_tag(actual_html, 'form input', type: 'text', name: 'outer_user_account[username]')
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
it 'should display form specifying default builder setting' do
|
|
52
|
-
self.expects(:settings).returns(stub(:
|
|
53
|
-
actual_html = form_for(@user, '/register', :
|
|
54
|
-
assert_html_has_tag(actual_html, 'form',
|
|
55
|
-
assert_html_has_tag(actual_html, 'span', :
|
|
56
|
+
self.expects(:settings).returns(stub(default_builder: 'FakeFormBuilder', protect_from_csrf: false)).at_least_once
|
|
57
|
+
actual_html = form_for(@user, '/register', id: 'register', "accept-charset": 'UTF-8', method: 'post', &:foo_field)
|
|
58
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', method: 'post')
|
|
59
|
+
assert_html_has_tag(actual_html, 'span', content: 'bar')
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
it 'should display correct form html with remote option' do
|
|
59
|
-
actual_html = form_for(@user, '/update',
|
|
60
|
-
assert_html_has_tag(actual_html, 'form',
|
|
63
|
+
actual_html = form_for(@user, '/update', 'accept-charset' => 'UTF-8', remote: true) { 'Demo' }
|
|
64
|
+
assert_html_has_tag(actual_html, 'form', 'accept-charset' => 'UTF-8', action: '/update', method: 'post', 'data-remote' => 'true')
|
|
61
65
|
end
|
|
62
66
|
|
|
63
67
|
it 'should display correct form html with namespace option' do
|
|
64
|
-
actual_html = form_for(@user, '/update', :
|
|
68
|
+
actual_html = form_for(@user, '/update', namespace: 'foo') do |f|
|
|
65
69
|
f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
|
|
66
70
|
end
|
|
67
71
|
|
|
68
|
-
assert_html_has_no_tag(actual_html, :form, :
|
|
69
|
-
assert_html_has_tag(actual_html, :input, :
|
|
70
|
-
assert_html_has_tag(actual_html, :input, :
|
|
72
|
+
assert_html_has_no_tag(actual_html, :form, namespace: 'foo')
|
|
73
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'user[first_name]', id: 'foo_user_first_name')
|
|
74
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'user[role_types_attributes][0][name]', id: 'foo_user_role_types_attributes_0_name')
|
|
71
75
|
end
|
|
72
76
|
|
|
73
77
|
it 'should display correct form html with :as option' do
|
|
74
|
-
actual_html = form_for(@user, '/update', :
|
|
78
|
+
actual_html = form_for(@user, '/update', as: :customer) do |f|
|
|
75
79
|
f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
|
|
76
80
|
end
|
|
77
81
|
|
|
78
|
-
assert_html_has_no_tag(actual_html, :form, :
|
|
79
|
-
assert_html_has_tag(actual_html, :input, :
|
|
80
|
-
assert_html_has_tag(actual_html, :input, :
|
|
82
|
+
assert_html_has_no_tag(actual_html, :form, as: 'customer')
|
|
83
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'customer[first_name]', id: 'customer_first_name')
|
|
84
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'customer[role_types_attributes][0][name]', id: 'customer_role_types_attributes_0_name')
|
|
81
85
|
end
|
|
82
86
|
|
|
83
87
|
it 'should display correct form html with remote option and method put' do
|
|
84
|
-
actual_html = form_for(@user, '/update',
|
|
85
|
-
assert_html_has_tag(actual_html, 'form',
|
|
86
|
-
assert_html_has_tag(actual_html, 'form input', :
|
|
88
|
+
actual_html = form_for(@user, '/update', 'accept-charset' => 'UTF-8', remote: true, method: 'put') { 'Demo' }
|
|
89
|
+
assert_html_has_tag(actual_html, 'form', 'accept-charset' => 'UTF-8', method: 'post', 'data-remote' => 'true')
|
|
90
|
+
assert_html_has_tag(actual_html, 'form input', type: 'hidden', name: '_method', value: 'put')
|
|
87
91
|
end
|
|
88
92
|
|
|
89
93
|
it 'should display correct form html with method :put' do
|
|
90
|
-
actual_html = form_for(@user, '/update',
|
|
91
|
-
assert_html_has_tag(actual_html, 'form',
|
|
92
|
-
assert_html_has_tag(actual_html, 'form input', :
|
|
94
|
+
actual_html = form_for(@user, '/update', "accept-charset": 'UTF-8', method: 'put') { 'Demo' }
|
|
95
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/update', method: 'post')
|
|
96
|
+
assert_html_has_tag(actual_html, 'form input', type: 'hidden', name: '_method', value: 'put')
|
|
93
97
|
end
|
|
94
98
|
|
|
95
99
|
it 'should display correct form html with method :delete' do
|
|
96
|
-
actual_html = form_for(@user, '/destroy',
|
|
97
|
-
assert_html_has_tag(actual_html, 'form',
|
|
98
|
-
assert_html_has_tag(actual_html, 'form input', :
|
|
100
|
+
actual_html = form_for(@user, '/destroy', "accept-charset": 'UTF-8', method: 'delete') { 'Demo' }
|
|
101
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/destroy', method: 'post')
|
|
102
|
+
assert_html_has_tag(actual_html, 'form input', type: 'hidden', name: '_method', value: 'delete')
|
|
99
103
|
end
|
|
100
104
|
|
|
101
105
|
it 'should display correct form html with multipart' do
|
|
102
|
-
actual_html = form_for(@user, '/register',
|
|
103
|
-
assert_html_has_tag(actual_html, 'form',
|
|
106
|
+
actual_html = form_for(@user, '/register', "accept-charset": 'UTF-8', multipart: true) { 'Demo' }
|
|
107
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', enctype: 'multipart/form-data')
|
|
104
108
|
end
|
|
105
109
|
|
|
106
110
|
it 'should support changing form builder type' do
|
|
107
|
-
form_html = proc { form_for(@user, '/register',
|
|
111
|
+
form_html = proc { form_for(@user, '/register', "accept-charset": 'UTF-8', builder: 'AbstractFormBuilder') { |f| f.text_field_block(:name) } }
|
|
108
112
|
assert_raises(NoMethodError) { form_html.call }
|
|
109
113
|
end
|
|
110
114
|
|
|
@@ -114,91 +118,91 @@ describe "FormBuilder" do
|
|
|
114
118
|
end
|
|
115
119
|
|
|
116
120
|
it 'should display fail for form with nil object' do
|
|
117
|
-
assert_raises(RuntimeError) { form_for(@not_real, '/register', :
|
|
121
|
+
assert_raises(RuntimeError) { form_for(@not_real, '/register', id: 'register', method: 'post') { 'Demo' } }
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
it 'should display correct form in haml' do
|
|
121
|
-
get
|
|
122
|
-
assert_response_has_tag :form, :
|
|
123
|
-
assert_response_has_tag :form, :
|
|
124
|
-
assert_response_has_tag :form, :
|
|
125
|
-
assert_response_has_tag :input, :
|
|
125
|
+
get '/haml/form_for'
|
|
126
|
+
assert_response_has_tag :form, action: '/demo', id: 'demo'
|
|
127
|
+
assert_response_has_tag :form, action: '/another_demo', id: 'demo2', method: 'get'
|
|
128
|
+
assert_response_has_tag :form, action: '/third_demo', id: 'demo3', method: 'get'
|
|
129
|
+
assert_response_has_tag :input, name: 'authenticity_token'
|
|
126
130
|
end
|
|
127
131
|
|
|
128
132
|
it 'should display correct form in erb' do
|
|
129
|
-
get
|
|
130
|
-
assert_response_has_tag :form, :
|
|
131
|
-
assert_response_has_tag :form, :
|
|
132
|
-
assert_response_has_tag :form, :
|
|
133
|
-
assert_response_has_tag :input, :
|
|
133
|
+
get '/erb/form_for'
|
|
134
|
+
assert_response_has_tag :form, action: '/demo', id: 'demo'
|
|
135
|
+
assert_response_has_tag :form, action: '/another_demo', id: 'demo2', method: 'get'
|
|
136
|
+
assert_response_has_tag :form, action: '/third_demo', id: 'demo3', method: 'get'
|
|
137
|
+
assert_response_has_tag :input, name: 'authenticity_token'
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
it 'should display correct form in slim' do
|
|
137
|
-
get
|
|
138
|
-
assert_response_has_tag :form, :
|
|
139
|
-
assert_response_has_tag :form, :
|
|
140
|
-
assert_response_has_tag :form, :
|
|
141
|
-
assert_response_has_tag :input, :
|
|
141
|
+
get '/slim/form_for'
|
|
142
|
+
assert_response_has_tag :form, action: '/demo', id: 'demo'
|
|
143
|
+
assert_response_has_tag :form, action: '/another_demo', id: 'demo2', method: 'get'
|
|
144
|
+
assert_response_has_tag :form, action: '/third_demo', id: 'demo3', method: 'get'
|
|
145
|
+
assert_response_has_tag :input, name: 'authenticity_token'
|
|
142
146
|
end
|
|
143
147
|
|
|
144
148
|
it 'should have a class of "invalid" for fields with errors' do
|
|
145
|
-
actual_html = form_for(@user, '/register') {|f| f.text_field(:email) }
|
|
146
|
-
assert_html_has_tag(actual_html, :input, :
|
|
149
|
+
actual_html = form_for(@user, '/register') { |f| f.text_field(:email) }
|
|
150
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'user[email]', id: 'user_email', class: 'invalid')
|
|
147
151
|
end
|
|
148
152
|
|
|
149
153
|
it 'should not have a class of "invalid" for fields with no errors' do
|
|
150
|
-
actual_html = form_for(@user, '/register') {|f| f.text_field(:first_name) }
|
|
151
|
-
assert_html_has_no_tag(actual_html, :input, :
|
|
154
|
+
actual_html = form_for(@user, '/register') { |f| f.text_field(:first_name) }
|
|
155
|
+
assert_html_has_no_tag(actual_html, :input, type: 'text', name: 'user[first_name]', id: 'user_first_name', class: 'invalid')
|
|
152
156
|
end
|
|
153
157
|
end
|
|
154
158
|
|
|
155
159
|
describe 'for #fields_for method' do
|
|
156
160
|
it 'should display correct fields html' do
|
|
157
161
|
actual_html = fields_for(@user) { |f| f.text_field(:first_name) }
|
|
158
|
-
assert_html_has_tag(actual_html, :input, :
|
|
162
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'user[first_name]', id: 'user_first_name')
|
|
159
163
|
end
|
|
160
164
|
|
|
161
165
|
it 'should display correct fields html with symbol object' do
|
|
162
166
|
actual_html = fields_for(:markup_user) { |f| f.text_field(:first_name) }
|
|
163
|
-
assert_html_has_tag(actual_html, :input, :
|
|
167
|
+
assert_html_has_tag(actual_html, :input, type: 'text', name: 'markup_user[first_name]', id: 'markup_user_first_name')
|
|
164
168
|
end
|
|
165
169
|
|
|
166
170
|
it 'should display fail for nil object' do
|
|
167
|
-
assert_raises(RuntimeError) { fields_for(@not_real) { |
|
|
171
|
+
assert_raises(RuntimeError) { fields_for(@not_real) { |_f| 'Demo' } }
|
|
168
172
|
end
|
|
169
173
|
|
|
170
174
|
it 'should respect the builder of parent' do
|
|
171
175
|
assert_raises(NoMethodError) do
|
|
172
|
-
form_for(@user, '/register', builder:
|
|
176
|
+
form_for(@user, '/register', builder: 'AbstractFormBuilder') do |f|
|
|
173
177
|
f.fields_for(:role_types, @user.role_types) do |field|
|
|
174
|
-
field.submit_block
|
|
178
|
+
field.submit_block 'Submit'
|
|
175
179
|
end
|
|
176
180
|
end
|
|
177
181
|
end
|
|
178
182
|
end
|
|
179
183
|
|
|
180
184
|
it 'should display correct simple fields in haml' do
|
|
181
|
-
get
|
|
182
|
-
assert_response_has_tag :form, :
|
|
183
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
184
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
185
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
185
|
+
get '/haml/fields_for'
|
|
186
|
+
assert_response_has_tag :form, action: '/demo1', id: 'demo-fields-for'
|
|
187
|
+
assert_response_has_tag '#demo-fields-for input', type: 'text', name: 'markup_user[gender]', value: 'male'
|
|
188
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_edit]', value: '1', checked: 'checked'
|
|
189
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_delete]'
|
|
186
190
|
end
|
|
187
191
|
|
|
188
192
|
it 'should display correct simple fields in erb' do
|
|
189
|
-
get
|
|
190
|
-
assert_response_has_tag :form, :
|
|
191
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
192
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
193
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
193
|
+
get '/erb/fields_for'
|
|
194
|
+
assert_response_has_tag :form, action: '/demo1', id: 'demo-fields-for'
|
|
195
|
+
assert_response_has_tag '#demo-fields-for input', type: 'text', name: 'markup_user[gender]', value: 'male'
|
|
196
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_edit]', value: '1', checked: 'checked'
|
|
197
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_delete]'
|
|
194
198
|
end
|
|
195
199
|
|
|
196
200
|
it 'should display correct simple fields in slim' do
|
|
197
|
-
get
|
|
198
|
-
assert_response_has_tag :form, :
|
|
199
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
200
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
201
|
-
assert_response_has_tag '#demo-fields-for input', :
|
|
201
|
+
get '/slim/fields_for'
|
|
202
|
+
assert_response_has_tag :form, action: '/demo1', id: 'demo-fields-for'
|
|
203
|
+
assert_response_has_tag '#demo-fields-for input', type: 'text', name: 'markup_user[gender]', value: 'male'
|
|
204
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_edit]', value: '1', checked: 'checked'
|
|
205
|
+
assert_response_has_tag '#demo-fields-for input', type: 'checkbox', name: 'permission[can_delete]'
|
|
202
206
|
end
|
|
203
207
|
end
|
|
204
208
|
|
|
@@ -208,56 +212,56 @@ describe "FormBuilder" do
|
|
|
208
212
|
|
|
209
213
|
describe 'for #error_messages method' do
|
|
210
214
|
it 'should display correct form html with no record' do
|
|
211
|
-
actual_html = standard_builder(@user_none).error_messages(:
|
|
215
|
+
actual_html = standard_builder(@user_none).error_messages(header_message: 'Demo form cannot be saved')
|
|
212
216
|
assert_empty actual_html
|
|
213
217
|
end
|
|
214
218
|
|
|
215
219
|
it 'should display correct form html with valid record' do
|
|
216
|
-
actual_html = standard_builder.error_messages(:
|
|
217
|
-
assert_html_has_tag(actual_html, '#field-errors h2', :
|
|
218
|
-
assert_html_has_tag(actual_html, '#field-errors ul li', :
|
|
219
|
-
assert_html_has_tag(actual_html, '#field-errors ul li', :
|
|
220
|
-
assert_html_has_tag(actual_html, '#field-errors', :
|
|
221
|
-
assert_html_has_tag(actual_html, '#field-errors', :
|
|
220
|
+
actual_html = standard_builder.error_messages(header_message: 'Demo form cannot be saved', style: 'foo:bar', class: 'mine')
|
|
221
|
+
assert_html_has_tag(actual_html, '#field-errors h2', content: 'Demo form cannot be saved')
|
|
222
|
+
assert_html_has_tag(actual_html, '#field-errors ul li', content: 'B must be valid')
|
|
223
|
+
assert_html_has_tag(actual_html, '#field-errors ul li', content: 'A must be present')
|
|
224
|
+
assert_html_has_tag(actual_html, '#field-errors', style: 'foo:bar')
|
|
225
|
+
assert_html_has_tag(actual_html, '#field-errors', class: 'mine')
|
|
222
226
|
end
|
|
223
227
|
|
|
224
228
|
it 'should display correct form in haml' do
|
|
225
|
-
get
|
|
226
|
-
assert_response_has_tag '#demo div.field-errors h2', :
|
|
227
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
228
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
229
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
230
|
-
assert_response_has_tag '#demo2 div.field-errors h2', :
|
|
231
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
232
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
233
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
234
|
-
assert_response_has_tag '#demo input', :
|
|
229
|
+
get '/haml/form_for'
|
|
230
|
+
assert_response_has_tag '#demo div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
231
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Fake must be valid'
|
|
232
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Second must be present'
|
|
233
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Third must be a number'
|
|
234
|
+
assert_response_has_tag '#demo2 div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
235
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Fake must be valid'
|
|
236
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Second must be present'
|
|
237
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Third must be a number'
|
|
238
|
+
assert_response_has_tag '#demo input', name: 'markup_user[email]', class: 'string invalid'
|
|
235
239
|
end
|
|
236
240
|
|
|
237
241
|
it 'should display correct form in erb' do
|
|
238
|
-
get
|
|
239
|
-
assert_response_has_tag '#demo div.field-errors h2', :
|
|
240
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
241
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
242
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
243
|
-
assert_response_has_tag '#demo2 div.field-errors h2', :
|
|
244
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
245
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
246
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
247
|
-
assert_response_has_tag '#demo input', :
|
|
242
|
+
get '/erb/form_for'
|
|
243
|
+
assert_response_has_tag '#demo div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
244
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Fake must be valid'
|
|
245
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Second must be present'
|
|
246
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Third must be a number'
|
|
247
|
+
assert_response_has_tag '#demo2 div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
248
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Fake must be valid'
|
|
249
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Second must be present'
|
|
250
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Third must be a number'
|
|
251
|
+
assert_response_has_tag '#demo input', name: 'markup_user[email]', class: 'string invalid'
|
|
248
252
|
end
|
|
249
253
|
|
|
250
254
|
it 'should display correct form in slim' do
|
|
251
|
-
get
|
|
252
|
-
assert_response_has_tag '#demo div.field-errors h2', :
|
|
253
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
254
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
255
|
-
assert_response_has_tag '#demo div.field-errors ul li', :
|
|
256
|
-
assert_response_has_tag '#demo2 div.field-errors h2', :
|
|
257
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
258
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
259
|
-
assert_response_has_tag '#demo2 div.field-errors ul li', :
|
|
260
|
-
assert_response_has_tag '#demo input', :
|
|
255
|
+
get '/slim/form_for'
|
|
256
|
+
assert_response_has_tag '#demo div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
257
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Fake must be valid'
|
|
258
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Second must be present'
|
|
259
|
+
assert_response_has_tag '#demo div.field-errors ul li', content: 'Third must be a number'
|
|
260
|
+
assert_response_has_tag '#demo2 div.field-errors h2', content: 'custom MarkupUser cannot be saved!'
|
|
261
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Fake must be valid'
|
|
262
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Second must be present'
|
|
263
|
+
assert_response_has_tag '#demo2 div.field-errors ul li', content: 'Third must be a number'
|
|
264
|
+
assert_response_has_tag '#demo input', name: 'markup_user[email]', class: 'string invalid'
|
|
261
265
|
end
|
|
262
266
|
end
|
|
263
267
|
|
|
@@ -268,295 +272,295 @@ describe "FormBuilder" do
|
|
|
268
272
|
end
|
|
269
273
|
|
|
270
274
|
it 'should display error for specified invalid object' do
|
|
271
|
-
actual_html = standard_builder(@user).error_message_on(:a, :
|
|
272
|
-
assert_html_has_tag(actual_html, 'span.error', :
|
|
275
|
+
actual_html = standard_builder(@user).error_message_on(:a, prepend: 'foo', append: 'bar')
|
|
276
|
+
assert_html_has_tag(actual_html, 'span.error', content: 'foo must be present bar')
|
|
273
277
|
end
|
|
274
278
|
|
|
275
279
|
it 'should display error for specified invalid object not matching class name' do
|
|
276
|
-
@bob = mock_model(
|
|
277
|
-
actual_html = standard_builder(@bob).error_message_on(:foo, :
|
|
278
|
-
assert_html_has_tag(actual_html, 'span.error', :
|
|
280
|
+
@bob = mock_model('User', first_name: 'Frank', errors: { foo: 'must be bob' })
|
|
281
|
+
actual_html = standard_builder(@bob).error_message_on(:foo, prepend: 'foo', append: 'bar')
|
|
282
|
+
assert_html_has_tag(actual_html, 'span.error', content: 'foo must be bob bar')
|
|
279
283
|
end
|
|
280
284
|
end
|
|
281
285
|
|
|
282
286
|
describe 'for #label method' do
|
|
283
287
|
it 'should display correct label html' do
|
|
284
|
-
actual_html = standard_builder.label(:first_name, :
|
|
285
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
288
|
+
actual_html = standard_builder.label(:first_name, class: 'large', caption: 'F. Name: ')
|
|
289
|
+
assert_html_has_tag(actual_html, 'label', class: 'large', for: 'user_first_name', content: 'F. Name: ')
|
|
286
290
|
assert_html_has_no_tag(actual_html, 'label#user_first_name')
|
|
287
291
|
end
|
|
288
292
|
|
|
289
293
|
it 'should set specific content inside the label if a block was provided' do
|
|
290
|
-
actual_html = standard_builder.label(:admin, :
|
|
291
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
294
|
+
actual_html = standard_builder.label(:admin, class: 'large') { input_tag :checkbox }
|
|
295
|
+
assert_html_has_tag(actual_html, 'label', class: 'large', for: 'user_admin', content: 'Admin: ')
|
|
292
296
|
assert_html_has_tag(actual_html, 'label input[type=checkbox]')
|
|
293
297
|
end
|
|
294
298
|
|
|
295
299
|
it 'should display correct label in haml' do
|
|
296
|
-
get
|
|
297
|
-
assert_response_has_tag '#demo label', :
|
|
298
|
-
assert_response_has_tag '#demo label', :
|
|
299
|
-
assert_response_has_tag '#demo2 label', :
|
|
300
|
+
get '/haml/form_for'
|
|
301
|
+
assert_response_has_tag '#demo label', content: 'Login: ', class: 'user-label'
|
|
302
|
+
assert_response_has_tag '#demo label', content: 'About Me: '
|
|
303
|
+
assert_response_has_tag '#demo2 label', content: 'Nickname: ', class: 'label'
|
|
300
304
|
end
|
|
301
305
|
|
|
302
306
|
it 'should display correct label in erb' do
|
|
303
|
-
get
|
|
304
|
-
assert_response_has_tag '#demo label', :
|
|
305
|
-
assert_response_has_tag '#demo label', :
|
|
306
|
-
assert_response_has_tag '#demo2 label', :
|
|
307
|
+
get '/erb/form_for'
|
|
308
|
+
assert_response_has_tag '#demo label', content: 'Login: ', class: 'user-label'
|
|
309
|
+
assert_response_has_tag '#demo label', content: 'About Me: '
|
|
310
|
+
assert_response_has_tag '#demo2 label', content: 'Nickname: ', class: 'label'
|
|
307
311
|
end
|
|
308
312
|
|
|
309
313
|
it 'should display correct label in slim' do
|
|
310
|
-
get
|
|
311
|
-
assert_response_has_tag '#demo label', :
|
|
312
|
-
assert_response_has_tag '#demo label', :
|
|
313
|
-
assert_response_has_tag '#demo2 label', :
|
|
314
|
+
get '/slim/form_for'
|
|
315
|
+
assert_response_has_tag '#demo label', content: 'Login: ', class: 'user-label'
|
|
316
|
+
assert_response_has_tag '#demo label', content: 'About Me: '
|
|
317
|
+
assert_response_has_tag '#demo2 label', content: 'Nickname: ', class: 'label'
|
|
314
318
|
end
|
|
315
319
|
end
|
|
316
320
|
|
|
317
321
|
describe 'for #hidden_field method' do
|
|
318
322
|
it 'should display correct hidden field html' do
|
|
319
|
-
actual_html = standard_builder.hidden_field(:session_id, :
|
|
320
|
-
assert_html_has_tag(actual_html, 'input.hidden[type=hidden]', :
|
|
323
|
+
actual_html = standard_builder.hidden_field(:session_id, class: 'hidden')
|
|
324
|
+
assert_html_has_tag(actual_html, 'input.hidden[type=hidden]', value: '54', id: 'user_session_id', name: 'user[session_id]')
|
|
321
325
|
end
|
|
322
326
|
|
|
323
327
|
it 'should display correct hidden field in haml' do
|
|
324
|
-
get
|
|
325
|
-
assert_response_has_tag '#demo input[type=hidden]', :
|
|
326
|
-
assert_response_has_tag '#demo2 input', :
|
|
328
|
+
get '/haml/form_for'
|
|
329
|
+
assert_response_has_tag '#demo input[type=hidden]', id: 'markup_user_session_id', value: '45'
|
|
330
|
+
assert_response_has_tag '#demo2 input', type: 'hidden', name: 'markup_user[session_id]'
|
|
327
331
|
end
|
|
328
332
|
|
|
329
333
|
it 'should display correct hidden field in erb' do
|
|
330
|
-
get
|
|
331
|
-
assert_response_has_tag '#demo input[type=hidden]', :
|
|
332
|
-
assert_response_has_tag '#demo2 input', :
|
|
334
|
+
get '/erb/form_for'
|
|
335
|
+
assert_response_has_tag '#demo input[type=hidden]', id: 'markup_user_session_id', value: '45'
|
|
336
|
+
assert_response_has_tag '#demo2 input', type: 'hidden', name: 'markup_user[session_id]'
|
|
333
337
|
end
|
|
334
338
|
|
|
335
339
|
it 'should display correct hidden field in slim' do
|
|
336
|
-
get
|
|
337
|
-
assert_response_has_tag '#demo input[type=hidden]', :
|
|
338
|
-
assert_response_has_tag '#demo2 input', :
|
|
340
|
+
get '/slim/form_for'
|
|
341
|
+
assert_response_has_tag '#demo input[type=hidden]', id: 'markup_user_session_id', value: '45'
|
|
342
|
+
assert_response_has_tag '#demo2 input', type: 'hidden', name: 'markup_user[session_id]'
|
|
339
343
|
end
|
|
340
344
|
end
|
|
341
345
|
|
|
342
346
|
describe 'for #text_field method' do
|
|
343
347
|
it 'should display correct text field html' do
|
|
344
|
-
actual_html = standard_builder.text_field(:first_name, :
|
|
345
|
-
assert_html_has_tag(actual_html, 'input.large[type=text]', :
|
|
348
|
+
actual_html = standard_builder.text_field(:first_name, class: 'large')
|
|
349
|
+
assert_html_has_tag(actual_html, 'input.large[type=text]', value: 'Joe', id: 'user_first_name', name: 'user[first_name]')
|
|
346
350
|
end
|
|
347
351
|
|
|
348
352
|
it 'should display correct text field in haml' do
|
|
349
|
-
get
|
|
350
|
-
assert_response_has_tag '#demo input.user-text[type=text]', :
|
|
351
|
-
assert_response_has_tag '#demo2 input', :
|
|
353
|
+
get '/haml/form_for'
|
|
354
|
+
assert_response_has_tag '#demo input.user-text[type=text]', id: 'markup_user_username', value: 'John'
|
|
355
|
+
assert_response_has_tag '#demo2 input', type: 'text', class: 'input', name: 'markup_user[username]'
|
|
352
356
|
end
|
|
353
357
|
|
|
354
358
|
it 'should display correct text field in erb' do
|
|
355
|
-
get
|
|
356
|
-
assert_response_has_tag '#demo input.user-text[type=text]', :
|
|
357
|
-
assert_response_has_tag '#demo2 input', :
|
|
359
|
+
get '/erb/form_for'
|
|
360
|
+
assert_response_has_tag '#demo input.user-text[type=text]', id: 'markup_user_username', value: 'John'
|
|
361
|
+
assert_response_has_tag '#demo2 input', type: 'text', class: 'input', name: 'markup_user[username]'
|
|
358
362
|
end
|
|
359
363
|
|
|
360
364
|
it 'should display correct text field in slim' do
|
|
361
|
-
get
|
|
362
|
-
assert_response_has_tag '#demo input.user-text[type=text]', :
|
|
363
|
-
assert_response_has_tag '#demo2 input', :
|
|
365
|
+
get '/slim/form_for'
|
|
366
|
+
assert_response_has_tag '#demo input.user-text[type=text]', id: 'markup_user_username', value: 'John'
|
|
367
|
+
assert_response_has_tag '#demo2 input', type: 'text', class: 'input', name: 'markup_user[username]'
|
|
364
368
|
end
|
|
365
369
|
end
|
|
366
370
|
|
|
367
371
|
describe 'for #number_field method' do
|
|
368
372
|
it 'should display correct number field html' do
|
|
369
|
-
actual_html = standard_builder.number_field(:age, :
|
|
370
|
-
assert_html_has_tag(actual_html, 'input.numeric[type=number]', :
|
|
373
|
+
actual_html = standard_builder.number_field(:age, class: 'numeric')
|
|
374
|
+
assert_html_has_tag(actual_html, 'input.numeric[type=number]', id: 'user_age', name: 'user[age]')
|
|
371
375
|
end
|
|
372
376
|
|
|
373
377
|
it 'should display correct number field in haml' do
|
|
374
|
-
get
|
|
375
|
-
assert_response_has_tag '#demo input.numeric[type=number]', :
|
|
378
|
+
get '/haml/form_for'
|
|
379
|
+
assert_response_has_tag '#demo input.numeric[type=number]', id: 'markup_user_age'
|
|
376
380
|
end
|
|
377
381
|
|
|
378
382
|
it 'should display correct number field in erb' do
|
|
379
|
-
get
|
|
380
|
-
assert_response_has_tag '#demo input.numeric[type=number]', :
|
|
383
|
+
get '/erb/form_for'
|
|
384
|
+
assert_response_has_tag '#demo input.numeric[type=number]', id: 'markup_user_age'
|
|
381
385
|
end
|
|
382
386
|
|
|
383
387
|
it 'should display correct number field in slim' do
|
|
384
|
-
get
|
|
385
|
-
assert_response_has_tag '#demo input.numeric[type=number]', :
|
|
388
|
+
get '/slim/form_for'
|
|
389
|
+
assert_response_has_tag '#demo input.numeric[type=number]', id: 'markup_user_age'
|
|
386
390
|
end
|
|
387
391
|
end
|
|
388
392
|
|
|
389
393
|
describe 'for #telephone_field method' do
|
|
390
394
|
it 'should display correct telephone field html' do
|
|
391
|
-
actual_html = standard_builder.telephone_field(:telephone, :
|
|
392
|
-
assert_html_has_tag(actual_html, 'input.numeric[type=tel]', :
|
|
395
|
+
actual_html = standard_builder.telephone_field(:telephone, class: 'numeric')
|
|
396
|
+
assert_html_has_tag(actual_html, 'input.numeric[type=tel]', id: 'user_telephone', name: 'user[telephone]')
|
|
393
397
|
end
|
|
394
398
|
|
|
395
399
|
it 'should display correct telephone field in haml' do
|
|
396
|
-
get
|
|
397
|
-
assert_response_has_tag '#demo input.numeric[type=tel]', :
|
|
400
|
+
get '/haml/form_for'
|
|
401
|
+
assert_response_has_tag '#demo input.numeric[type=tel]', id: 'markup_user_telephone'
|
|
398
402
|
end
|
|
399
403
|
|
|
400
404
|
it 'should display correct telephone field in erb' do
|
|
401
|
-
get
|
|
402
|
-
assert_response_has_tag '#demo input.numeric[type=tel]', :
|
|
405
|
+
get '/erb/form_for'
|
|
406
|
+
assert_response_has_tag '#demo input.numeric[type=tel]', id: 'markup_user_telephone'
|
|
403
407
|
end
|
|
404
408
|
|
|
405
409
|
it 'should display correct telephone field in slim' do
|
|
406
|
-
get
|
|
407
|
-
assert_response_has_tag '#demo input.numeric[type=tel]', :
|
|
410
|
+
get '/slim/form_for'
|
|
411
|
+
assert_response_has_tag '#demo input.numeric[type=tel]', id: 'markup_user_telephone'
|
|
408
412
|
end
|
|
409
413
|
end
|
|
410
414
|
|
|
411
415
|
describe 'for #search_field method' do
|
|
412
416
|
it 'should display correct search field html' do
|
|
413
|
-
actual_html = standard_builder.search_field(:search, :
|
|
414
|
-
assert_html_has_tag(actual_html, 'input.string[type=search]', :
|
|
417
|
+
actual_html = standard_builder.search_field(:search, class: 'string')
|
|
418
|
+
assert_html_has_tag(actual_html, 'input.string[type=search]', id: 'user_search', name: 'user[search]')
|
|
415
419
|
end
|
|
416
420
|
|
|
417
421
|
it 'should display correct search field in haml' do
|
|
418
|
-
get
|
|
419
|
-
assert_response_has_tag '#demo input.string[type=search]', :
|
|
422
|
+
get '/haml/form_for'
|
|
423
|
+
assert_response_has_tag '#demo input.string[type=search]', id: 'markup_user_search'
|
|
420
424
|
end
|
|
421
425
|
|
|
422
426
|
it 'should display correct search field in erb' do
|
|
423
|
-
get
|
|
424
|
-
assert_response_has_tag '#demo input.string[type=search]', :
|
|
427
|
+
get '/erb/form_for'
|
|
428
|
+
assert_response_has_tag '#demo input.string[type=search]', id: 'markup_user_search'
|
|
425
429
|
end
|
|
426
430
|
|
|
427
431
|
it 'should display correct search field in slim' do
|
|
428
|
-
get
|
|
429
|
-
assert_response_has_tag '#demo input.string[type=search]', :
|
|
432
|
+
get '/slim/form_for'
|
|
433
|
+
assert_response_has_tag '#demo input.string[type=search]', id: 'markup_user_search'
|
|
430
434
|
end
|
|
431
435
|
end
|
|
432
436
|
|
|
433
437
|
describe 'for #email_field method' do
|
|
434
438
|
it 'should display correct email field html' do
|
|
435
|
-
actual_html = standard_builder.email_field(:email, :
|
|
436
|
-
assert_html_has_tag(actual_html, 'input.string[type=email]', :
|
|
439
|
+
actual_html = standard_builder.email_field(:email, class: 'string')
|
|
440
|
+
assert_html_has_tag(actual_html, 'input.string[type=email]', id: 'user_email', name: 'user[email]')
|
|
437
441
|
end
|
|
438
442
|
|
|
439
443
|
it 'should display correct email field in haml' do
|
|
440
|
-
get
|
|
441
|
-
assert_response_has_tag '#demo input.string[type=email]', :
|
|
444
|
+
get '/haml/form_for'
|
|
445
|
+
assert_response_has_tag '#demo input.string[type=email]', id: 'markup_user_email'
|
|
442
446
|
end
|
|
443
447
|
|
|
444
448
|
it 'should display correct email field in erb' do
|
|
445
|
-
get
|
|
446
|
-
assert_response_has_tag '#demo input.string[type=email]', :
|
|
449
|
+
get '/erb/form_for'
|
|
450
|
+
assert_response_has_tag '#demo input.string[type=email]', id: 'markup_user_email'
|
|
447
451
|
end
|
|
448
452
|
|
|
449
453
|
it 'should display correct email field in slim' do
|
|
450
|
-
get
|
|
451
|
-
assert_response_has_tag '#demo input.string[type=email]', :
|
|
454
|
+
get '/slim/form_for'
|
|
455
|
+
assert_response_has_tag '#demo input.string[type=email]', id: 'markup_user_email'
|
|
452
456
|
end
|
|
453
457
|
end
|
|
454
458
|
|
|
455
459
|
describe 'for #url_field method' do
|
|
456
460
|
it 'should display correct url field html' do
|
|
457
|
-
actual_html = standard_builder.url_field(:webpage, :
|
|
458
|
-
assert_html_has_tag(actual_html, 'input.string[type=url]', :
|
|
461
|
+
actual_html = standard_builder.url_field(:webpage, class: 'string')
|
|
462
|
+
assert_html_has_tag(actual_html, 'input.string[type=url]', id: 'user_webpage', name: 'user[webpage]')
|
|
459
463
|
end
|
|
460
464
|
|
|
461
465
|
it 'should display correct url field in haml' do
|
|
462
|
-
get
|
|
463
|
-
assert_response_has_tag '#demo input.string[type=url]', :
|
|
466
|
+
get '/haml/form_for'
|
|
467
|
+
assert_response_has_tag '#demo input.string[type=url]', id: 'markup_user_webpage'
|
|
464
468
|
end
|
|
465
469
|
|
|
466
470
|
it 'should display correct url field in erb' do
|
|
467
|
-
get
|
|
468
|
-
assert_response_has_tag '#demo input.string[type=url]', :
|
|
471
|
+
get '/erb/form_for'
|
|
472
|
+
assert_response_has_tag '#demo input.string[type=url]', id: 'markup_user_webpage'
|
|
469
473
|
end
|
|
470
474
|
|
|
471
475
|
it 'should display correct url field in slim' do
|
|
472
|
-
get
|
|
473
|
-
assert_response_has_tag '#demo input.string[type=url]', :
|
|
476
|
+
get '/slim/form_for'
|
|
477
|
+
assert_response_has_tag '#demo input.string[type=url]', id: 'markup_user_webpage'
|
|
474
478
|
end
|
|
475
479
|
end
|
|
476
480
|
|
|
477
481
|
describe 'for #check_box method' do
|
|
478
482
|
it 'should display correct checkbox html' do
|
|
479
|
-
actual_html = standard_builder.check_box(:confirm_destroy, :
|
|
480
|
-
assert_html_has_tag(actual_html, 'input.large[type=checkbox]', :
|
|
481
|
-
assert_html_has_tag(actual_html, 'input[type=hidden]', :
|
|
483
|
+
actual_html = standard_builder.check_box(:confirm_destroy, class: 'large')
|
|
484
|
+
assert_html_has_tag(actual_html, 'input.large[type=checkbox]', id: 'user_confirm_destroy', name: 'user[confirm_destroy]')
|
|
485
|
+
assert_html_has_tag(actual_html, 'input[type=hidden]', name: 'user[confirm_destroy]', value: '0')
|
|
482
486
|
end
|
|
483
487
|
|
|
484
488
|
it 'should display correct checkbox html when checked' do
|
|
485
|
-
actual_html = standard_builder.check_box(:confirm_destroy, :
|
|
486
|
-
assert_html_has_tag(actual_html, 'input[type=checkbox]', :
|
|
489
|
+
actual_html = standard_builder.check_box(:confirm_destroy, checked: true)
|
|
490
|
+
assert_html_has_tag(actual_html, 'input[type=checkbox]', checked: 'checked', name: 'user[confirm_destroy]')
|
|
487
491
|
end
|
|
488
492
|
|
|
489
493
|
it 'should display correct checkbox html as checked when object value matches' do
|
|
490
|
-
@user.stubs(:
|
|
491
|
-
actual_html = standard_builder.check_box(:show_favorites, :
|
|
492
|
-
assert_html_has_tag(actual_html, 'input[type=checkbox]', :
|
|
494
|
+
@user.stubs(show_favorites: 'human')
|
|
495
|
+
actual_html = standard_builder.check_box(:show_favorites, value: 'human')
|
|
496
|
+
assert_html_has_tag(actual_html, 'input[type=checkbox]', checked: 'checked', name: 'user[show_favorites]')
|
|
493
497
|
end
|
|
494
498
|
|
|
495
499
|
it 'should display correct checkbox html as checked when object value is true' do
|
|
496
|
-
@user.stubs(:
|
|
497
|
-
actual_html = standard_builder.check_box(:show_favorites, :
|
|
498
|
-
assert_html_has_tag(actual_html, 'input[type=checkbox]', :
|
|
500
|
+
@user.stubs(show_favorites: true)
|
|
501
|
+
actual_html = standard_builder.check_box(:show_favorites, value: '1')
|
|
502
|
+
assert_html_has_tag(actual_html, 'input[type=checkbox]', checked: 'checked', name: 'user[show_favorites]')
|
|
499
503
|
end
|
|
500
504
|
|
|
501
505
|
it 'should display correct checkbox html as unchecked when object value does not match' do
|
|
502
|
-
@user.stubs(:
|
|
503
|
-
actual_html = standard_builder.check_box(:show_favorites, :
|
|
504
|
-
assert_html_has_no_tag(actual_html, 'input[type=checkbox]', :
|
|
506
|
+
@user.stubs(show_favorites: 'alien')
|
|
507
|
+
actual_html = standard_builder.check_box(:show_favorites, value: 'human')
|
|
508
|
+
assert_html_has_no_tag(actual_html, 'input[type=checkbox]', checked: 'checked')
|
|
505
509
|
end
|
|
506
510
|
|
|
507
511
|
it 'should display correct checkbox html as unchecked when object value is false' do
|
|
508
|
-
@user.stubs(:
|
|
509
|
-
actual_html = standard_builder.check_box(:show_favorites, :
|
|
510
|
-
assert_html_has_no_tag(actual_html, 'input[type=checkbox]', :
|
|
512
|
+
@user.stubs(show_favorites: false)
|
|
513
|
+
actual_html = standard_builder.check_box(:show_favorites, value: '1')
|
|
514
|
+
assert_html_has_no_tag(actual_html, 'input[type=checkbox]', checked: 'checked')
|
|
511
515
|
end
|
|
512
516
|
|
|
513
517
|
it 'should display correct unchecked hidden field when specified' do
|
|
514
|
-
actual_html = standard_builder.check_box(:show_favorites, :
|
|
515
|
-
assert_html_has_tag(actual_html, 'input[type=hidden]', :
|
|
518
|
+
actual_html = standard_builder.check_box(:show_favorites, value: 'female', uncheck_value: 'false')
|
|
519
|
+
assert_html_has_tag(actual_html, 'input[type=hidden]', name: 'user[show_favorites]', value: 'false')
|
|
516
520
|
end
|
|
517
521
|
|
|
518
522
|
it 'should display correct checkbox in haml' do
|
|
519
|
-
get
|
|
520
|
-
assert_response_has_tag '#demo input[type=checkbox]', :
|
|
523
|
+
get '/haml/form_for'
|
|
524
|
+
assert_response_has_tag '#demo input[type=checkbox]', checked: 'checked', id: 'markup_user_remember_me', name: 'markup_user[remember_me]'
|
|
521
525
|
end
|
|
522
526
|
|
|
523
527
|
it 'should display correct checkbox in erb' do
|
|
524
|
-
get
|
|
525
|
-
assert_response_has_tag '#demo input[type=checkbox]', :
|
|
528
|
+
get '/erb/form_for'
|
|
529
|
+
assert_response_has_tag '#demo input[type=checkbox]', checked: 'checked', id: 'markup_user_remember_me', name: 'markup_user[remember_me]'
|
|
526
530
|
end
|
|
527
531
|
|
|
528
532
|
it 'should display correct checkbox in slim' do
|
|
529
|
-
get
|
|
530
|
-
assert_response_has_tag '#demo input[type=checkbox]', :
|
|
533
|
+
get '/slim/form_for'
|
|
534
|
+
assert_response_has_tag '#demo input[type=checkbox]', checked: 'checked', id: 'markup_user_remember_me', name: 'markup_user[remember_me]'
|
|
531
535
|
end
|
|
532
536
|
end
|
|
533
537
|
|
|
534
538
|
describe 'for #check_box_group and #radio_button_group methods' do
|
|
535
539
|
it 'should display checkbox group html' do
|
|
536
|
-
checkboxes = standard_builder.check_box_group(:role, :
|
|
537
|
-
assert_html_has_tag(checkboxes, 'input[type=checkbox]', :
|
|
538
|
-
assert_html_has_no_tag(checkboxes, 'input[type=checkbox][checked]', :
|
|
539
|
-
assert_html_has_tag(checkboxes, 'input[type=checkbox]', :
|
|
540
|
+
checkboxes = standard_builder.check_box_group(:role, collection: @user.role_types, fields: %i[name id], selected: [2, 3])
|
|
541
|
+
assert_html_has_tag(checkboxes, 'input[type=checkbox]', value: '1')
|
|
542
|
+
assert_html_has_no_tag(checkboxes, 'input[type=checkbox][checked]', value: '1')
|
|
543
|
+
assert_html_has_tag(checkboxes, 'input[type=checkbox]', checked: 'checked', value: '2')
|
|
540
544
|
assert_html_has_tag(checkboxes, 'label[for=user_role_3] input[name="user[role][]"][value="3"][checked]')
|
|
541
545
|
end
|
|
542
546
|
|
|
543
547
|
it 'should display checkbox group html and extract selected values from the object' do
|
|
544
|
-
checkboxes = standard_builder.check_box_group(:roles, :
|
|
548
|
+
checkboxes = standard_builder.check_box_group(:roles, collection: @user.role_types, fields: %i[name id])
|
|
545
549
|
assert_html_has_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="1"][checked]')
|
|
546
550
|
assert_html_has_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="3"][checked]')
|
|
547
551
|
assert_html_has_no_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="2"][checked]')
|
|
548
552
|
end
|
|
549
553
|
|
|
550
554
|
it 'should display radio group html' do
|
|
551
|
-
radios = standard_builder.radio_button_group(:role, :
|
|
552
|
-
assert_html_has_tag(radios, 'input[type=radio]', :
|
|
553
|
-
assert_html_has_no_tag(radios, 'input[type=radio][checked]', :
|
|
554
|
-
assert_html_has_tag(radios, 'input[type=radio]', :
|
|
555
|
+
radios = standard_builder.radio_button_group(:role, options: %w[red yellow blue], selected: 'yellow')
|
|
556
|
+
assert_html_has_tag(radios, 'input[type=radio]', value: 'red')
|
|
557
|
+
assert_html_has_no_tag(radios, 'input[type=radio][checked]', value: 'red')
|
|
558
|
+
assert_html_has_tag(radios, 'input[type=radio]', checked: 'checked', value: 'yellow')
|
|
555
559
|
assert_html_has_tag(radios, 'label[for=user_role_blue] input[name="user[role]"][value=blue]')
|
|
556
560
|
end
|
|
557
561
|
|
|
558
562
|
it 'should display radio group html and extract selected value from the object' do
|
|
559
|
-
radios = standard_builder.radio_button_group(:role, :
|
|
563
|
+
radios = standard_builder.radio_button_group(:role, collection: @user.role_types)
|
|
560
564
|
assert_html_has_tag(radios, 'input[type=radio][value="1"][checked]')
|
|
561
565
|
assert_html_has_no_tag(radios, 'input[type=radio][value="2"][checked]')
|
|
562
566
|
end
|
|
@@ -564,261 +568,259 @@ describe "FormBuilder" do
|
|
|
564
568
|
|
|
565
569
|
describe 'for #radio_button method' do
|
|
566
570
|
it 'should display correct radio button html' do
|
|
567
|
-
actual_html = standard_builder.radio_button(:gender, :
|
|
568
|
-
assert_html_has_tag(actual_html, 'input.large[type=radio]', :
|
|
571
|
+
actual_html = standard_builder.radio_button(:gender, value: 'male', class: 'large')
|
|
572
|
+
assert_html_has_tag(actual_html, 'input.large[type=radio]', id: 'user_gender_male', name: 'user[gender]', value: 'male')
|
|
569
573
|
end
|
|
570
574
|
|
|
571
575
|
it 'should display correct radio button html when checked' do
|
|
572
|
-
actual_html = standard_builder.radio_button(:gender, :
|
|
573
|
-
assert_html_has_tag(actual_html, 'input[type=radio]', :
|
|
576
|
+
actual_html = standard_builder.radio_button(:gender, checked: true)
|
|
577
|
+
assert_html_has_tag(actual_html, 'input[type=radio]', checked: 'checked', name: 'user[gender]')
|
|
574
578
|
end
|
|
575
579
|
|
|
576
580
|
it 'should display correct radio button html as checked when object value matches' do
|
|
577
|
-
@user.stubs(:
|
|
578
|
-
actual_html = standard_builder.radio_button(:gender, :
|
|
579
|
-
assert_html_has_tag(actual_html, 'input[type=radio]', :
|
|
581
|
+
@user.stubs(gender: 'male')
|
|
582
|
+
actual_html = standard_builder.radio_button(:gender, value: 'male')
|
|
583
|
+
assert_html_has_tag(actual_html, 'input[type=radio]', checked: 'checked', name: 'user[gender]')
|
|
580
584
|
end
|
|
581
585
|
|
|
582
586
|
it 'should display correct radio button html as unchecked when object value does not match' do
|
|
583
|
-
@user.stubs(:
|
|
584
|
-
actual_html = standard_builder.radio_button(:gender, :
|
|
585
|
-
assert_html_has_no_tag(actual_html, 'input[type=radio]', :
|
|
587
|
+
@user.stubs(gender: 'male')
|
|
588
|
+
actual_html = standard_builder.radio_button(:gender, value: 'female')
|
|
589
|
+
assert_html_has_no_tag(actual_html, 'input[type=radio]', checked: 'checked')
|
|
586
590
|
end
|
|
587
591
|
|
|
588
592
|
it 'should display correct radio button in haml' do
|
|
589
|
-
get
|
|
590
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
591
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
592
|
-
assert_response_has_tag '#demo input[type=radio][checked=checked]', :
|
|
593
|
+
get '/haml/form_for'
|
|
594
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_male', name: 'markup_user[gender]', value: 'male'
|
|
595
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_female', name: 'markup_user[gender]', value: 'female'
|
|
596
|
+
assert_response_has_tag '#demo input[type=radio][checked=checked]', id: 'markup_user_gender_male'
|
|
593
597
|
end
|
|
594
598
|
|
|
595
599
|
it 'should display correct radio button in erb' do
|
|
596
|
-
get
|
|
597
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
598
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
599
|
-
assert_response_has_tag '#demo input[type=radio][checked=checked]', :
|
|
600
|
+
get '/erb/form_for'
|
|
601
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_male', name: 'markup_user[gender]', value: 'male'
|
|
602
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_female', name: 'markup_user[gender]', value: 'female'
|
|
603
|
+
assert_response_has_tag '#demo input[type=radio][checked=checked]', id: 'markup_user_gender_male'
|
|
600
604
|
end
|
|
601
605
|
|
|
602
606
|
it 'should display correct radio button in slim' do
|
|
603
|
-
get
|
|
604
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
605
|
-
assert_response_has_tag '#demo input[type=radio]', :
|
|
606
|
-
assert_response_has_tag '#demo input[type=radio][checked=checked]', :
|
|
607
|
+
get '/slim/form_for'
|
|
608
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_male', name: 'markup_user[gender]', value: 'male'
|
|
609
|
+
assert_response_has_tag '#demo input[type=radio]', id: 'markup_user_gender_female', name: 'markup_user[gender]', value: 'female'
|
|
610
|
+
assert_response_has_tag '#demo input[type=radio][checked=checked]', id: 'markup_user_gender_male'
|
|
607
611
|
end
|
|
608
612
|
end
|
|
609
613
|
|
|
610
614
|
describe 'for #text_area method' do
|
|
611
615
|
it 'should display correct text_area html' do
|
|
612
|
-
actual_html = standard_builder.text_area(:about, :
|
|
613
|
-
assert_html_has_tag(actual_html, 'textarea.large', :
|
|
616
|
+
actual_html = standard_builder.text_area(:about, class: 'large')
|
|
617
|
+
assert_html_has_tag(actual_html, 'textarea.large', id: 'user_about', name: 'user[about]')
|
|
614
618
|
end
|
|
615
619
|
|
|
616
620
|
it 'should display correct text_area html and content' do
|
|
617
|
-
actual_html = standard_builder.text_area(:about, :
|
|
618
|
-
assert_html_has_tag(actual_html, 'textarea', :
|
|
621
|
+
actual_html = standard_builder.text_area(:about, value: 'Demo', rows: '5', cols: '6')
|
|
622
|
+
assert_html_has_tag(actual_html, 'textarea', id: 'user_about', content: 'Demo', rows: '5', cols: '6')
|
|
619
623
|
end
|
|
620
624
|
|
|
621
625
|
it 'should display correct text_area in haml' do
|
|
622
|
-
get
|
|
623
|
-
assert_response_has_tag '#demo textarea', :
|
|
624
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
626
|
+
get '/haml/form_for'
|
|
627
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
628
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
625
629
|
end
|
|
626
630
|
|
|
627
631
|
it 'should display correct text_area in erb' do
|
|
628
|
-
get
|
|
629
|
-
assert_response_has_tag '#demo textarea', :
|
|
630
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
632
|
+
get '/erb/form_for'
|
|
633
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
634
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
631
635
|
end
|
|
632
636
|
|
|
633
637
|
it 'should display correct text_area in slim' do
|
|
634
|
-
get
|
|
635
|
-
assert_response_has_tag '#demo textarea', :
|
|
636
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
638
|
+
get '/slim/form_for'
|
|
639
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
640
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
637
641
|
end
|
|
638
642
|
end
|
|
639
643
|
|
|
640
644
|
describe 'for #password_field method' do
|
|
641
645
|
it 'should display correct password_field html' do
|
|
642
|
-
actual_html = standard_builder.password_field(:code, :
|
|
643
|
-
assert_html_has_tag(actual_html, 'input.large[type=password]', :
|
|
646
|
+
actual_html = standard_builder.password_field(:code, class: 'large')
|
|
647
|
+
assert_html_has_tag(actual_html, 'input.large[type=password]', id: 'user_code', name: 'user[code]')
|
|
644
648
|
end
|
|
645
649
|
|
|
646
650
|
it 'should display correct password_field in haml' do
|
|
647
|
-
get
|
|
648
|
-
assert_response_has_tag '#demo input', :
|
|
649
|
-
assert_response_has_tag '#demo2 input', :
|
|
651
|
+
get '/haml/form_for'
|
|
652
|
+
assert_response_has_tag '#demo input', type: 'password', class: 'user-password', value: 'secret'
|
|
653
|
+
assert_response_has_tag '#demo2 input', type: 'password', class: 'input', name: 'markup_user[code]'
|
|
650
654
|
end
|
|
651
655
|
|
|
652
656
|
it 'should display correct password_field in erb' do
|
|
653
|
-
get
|
|
654
|
-
assert_response_has_tag '#demo input', :
|
|
655
|
-
assert_response_has_tag '#demo2 input', :
|
|
657
|
+
get '/erb/form_for'
|
|
658
|
+
assert_response_has_tag '#demo input', type: 'password', class: 'user-password', value: 'secret'
|
|
659
|
+
assert_response_has_tag '#demo2 input', type: 'password', class: 'input', name: 'markup_user[code]'
|
|
656
660
|
end
|
|
657
661
|
|
|
658
662
|
it 'should display correct password_field in slim' do
|
|
659
|
-
get
|
|
660
|
-
assert_response_has_tag '#demo input', :
|
|
661
|
-
assert_response_has_tag '#demo2 input', :
|
|
663
|
+
get '/slim/form_for'
|
|
664
|
+
assert_response_has_tag '#demo input', type: 'password', class: 'user-password', value: 'secret'
|
|
665
|
+
assert_response_has_tag '#demo2 input', type: 'password', class: 'input', name: 'markup_user[code]'
|
|
662
666
|
end
|
|
663
667
|
end
|
|
664
668
|
|
|
665
669
|
describe 'for #file_field method' do
|
|
666
670
|
it 'should display correct file_field html' do
|
|
667
|
-
actual_html = standard_builder.file_field(:photo, :
|
|
668
|
-
assert_html_has_tag(actual_html, 'input.large[type=file]', :
|
|
671
|
+
actual_html = standard_builder.file_field(:photo, class: 'large')
|
|
672
|
+
assert_html_has_tag(actual_html, 'input.large[type=file]', id: 'user_photo', name: 'user[photo]')
|
|
669
673
|
end
|
|
670
674
|
|
|
671
675
|
it 'should display correct file_field in haml' do
|
|
672
|
-
get
|
|
673
|
-
assert_response_has_tag '#demo input.user-photo', :
|
|
674
|
-
assert_response_has_tag '#demo2 input.upload', :
|
|
676
|
+
get '/haml/form_for'
|
|
677
|
+
assert_response_has_tag '#demo input.user-photo', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
678
|
+
assert_response_has_tag '#demo2 input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
675
679
|
end
|
|
676
680
|
|
|
677
681
|
it 'should display correct file_field in erb' do
|
|
678
|
-
get
|
|
679
|
-
assert_response_has_tag '#demo input.user-photo', :
|
|
680
|
-
assert_response_has_tag '#demo2 input.upload', :
|
|
682
|
+
get '/erb/form_for'
|
|
683
|
+
assert_response_has_tag '#demo input.user-photo', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
684
|
+
assert_response_has_tag '#demo2 input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
681
685
|
end
|
|
682
686
|
|
|
683
687
|
it 'should display correct file_field in slim' do
|
|
684
|
-
get
|
|
685
|
-
assert_response_has_tag '#demo input.user-photo', :
|
|
686
|
-
assert_response_has_tag '#demo2 input.upload', :
|
|
688
|
+
get '/slim/form_for'
|
|
689
|
+
assert_response_has_tag '#demo input.user-photo', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
690
|
+
assert_response_has_tag '#demo2 input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
687
691
|
end
|
|
688
692
|
|
|
689
693
|
it 'should display correct form html with multipart, even if no multipart option is specified' do
|
|
690
|
-
actual_html = form_for(@user, '/register',
|
|
691
|
-
assert_html_has_tag(actual_html, 'form',
|
|
694
|
+
actual_html = form_for(@user, '/register', "accept-charset": 'UTF-8') { |f| f.file_field :photo }
|
|
695
|
+
assert_html_has_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', enctype: 'multipart/form-data')
|
|
692
696
|
end
|
|
693
697
|
|
|
694
698
|
it 'should display correct form html without multipart, if multipart option is specified false' do
|
|
695
|
-
actual_html = form_for(@user, '/register',
|
|
696
|
-
assert_html_has_no_tag(actual_html, 'form',
|
|
699
|
+
actual_html = form_for(@user, '/register', "accept-charset": 'UTF-8', multipart: false) { |f| f.file_field :photo }
|
|
700
|
+
assert_html_has_no_tag(actual_html, 'form', "accept-charset": 'UTF-8', action: '/register', enctype: 'multipart/form-data')
|
|
697
701
|
end
|
|
698
|
-
|
|
699
702
|
end
|
|
700
703
|
|
|
701
704
|
describe 'for #select method' do
|
|
702
705
|
it 'should display correct select html' do
|
|
703
|
-
actual_html = standard_builder.select(:state, :
|
|
704
|
-
assert_html_has_tag(actual_html, 'select.selecty', :
|
|
705
|
-
assert_html_has_tag(actual_html, 'select.selecty option', :
|
|
706
|
-
assert_html_has_tag(actual_html, 'select.selecty option', :
|
|
707
|
-
assert_html_has_tag(actual_html, 'select.selecty option', :
|
|
708
|
-
assert_html_has_tag(actual_html, 'select.selecty option', :
|
|
706
|
+
actual_html = standard_builder.select(:state, options: %w[California Texas Wyoming], class: 'selecty')
|
|
707
|
+
assert_html_has_tag(actual_html, 'select.selecty', id: 'user_state', name: 'user[state]')
|
|
708
|
+
assert_html_has_tag(actual_html, 'select.selecty option', count: 3)
|
|
709
|
+
assert_html_has_tag(actual_html, 'select.selecty option', value: 'California', content: 'California')
|
|
710
|
+
assert_html_has_tag(actual_html, 'select.selecty option', value: 'Texas', content: 'Texas')
|
|
711
|
+
assert_html_has_tag(actual_html, 'select.selecty option', value: 'Wyoming', content: 'Wyoming')
|
|
709
712
|
end
|
|
710
713
|
|
|
711
714
|
it 'should display correct select html with selected item if it matches value' do
|
|
712
|
-
@user.stubs(:
|
|
713
|
-
actual_html = standard_builder.select(:state, :
|
|
714
|
-
assert_html_has_tag(actual_html, 'select', :
|
|
715
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
716
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
715
|
+
@user.stubs(state: 'California')
|
|
716
|
+
actual_html = standard_builder.select(:state, options: %w[California Texas Wyoming])
|
|
717
|
+
assert_html_has_tag(actual_html, 'select', id: 'user_state', name: 'user[state]')
|
|
718
|
+
assert_html_has_tag(actual_html, 'select option', selected: 'selected', count: 1)
|
|
719
|
+
assert_html_has_tag(actual_html, 'select option', value: 'California', selected: 'selected')
|
|
717
720
|
end
|
|
718
721
|
|
|
719
722
|
it 'should display correct select html with selected item if it matches full value' do
|
|
720
|
-
@user.stubs(:
|
|
721
|
-
actual_html = standard_builder.select(:state, :
|
|
722
|
-
assert_html_has_tag(actual_html, 'select', :
|
|
723
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
724
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
725
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
723
|
+
@user.stubs(state: 'Cali')
|
|
724
|
+
actual_html = standard_builder.select(:state, options: %w[Cali California Texas Wyoming])
|
|
725
|
+
assert_html_has_tag(actual_html, 'select', id: 'user_state', name: 'user[state]')
|
|
726
|
+
assert_html_has_tag(actual_html, 'select option', selected: 'selected', count: 1)
|
|
727
|
+
assert_html_has_tag(actual_html, 'select option', value: 'Cali', selected: 'selected')
|
|
728
|
+
assert_html_has_tag(actual_html, 'select option', value: 'California')
|
|
726
729
|
end
|
|
727
730
|
|
|
728
731
|
it 'should display correct select html with multiple selected items' do
|
|
729
|
-
@user.stubs(:
|
|
732
|
+
@user.stubs(pickles: %w[foo bar])
|
|
730
733
|
actual_html = standard_builder.select(
|
|
731
|
-
:pickles, :
|
|
734
|
+
:pickles, options: [['Foo', 'foo'], ['Bar', 'bar'], ['Baz', 'baz'], ['Bar Buz', 'bar buz']]
|
|
732
735
|
)
|
|
733
|
-
assert_html_has_tag(actual_html, 'option', :
|
|
734
|
-
assert_html_has_tag(actual_html, 'option', :
|
|
735
|
-
assert_html_has_tag(actual_html, 'option', :
|
|
736
|
-
assert_html_has_tag(actual_html, 'option', :
|
|
736
|
+
assert_html_has_tag(actual_html, 'option', value: 'foo', content: 'Foo', selected: 'selected')
|
|
737
|
+
assert_html_has_tag(actual_html, 'option', value: 'bar', content: 'Bar', selected: 'selected')
|
|
738
|
+
assert_html_has_tag(actual_html, 'option', value: 'baz', content: 'Baz')
|
|
739
|
+
assert_html_has_tag(actual_html, 'option', value: 'bar buz', content: 'Bar Buz')
|
|
737
740
|
end
|
|
738
741
|
|
|
739
742
|
it 'should display correct select html with include_blank true' do
|
|
740
|
-
actual_html = standard_builder.select(:state, :
|
|
741
|
-
assert_html_has_tag(actual_html, 'select', :
|
|
742
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
743
|
-
assert_html_has_tag(actual_html, 'select option:first-child', :
|
|
744
|
-
assert_html_has_tag(actual_html, 'select option:first-child', :
|
|
743
|
+
actual_html = standard_builder.select(:state, options: %w[California Texas Wyoming], include_blank: true)
|
|
744
|
+
assert_html_has_tag(actual_html, 'select', id: 'user_state', name: 'user[state]')
|
|
745
|
+
assert_html_has_tag(actual_html, 'select option', count: 4)
|
|
746
|
+
assert_html_has_tag(actual_html, 'select option:first-child', content: '')
|
|
747
|
+
assert_html_has_tag(actual_html, 'select option:first-child', value: '')
|
|
745
748
|
end
|
|
746
749
|
|
|
747
750
|
it 'should display correct select html with include_blank string' do
|
|
748
|
-
actual_html = standard_builder.select(:state, :
|
|
749
|
-
assert_html_has_tag(actual_html, 'select', :
|
|
750
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
751
|
-
assert_html_has_tag(actual_html, 'select option:first-child', :
|
|
752
|
-
assert_html_has_tag(actual_html, 'select option:first-child', :
|
|
751
|
+
actual_html = standard_builder.select(:state, options: %w[California Texas Wyoming], include_blank: 'Select')
|
|
752
|
+
assert_html_has_tag(actual_html, 'select', id: 'user_state', name: 'user[state]')
|
|
753
|
+
assert_html_has_tag(actual_html, 'select option', count: 4)
|
|
754
|
+
assert_html_has_tag(actual_html, 'select option:first-child', content: 'Select')
|
|
755
|
+
assert_html_has_tag(actual_html, 'select option:first-child', value: '')
|
|
753
756
|
end
|
|
754
757
|
|
|
755
758
|
it 'should display correct select html with collection passed in' do
|
|
756
|
-
actual_html = standard_builder.select(:role, :
|
|
757
|
-
assert_html_has_tag(actual_html, 'select', :
|
|
758
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
759
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
760
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
761
|
-
assert_html_has_tag(actual_html, 'select option', :
|
|
759
|
+
actual_html = standard_builder.select(:role, collection: @user.role_types, fields: %i[name id])
|
|
760
|
+
assert_html_has_tag(actual_html, 'select', id: 'user_role', name: 'user[role]')
|
|
761
|
+
assert_html_has_tag(actual_html, 'select option', count: 3)
|
|
762
|
+
assert_html_has_tag(actual_html, 'select option', value: '1', content: 'Admin', selected: 'selected')
|
|
763
|
+
assert_html_has_tag(actual_html, 'select option', value: '2', content: 'Moderate')
|
|
764
|
+
assert_html_has_tag(actual_html, 'select option', value: '3', content: 'Limited')
|
|
762
765
|
end
|
|
763
766
|
|
|
764
767
|
it 'should display correct select in haml' do
|
|
765
|
-
get
|
|
766
|
-
assert_response_has_tag '#demo textarea', :
|
|
767
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
768
|
+
get '/haml/form_for'
|
|
769
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
770
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
768
771
|
end
|
|
769
772
|
|
|
770
773
|
it 'should display correct select in erb' do
|
|
771
|
-
get
|
|
772
|
-
assert_response_has_tag '#demo textarea', :
|
|
773
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
774
|
+
get '/erb/form_for'
|
|
775
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
776
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
774
777
|
end
|
|
775
778
|
|
|
776
779
|
it 'should display correct select in slim' do
|
|
777
|
-
get
|
|
778
|
-
assert_response_has_tag '#demo textarea', :
|
|
779
|
-
assert_response_has_tag '#demo2 textarea', :
|
|
780
|
+
get '/slim/form_for'
|
|
781
|
+
assert_response_has_tag '#demo textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'user-about'
|
|
782
|
+
assert_response_has_tag '#demo2 textarea', name: 'markup_user[about]', id: 'markup_user_about', class: 'textarea'
|
|
780
783
|
end
|
|
781
784
|
end
|
|
782
785
|
|
|
783
786
|
describe 'for #submit method' do
|
|
784
787
|
it 'should display correct submit button html with no options' do
|
|
785
788
|
actual_html = standard_builder.submit
|
|
786
|
-
assert_html_has_tag(actual_html, 'input[type=submit]', :
|
|
789
|
+
assert_html_has_tag(actual_html, 'input[type=submit]', value: 'Submit')
|
|
787
790
|
end
|
|
788
791
|
|
|
789
|
-
|
|
790
792
|
it 'should display correct submit button html with no caption' do
|
|
791
|
-
actual_html = standard_builder.submit(:
|
|
792
|
-
assert_html_has_tag(actual_html, 'input.btn[type=submit]', :
|
|
793
|
+
actual_html = standard_builder.submit(class: 'btn')
|
|
794
|
+
assert_html_has_tag(actual_html, 'input.btn[type=submit]', value: 'Submit')
|
|
793
795
|
end
|
|
794
796
|
|
|
795
797
|
it 'should display correct submit button html with nil caption' do
|
|
796
|
-
actual_html = standard_builder.submit(nil, :
|
|
798
|
+
actual_html = standard_builder.submit(nil, class: 'btn')
|
|
797
799
|
assert_html_has_tag(actual_html, 'input.btn[type=submit]')
|
|
798
800
|
assert actual_html !~ %r{ value \* = }x
|
|
799
801
|
end
|
|
800
802
|
|
|
801
803
|
it 'should display correct submit button html' do
|
|
802
|
-
actual_html = standard_builder.submit(
|
|
803
|
-
assert_html_has_tag(actual_html, 'input.large[type=submit]', :
|
|
804
|
+
actual_html = standard_builder.submit('Commit', class: 'large')
|
|
805
|
+
assert_html_has_tag(actual_html, 'input.large[type=submit]', value: 'Commit')
|
|
804
806
|
end
|
|
805
807
|
|
|
806
808
|
it 'should display correct submit button in haml' do
|
|
807
|
-
get
|
|
808
|
-
assert_response_has_tag '#demo input', :
|
|
809
|
-
assert_response_has_tag '#demo2 input', :
|
|
809
|
+
get '/haml/form_for'
|
|
810
|
+
assert_response_has_tag '#demo input', type: 'submit', id: 'demo-button', class: 'success'
|
|
811
|
+
assert_response_has_tag '#demo2 input', type: 'submit', class: 'button', value: 'Create'
|
|
810
812
|
end
|
|
811
813
|
|
|
812
814
|
it 'should display correct submit button in erb' do
|
|
813
|
-
get
|
|
814
|
-
assert_response_has_tag '#demo input', :
|
|
815
|
-
assert_response_has_tag '#demo2 input', :
|
|
815
|
+
get '/erb/form_for'
|
|
816
|
+
assert_response_has_tag '#demo input', type: 'submit', id: 'demo-button', class: 'success'
|
|
817
|
+
assert_response_has_tag '#demo2 input', type: 'submit', class: 'button', value: 'Create'
|
|
816
818
|
end
|
|
817
819
|
|
|
818
820
|
it 'should display correct submit button in slim' do
|
|
819
|
-
get
|
|
820
|
-
assert_response_has_tag '#demo input', :
|
|
821
|
-
assert_response_has_tag '#demo2 input', :
|
|
821
|
+
get '/slim/form_for'
|
|
822
|
+
assert_response_has_tag '#demo input', type: 'submit', id: 'demo-button', class: 'success'
|
|
823
|
+
assert_response_has_tag '#demo2 input', type: 'submit', class: 'button', value: 'Create'
|
|
822
824
|
end
|
|
823
825
|
end
|
|
824
826
|
|
|
@@ -829,54 +831,53 @@ describe "FormBuilder" do
|
|
|
829
831
|
|
|
830
832
|
it 'should display correct image submit button html with no options' do
|
|
831
833
|
actual_html = standard_builder.image_submit('buttons/ok.png')
|
|
832
|
-
assert_html_has_tag(actual_html, 'input[type=image]', :
|
|
834
|
+
assert_html_has_tag(actual_html, 'input[type=image]', src: "/images/buttons/ok.png?#{@stamp}")
|
|
833
835
|
end
|
|
834
836
|
|
|
835
837
|
it 'should display correct image submit button html' do
|
|
836
|
-
actual_html = standard_builder.image_submit('/system/ok.png', :
|
|
837
|
-
assert_html_has_tag(actual_html, 'input.large[type=image]', :
|
|
838
|
+
actual_html = standard_builder.image_submit('/system/ok.png', class: 'large')
|
|
839
|
+
assert_html_has_tag(actual_html, 'input.large[type=image]', src: '/system/ok.png')
|
|
838
840
|
end
|
|
839
841
|
|
|
840
842
|
it 'should display correct image submit button in haml' do
|
|
841
|
-
get
|
|
842
|
-
assert_response_has_tag '#demo input', :
|
|
843
|
-
assert_response_has_tag '#demo2 input', :
|
|
843
|
+
get '/haml/form_for'
|
|
844
|
+
assert_response_has_tag '#demo input', type: 'image', id: 'image-button', src: "/images/buttons/post.png?#{@stamp}"
|
|
845
|
+
assert_response_has_tag '#demo2 input', type: 'image', class: 'image', src: "/images/buttons/ok.png?#{@stamp}"
|
|
844
846
|
end
|
|
845
847
|
|
|
846
848
|
it 'should display correct image submit button in erb' do
|
|
847
|
-
get
|
|
848
|
-
assert_response_has_tag '#demo input', :
|
|
849
|
-
assert_response_has_tag '#demo2 input', :
|
|
849
|
+
get '/erb/form_for'
|
|
850
|
+
assert_response_has_tag '#demo input', type: 'image', id: 'image-button', src: "/images/buttons/post.png?#{@stamp}"
|
|
851
|
+
assert_response_has_tag '#demo2 input', type: 'image', class: 'image', src: "/images/buttons/ok.png?#{@stamp}"
|
|
850
852
|
end
|
|
851
853
|
|
|
852
854
|
it 'should display correct image submit button in slim' do
|
|
853
|
-
get
|
|
854
|
-
assert_response_has_tag '#demo input', :
|
|
855
|
-
assert_response_has_tag '#demo2 input', :
|
|
855
|
+
get '/slim/form_for'
|
|
856
|
+
assert_response_has_tag '#demo input', type: 'image', id: 'image-button', src: "/images/buttons/post.png?#{@stamp}"
|
|
857
|
+
assert_response_has_tag '#demo2 input', type: 'image', class: 'image', src: "/images/buttons/ok.png?#{@stamp}"
|
|
856
858
|
end
|
|
857
859
|
end
|
|
858
860
|
|
|
859
861
|
describe 'for #fields_for method' do
|
|
860
862
|
before do
|
|
861
|
-
@telephone = mock_model(
|
|
863
|
+
@telephone = mock_model('Telephone', number: '4568769876')
|
|
862
864
|
@user.stubs(:telephone).returns(@telephone)
|
|
863
|
-
@businesses = [
|
|
864
|
-
@businesses <<
|
|
865
|
-
@addresses = [
|
|
866
|
-
@addresses <<
|
|
865
|
+
@businesses = [mock_model('Business', name: 'Silver', new_record?: false, id: 20)]
|
|
866
|
+
@businesses << mock_model('Business', name: 'Gold', new_record?: true)
|
|
867
|
+
@addresses = [mock_model('Address', name: 'Foo', new_record?: false, id: 20, businesses: @businesses)]
|
|
868
|
+
@addresses << mock_model('Address', name: 'Bar', new_record?: true, businesses: @businesses)
|
|
867
869
|
@user.stubs(:addresses).returns(@addresses)
|
|
868
870
|
end
|
|
869
871
|
|
|
870
872
|
it 'should display nested children fields one-to-one within form' do
|
|
871
873
|
actual_html = standard_builder.fields_for :telephone do |child_form|
|
|
872
|
-
child_form.label(:number) +
|
|
873
|
-
child_form.text_field(:number) +
|
|
874
|
-
child_form.check_box('_destroy')
|
|
874
|
+
child_form.label(:number) + child_form.text_field(:number) + child_form.check_box('_destroy')
|
|
875
875
|
end
|
|
876
|
-
|
|
877
|
-
assert_html_has_tag(actual_html, '
|
|
878
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
879
|
-
assert_html_has_tag(actual_html, 'input',
|
|
876
|
+
|
|
877
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_telephone_attributes_number')
|
|
878
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_telephone_attributes_number', name: 'user[telephone_attributes][number]', value: '4568769876')
|
|
879
|
+
assert_html_has_tag(actual_html, 'input', type: 'hidden', name: 'user[telephone_attributes][_destroy]', value: '0')
|
|
880
|
+
assert_html_has_tag(actual_html, 'input', type: 'checkbox', id: 'user_telephone_attributes__destroy', name: 'user[telephone_attributes][_destroy]', value: '1')
|
|
880
881
|
end
|
|
881
882
|
|
|
882
883
|
it 'should display nested children fields one-to-many within form' do
|
|
@@ -886,127 +887,127 @@ describe "FormBuilder" do
|
|
|
886
887
|
html << child_form.text_field(:name)
|
|
887
888
|
end
|
|
888
889
|
# Address 1 (Saved)
|
|
889
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
890
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
891
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
892
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
890
|
+
assert_html_has_tag(actual_html, 'input', type: 'hidden', id: 'user_addresses_attributes_0_id', name: 'user[addresses_attributes][0][id]', value: '20')
|
|
891
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_0_name', content: 'Name')
|
|
892
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_0_name', name: 'user[addresses_attributes][0][name]')
|
|
893
|
+
assert_html_has_tag(actual_html, 'input', type: 'checkbox', id: 'user_addresses_attributes_0__destroy', name: 'user[addresses_attributes][0][_destroy]')
|
|
893
894
|
# Address 2 (New)
|
|
894
|
-
assert_html_has_no_tag(actual_html, 'input', :
|
|
895
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
896
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
897
|
-
assert_html_has_no_tag(actual_html, 'input', :
|
|
895
|
+
assert_html_has_no_tag(actual_html, 'input', type: 'hidden', id: 'user_addresses_attributes_1_id')
|
|
896
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_1_name', content: 'Name')
|
|
897
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_1_name', name: 'user[addresses_attributes][1][name]')
|
|
898
|
+
assert_html_has_no_tag(actual_html, 'input', type: 'checkbox', id: 'user_addresses_attributes_1__destroy')
|
|
898
899
|
end
|
|
899
900
|
|
|
900
901
|
it 'should display fields for explicit instance object' do
|
|
901
|
-
address = mock_model(
|
|
902
|
+
address = mock_model('Address', name: 'Page', new_record?: false, id: 40)
|
|
902
903
|
actual_html = standard_builder.fields_for(:addresses, address) do |child_form|
|
|
903
904
|
html = child_form.label(:name)
|
|
904
905
|
html << child_form.text_field(:name)
|
|
905
906
|
html << child_form.check_box('_destroy')
|
|
906
907
|
end
|
|
907
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
908
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
909
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
910
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
908
|
+
assert_html_has_tag(actual_html, 'input', type: 'hidden', id: 'user_addresses_attributes_0_id', name: 'user[addresses_attributes][0][id]', value: '40')
|
|
909
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_0_name', content: 'Name')
|
|
910
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_0_name', name: 'user[addresses_attributes][0][name]', value: 'Page')
|
|
911
|
+
assert_html_has_tag(actual_html, 'input', type: 'checkbox', id: 'user_addresses_attributes_0__destroy', name: 'user[addresses_attributes][0][_destroy]', value: '1')
|
|
911
912
|
end
|
|
912
913
|
|
|
913
914
|
it 'should display fields for collection object' do
|
|
914
|
-
addresses = @addresses + [mock_model(
|
|
915
|
+
addresses = @addresses + [mock_model('Address', name: 'Walter', new_record?: false, id: 50)]
|
|
915
916
|
actual_html = standard_builder.fields_for(:addresses, addresses) do |child_form|
|
|
916
|
-
child_form.label(:name) +
|
|
917
|
-
child_form.text_field(:name) +
|
|
918
|
-
child_form.check_box('_destroy')
|
|
917
|
+
child_form.label(:name) + child_form.text_field(:name) + child_form.check_box('_destroy')
|
|
919
918
|
end
|
|
919
|
+
|
|
920
920
|
# Address 1
|
|
921
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
922
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
923
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
924
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
921
|
+
assert_html_has_tag(actual_html, 'input', type: 'hidden', id: 'user_addresses_attributes_0_id', name: 'user[addresses_attributes][0][id]', value: '20')
|
|
922
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_0_name', content: 'Name')
|
|
923
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_0_name', name: 'user[addresses_attributes][0][name]', value: 'Foo')
|
|
924
|
+
assert_html_has_tag(actual_html, 'input', type: 'checkbox', id: 'user_addresses_attributes_0__destroy', name: 'user[addresses_attributes][0][_destroy]')
|
|
925
925
|
# Address 3
|
|
926
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
927
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
928
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
929
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
926
|
+
assert_html_has_tag(actual_html, 'input', type: 'hidden', id: 'user_addresses_attributes_2_id', value: '50')
|
|
927
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_2_name', content: 'Name')
|
|
928
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_2_name', name: 'user[addresses_attributes][2][name]', value: 'Walter')
|
|
929
|
+
assert_html_has_tag(actual_html, 'input', type: 'checkbox', id: 'user_addresses_attributes_2__destroy')
|
|
930
930
|
end
|
|
931
931
|
|
|
932
932
|
it 'should display fields for arbitrarily deep nested forms' do
|
|
933
933
|
actual_html = standard_builder.fields_for :addresses do |child_form|
|
|
934
934
|
child_form.fields_for(:businesses) do |second_child_form|
|
|
935
935
|
second_child_form.label(:name) +
|
|
936
|
-
|
|
937
|
-
|
|
936
|
+
second_child_form.text_field(:name) +
|
|
937
|
+
second_child_form.check_box('_destroy')
|
|
938
938
|
end
|
|
939
939
|
end
|
|
940
|
-
|
|
941
|
-
assert_html_has_tag(actual_html, '
|
|
940
|
+
|
|
941
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_1_businesses_attributes_0_name', content: 'Name')
|
|
942
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_1_businesses_attributes_0_name', name: 'user[addresses_attributes][1][businesses_attributes][0][name]')
|
|
942
943
|
end
|
|
943
944
|
|
|
944
945
|
it 'should display fields for nested forms with custom indices' do
|
|
945
946
|
actual_html = standard_builder.fields_for :addresses do |child_form|
|
|
946
947
|
html = ''.html_safe
|
|
947
948
|
child_form.object.businesses.each_with_index do |business, i|
|
|
948
|
-
html += child_form.fields_for(:businesses, business, :
|
|
949
|
+
html += child_form.fields_for(:businesses, business, index: ('a'..'z').to_a[i]) do |second_child_form|
|
|
949
950
|
second_child_form.label(:name) +
|
|
950
|
-
|
|
951
|
-
|
|
951
|
+
second_child_form.text_field(:name) +
|
|
952
|
+
second_child_form.check_box('_destroy')
|
|
952
953
|
end
|
|
953
954
|
end
|
|
954
955
|
html
|
|
955
956
|
end
|
|
956
957
|
|
|
957
|
-
assert_html_has_tag(actual_html, 'label', :
|
|
958
|
-
assert_html_has_tag(actual_html, 'input', :
|
|
958
|
+
assert_html_has_tag(actual_html, 'label', for: 'user_addresses_attributes_1_businesses_attributes_a_name', content: 'Name')
|
|
959
|
+
assert_html_has_tag(actual_html, 'input', type: 'text', id: 'user_addresses_attributes_1_businesses_attributes_a_name', name: 'user[addresses_attributes][1][businesses_attributes][a][name]')
|
|
959
960
|
end
|
|
960
961
|
|
|
961
962
|
it 'should display nested children fields in erb' do
|
|
962
|
-
get
|
|
963
|
+
get '/erb/fields_for'
|
|
963
964
|
# Telephone
|
|
964
|
-
assert_response_has_tag('label', :
|
|
965
|
-
assert_response_has_tag('input', :
|
|
965
|
+
assert_response_has_tag('label', for: 'markup_user_telephone_attributes_number')
|
|
966
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_telephone_attributes_number', name: 'markup_user[telephone_attributes][number]', value: '62634576545')
|
|
966
967
|
# Address 1 (Saved)
|
|
967
|
-
assert_response_has_tag('input', :
|
|
968
|
-
assert_response_has_tag('label', :
|
|
969
|
-
assert_response_has_tag('input', :
|
|
970
|
-
assert_response_has_tag('input', :
|
|
968
|
+
assert_response_has_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_0_id', name: 'markup_user[addresses_attributes][0][id]', value: '25')
|
|
969
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_0_name', content: 'Name')
|
|
970
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_0_name', name: 'markup_user[addresses_attributes][0][name]')
|
|
971
|
+
assert_response_has_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_0__destroy', name: 'markup_user[addresses_attributes][0][_destroy]')
|
|
971
972
|
# Address 2 (New)
|
|
972
|
-
assert_response_has_no_tag('input', :
|
|
973
|
-
assert_response_has_tag('label', :
|
|
974
|
-
assert_response_has_tag('input', :
|
|
975
|
-
assert_response_has_no_tag('input', :
|
|
973
|
+
assert_response_has_no_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_1_id')
|
|
974
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_1_name', content: 'Name')
|
|
975
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_1_name', name: 'markup_user[addresses_attributes][1][name]')
|
|
976
|
+
assert_response_has_no_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_1__destroy')
|
|
976
977
|
end
|
|
977
978
|
|
|
978
979
|
it 'should display nested children fields in haml' do
|
|
979
|
-
get
|
|
980
|
+
get '/haml/fields_for'
|
|
980
981
|
# Telephone
|
|
981
|
-
assert_response_has_tag('label', :
|
|
982
|
-
assert_response_has_tag('input', :
|
|
982
|
+
assert_response_has_tag('label', for: 'markup_user_telephone_attributes_number')
|
|
983
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_telephone_attributes_number', name: 'markup_user[telephone_attributes][number]', value: '62634576545')
|
|
983
984
|
# Address 1 (Saved)
|
|
984
|
-
assert_response_has_tag('input', :
|
|
985
|
-
assert_response_has_tag('label', :
|
|
986
|
-
assert_response_has_tag('input', :
|
|
987
|
-
assert_response_has_tag('input', :
|
|
985
|
+
assert_response_has_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_0_id', name: 'markup_user[addresses_attributes][0][id]', value: '25')
|
|
986
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_0_name', content: 'Name')
|
|
987
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_0_name', name: 'markup_user[addresses_attributes][0][name]')
|
|
988
|
+
assert_response_has_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_0__destroy', name: 'markup_user[addresses_attributes][0][_destroy]')
|
|
988
989
|
# Address 2 (New)
|
|
989
|
-
assert_response_has_no_tag('input', :
|
|
990
|
-
assert_response_has_tag('label', :
|
|
991
|
-
assert_response_has_tag('input', :
|
|
992
|
-
assert_response_has_no_tag('input', :
|
|
990
|
+
assert_response_has_no_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_1_id')
|
|
991
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_1_name', content: 'Name')
|
|
992
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_1_name', name: 'markup_user[addresses_attributes][1][name]')
|
|
993
|
+
assert_response_has_no_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_1__destroy')
|
|
993
994
|
end
|
|
994
995
|
|
|
995
996
|
it 'should display nested children fields in slim' do
|
|
996
|
-
get
|
|
997
|
+
get '/slim/fields_for'
|
|
997
998
|
# Telephone
|
|
998
|
-
assert_response_has_tag('label', :
|
|
999
|
-
assert_response_has_tag('input', :
|
|
999
|
+
assert_response_has_tag('label', for: 'markup_user_telephone_attributes_number')
|
|
1000
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_telephone_attributes_number', name: 'markup_user[telephone_attributes][number]', value: '62634576545')
|
|
1000
1001
|
# Address 1 (Saved)
|
|
1001
|
-
assert_response_has_tag('input', :
|
|
1002
|
-
assert_response_has_tag('label', :
|
|
1003
|
-
assert_response_has_tag('input', :
|
|
1004
|
-
assert_response_has_tag('input', :
|
|
1002
|
+
assert_response_has_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_0_id', name: 'markup_user[addresses_attributes][0][id]', value: '25')
|
|
1003
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_0_name', content: 'Name')
|
|
1004
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_0_name', name: 'markup_user[addresses_attributes][0][name]')
|
|
1005
|
+
assert_response_has_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_0__destroy', name: 'markup_user[addresses_attributes][0][_destroy]')
|
|
1005
1006
|
# Address 2 (New)
|
|
1006
|
-
assert_response_has_no_tag('input', :
|
|
1007
|
-
assert_response_has_tag('label', :
|
|
1008
|
-
assert_response_has_tag('input', :
|
|
1009
|
-
assert_response_has_no_tag('input', :
|
|
1007
|
+
assert_response_has_no_tag('input', type: 'hidden', id: 'markup_user_addresses_attributes_1_id')
|
|
1008
|
+
assert_response_has_tag('label', for: 'markup_user_addresses_attributes_1_name', content: 'Name')
|
|
1009
|
+
assert_response_has_tag('input', type: 'text', id: 'markup_user_addresses_attributes_1_name', name: 'markup_user[addresses_attributes][1][name]')
|
|
1010
|
+
assert_response_has_no_tag('input', type: 'checkbox', id: 'markup_user_addresses_attributes_1__destroy')
|
|
1010
1011
|
end
|
|
1011
1012
|
end
|
|
1012
1013
|
|
|
@@ -1016,183 +1017,183 @@ describe "FormBuilder" do
|
|
|
1016
1017
|
|
|
1017
1018
|
describe 'for #text_field_block method' do
|
|
1018
1019
|
it 'should display correct text field block html' do
|
|
1019
|
-
actual_html = standard_builder.text_field_block(:first_name, :
|
|
1020
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1021
|
-
assert_html_has_tag(actual_html, 'p input.large[type=text]', :
|
|
1020
|
+
actual_html = standard_builder.text_field_block(:first_name, class: 'large', caption: 'FName')
|
|
1021
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_first_name', content: 'FName')
|
|
1022
|
+
assert_html_has_tag(actual_html, 'p input.large[type=text]', value: 'Joe', id: 'user_first_name', name: 'user[first_name]')
|
|
1022
1023
|
end
|
|
1023
1024
|
|
|
1024
1025
|
it 'should display correct text field block in haml' do
|
|
1025
|
-
get
|
|
1026
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1027
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1026
|
+
get '/haml/form_for'
|
|
1027
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_username', content: 'Nickname: ', class: 'label'
|
|
1028
|
+
assert_response_has_tag '#demo2 p input', type: 'text', name: 'markup_user[username]', id: 'markup_user_username'
|
|
1028
1029
|
end
|
|
1029
1030
|
|
|
1030
1031
|
it 'should display correct text field block in erb' do
|
|
1031
|
-
get
|
|
1032
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1033
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1032
|
+
get '/erb/form_for'
|
|
1033
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_username', content: 'Nickname: ', class: 'label'
|
|
1034
|
+
assert_response_has_tag '#demo2 p input', type: 'text', name: 'markup_user[username]', id: 'markup_user_username'
|
|
1034
1035
|
end
|
|
1035
1036
|
|
|
1036
1037
|
it 'should display correct text field block in slim' do
|
|
1037
|
-
get
|
|
1038
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1039
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1038
|
+
get '/slim/form_for'
|
|
1039
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_username', content: 'Nickname: ', class: 'label'
|
|
1040
|
+
assert_response_has_tag '#demo2 p input', type: 'text', name: 'markup_user[username]', id: 'markup_user_username'
|
|
1040
1041
|
end
|
|
1041
1042
|
end
|
|
1042
1043
|
|
|
1043
1044
|
describe 'for #text_area_block method' do
|
|
1044
1045
|
it 'should display correct text area block html' do
|
|
1045
|
-
actual_html = standard_builder.text_area_block(:about, :
|
|
1046
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1047
|
-
assert_html_has_tag(actual_html, 'p textarea', :
|
|
1046
|
+
actual_html = standard_builder.text_area_block(:about, class: 'large', caption: 'About Me')
|
|
1047
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_about', content: 'About Me')
|
|
1048
|
+
assert_html_has_tag(actual_html, 'p textarea', id: 'user_about', name: 'user[about]')
|
|
1048
1049
|
end
|
|
1049
1050
|
|
|
1050
1051
|
it 'should display correct text area block in haml' do
|
|
1051
|
-
get
|
|
1052
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1053
|
-
assert_response_has_tag '#demo2 p textarea', :
|
|
1052
|
+
get '/haml/form_for'
|
|
1053
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_about', content: 'About: '
|
|
1054
|
+
assert_response_has_tag '#demo2 p textarea', name: 'markup_user[about]', id: 'markup_user_about'
|
|
1054
1055
|
end
|
|
1055
1056
|
|
|
1056
1057
|
it 'should display correct text area block in erb' do
|
|
1057
|
-
get
|
|
1058
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1059
|
-
assert_response_has_tag '#demo2 p textarea', :
|
|
1058
|
+
get '/erb/form_for'
|
|
1059
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_about', content: 'About: '
|
|
1060
|
+
assert_response_has_tag '#demo2 p textarea', name: 'markup_user[about]', id: 'markup_user_about'
|
|
1060
1061
|
end
|
|
1061
1062
|
|
|
1062
1063
|
it 'should display correct text area block in slim' do
|
|
1063
|
-
get
|
|
1064
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1065
|
-
assert_response_has_tag '#demo2 p textarea', :
|
|
1064
|
+
get '/slim/form_for'
|
|
1065
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_about', content: 'About: '
|
|
1066
|
+
assert_response_has_tag '#demo2 p textarea', name: 'markup_user[about]', id: 'markup_user_about'
|
|
1066
1067
|
end
|
|
1067
1068
|
end
|
|
1068
1069
|
|
|
1069
1070
|
describe 'for #password_field_block method' do
|
|
1070
1071
|
it 'should display correct password field block html' do
|
|
1071
|
-
actual_html = standard_builder.password_field_block(:keycode, :
|
|
1072
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1073
|
-
assert_html_has_tag(actual_html, 'p input.large[type=password]', :
|
|
1072
|
+
actual_html = standard_builder.password_field_block(:keycode, class: 'large', caption: 'Code: ')
|
|
1073
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_keycode', content: 'Code: ')
|
|
1074
|
+
assert_html_has_tag(actual_html, 'p input.large[type=password]', id: 'user_keycode', name: 'user[keycode]')
|
|
1074
1075
|
end
|
|
1075
1076
|
|
|
1076
1077
|
it 'should display correct password field block in haml' do
|
|
1077
|
-
get
|
|
1078
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1079
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1078
|
+
get '/haml/form_for'
|
|
1079
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_code', content: 'Code: '
|
|
1080
|
+
assert_response_has_tag '#demo2 p input', type: 'password', name: 'markup_user[code]', id: 'markup_user_code'
|
|
1080
1081
|
end
|
|
1081
1082
|
|
|
1082
1083
|
it 'should display correct password field block in erb' do
|
|
1083
|
-
get
|
|
1084
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1085
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1084
|
+
get '/erb/form_for'
|
|
1085
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_code', content: 'Code: '
|
|
1086
|
+
assert_response_has_tag '#demo2 p input', type: 'password', name: 'markup_user[code]', id: 'markup_user_code'
|
|
1086
1087
|
end
|
|
1087
1088
|
|
|
1088
1089
|
it 'should display correct password field block in slim' do
|
|
1089
|
-
get
|
|
1090
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1091
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1090
|
+
get '/slim/form_for'
|
|
1091
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_code', content: 'Code: '
|
|
1092
|
+
assert_response_has_tag '#demo2 p input', type: 'password', name: 'markup_user[code]', id: 'markup_user_code'
|
|
1092
1093
|
end
|
|
1093
1094
|
end
|
|
1094
1095
|
|
|
1095
1096
|
describe 'for #file_field_block method' do
|
|
1096
1097
|
it 'should display correct file field block html' do
|
|
1097
|
-
actual_html = standard_builder.file_field_block(:photo, :
|
|
1098
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1099
|
-
assert_html_has_tag(actual_html, 'p input.large[type=file]', :
|
|
1098
|
+
actual_html = standard_builder.file_field_block(:photo, class: 'large', caption: 'Photo: ')
|
|
1099
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_photo', content: 'Photo: ')
|
|
1100
|
+
assert_html_has_tag(actual_html, 'p input.large[type=file]', id: 'user_photo', name: 'user[photo]')
|
|
1100
1101
|
end
|
|
1101
1102
|
|
|
1102
1103
|
it 'should display correct file field block in haml' do
|
|
1103
|
-
get
|
|
1104
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1105
|
-
assert_response_has_tag '#demo2 p input.upload', :
|
|
1104
|
+
get '/haml/form_for'
|
|
1105
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_photo', content: 'Photo: '
|
|
1106
|
+
assert_response_has_tag '#demo2 p input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
1106
1107
|
end
|
|
1107
1108
|
|
|
1108
1109
|
it 'should display correct file field block in erb' do
|
|
1109
|
-
get
|
|
1110
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1111
|
-
assert_response_has_tag '#demo2 p input.upload', :
|
|
1110
|
+
get '/erb/form_for'
|
|
1111
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_photo', content: 'Photo: '
|
|
1112
|
+
assert_response_has_tag '#demo2 p input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
1112
1113
|
end
|
|
1113
1114
|
|
|
1114
1115
|
it 'should display correct file field block in slim' do
|
|
1115
|
-
get
|
|
1116
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1117
|
-
assert_response_has_tag '#demo2 p input.upload', :
|
|
1116
|
+
get '/slim/form_for'
|
|
1117
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_photo', content: 'Photo: '
|
|
1118
|
+
assert_response_has_tag '#demo2 p input.upload', type: 'file', name: 'markup_user[photo]', id: 'markup_user_photo'
|
|
1118
1119
|
end
|
|
1119
1120
|
end
|
|
1120
1121
|
|
|
1121
1122
|
describe 'for #check_box_block method' do
|
|
1122
1123
|
it 'should display correct check box block html' do
|
|
1123
|
-
actual_html = standard_builder.check_box_block(:remember_me, :
|
|
1124
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1125
|
-
assert_html_has_tag(actual_html, 'p input.large[type=checkbox]', :
|
|
1124
|
+
actual_html = standard_builder.check_box_block(:remember_me, class: 'large', caption: 'Remember session?')
|
|
1125
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_remember_me', content: 'Remember session?')
|
|
1126
|
+
assert_html_has_tag(actual_html, 'p input.large[type=checkbox]', id: 'user_remember_me', name: 'user[remember_me]')
|
|
1126
1127
|
end
|
|
1127
1128
|
|
|
1128
1129
|
it 'should display correct check box block in haml' do
|
|
1129
|
-
get
|
|
1130
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1131
|
-
assert_response_has_tag '#demo2 p input.checker', :
|
|
1130
|
+
get '/haml/form_for'
|
|
1131
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_remember_me', content: 'Remember me: '
|
|
1132
|
+
assert_response_has_tag '#demo2 p input.checker', type: 'checkbox', name: 'markup_user[remember_me]'
|
|
1132
1133
|
end
|
|
1133
1134
|
|
|
1134
1135
|
it 'should display correct check box block in erb' do
|
|
1135
|
-
get
|
|
1136
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1137
|
-
assert_response_has_tag '#demo2 p input.checker', :
|
|
1136
|
+
get '/erb/form_for'
|
|
1137
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_remember_me', content: 'Remember me: '
|
|
1138
|
+
assert_response_has_tag '#demo2 p input.checker', type: 'checkbox', name: 'markup_user[remember_me]'
|
|
1138
1139
|
end
|
|
1139
1140
|
|
|
1140
1141
|
it 'should display correct check box block in slim' do
|
|
1141
|
-
get
|
|
1142
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1143
|
-
assert_response_has_tag '#demo2 p input.checker', :
|
|
1142
|
+
get '/slim/form_for'
|
|
1143
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_remember_me', content: 'Remember me: '
|
|
1144
|
+
assert_response_has_tag '#demo2 p input.checker', type: 'checkbox', name: 'markup_user[remember_me]'
|
|
1144
1145
|
end
|
|
1145
1146
|
end
|
|
1146
1147
|
|
|
1147
1148
|
describe 'for #select_block method' do
|
|
1148
1149
|
it 'should display correct select_block block html' do
|
|
1149
|
-
actual_html = standard_builder.select_block(:country, :
|
|
1150
|
-
assert_html_has_tag(actual_html, 'p label', :
|
|
1151
|
-
assert_html_has_tag(actual_html, 'p select', :
|
|
1152
|
-
assert_html_has_tag(actual_html, 'p select option', :
|
|
1153
|
-
assert_html_has_tag(actual_html, 'p select option', :
|
|
1150
|
+
actual_html = standard_builder.select_block(:country, options: %w[USA Canada], class: 'large', caption: 'Your country')
|
|
1151
|
+
assert_html_has_tag(actual_html, 'p label', for: 'user_country', content: 'Your country')
|
|
1152
|
+
assert_html_has_tag(actual_html, 'p select', id: 'user_country', name: 'user[country]')
|
|
1153
|
+
assert_html_has_tag(actual_html, 'p select option', content: 'USA')
|
|
1154
|
+
assert_html_has_tag(actual_html, 'p select option', content: 'Canada')
|
|
1154
1155
|
end
|
|
1155
1156
|
|
|
1156
1157
|
it 'should display correct select_block block in haml' do
|
|
1157
|
-
get
|
|
1158
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1159
|
-
assert_response_has_tag '#demo2 p select', :
|
|
1160
|
-
assert_response_has_tag '#demo2 p select option', :
|
|
1161
|
-
assert_response_has_tag '#demo2 p select option', :
|
|
1158
|
+
get '/haml/form_for'
|
|
1159
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_state', content: 'State: '
|
|
1160
|
+
assert_response_has_tag '#demo2 p select', name: 'markup_user[state]', id: 'markup_user_state'
|
|
1161
|
+
assert_response_has_tag '#demo2 p select option', content: 'California'
|
|
1162
|
+
assert_response_has_tag '#demo2 p select option', content: 'Texas'
|
|
1162
1163
|
end
|
|
1163
1164
|
|
|
1164
1165
|
it 'should display correct select_block block in erb' do
|
|
1165
|
-
get
|
|
1166
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1167
|
-
assert_response_has_tag '#demo2 p select', :
|
|
1166
|
+
get '/erb/form_for'
|
|
1167
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_state', content: 'State: '
|
|
1168
|
+
assert_response_has_tag '#demo2 p select', name: 'markup_user[state]', id: 'markup_user_state'
|
|
1168
1169
|
end
|
|
1169
1170
|
|
|
1170
1171
|
it 'should display correct select_block block in slim' do
|
|
1171
|
-
get
|
|
1172
|
-
assert_response_has_tag '#demo2 p label', :
|
|
1173
|
-
assert_response_has_tag '#demo2 p select', :
|
|
1172
|
+
get '/slim/form_for'
|
|
1173
|
+
assert_response_has_tag '#demo2 p label', for: 'markup_user_state', content: 'State: '
|
|
1174
|
+
assert_response_has_tag '#demo2 p select', name: 'markup_user[state]', id: 'markup_user_state'
|
|
1174
1175
|
end
|
|
1175
1176
|
end
|
|
1176
1177
|
|
|
1177
1178
|
describe 'for #submit_block method' do
|
|
1178
1179
|
it 'should display correct submit block html' do
|
|
1179
|
-
actual_html = standard_builder.submit_block(
|
|
1180
|
-
assert_html_has_tag(actual_html, 'p input.large[type=submit]', :
|
|
1180
|
+
actual_html = standard_builder.submit_block('Update', class: 'large')
|
|
1181
|
+
assert_html_has_tag(actual_html, 'p input.large[type=submit]', value: 'Update')
|
|
1181
1182
|
end
|
|
1182
1183
|
|
|
1183
1184
|
it 'should display correct submit block in haml' do
|
|
1184
|
-
get
|
|
1185
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1185
|
+
get '/haml/form_for'
|
|
1186
|
+
assert_response_has_tag '#demo2 p input', type: 'submit', class: 'button'
|
|
1186
1187
|
end
|
|
1187
1188
|
|
|
1188
1189
|
it 'should display correct submit block in erb' do
|
|
1189
|
-
get
|
|
1190
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1190
|
+
get '/erb/form_for'
|
|
1191
|
+
assert_response_has_tag '#demo2 p input', type: 'submit', class: 'button'
|
|
1191
1192
|
end
|
|
1192
1193
|
|
|
1193
1194
|
it 'should display correct submit block in slim' do
|
|
1194
|
-
get
|
|
1195
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1195
|
+
get '/slim/form_for'
|
|
1196
|
+
assert_response_has_tag '#demo2 p input', type: 'submit', class: 'button'
|
|
1196
1197
|
end
|
|
1197
1198
|
end
|
|
1198
1199
|
|
|
@@ -1202,256 +1203,256 @@ describe "FormBuilder" do
|
|
|
1202
1203
|
end
|
|
1203
1204
|
|
|
1204
1205
|
it 'should display correct image submit block html' do
|
|
1205
|
-
actual_html = standard_builder.image_submit_block(
|
|
1206
|
-
assert_html_has_tag(actual_html, 'p input.large[type=image]', :
|
|
1206
|
+
actual_html = standard_builder.image_submit_block('buttons/ok.png', class: 'large')
|
|
1207
|
+
assert_html_has_tag(actual_html, 'p input.large[type=image]', src: "/images/buttons/ok.png?#{@stamp}")
|
|
1207
1208
|
end
|
|
1208
1209
|
|
|
1209
1210
|
it 'should display correct image submit block in haml' do
|
|
1210
|
-
get
|
|
1211
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1211
|
+
get '/haml/form_for'
|
|
1212
|
+
assert_response_has_tag '#demo2 p input', type: 'image', class: 'image', src: "/images/buttons/ok.png?#{@stamp}"
|
|
1212
1213
|
end
|
|
1213
1214
|
|
|
1214
1215
|
it 'should display correct image submit block in slim' do
|
|
1215
|
-
get
|
|
1216
|
-
assert_response_has_tag '#demo2 p input', :
|
|
1216
|
+
get '/slim/form_for'
|
|
1217
|
+
assert_response_has_tag '#demo2 p input', type: 'image', class: 'image', src: "/images/buttons/ok.png?#{@stamp}"
|
|
1217
1218
|
end
|
|
1218
1219
|
end
|
|
1219
1220
|
|
|
1220
1221
|
describe 'for #datetime_field method' do
|
|
1221
1222
|
it 'should display correct datetime field html' do
|
|
1222
1223
|
actual_html = standard_builder.datetime_field(:datetime)
|
|
1223
|
-
assert_html_has_tag(actual_html, 'input[type=datetime]', :
|
|
1224
|
+
assert_html_has_tag(actual_html, 'input[type=datetime]', id: 'user_datetime', name: 'user[datetime]')
|
|
1224
1225
|
end
|
|
1225
1226
|
|
|
1226
1227
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1227
1228
|
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
|
1228
1229
|
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
|
1229
1230
|
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
|
1230
|
-
actual_html = standard_builder.datetime_field(:datetime, :
|
|
1231
|
+
actual_html = standard_builder.datetime_field(:datetime, max: max, min: min, value: value)
|
|
1231
1232
|
expected = {
|
|
1232
|
-
:
|
|
1233
|
-
:
|
|
1234
|
-
:
|
|
1235
|
-
:
|
|
1233
|
+
id: 'user_datetime',
|
|
1234
|
+
max: '2000-04-01T12:00:00.000+0000',
|
|
1235
|
+
min: '1993-02-24T12:30:45.000+0000',
|
|
1236
|
+
value: '2000-04-01T12:00:00.000+0000'
|
|
1236
1237
|
}
|
|
1237
1238
|
assert_html_has_tag(actual_html, 'input[type=datetime]', expected)
|
|
1238
1239
|
end
|
|
1239
1240
|
|
|
1240
1241
|
it 'should display correct datetime field in haml' do
|
|
1241
|
-
get
|
|
1242
|
-
assert_response_has_tag '#demo input[type=datetime]', :
|
|
1242
|
+
get '/haml/form_for'
|
|
1243
|
+
assert_response_has_tag '#demo input[type=datetime]', id: 'markup_user_datetime', max: '2000-04-01T12:00:00.000+0000'
|
|
1243
1244
|
end
|
|
1244
1245
|
|
|
1245
1246
|
it 'should display correct datetime field in erb' do
|
|
1246
|
-
get
|
|
1247
|
-
assert_response_has_tag '#demo input[type=datetime]', :
|
|
1247
|
+
get '/erb/form_for'
|
|
1248
|
+
assert_response_has_tag '#demo input[type=datetime]', id: 'markup_user_datetime', max: '2000-04-01T12:00:00.000+0000'
|
|
1248
1249
|
end
|
|
1249
1250
|
|
|
1250
1251
|
it 'should display correct datetime field in slim' do
|
|
1251
|
-
get
|
|
1252
|
-
assert_response_has_tag '#demo input[type=datetime]', :
|
|
1252
|
+
get '/slim/form_for'
|
|
1253
|
+
assert_response_has_tag '#demo input[type=datetime]', id: 'markup_user_datetime', max: '2000-04-01T12:00:00.000+0000'
|
|
1253
1254
|
end
|
|
1254
1255
|
end
|
|
1255
1256
|
|
|
1256
1257
|
describe 'for #datetime_local_field method' do
|
|
1257
1258
|
it 'should display correct datetime-local field html' do
|
|
1258
1259
|
actual_html = standard_builder.datetime_local_field(:datetime_local)
|
|
1259
|
-
assert_html_has_tag(actual_html, 'input[type=datetime-local]', :
|
|
1260
|
+
assert_html_has_tag(actual_html, 'input[type=datetime-local]', id: 'user_datetime_local', name: 'user[datetime_local]')
|
|
1260
1261
|
end
|
|
1261
1262
|
|
|
1262
1263
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1263
1264
|
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
|
1264
1265
|
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
|
1265
1266
|
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
|
1266
|
-
actual_html = standard_builder.datetime_local_field(:datetime_local, :
|
|
1267
|
+
actual_html = standard_builder.datetime_local_field(:datetime_local, max: max, min: min, value: value)
|
|
1267
1268
|
expected = {
|
|
1268
|
-
:
|
|
1269
|
-
:
|
|
1270
|
-
:
|
|
1271
|
-
:
|
|
1269
|
+
id: 'user_datetime_local',
|
|
1270
|
+
max: '2000-04-01T12:00:00',
|
|
1271
|
+
min: '1993-02-24T12:30:45',
|
|
1272
|
+
value: '2000-04-01T12:00:00'
|
|
1272
1273
|
}
|
|
1273
1274
|
assert_html_has_tag(actual_html, 'input[type=datetime-local]', expected)
|
|
1274
1275
|
end
|
|
1275
1276
|
|
|
1276
1277
|
it 'should display correct datetime-local field in haml' do
|
|
1277
|
-
get
|
|
1278
|
-
assert_response_has_tag '#demo input[type=datetime-local]', :
|
|
1278
|
+
get '/haml/form_for'
|
|
1279
|
+
assert_response_has_tag '#demo input[type=datetime-local]', id: 'markup_user_datetime_local'
|
|
1279
1280
|
end
|
|
1280
1281
|
|
|
1281
1282
|
it 'should display correct datetime-local field in erb' do
|
|
1282
|
-
get
|
|
1283
|
-
assert_response_has_tag '#demo input[type=datetime-local]', :
|
|
1283
|
+
get '/erb/form_for'
|
|
1284
|
+
assert_response_has_tag '#demo input[type=datetime-local]', id: 'markup_user_datetime_local'
|
|
1284
1285
|
end
|
|
1285
1286
|
|
|
1286
1287
|
it 'should display correct datetime-local field in slim' do
|
|
1287
|
-
get
|
|
1288
|
-
assert_response_has_tag '#demo input[type=datetime-local]', :
|
|
1288
|
+
get '/slim/form_for'
|
|
1289
|
+
assert_response_has_tag '#demo input[type=datetime-local]', id: 'markup_user_datetime_local'
|
|
1289
1290
|
end
|
|
1290
1291
|
end
|
|
1291
1292
|
|
|
1292
1293
|
describe 'for #date_field method' do
|
|
1293
1294
|
it 'should display correct date field html' do
|
|
1294
1295
|
actual_html = standard_builder.date_field(:date)
|
|
1295
|
-
assert_html_has_tag(actual_html, 'input[type=date]', :
|
|
1296
|
+
assert_html_has_tag(actual_html, 'input[type=date]', id: 'user_date', name: 'user[date]')
|
|
1296
1297
|
end
|
|
1297
1298
|
|
|
1298
1299
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1299
1300
|
max = DateTime.new(2000, 4, 1)
|
|
1300
1301
|
min = DateTime.new(1993, 2, 24)
|
|
1301
1302
|
value = DateTime.new(2000, 4, 1)
|
|
1302
|
-
actual_html = standard_builder.date_field(:date, :
|
|
1303
|
+
actual_html = standard_builder.date_field(:date, max: max, min: min, value: value)
|
|
1303
1304
|
expected = {
|
|
1304
|
-
:
|
|
1305
|
-
:
|
|
1306
|
-
:
|
|
1307
|
-
:
|
|
1305
|
+
id: 'user_date',
|
|
1306
|
+
max: '2000-04-01',
|
|
1307
|
+
min: '1993-02-24',
|
|
1308
|
+
value: '2000-04-01'
|
|
1308
1309
|
}
|
|
1309
1310
|
assert_html_has_tag(actual_html, 'input[type=date]', expected)
|
|
1310
1311
|
end
|
|
1311
1312
|
|
|
1312
1313
|
it 'should display correct date field in haml' do
|
|
1313
|
-
get
|
|
1314
|
-
assert_response_has_tag '#demo input[type=date]', :
|
|
1314
|
+
get '/haml/form_for'
|
|
1315
|
+
assert_response_has_tag '#demo input[type=date]', id: 'markup_user_date'
|
|
1315
1316
|
end
|
|
1316
1317
|
|
|
1317
1318
|
it 'should display correct date field in erb' do
|
|
1318
|
-
get
|
|
1319
|
-
assert_response_has_tag '#demo input[type=date]', :
|
|
1319
|
+
get '/erb/form_for'
|
|
1320
|
+
assert_response_has_tag '#demo input[type=date]', id: 'markup_user_date'
|
|
1320
1321
|
end
|
|
1321
1322
|
|
|
1322
1323
|
it 'should display correct date field in slim' do
|
|
1323
|
-
get
|
|
1324
|
-
assert_response_has_tag '#demo input[type=date]', :
|
|
1324
|
+
get '/slim/form_for'
|
|
1325
|
+
assert_response_has_tag '#demo input[type=date]', id: 'markup_user_date'
|
|
1325
1326
|
end
|
|
1326
1327
|
end
|
|
1327
1328
|
|
|
1328
1329
|
describe 'for #month_field method' do
|
|
1329
1330
|
it 'should display correct month field html' do
|
|
1330
1331
|
actual_html = standard_builder.month_field(:month)
|
|
1331
|
-
assert_html_has_tag(actual_html, 'input[type=month]', :
|
|
1332
|
+
assert_html_has_tag(actual_html, 'input[type=month]', id: 'user_month', name: 'user[month]')
|
|
1332
1333
|
end
|
|
1333
1334
|
|
|
1334
1335
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1335
1336
|
max = DateTime.new(2000, 4, 1)
|
|
1336
1337
|
min = DateTime.new(1993, 2, 24)
|
|
1337
1338
|
value = DateTime.new(2000, 4, 1)
|
|
1338
|
-
actual_html = standard_builder.month_field(:month, :
|
|
1339
|
+
actual_html = standard_builder.month_field(:month, max: max, min: min, value: value)
|
|
1339
1340
|
expected = {
|
|
1340
|
-
:
|
|
1341
|
-
:
|
|
1342
|
-
:
|
|
1343
|
-
:
|
|
1341
|
+
id: 'user_month',
|
|
1342
|
+
max: '2000-04',
|
|
1343
|
+
min: '1993-02',
|
|
1344
|
+
value: '2000-04'
|
|
1344
1345
|
}
|
|
1345
1346
|
assert_html_has_tag(actual_html, 'input[type=month]', expected)
|
|
1346
1347
|
end
|
|
1347
1348
|
|
|
1348
1349
|
it 'should display correct month field in haml' do
|
|
1349
|
-
get
|
|
1350
|
-
assert_response_has_tag '#demo input[type=month]', :
|
|
1350
|
+
get '/haml/form_for'
|
|
1351
|
+
assert_response_has_tag '#demo input[type=month]', id: 'markup_user_month'
|
|
1351
1352
|
end
|
|
1352
1353
|
|
|
1353
1354
|
it 'should display correct month field in erb' do
|
|
1354
|
-
get
|
|
1355
|
-
assert_response_has_tag '#demo input[type=month]', :
|
|
1355
|
+
get '/erb/form_for'
|
|
1356
|
+
assert_response_has_tag '#demo input[type=month]', id: 'markup_user_month'
|
|
1356
1357
|
end
|
|
1357
1358
|
|
|
1358
1359
|
it 'should display correct month field in slim' do
|
|
1359
|
-
get
|
|
1360
|
-
assert_response_has_tag '#demo input[type=month]', :
|
|
1360
|
+
get '/slim/form_for'
|
|
1361
|
+
assert_response_has_tag '#demo input[type=month]', id: 'markup_user_month'
|
|
1361
1362
|
end
|
|
1362
1363
|
end
|
|
1363
1364
|
|
|
1364
1365
|
describe 'for #week_field method' do
|
|
1365
1366
|
it 'should display correct week field html' do
|
|
1366
1367
|
actual_html = standard_builder.week_field(:week)
|
|
1367
|
-
assert_html_has_tag(actual_html, 'input[type=week]', :
|
|
1368
|
+
assert_html_has_tag(actual_html, 'input[type=week]', id: 'user_week', name: 'user[week]')
|
|
1368
1369
|
end
|
|
1369
1370
|
|
|
1370
1371
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1371
1372
|
max = DateTime.new(2000, 4, 1)
|
|
1372
1373
|
min = DateTime.new(1993, 2, 24)
|
|
1373
1374
|
value = DateTime.new(2000, 4, 1)
|
|
1374
|
-
actual_html = standard_builder.week_field(:week, :
|
|
1375
|
+
actual_html = standard_builder.week_field(:week, max: max, min: min, value: value)
|
|
1375
1376
|
expected = {
|
|
1376
|
-
:
|
|
1377
|
-
:
|
|
1378
|
-
:
|
|
1379
|
-
:
|
|
1377
|
+
id: 'user_week',
|
|
1378
|
+
max: '2000-W13',
|
|
1379
|
+
min: '1993-W08',
|
|
1380
|
+
value: '2000-W13'
|
|
1380
1381
|
}
|
|
1381
1382
|
assert_html_has_tag(actual_html, 'input[type=week]', expected)
|
|
1382
1383
|
end
|
|
1383
1384
|
|
|
1384
1385
|
it 'should display correct week field in haml' do
|
|
1385
|
-
get
|
|
1386
|
-
assert_response_has_tag '#demo input[type=week]', :
|
|
1386
|
+
get '/haml/form_for'
|
|
1387
|
+
assert_response_has_tag '#demo input[type=week]', id: 'markup_user_week'
|
|
1387
1388
|
end
|
|
1388
1389
|
|
|
1389
1390
|
it 'should display correct week field in erb' do
|
|
1390
|
-
get
|
|
1391
|
-
assert_response_has_tag '#demo input[type=week]', :
|
|
1391
|
+
get '/erb/form_for'
|
|
1392
|
+
assert_response_has_tag '#demo input[type=week]', id: 'markup_user_week'
|
|
1392
1393
|
end
|
|
1393
1394
|
|
|
1394
1395
|
it 'should display correct week field in slim' do
|
|
1395
|
-
get
|
|
1396
|
-
assert_response_has_tag '#demo input[type=week]', :
|
|
1396
|
+
get '/slim/form_for'
|
|
1397
|
+
assert_response_has_tag '#demo input[type=week]', id: 'markup_user_week'
|
|
1397
1398
|
end
|
|
1398
1399
|
end
|
|
1399
1400
|
|
|
1400
1401
|
describe 'for #time_field method' do
|
|
1401
1402
|
it 'should display correct time field html' do
|
|
1402
1403
|
actual_html = standard_builder.time_field(:time)
|
|
1403
|
-
assert_html_has_tag(actual_html, 'input[type=time]', :
|
|
1404
|
+
assert_html_has_tag(actual_html, 'input[type=time]', id: 'user_time', name: 'user[time]')
|
|
1404
1405
|
end
|
|
1405
1406
|
|
|
1406
1407
|
it 'should format DateTime to correct value if min and max and value options exist' do
|
|
1407
1408
|
max = Time.new(2008, 6, 21, 13, 30, 0)
|
|
1408
1409
|
min = Time.new(1993, 2, 24, 1, 19, 12)
|
|
1409
1410
|
value = Time.new(2008, 6, 21, 13, 30, 0)
|
|
1410
|
-
actual_html = standard_builder.time_field(:time, :
|
|
1411
|
+
actual_html = standard_builder.time_field(:time, max: max, min: min, value: value)
|
|
1411
1412
|
expected = {
|
|
1412
|
-
:
|
|
1413
|
-
:
|
|
1414
|
-
:
|
|
1415
|
-
:
|
|
1413
|
+
id: 'user_time',
|
|
1414
|
+
max: '13:30:00.000',
|
|
1415
|
+
min: '01:19:12.000',
|
|
1416
|
+
value: '13:30:00.000'
|
|
1416
1417
|
}
|
|
1417
1418
|
assert_html_has_tag(actual_html, 'input[type=time]', expected)
|
|
1418
1419
|
end
|
|
1419
1420
|
|
|
1420
1421
|
it 'should display correct time field in haml' do
|
|
1421
|
-
get
|
|
1422
|
-
assert_response_has_tag '#demo input[type=time]', :
|
|
1422
|
+
get '/haml/form_for'
|
|
1423
|
+
assert_response_has_tag '#demo input[type=time]', id: 'markup_user_time'
|
|
1423
1424
|
end
|
|
1424
1425
|
|
|
1425
1426
|
it 'should display correct time field in erb' do
|
|
1426
|
-
get
|
|
1427
|
-
assert_response_has_tag '#demo input[type=time]', :
|
|
1427
|
+
get '/erb/form_for'
|
|
1428
|
+
assert_response_has_tag '#demo input[type=time]', id: 'markup_user_time'
|
|
1428
1429
|
end
|
|
1429
1430
|
|
|
1430
1431
|
it 'should display correct time field in slim' do
|
|
1431
|
-
get
|
|
1432
|
-
assert_response_has_tag '#demo input[type=time]', :
|
|
1432
|
+
get '/slim/form_for'
|
|
1433
|
+
assert_response_has_tag '#demo input[type=time]', id: 'markup_user_time'
|
|
1433
1434
|
end
|
|
1434
1435
|
end
|
|
1435
1436
|
|
|
1436
1437
|
describe 'for #color_field method' do
|
|
1437
1438
|
it 'should display correct color field html' do
|
|
1438
1439
|
actual_html = standard_builder.color_field(:color)
|
|
1439
|
-
assert_html_has_tag(actual_html, 'input[type=color]', :
|
|
1440
|
+
assert_html_has_tag(actual_html, 'input[type=color]', id: 'user_color', name: 'user[color]')
|
|
1440
1441
|
end
|
|
1441
1442
|
|
|
1442
1443
|
it 'should display correct color field in haml' do
|
|
1443
|
-
get
|
|
1444
|
-
assert_response_has_tag '#demo input[type=color]', :
|
|
1444
|
+
get '/haml/form_for'
|
|
1445
|
+
assert_response_has_tag '#demo input[type=color]', id: 'markup_user_color', value: '#ff0000'
|
|
1445
1446
|
end
|
|
1446
1447
|
|
|
1447
1448
|
it 'should display correct color field in erb' do
|
|
1448
|
-
get
|
|
1449
|
-
assert_response_has_tag '#demo input[type=color]', :
|
|
1449
|
+
get '/erb/form_for'
|
|
1450
|
+
assert_response_has_tag '#demo input[type=color]', id: 'markup_user_color', value: '#ff0000'
|
|
1450
1451
|
end
|
|
1451
1452
|
|
|
1452
1453
|
it 'should display correct color field in slim' do
|
|
1453
|
-
get
|
|
1454
|
-
assert_response_has_tag '#demo input[type=color]', :
|
|
1454
|
+
get '/slim/form_for'
|
|
1455
|
+
assert_response_has_tag '#demo input[type=color]', id: 'markup_user_color', value: '#ff0000'
|
|
1455
1456
|
end
|
|
1456
1457
|
end
|
|
1457
1458
|
end
|