formtastic 3.1.5 → 4.0.0.rc1
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 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -2
- data/.travis.yml +28 -40
- data/CHANGELOG.md +49 -0
- data/DEPRECATIONS +1 -1
- data/Gemfile.lock +104 -0
- data/README.md +628 -629
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +8 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +5 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +8 -24
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
- data/lib/formtastic/helpers/input_helper.rb +18 -76
- data/lib/formtastic/helpers/inputs_helper.rb +12 -3
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/collections.rb +1 -5
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +19 -9
- data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/select_input.rb +1 -1
- data/lib/formtastic/localizer.rb +5 -7
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +4 -6
- data/script/integration-template.rb +71 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +33 -33
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +6 -6
- data/spec/inputs/base/validations_spec.rb +157 -19
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +96 -95
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +63 -65
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +4 -4
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +92 -96
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +19 -19
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +163 -223
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1301
- data/spec/support/test_environment.rb +23 -9
- metadata +33 -123
- data/Appraisals +0 -43
- data/CHANGELOG +0 -54
- data/gemfiles/rails_3.2.gemfile +0 -9
- data/gemfiles/rails_4.0.4.gemfile +0 -8
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/gemfiles/rails_4.2.gemfile +0 -8
- data/gemfiles/rails_4.gemfile +0 -8
- data/gemfiles/rails_5.0.gemfile +0 -8
- data/gemfiles/rails_edge.gemfile +0 -15
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'boolean input' do
|
4
|
+
RSpec.describe 'boolean input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -23,31 +23,31 @@ describe 'boolean input' do
|
|
23
23
|
it_should_apply_error_logic_for_input_type(:boolean)
|
24
24
|
|
25
25
|
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.
|
26
|
+
expect(output_buffer).not_to have_tag('label.label')
|
27
|
+
expect(output_buffer).to have_tag('form li label', :count => 1)
|
28
|
+
expect(output_buffer).to have_tag('form li label[@for="post_allow_comments"]')
|
29
|
+
expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
|
30
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"]', :count => 1)
|
31
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"]', :count => 1)
|
32
|
+
expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should not add a "name" attribute to the label' do
|
36
|
-
output_buffer.
|
36
|
+
expect(output_buffer).not_to have_tag('form li label[@name]')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should generate a checkbox input' do
|
40
|
-
output_buffer.
|
41
|
-
output_buffer.
|
42
|
-
output_buffer.
|
43
|
-
output_buffer.
|
44
|
-
output_buffer.
|
40
|
+
expect(output_buffer).to have_tag('form li label input')
|
41
|
+
expect(output_buffer).to have_tag('form li label input#post_allow_comments')
|
42
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
|
43
|
+
expect(output_buffer).to have_tag('form li label input[@name="post[allow_comments]"]')
|
44
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"]')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should generate a checked input if object.method returns true' do
|
48
|
-
output_buffer.
|
49
|
-
output_buffer.
|
50
|
-
output_buffer.
|
48
|
+
expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
|
49
|
+
expect(output_buffer).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
|
50
|
+
expect(output_buffer).to have_tag('form li input#post_allow_comments', :count => 1)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -55,7 +55,7 @@ describe 'boolean input' do
|
|
55
55
|
concat(semantic_form_for(@new_post) do |builder|
|
56
56
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
|
57
57
|
end)
|
58
|
-
output_buffer.
|
58
|
+
expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should name the hidden input with the :name html_option' do
|
@@ -63,8 +63,8 @@ describe 'boolean input' do
|
|
63
63
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
64
64
|
end)
|
65
65
|
|
66
|
-
output_buffer.
|
67
|
-
output_buffer.
|
66
|
+
expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
67
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should name the hidden input with the :name html_option' do
|
@@ -72,93 +72,93 @@ describe 'boolean input' do
|
|
72
72
|
concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
|
73
73
|
end)
|
74
74
|
|
75
|
-
output_buffer.
|
76
|
-
output_buffer.
|
75
|
+
expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
|
76
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
|
80
80
|
concat(semantic_form_for(@new_post) do |builder|
|
81
81
|
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
|
82
82
|
end)
|
83
|
-
output_buffer.
|
84
|
-
output_buffer.
|
83
|
+
expect(output_buffer).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
|
84
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
|
88
88
|
concat(semantic_form_for(@new_post) do |builder|
|
89
89
|
concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
|
90
90
|
end)
|
91
|
-
output_buffer.
|
92
|
-
output_buffer.
|
91
|
+
expect(output_buffer).to have_tag('form li label input[@id="custom_id"]')
|
92
|
+
expect(output_buffer).to have_tag('form li label[@for="custom_id"]')
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should allow checked and unchecked values to be sent' do
|
96
96
|
concat(semantic_form_for(@new_post) do |builder|
|
97
97
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
|
98
98
|
end)
|
99
|
-
output_buffer.
|
100
|
-
output_buffer.
|
101
|
-
output_buffer.
|
99
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
|
100
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
|
101
|
+
expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should generate a checked input if object.method returns checked value' do
|
105
|
-
@new_post.
|
105
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
106
106
|
|
107
107
|
concat(semantic_form_for(@new_post) do |builder|
|
108
108
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
109
109
|
end)
|
110
110
|
|
111
|
-
output_buffer.
|
111
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should not generate a checked input if object.method returns unchecked value' do
|
115
|
-
@new_post.
|
115
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
116
116
|
|
117
117
|
concat(semantic_form_for(@new_post) do |builder|
|
118
118
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
119
119
|
end)
|
120
120
|
|
121
|
-
output_buffer.
|
121
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should generate a checked input if object.method returns checked value' do
|
125
|
-
@new_post.
|
125
|
+
allow(@new_post).to receive(:allow_comments).and_return('yes')
|
126
126
|
|
127
127
|
concat(semantic_form_for(@new_post) do |builder|
|
128
128
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
129
129
|
end)
|
130
130
|
|
131
|
-
output_buffer.
|
131
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'should generate a checked input for boolean database values compared to string checked values' do
|
135
|
-
@new_post.
|
135
|
+
allow(@new_post).to receive(:foo).and_return(1)
|
136
136
|
|
137
137
|
concat(semantic_form_for(@new_post) do |builder|
|
138
138
|
concat(builder.input(:foo, :as => :boolean))
|
139
139
|
end)
|
140
140
|
|
141
|
-
output_buffer.
|
141
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should generate a checked input if object.method returns checked value when inverted' do
|
145
|
-
@new_post.
|
145
|
+
allow(@new_post).to receive(:allow_comments).and_return(0)
|
146
146
|
|
147
147
|
concat(semantic_form_for(@new_post) do |builder|
|
148
148
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
|
149
149
|
end)
|
150
150
|
|
151
|
-
output_buffer.
|
151
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'should not generate a checked input if object.method returns unchecked value' do
|
155
|
-
@new_post.
|
155
|
+
allow(@new_post).to receive(:allow_comments).and_return('no')
|
156
156
|
|
157
157
|
concat(semantic_form_for(@new_post) do |builder|
|
158
158
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
|
159
159
|
end)
|
160
160
|
|
161
|
-
output_buffer.
|
161
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'should generate a label and a checkbox even if no object is given' do
|
@@ -166,21 +166,21 @@ describe 'boolean input' do
|
|
166
166
|
concat(builder.input(:allow_comments, :as => :boolean))
|
167
167
|
end)
|
168
168
|
|
169
|
-
output_buffer.
|
170
|
-
output_buffer.
|
171
|
-
output_buffer.
|
169
|
+
expect(output_buffer).to have_tag('form li label[@for="project_allow_comments"]')
|
170
|
+
expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
|
171
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
|
172
172
|
|
173
|
-
output_buffer.
|
174
|
-
output_buffer.
|
175
|
-
output_buffer.
|
173
|
+
expect(output_buffer).to have_tag('form li label input#project_allow_comments')
|
174
|
+
expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
|
175
|
+
expect(output_buffer).to have_tag('form li label input[@name="project[allow_comments]"]')
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should not pass input_html options down to the label html' do
|
179
179
|
concat(semantic_form_for(@new_post) do |builder|
|
180
180
|
builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
|
181
181
|
end)
|
182
|
-
output_buffer.
|
183
|
-
output_buffer.
|
182
|
+
expect(output_buffer).not_to have_tag('label[tabindex]')
|
183
|
+
expect(output_buffer).not_to have_tag('label[x]')
|
184
184
|
end
|
185
185
|
|
186
186
|
context "when required" do
|
@@ -190,7 +190,7 @@ describe 'boolean input' do
|
|
190
190
|
concat(semantic_form_for(@new_post) do |builder|
|
191
191
|
concat(builder.input(:title, :as => :boolean, :required => true))
|
192
192
|
end)
|
193
|
-
output_buffer.
|
193
|
+
expect(output_buffer).to have_tag("input[@required]")
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -199,7 +199,7 @@ describe 'boolean input' do
|
|
199
199
|
concat(semantic_form_for(@new_post) do |builder|
|
200
200
|
concat(builder.input(:title, :as => :boolean))
|
201
201
|
end)
|
202
|
-
output_buffer.
|
202
|
+
expect(output_buffer).not_to have_tag("input[@required]")
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -235,19 +235,19 @@ describe 'boolean input' do
|
|
235
235
|
end
|
236
236
|
|
237
237
|
it 'should index the id of the wrapper' do
|
238
|
-
output_buffer.
|
238
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'should index the id of the input tag' do
|
242
|
-
output_buffer.
|
242
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'should index the name of the hidden input' do
|
246
|
-
output_buffer.
|
246
|
+
expect(output_buffer).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
|
247
247
|
end
|
248
248
|
|
249
249
|
it 'should index the name of the checkbox input' do
|
250
|
-
output_buffer.
|
250
|
+
expect(output_buffer).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
|
251
251
|
end
|
252
252
|
|
253
253
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'check_boxes input' do
|
4
|
+
RSpec.describe 'check_boxes input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -31,75 +31,75 @@ describe 'check_boxes input' do
|
|
31
31
|
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
|
32
32
|
|
33
33
|
it 'should generate a legend containing a label with text for the input' do
|
34
|
-
output_buffer.
|
35
|
-
output_buffer.
|
34
|
+
expect(output_buffer).to have_tag('form li fieldset legend.label label')
|
35
|
+
expect(output_buffer).to have_tag('form li fieldset legend.label label', :text => /Posts/)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should not link the label within the legend to any input' do
|
39
|
-
output_buffer.
|
39
|
+
expect(output_buffer).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should generate an ordered list with an li.choice for each choice' do
|
43
|
-
output_buffer.
|
44
|
-
output_buffer.
|
43
|
+
expect(output_buffer).to have_tag('form li fieldset ol')
|
44
|
+
expect(output_buffer).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should have one option with a "checked" attribute' do
|
48
|
-
output_buffer.
|
48
|
+
expect(output_buffer).to have_tag('form li input[@checked]', :count => 1)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should not generate hidden inputs with default value blank' do
|
52
|
-
output_buffer.
|
52
|
+
expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should not render hidden inputs inside the ol' do
|
56
|
-
output_buffer.
|
56
|
+
expect(output_buffer).not_to have_tag("form li fieldset ol li input[@type='hidden']")
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should render one hidden input for each choice outside the ol' do
|
60
|
-
output_buffer.
|
60
|
+
expect(output_buffer).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "each choice" do
|
64
64
|
|
65
65
|
it 'should not give the choice label the .label class' do
|
66
|
-
output_buffer.
|
66
|
+
expect(output_buffer).not_to have_tag('li.choice label.label')
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should not be marked as required' do
|
70
|
-
output_buffer.
|
70
|
+
expect(output_buffer).not_to have_tag('li.choice input[@required]')
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should contain a label for the radio input with a nested input and label text' do
|
74
74
|
::Post.all.each do |post|
|
75
|
-
output_buffer.
|
76
|
-
output_buffer.
|
75
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
76
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should use values as li.class when value_as_class is true' do
|
81
81
|
::Post.all.each do |post|
|
82
|
-
output_buffer.
|
82
|
+
expect(output_buffer).to have_tag("form li fieldset ol li.post_#{post.id} label")
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should have a checkbox input but no hidden field for each post' do
|
87
87
|
::Post.all.each do |post|
|
88
|
-
output_buffer.
|
89
|
-
output_buffer.
|
88
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
89
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
|
94
|
-
output_buffer.
|
94
|
+
expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'the hidden field with an empty array value should be followed by the ol' do
|
98
|
-
output_buffer.
|
98
|
+
expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should not have a hidden field with an empty string value for the collection' do
|
102
|
-
output_buffer.
|
102
|
+
expect(output_buffer).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
|
@@ -110,21 +110,21 @@ describe 'check_boxes input' do
|
|
110
110
|
end)
|
111
111
|
|
112
112
|
::Post.all.each do |post|
|
113
|
-
output_buffer.
|
114
|
-
output_buffer.
|
115
|
-
output_buffer.
|
113
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
114
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
|
115
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should mark input as checked if it's the the existing choice" do
|
121
|
-
::Post.all.include?(@fred.posts.first).
|
122
|
-
output_buffer.
|
121
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
122
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
describe 'and no object is given' do
|
127
|
-
before(:
|
127
|
+
before(:example) do
|
128
128
|
output_buffer.replace ''
|
129
129
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
130
130
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
|
@@ -132,26 +132,26 @@ describe 'check_boxes input' do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'should generate a fieldset with legend' do
|
135
|
-
output_buffer.
|
135
|
+
expect(output_buffer).to have_tag('form li fieldset legend', :text => /Author/)
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'shold generate an li tag for each item in the collection' do
|
139
|
-
output_buffer.
|
139
|
+
expect(output_buffer).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'should generate labels for each item' do
|
143
143
|
::Author.all.each do |author|
|
144
|
-
output_buffer.
|
145
|
-
output_buffer.
|
144
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
|
145
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should generate inputs for each item' do
|
150
150
|
::Author.all.each do |author|
|
151
|
-
output_buffer.
|
152
|
-
output_buffer.
|
153
|
-
output_buffer.
|
154
|
-
output_buffer.
|
151
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
152
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@type='checkbox']")
|
153
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
154
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -160,8 +160,9 @@ describe 'check_boxes input' do
|
|
160
160
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
161
161
|
end)
|
162
162
|
|
163
|
-
output_buffer.
|
164
|
-
label.
|
163
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
|
164
|
+
expect(label).to have_text('<b>Item 1</b>', count: 1)
|
165
|
+
expect(label).to have_text('<b>Item 2</b>', count: 1)
|
165
166
|
end
|
166
167
|
end
|
167
168
|
end
|
@@ -178,18 +179,18 @@ describe 'check_boxes input' do
|
|
178
179
|
|
179
180
|
it 'should have a checkbox input for each post' do
|
180
181
|
::Post.all.each do |post|
|
181
|
-
output_buffer.
|
182
|
-
output_buffer.
|
182
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
183
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
|
183
184
|
end
|
184
185
|
end
|
185
186
|
|
186
187
|
it "should mark input as checked if it's the the existing choice" do
|
187
|
-
::Post.all.include?(@fred.posts.first).
|
188
|
-
output_buffer.
|
188
|
+
expect(::Post.all.include?(@fred.posts.first)).to be_truthy
|
189
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
|
189
190
|
end
|
190
191
|
|
191
192
|
it 'should not generate empty hidden inputs' do
|
192
|
-
output_buffer.
|
193
|
+
expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
|
193
194
|
end
|
194
195
|
end
|
195
196
|
|
@@ -200,7 +201,7 @@ describe 'check_boxes input' do
|
|
200
201
|
|
201
202
|
describe "no disabled items" do
|
202
203
|
before do
|
203
|
-
@new_post.
|
204
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
204
205
|
|
205
206
|
concat(semantic_form_for(@new_post) do |builder|
|
206
207
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
|
@@ -208,13 +209,13 @@ describe 'check_boxes input' do
|
|
208
209
|
end
|
209
210
|
|
210
211
|
it 'should not have any disabled item(s)' do
|
211
|
-
output_buffer.
|
212
|
+
expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
|
212
213
|
end
|
213
214
|
end
|
214
215
|
|
215
216
|
describe "single disabled item" do
|
216
217
|
before do
|
217
|
-
@new_post.
|
218
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
218
219
|
|
219
220
|
concat(semantic_form_for(@new_post) do |builder|
|
220
221
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
|
@@ -222,15 +223,15 @@ describe 'check_boxes input' do
|
|
222
223
|
end
|
223
224
|
|
224
225
|
it "should have one item disabled; the specified one" do
|
225
|
-
output_buffer.
|
226
|
-
output_buffer.
|
227
|
-
output_buffer.
|
226
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
|
227
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
228
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
228
229
|
end
|
229
230
|
end
|
230
231
|
|
231
232
|
describe "multiple disabled items" do
|
232
233
|
before do
|
233
|
-
@new_post.
|
234
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
234
235
|
|
235
236
|
concat(semantic_form_for(@new_post) do |builder|
|
236
237
|
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
|
@@ -238,11 +239,11 @@ describe 'check_boxes input' do
|
|
238
239
|
end
|
239
240
|
|
240
241
|
it "should have multiple items disabled; the specified ones" do
|
241
|
-
output_buffer.
|
242
|
-
output_buffer.
|
243
|
-
output_buffer.
|
244
|
-
output_buffer.
|
245
|
-
output_buffer.
|
242
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
|
243
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
|
244
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
|
245
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
|
246
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
246
247
|
end
|
247
248
|
end
|
248
249
|
|
@@ -253,7 +254,7 @@ describe 'check_boxes input' do
|
|
253
254
|
before do
|
254
255
|
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
255
256
|
with_config :i18n_lookups_by_default, true do
|
256
|
-
@new_post.
|
257
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
257
258
|
concat(semantic_form_for(@new_post) do |builder|
|
258
259
|
concat(builder.input(:authors, :as => :check_boxes))
|
259
260
|
end)
|
@@ -265,63 +266,63 @@ describe 'check_boxes input' do
|
|
265
266
|
end
|
266
267
|
|
267
268
|
it "should do foo" do
|
268
|
-
output_buffer.
|
269
|
+
expect(output_buffer).to have_tag("legend.label label", :text => /Translated/)
|
269
270
|
end
|
270
271
|
|
271
272
|
end
|
272
273
|
|
273
274
|
describe "when :label option is set" do
|
274
275
|
before do
|
275
|
-
@new_post.
|
276
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
276
277
|
concat(semantic_form_for(@new_post) do |builder|
|
277
278
|
concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
|
278
279
|
end)
|
279
280
|
end
|
280
281
|
|
281
282
|
it "should output the correct label title" do
|
282
|
-
output_buffer.
|
283
|
+
expect(output_buffer).to have_tag("legend.label label", :text => /The authors/)
|
283
284
|
end
|
284
285
|
end
|
285
286
|
|
286
287
|
describe "when :label option is false" do
|
287
288
|
before do
|
288
289
|
@output_buffer = ''
|
289
|
-
@new_post.
|
290
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
290
291
|
concat(semantic_form_for(@new_post) do |builder|
|
291
292
|
concat(builder.input(:authors, :as => :check_boxes, :label => false))
|
292
293
|
end)
|
293
294
|
end
|
294
295
|
|
295
296
|
it "should not output the legend" do
|
296
|
-
output_buffer.
|
297
|
+
expect(output_buffer).not_to have_tag("legend.label")
|
297
298
|
end
|
298
299
|
|
299
300
|
it "should not cause escaped HTML" do
|
300
|
-
output_buffer.
|
301
|
+
expect(output_buffer).not_to include(">")
|
301
302
|
end
|
302
303
|
|
303
304
|
end
|
304
305
|
|
305
306
|
describe "when :required option is true" do
|
306
307
|
before do
|
307
|
-
@new_post.
|
308
|
+
allow(@new_post).to receive(:author_ids).and_return(nil)
|
308
309
|
concat(semantic_form_for(@new_post) do |builder|
|
309
310
|
concat(builder.input(:authors, :as => :check_boxes, :required => true))
|
310
311
|
end)
|
311
312
|
end
|
312
313
|
|
313
314
|
it "should output the correct label title" do
|
314
|
-
output_buffer.
|
315
|
+
expect(output_buffer).to have_tag("legend.label label abbr")
|
315
316
|
end
|
316
317
|
end
|
317
318
|
end
|
318
319
|
|
319
320
|
describe 'for a enum column' do
|
320
321
|
before do
|
321
|
-
@new_post.
|
322
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
322
323
|
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
323
|
-
@new_post.class.
|
324
|
-
@new_post.
|
324
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
325
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
325
326
|
end
|
326
327
|
|
327
328
|
it 'should have a select inside the wrapper' do
|
@@ -346,14 +347,14 @@ describe 'check_boxes input' do
|
|
346
347
|
|
347
348
|
it 'should render checkboxes' do
|
348
349
|
# I'm aware these two lines test the same thing
|
349
|
-
output_buffer.
|
350
|
-
output_buffer.
|
350
|
+
expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
|
351
|
+
expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
351
352
|
end
|
352
353
|
|
353
354
|
it 'should only select checkboxes that are present in the association' do
|
354
355
|
# I'm aware these two lines test the same thing
|
355
|
-
output_buffer.
|
356
|
-
output_buffer.
|
356
|
+
expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
|
357
|
+
expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
357
358
|
end
|
358
359
|
|
359
360
|
end
|
@@ -371,14 +372,14 @@ describe 'check_boxes input' do
|
|
371
372
|
|
372
373
|
it 'should render checkboxes' do
|
373
374
|
# I'm aware these two lines test the same thing
|
374
|
-
output_buffer.
|
375
|
-
output_buffer.
|
375
|
+
expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
|
376
|
+
expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
|
376
377
|
end
|
377
378
|
|
378
379
|
it 'should only select checkboxes that are present in the association' do
|
379
380
|
# I'm aware these two lines test the same thing
|
380
|
-
output_buffer.
|
381
|
-
output_buffer.
|
381
|
+
expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
|
382
|
+
expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
|
382
383
|
end
|
383
384
|
|
384
385
|
end
|
@@ -392,17 +393,17 @@ describe 'check_boxes input' do
|
|
392
393
|
|
393
394
|
it 'to set the right input value' do
|
394
395
|
item = double('item')
|
395
|
-
item.
|
396
|
-
item.
|
397
|
-
item.
|
398
|
-
@new_post.author.
|
396
|
+
expect(item).not_to receive(:id)
|
397
|
+
allow(item).to receive(:custom_value).and_return('custom_value')
|
398
|
+
expect(item).to receive(:custom_value).exactly(3).times
|
399
|
+
expect(@new_post.author).to receive(:custom_value).exactly(1).times
|
399
400
|
|
400
401
|
with_deprecation_silenced do
|
401
402
|
concat(semantic_form_for(@new_post) do |builder|
|
402
403
|
concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
|
403
404
|
end)
|
404
405
|
end
|
405
|
-
output_buffer.
|
406
|
+
expect(output_buffer).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
|
406
407
|
end
|
407
408
|
end
|
408
409
|
end
|
@@ -411,7 +412,7 @@ describe 'check_boxes input' do
|
|
411
412
|
before do
|
412
413
|
@output_buffer = ''
|
413
414
|
mock_everything
|
414
|
-
@fred.
|
415
|
+
allow(@fred).to receive(:genres) { ['fiction', 'biography'] }
|
415
416
|
|
416
417
|
concat(semantic_form_for(@fred) do |builder|
|
417
418
|
concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
|
@@ -419,8 +420,8 @@ describe 'check_boxes input' do
|
|
419
420
|
end
|
420
421
|
|
421
422
|
it 'should check the correct checkboxes' do
|
422
|
-
output_buffer.
|
423
|
-
output_buffer.
|
423
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
|
424
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
|
424
425
|
end
|
425
426
|
end
|
426
427
|
|
@@ -428,7 +429,7 @@ describe 'check_boxes input' do
|
|
428
429
|
before do
|
429
430
|
@output_buffer = ''
|
430
431
|
mock_everything
|
431
|
-
@fred.
|
432
|
+
allow(@fred).to receive(:roles) { Set.new([:reviewer, :admin]) }
|
432
433
|
|
433
434
|
concat(semantic_form_for(@fred) do |builder|
|
434
435
|
concat(builder.input(:roles, :as => :check_boxes, :collection => [['User', :user], ['Reviewer', :reviewer], ['Administrator', :admin]]))
|
@@ -436,9 +437,9 @@ describe 'check_boxes input' do
|
|
436
437
|
end
|
437
438
|
|
438
439
|
it 'should check the correct checkboxes' do
|
439
|
-
output_buffer.
|
440
|
-
output_buffer.
|
441
|
-
output_buffer.
|
440
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='user']")
|
441
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
|
442
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
|
442
443
|
end
|
443
444
|
end
|
444
445
|
|
@@ -454,7 +455,7 @@ describe 'check_boxes input' do
|
|
454
455
|
end
|
455
456
|
|
456
457
|
it "should have a label for #context2_author_post_ids_19" do
|
457
|
-
output_buffer.
|
458
|
+
expect(output_buffer).to have_tag("form li label[@for='context2_author_post_ids_19']")
|
458
459
|
end
|
459
460
|
|
460
461
|
it_should_have_input_with_id('context2_author_post_ids_19')
|
@@ -475,15 +476,15 @@ describe 'check_boxes input' do
|
|
475
476
|
end
|
476
477
|
|
477
478
|
it 'should index the id of the wrapper' do
|
478
|
-
output_buffer.
|
479
|
+
expect(output_buffer).to have_tag("li#author_post_3_authors_input")
|
479
480
|
end
|
480
481
|
|
481
482
|
it 'should index the id of the input tag' do
|
482
|
-
output_buffer.
|
483
|
+
expect(output_buffer).to have_tag("input#author_post_3_author_ids_42")
|
483
484
|
end
|
484
485
|
|
485
486
|
it 'should index the name of the checkbox input' do
|
486
|
-
output_buffer.
|
487
|
+
expect(output_buffer).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
|
487
488
|
end
|
488
489
|
|
489
490
|
end
|
@@ -502,18 +503,18 @@ describe 'check_boxes input' do
|
|
502
503
|
|
503
504
|
it "should use array items for labels and values" do
|
504
505
|
@_collection.each do |post|
|
505
|
-
output_buffer.
|
506
|
-
output_buffer.
|
506
|
+
expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
|
507
|
+
expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
|
507
508
|
end
|
508
509
|
end
|
509
510
|
|
510
511
|
it "should not check any items" do
|
511
|
-
output_buffer.
|
512
|
+
expect(output_buffer).to have_tag('form li input[@checked]', :count => 0)
|
512
513
|
end
|
513
514
|
|
514
515
|
describe "and the attribute has values" do
|
515
516
|
before do
|
516
|
-
@fred.
|
517
|
+
allow(@fred).to receive(:posts) { [1] }
|
517
518
|
|
518
519
|
concat(semantic_form_for(@fred) do |builder|
|
519
520
|
concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
|
@@ -521,7 +522,7 @@ describe 'check_boxes input' do
|
|
521
522
|
end
|
522
523
|
|
523
524
|
it "should check the appropriate items" do
|
524
|
-
output_buffer.
|
525
|
+
expect(output_buffer).to have_tag("form li input[@value='1'][@checked]")
|
525
526
|
end
|
526
527
|
end
|
527
528
|
|
@@ -536,7 +537,7 @@ describe 'check_boxes input' do
|
|
536
537
|
|
537
538
|
it "should have injected the html attributes" do
|
538
539
|
@_collection.each do |v|
|
539
|
-
output_buffer.
|
540
|
+
expect(output_buffer).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
|
540
541
|
end
|
541
542
|
end
|
542
543
|
end
|