formtastic 3.0.0 → 5.0.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 +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'boolean input' do
|
|
5
|
+
RSpec.describe 'boolean input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -16,38 +17,38 @@ describe 'boolean input' do
|
|
|
16
17
|
concat(builder.input(:allow_comments, :as => :boolean))
|
|
17
18
|
end)
|
|
18
19
|
end
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
it_should_have_input_wrapper_with_class("boolean")
|
|
21
22
|
it_should_have_input_wrapper_with_class(:input)
|
|
22
23
|
it_should_have_input_wrapper_with_id("post_allow_comments_input")
|
|
23
24
|
it_should_apply_error_logic_for_input_type(:boolean)
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
it 'should generate a label containing the input' do
|
|
26
|
-
output_buffer.
|
|
27
|
-
output_buffer.
|
|
28
|
-
output_buffer.
|
|
29
|
-
output_buffer.
|
|
30
|
-
output_buffer.
|
|
31
|
-
output_buffer.
|
|
32
|
-
output_buffer.
|
|
27
|
+
expect(output_buffer.to_str).not_to have_tag('label.label')
|
|
28
|
+
expect(output_buffer.to_str).to have_tag('form li label', :count => 1)
|
|
29
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="post_allow_comments"]')
|
|
30
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
|
|
31
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]', :count => 1)
|
|
32
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"]', :count => 1)
|
|
33
|
+
expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
|
|
33
34
|
end
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
it 'should not add a "name" attribute to the label' do
|
|
36
|
-
output_buffer.
|
|
37
|
+
expect(output_buffer.to_str).not_to have_tag('form li label[@name]')
|
|
37
38
|
end
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
it 'should generate a checkbox input' do
|
|
40
|
-
output_buffer.
|
|
41
|
-
output_buffer.
|
|
42
|
-
output_buffer.
|
|
43
|
-
output_buffer.
|
|
44
|
-
output_buffer.
|
|
41
|
+
expect(output_buffer.to_str).to have_tag('form li label input')
|
|
42
|
+
expect(output_buffer.to_str).to have_tag('form li label input#post_allow_comments')
|
|
43
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
44
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@name="post[allow_comments]"]')
|
|
45
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"]')
|
|
45
46
|
end
|
|
46
|
-
|
|
47
|
+
|
|
47
48
|
it 'should generate a checked input if object.method returns true' do
|
|
48
|
-
output_buffer.
|
|
49
|
-
output_buffer.
|
|
50
|
-
output_buffer.
|
|
49
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
|
|
50
|
+
expect(output_buffer.to_str).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
|
|
51
|
+
expect(output_buffer.to_str).to have_tag('form li input#post_allow_comments', :count => 1)
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
|
|
@@ -55,7 +56,7 @@ describe 'boolean input' do
|
|
|
55
56
|
concat(semantic_form_for(@new_post) do |builder|
|
|
56
57
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
|
|
57
58
|
end)
|
|
58
|
-
output_buffer.
|
|
59
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
it 'should name the hidden input with the :name html_option' do
|
|
@@ -63,8 +64,8 @@ describe 'boolean input' do
|
|
|
63
64
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
|
64
65
|
end)
|
|
65
66
|
|
|
66
|
-
output_buffer.
|
|
67
|
-
output_buffer.
|
|
67
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
|
68
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
it 'should name the hidden input with the :name html_option' do
|
|
@@ -72,93 +73,93 @@ describe 'boolean input' do
|
|
|
72
73
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
|
73
74
|
end)
|
|
74
75
|
|
|
75
|
-
output_buffer.
|
|
76
|
-
output_buffer.
|
|
76
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
|
77
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
|
77
78
|
end
|
|
78
79
|
|
|
79
80
|
it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
|
|
80
81
|
concat(semantic_form_for(@new_post) do |builder|
|
|
81
82
|
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
|
|
82
83
|
end)
|
|
83
|
-
output_buffer.
|
|
84
|
-
output_buffer.
|
|
84
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
|
|
85
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
|
|
88
89
|
concat(semantic_form_for(@new_post) do |builder|
|
|
89
90
|
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
|
|
90
91
|
end)
|
|
91
|
-
output_buffer.
|
|
92
|
-
output_buffer.
|
|
92
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@id="custom_id"]')
|
|
93
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="custom_id"]')
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
it 'should allow checked and unchecked values to be sent' do
|
|
96
97
|
concat(semantic_form_for(@new_post) do |builder|
|
|
97
98
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
|
|
98
99
|
end)
|
|
99
|
-
output_buffer.
|
|
100
|
-
output_buffer.
|
|
101
|
-
output_buffer.
|
|
100
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
|
|
101
|
+
expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
|
|
102
|
+
expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
|
|
102
103
|
end
|
|
103
104
|
|
|
104
105
|
it 'should generate a checked input if object.method returns checked value' do
|
|
105
|
-
@new_post.
|
|
106
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
|
106
107
|
|
|
107
108
|
concat(semantic_form_for(@new_post) do |builder|
|
|
108
109
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
109
110
|
end)
|
|
110
111
|
|
|
111
|
-
output_buffer.
|
|
112
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
|
112
113
|
end
|
|
113
114
|
|
|
114
115
|
it 'should not generate a checked input if object.method returns unchecked value' do
|
|
115
|
-
@new_post.
|
|
116
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
|
116
117
|
|
|
117
118
|
concat(semantic_form_for(@new_post) do |builder|
|
|
118
119
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
119
120
|
end)
|
|
120
121
|
|
|
121
|
-
output_buffer.
|
|
122
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
it 'should generate a checked input if object.method returns checked value' do
|
|
125
|
-
@new_post.
|
|
126
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
|
126
127
|
|
|
127
128
|
concat(semantic_form_for(@new_post) do |builder|
|
|
128
129
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
129
130
|
end)
|
|
130
131
|
|
|
131
|
-
output_buffer.
|
|
132
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
|
132
133
|
end
|
|
133
134
|
|
|
134
135
|
it 'should generate a checked input for boolean database values compared to string checked values' do
|
|
135
|
-
@new_post.
|
|
136
|
+
allow(@new_post).to receive(:foo).and_return(1)
|
|
136
137
|
|
|
137
138
|
concat(semantic_form_for(@new_post) do |builder|
|
|
138
139
|
concat(builder.input(:foo, :as => :boolean))
|
|
139
140
|
end)
|
|
140
141
|
|
|
141
|
-
output_buffer.
|
|
142
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
|
|
142
143
|
end
|
|
143
144
|
|
|
144
145
|
it 'should generate a checked input if object.method returns checked value when inverted' do
|
|
145
|
-
@new_post.
|
|
146
|
+
allow(@new_post).to receive(:allow_comments).and_return(0)
|
|
146
147
|
|
|
147
148
|
concat(semantic_form_for(@new_post) do |builder|
|
|
148
149
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
|
|
149
150
|
end)
|
|
150
151
|
|
|
151
|
-
output_buffer.
|
|
152
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
|
|
152
153
|
end
|
|
153
154
|
|
|
154
155
|
it 'should not generate a checked input if object.method returns unchecked value' do
|
|
155
|
-
@new_post.
|
|
156
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
|
156
157
|
|
|
157
158
|
concat(semantic_form_for(@new_post) do |builder|
|
|
158
159
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
|
159
160
|
end)
|
|
160
161
|
|
|
161
|
-
output_buffer.
|
|
162
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
|
162
163
|
end
|
|
163
164
|
|
|
164
165
|
it 'should generate a label and a checkbox even if no object is given' do
|
|
@@ -166,49 +167,49 @@ describe 'boolean input' do
|
|
|
166
167
|
concat(builder.input(:allow_comments, :as => :boolean))
|
|
167
168
|
end)
|
|
168
169
|
|
|
169
|
-
output_buffer.
|
|
170
|
-
output_buffer.
|
|
171
|
-
output_buffer.
|
|
170
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="project_allow_comments"]')
|
|
171
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
|
|
172
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
172
173
|
|
|
173
|
-
output_buffer.
|
|
174
|
-
output_buffer.
|
|
175
|
-
output_buffer.
|
|
174
|
+
expect(output_buffer.to_str).to have_tag('form li label input#project_allow_comments')
|
|
175
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
|
|
176
|
+
expect(output_buffer.to_str).to have_tag('form li label input[@name="project[allow_comments]"]')
|
|
176
177
|
end
|
|
177
|
-
|
|
178
|
+
|
|
178
179
|
it 'should not pass input_html options down to the label html' do
|
|
179
180
|
concat(semantic_form_for(@new_post) do |builder|
|
|
180
181
|
builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
|
|
181
182
|
end)
|
|
182
|
-
output_buffer.
|
|
183
|
-
output_buffer.
|
|
183
|
+
expect(output_buffer.to_str).not_to have_tag('label[tabindex]')
|
|
184
|
+
expect(output_buffer.to_str).not_to have_tag('label[x]')
|
|
184
185
|
end
|
|
185
186
|
|
|
186
187
|
context "when required" do
|
|
187
|
-
|
|
188
|
+
|
|
188
189
|
it "should add the required attribute to the input's html options" do
|
|
189
190
|
with_config :use_required_attribute, true do
|
|
190
191
|
concat(semantic_form_for(@new_post) do |builder|
|
|
191
192
|
concat(builder.input(:title, :as => :boolean, :required => true))
|
|
192
193
|
end)
|
|
193
|
-
output_buffer.
|
|
194
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
194
195
|
end
|
|
195
196
|
end
|
|
196
|
-
|
|
197
|
+
|
|
197
198
|
it "should not add the required attribute to the boolean fields input's html options" do
|
|
198
199
|
with_config :use_required_attribute, true do
|
|
199
200
|
concat(semantic_form_for(@new_post) do |builder|
|
|
200
201
|
concat(builder.input(:title, :as => :boolean))
|
|
201
202
|
end)
|
|
202
|
-
output_buffer.
|
|
203
|
+
expect(output_buffer.to_str).not_to have_tag("input[@required]")
|
|
203
204
|
end
|
|
204
205
|
end
|
|
205
|
-
|
|
206
|
+
|
|
206
207
|
end
|
|
207
208
|
|
|
208
209
|
describe "when namespace is provided" do
|
|
209
210
|
|
|
210
211
|
before do
|
|
211
|
-
@output_buffer = ''
|
|
212
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
212
213
|
mock_everything
|
|
213
214
|
|
|
214
215
|
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
|
@@ -220,11 +221,11 @@ describe 'boolean input' do
|
|
|
220
221
|
it_should_have_an_inline_label_for("context2_post_allow_comments")
|
|
221
222
|
|
|
222
223
|
end
|
|
223
|
-
|
|
224
|
+
|
|
224
225
|
describe "when index is provided" do
|
|
225
226
|
|
|
226
227
|
before do
|
|
227
|
-
@output_buffer = ''
|
|
228
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
228
229
|
mock_everything
|
|
229
230
|
|
|
230
231
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -233,22 +234,22 @@ describe 'boolean input' do
|
|
|
233
234
|
end)
|
|
234
235
|
end)
|
|
235
236
|
end
|
|
236
|
-
|
|
237
|
+
|
|
237
238
|
it 'should index the id of the wrapper' do
|
|
238
|
-
output_buffer.
|
|
239
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
239
240
|
end
|
|
240
|
-
|
|
241
|
+
|
|
241
242
|
it 'should index the id of the input tag' do
|
|
242
|
-
output_buffer.
|
|
243
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
243
244
|
end
|
|
244
|
-
|
|
245
|
+
|
|
245
246
|
it 'should index the name of the hidden input' do
|
|
246
|
-
output_buffer.
|
|
247
|
+
expect(output_buffer.to_str).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
|
|
247
248
|
end
|
|
248
249
|
|
|
249
250
|
it 'should index the name of the checkbox input' do
|
|
250
|
-
output_buffer.
|
|
251
|
+
expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
|
|
251
252
|
end
|
|
252
|
-
|
|
253
|
+
|
|
253
254
|
end
|
|
254
255
|
end
|