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 'readonly option' do
|
4
|
+
RSpec.describe 'readonly option' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -20,7 +20,7 @@ describe 'readonly option' do
|
|
20
20
|
concat(semantic_form_for(@new_post) do |builder|
|
21
21
|
concat(builder.input(:title, :as => type, input_html: {readonly: true}))
|
22
22
|
end)
|
23
|
-
output_buffer.
|
23
|
+
expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -30,7 +30,7 @@ describe 'readonly option' do
|
|
30
30
|
concat(semantic_form_for(@new_post) do |builder|
|
31
31
|
concat(builder.input(:title, :as => type))
|
32
32
|
end)
|
33
|
-
output_buffer.
|
33
|
+
expect(output_buffer).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
describe "when column is readonly attribute" do
|
@@ -40,7 +40,7 @@ describe 'readonly option' do
|
|
40
40
|
concat(semantic_form_for(@new_post) do |builder|
|
41
41
|
concat(builder.input(:title, :as => type))
|
42
42
|
end)
|
43
|
-
output_buffer.
|
43
|
+
expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'search input' do
|
4
|
+
RSpec.describe 'search input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -56,15 +56,15 @@ describe 'search input' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should index the id of the wrapper' do
|
59
|
-
output_buffer.
|
59
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should index the id of the select tag' do
|
63
|
-
output_buffer.
|
63
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should index the name of the select tag' do
|
67
|
-
output_buffer.
|
67
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
@@ -75,7 +75,7 @@ describe 'search input' do
|
|
75
75
|
concat(semantic_form_for(@new_post) do |builder|
|
76
76
|
concat(builder.input(:title, :as => :search, :required => true))
|
77
77
|
end)
|
78
|
-
output_buffer.
|
78
|
+
expect(output_buffer).to have_tag("input[@required]")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'select input' do
|
4
|
+
RSpec.describe 'select input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -23,10 +23,10 @@ describe 'select input' do
|
|
23
23
|
|
24
24
|
it 'should have a option for each key and/or value' do
|
25
25
|
@array_with_values.each do |v|
|
26
|
-
output_buffer.
|
26
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
27
27
|
end
|
28
28
|
@array_with_keys_and_values.each do |v|
|
29
|
-
output_buffer.
|
29
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -43,26 +43,26 @@ describe 'select input' do
|
|
43
43
|
|
44
44
|
it 'should have a option for each key and/or value' do
|
45
45
|
@set_with_values.each do |v|
|
46
|
-
output_buffer.
|
46
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
47
47
|
end
|
48
48
|
@set_with_keys_and_values.each do |v|
|
49
|
-
output_buffer.
|
49
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "using a related model without reflection's options (Mongoid Document)" do
|
55
55
|
before do
|
56
|
-
@new_post.
|
56
|
+
allow(@new_post).to receive(:mongoid_reviewer)
|
57
57
|
concat(semantic_form_for(@new_post) do |builder|
|
58
58
|
concat(builder.input(:mongoid_reviewer, :as => :select))
|
59
59
|
end)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should draw select options' do
|
63
|
-
output_buffer.
|
64
|
-
output_buffer.
|
65
|
-
output_buffer.
|
63
|
+
expect(output_buffer).to have_tag('form li select')
|
64
|
+
expect(output_buffer).to have_tag('form li select#post_reviewer_id')
|
65
|
+
expect(output_buffer).not_to have_tag('form li select#post_mongoid_reviewer_id')
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -76,7 +76,7 @@ describe 'select input' do
|
|
76
76
|
|
77
77
|
it 'should have an option for each value' do
|
78
78
|
@range_with_values.each do |v|
|
79
|
-
output_buffer.
|
79
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -91,7 +91,7 @@ describe 'select input' do
|
|
91
91
|
|
92
92
|
it 'should render select options using provided HTML string' do
|
93
93
|
2.times do |v|
|
94
|
-
output_buffer.
|
94
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -125,8 +125,8 @@ describe 'select input' do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should render a select with at least options: true/false' do
|
128
|
-
output_buffer.
|
129
|
-
output_buffer.
|
128
|
+
expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /^Yes$/)
|
129
|
+
expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /^No$/)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -145,18 +145,18 @@ describe 'select input' do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should render a select with at least options: true/false' do
|
148
|
-
output_buffer.
|
149
|
-
output_buffer.
|
148
|
+
expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /#{@boolean_select_labels[:yes]}/)
|
149
|
+
expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /#{@boolean_select_labels[:no]}/)
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
describe 'for a enum column' do
|
155
155
|
before do
|
156
|
-
@new_post.
|
156
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
157
157
|
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
158
|
-
@new_post.class.
|
159
|
-
@new_post.
|
158
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
159
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
160
160
|
end
|
161
161
|
|
162
162
|
context 'single choice' do
|
@@ -174,40 +174,40 @@ describe 'select input' do
|
|
174
174
|
it_should_apply_error_logic_for_input_type(:select)
|
175
175
|
|
176
176
|
it 'should have a select inside the wrapper' do
|
177
|
-
output_buffer.
|
178
|
-
output_buffer.
|
177
|
+
expect(output_buffer).to have_tag('form li select')
|
178
|
+
expect(output_buffer).to have_tag('form li select#post_status')
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'should have a valid name' do
|
182
|
-
output_buffer.
|
183
|
-
output_buffer.
|
182
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]']")
|
183
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[status][]']")
|
184
184
|
end
|
185
185
|
|
186
186
|
it 'should not create a multi-select' do
|
187
|
-
output_buffer.
|
187
|
+
expect(output_buffer).not_to have_tag('form li select[@multiple]')
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should not add a hidden input' do
|
191
|
-
output_buffer.
|
191
|
+
expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should create a select without size' do
|
195
|
-
output_buffer.
|
195
|
+
expect(output_buffer).not_to have_tag('form li select[@size]')
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'should have a blank option' do
|
199
|
-
output_buffer.
|
199
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
200
200
|
end
|
201
201
|
|
202
202
|
it 'should have a select option for each defined enum status' do
|
203
|
-
output_buffer.
|
203
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]'] option", :count => @new_post.class.statuses.count + 1)
|
204
204
|
@new_post.class.statuses.each do |label, value|
|
205
|
-
output_buffer.
|
205
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{label}']", :text => /#{label.humanize}/)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'should have one option with a "selected" attribute (TODO)' do
|
210
|
-
output_buffer.
|
210
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]'] option[@selected]", :count => 1)
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -240,72 +240,68 @@ describe 'select input' do
|
|
240
240
|
it_should_use_the_collection_when_provided(:select, 'option')
|
241
241
|
|
242
242
|
it 'should have a select inside the wrapper' do
|
243
|
-
output_buffer.
|
244
|
-
output_buffer.
|
245
|
-
output_buffer.
|
243
|
+
expect(output_buffer).to have_tag('form li select')
|
244
|
+
expect(output_buffer).to have_tag('form li select#post_author_id')
|
245
|
+
expect(output_buffer).to have_tag('form li select#post_reviewer_id')
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'should have a valid name' do
|
249
|
-
output_buffer.
|
250
|
-
output_buffer.
|
251
|
-
output_buffer.
|
249
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]']")
|
250
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[author_id][]']")
|
251
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[reviewer_id][]']")
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'should not create a multi-select' do
|
255
|
-
output_buffer.
|
255
|
+
expect(output_buffer).not_to have_tag('form li select[@multiple]')
|
256
256
|
end
|
257
257
|
|
258
258
|
it 'should not add a hidden input' do
|
259
|
-
output_buffer.
|
259
|
+
expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should create a select without size' do
|
263
|
-
output_buffer.
|
263
|
+
expect(output_buffer).not_to have_tag('form li select[@size]')
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'should have a blank option' do
|
267
|
-
output_buffer.
|
267
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
268
268
|
end
|
269
269
|
|
270
270
|
it 'should have a select option for each Author' do
|
271
|
-
output_buffer.
|
271
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
|
272
272
|
::Author.all.each do |author|
|
273
|
-
output_buffer.
|
273
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
277
|
it 'should have one option with a "selected" attribute (bob)' do
|
278
|
-
output_buffer.
|
278
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
|
279
279
|
end
|
280
280
|
|
281
281
|
it 'should not singularize the association name' do
|
282
|
-
@new_post.
|
283
|
-
@new_post.
|
284
|
-
@new_post.
|
282
|
+
allow(@new_post).to receive(:author_status).and_return(@bob)
|
283
|
+
allow(@new_post).to receive(:author_status_id).and_return(@bob.id)
|
284
|
+
allow(@new_post).to receive(:column_for_attribute).and_return(double('column', :type => :integer, :limit => 255))
|
285
285
|
|
286
286
|
concat(semantic_form_for(@new_post) do |builder|
|
287
287
|
concat(builder.input(:author_status, :as => :select))
|
288
288
|
end)
|
289
289
|
|
290
|
-
output_buffer.
|
290
|
+
expect(output_buffer).to have_tag('form li select#post_author_status_id')
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
294
|
describe "for a belongs_to association with :conditions" do
|
295
295
|
before do
|
296
|
-
::Post.
|
296
|
+
allow(::Post).to receive(:reflect_on_association).with(:author) do
|
297
297
|
mock = double('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
|
298
|
-
mock.
|
298
|
+
allow(mock).to receive(:[]).with(:class_name).and_return("Author")
|
299
299
|
mock
|
300
300
|
end
|
301
301
|
end
|
302
302
|
|
303
303
|
it "should call author.(scoped|where) with association conditions" do
|
304
|
-
|
305
|
-
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
306
|
-
else
|
307
|
-
::Author.should_receive(:where).with({:active => true})
|
308
|
-
end
|
304
|
+
expect(::Author).to receive(:where).with({:active => true})
|
309
305
|
|
310
306
|
semantic_form_for(@new_post) do |builder|
|
311
307
|
concat(builder.input(:author, :as => :select))
|
@@ -329,31 +325,31 @@ describe 'select input' do
|
|
329
325
|
it_should_use_the_collection_when_provided(:select, 'option')
|
330
326
|
|
331
327
|
it 'should have a select inside the wrapper' do
|
332
|
-
output_buffer.
|
333
|
-
output_buffer.
|
328
|
+
expect(output_buffer).to have_tag('form li select')
|
329
|
+
expect(output_buffer).to have_tag('form li select#author_post_ids')
|
334
330
|
end
|
335
331
|
|
336
332
|
it 'should have a multi-select select' do
|
337
|
-
output_buffer.
|
333
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
|
338
334
|
end
|
339
335
|
|
340
336
|
it 'should append [] to the name attribute for multiple select' do
|
341
|
-
output_buffer.
|
337
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
|
342
338
|
end
|
343
339
|
|
344
340
|
it 'should have a hidden field' do
|
345
|
-
output_buffer.
|
341
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="author[post_ids][]"]', :count => 1)
|
346
342
|
end
|
347
343
|
|
348
344
|
it 'should have a select option for each Post' do
|
349
|
-
output_buffer.
|
345
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Post.all.size)
|
350
346
|
::Post.all.each do |post|
|
351
|
-
output_buffer.
|
347
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{post.id}']", :text => /#{post.to_label}/)
|
352
348
|
end
|
353
349
|
end
|
354
350
|
|
355
351
|
it 'should not have a blank option by default' do
|
356
|
-
output_buffer.
|
352
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']")
|
357
353
|
end
|
358
354
|
|
359
355
|
it 'should respect the :include_blank option for single selects' do
|
@@ -361,7 +357,7 @@ describe 'select input' do
|
|
361
357
|
concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
|
362
358
|
end)
|
363
359
|
|
364
|
-
output_buffer.
|
360
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
365
361
|
end
|
366
362
|
|
367
363
|
it 'should respect the :include_blank option for multiple selects' do
|
@@ -369,11 +365,11 @@ describe 'select input' do
|
|
369
365
|
concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
|
370
366
|
end)
|
371
367
|
|
372
|
-
output_buffer.
|
368
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
373
369
|
end
|
374
370
|
|
375
371
|
it 'should have one option with a "selected" attribute' do
|
376
|
-
output_buffer.
|
372
|
+
expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
|
377
373
|
end
|
378
374
|
end
|
379
375
|
|
@@ -393,23 +389,23 @@ describe 'select input' do
|
|
393
389
|
it_should_use_the_collection_when_provided(:select, 'option')
|
394
390
|
|
395
391
|
it 'should have a select inside the wrapper' do
|
396
|
-
output_buffer.
|
397
|
-
output_buffer.
|
392
|
+
expect(output_buffer).to have_tag('form li select')
|
393
|
+
expect(output_buffer).to have_tag('form li select#post_author_ids')
|
398
394
|
end
|
399
395
|
|
400
396
|
it 'should have a multi-select select' do
|
401
|
-
output_buffer.
|
397
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
|
402
398
|
end
|
403
399
|
|
404
400
|
it 'should have a select option for each Author' do
|
405
|
-
output_buffer.
|
401
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size)
|
406
402
|
::Author.all.each do |author|
|
407
|
-
output_buffer.
|
403
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
408
404
|
end
|
409
405
|
end
|
410
406
|
|
411
407
|
it 'should not have a blank option by default' do
|
412
|
-
output_buffer.
|
408
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']")
|
413
409
|
end
|
414
410
|
|
415
411
|
it 'should respect the :include_blank option for single selects' do
|
@@ -417,7 +413,7 @@ describe 'select input' do
|
|
417
413
|
concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
|
418
414
|
end)
|
419
415
|
|
420
|
-
output_buffer.
|
416
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
421
417
|
end
|
422
418
|
|
423
419
|
it 'should respect the :include_blank option for multiple selects' do
|
@@ -425,51 +421,51 @@ describe 'select input' do
|
|
425
421
|
concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
|
426
422
|
end)
|
427
423
|
|
428
|
-
output_buffer.
|
424
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
429
425
|
end
|
430
426
|
|
431
427
|
it 'should have one option with a "selected" attribute' do
|
432
|
-
output_buffer.
|
428
|
+
expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
|
433
429
|
end
|
434
430
|
end
|
435
431
|
|
436
432
|
describe 'when :prompt => "choose something" is set' do
|
437
433
|
before do
|
438
|
-
@new_post.
|
434
|
+
allow(@new_post).to receive(:author_id).and_return(nil)
|
439
435
|
concat(semantic_form_for(@new_post) do |builder|
|
440
436
|
concat(builder.input(:author, :as => :select, :prompt => "choose author"))
|
441
437
|
end)
|
442
438
|
end
|
443
439
|
|
444
440
|
it 'should have a select with prompt' do
|
445
|
-
output_buffer.
|
441
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", :text => /choose author/, :count => 1)
|
446
442
|
end
|
447
443
|
|
448
444
|
it 'should not have a second blank select option' do
|
449
|
-
output_buffer.
|
445
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", :count => 1)
|
450
446
|
end
|
451
447
|
end
|
452
448
|
|
453
449
|
describe 'when no object is given' do
|
454
|
-
before(:
|
450
|
+
before(:example) do
|
455
451
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
456
452
|
concat(builder.input(:author, :as => :select, :collection => ::Author.all))
|
457
453
|
end)
|
458
454
|
end
|
459
455
|
|
460
456
|
it 'should generate label' do
|
461
|
-
output_buffer.
|
462
|
-
output_buffer.
|
457
|
+
expect(output_buffer).to have_tag('form li label', :text => /Author/)
|
458
|
+
expect(output_buffer).to have_tag("form li label[@for='project_author']")
|
463
459
|
end
|
464
460
|
|
465
461
|
it 'should generate select inputs' do
|
466
|
-
output_buffer.
|
467
|
-
output_buffer.
|
462
|
+
expect(output_buffer).to have_tag('form li select#project_author')
|
463
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size + 1)
|
468
464
|
end
|
469
465
|
|
470
466
|
it 'should generate an option to each item' do
|
471
467
|
::Author.all.each do |author|
|
472
|
-
output_buffer.
|
468
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
473
469
|
end
|
474
470
|
end
|
475
471
|
end
|
@@ -480,7 +476,7 @@ describe 'select input' do
|
|
480
476
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
481
477
|
concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
|
482
478
|
end)
|
483
|
-
output_buffer.
|
479
|
+
expect(output_buffer).to have_tag("form li select[@name='project[author_name]']")
|
484
480
|
end
|
485
481
|
|
486
482
|
describe 'and :multiple is set to true through :input_html' do
|
@@ -488,7 +484,7 @@ describe 'select input' do
|
|
488
484
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
489
485
|
concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
|
490
486
|
end)
|
491
|
-
output_buffer.
|
487
|
+
expect(output_buffer).to have_tag("form li select[@multiple]")
|
492
488
|
end
|
493
489
|
end
|
494
490
|
|
@@ -497,14 +493,14 @@ describe 'select input' do
|
|
497
493
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
498
494
|
concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
|
499
495
|
end)
|
500
|
-
output_buffer.
|
496
|
+
expect(output_buffer).to have_tag("form li select[@multiple]")
|
501
497
|
end
|
502
498
|
end
|
503
499
|
|
504
500
|
end
|
505
501
|
|
506
502
|
describe 'when a grouped collection collection is given' do
|
507
|
-
before(:
|
503
|
+
before(:example) do
|
508
504
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
509
505
|
@grouped_opts = [['one', ['pencil', 'crayon', 'pen']],
|
510
506
|
['two', ['eyes', 'hands', 'feet']],
|
@@ -515,12 +511,12 @@ describe 'select input' do
|
|
515
511
|
|
516
512
|
it 'should generate an option to each item' do
|
517
513
|
@grouped_opts.each do |opt_pair|
|
518
|
-
output_buffer.
|
514
|
+
expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}']")
|
519
515
|
opt_pair[1].each do |v|
|
520
|
-
output_buffer.
|
516
|
+
expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
|
521
517
|
end
|
522
518
|
end
|
523
|
-
output_buffer.
|
519
|
+
expect(output_buffer).to have_tag("form li select optgroup option[@selected]","hands")
|
524
520
|
end
|
525
521
|
end
|
526
522
|
|
@@ -528,7 +524,7 @@ describe 'select input' do
|
|
528
524
|
before do
|
529
525
|
@output_buffer = ''
|
530
526
|
@some_meta_descriptions = ["One", "Two", "Three"]
|
531
|
-
@new_post.
|
527
|
+
allow(@new_post).to receive(:meta_description).at_least(:once)
|
532
528
|
end
|
533
529
|
|
534
530
|
describe ":as is not set" do
|
@@ -542,7 +538,7 @@ describe 'select input' do
|
|
542
538
|
end
|
543
539
|
|
544
540
|
it "should render a select field" do
|
545
|
-
output_buffer.
|
541
|
+
expect(output_buffer).to have_tag("form li select", :count => 2)
|
546
542
|
end
|
547
543
|
end
|
548
544
|
|
@@ -558,7 +554,7 @@ describe 'select input' do
|
|
558
554
|
end
|
559
555
|
|
560
556
|
it "should render a text field" do
|
561
|
-
output_buffer.
|
557
|
+
expect(output_buffer).to have_tag("form li input[@type='text']", :count => 2)
|
562
558
|
end
|
563
559
|
end
|
564
560
|
end
|
@@ -588,15 +584,15 @@ describe 'select input' do
|
|
588
584
|
end
|
589
585
|
|
590
586
|
it 'should index the id of the wrapper' do
|
591
|
-
output_buffer.
|
587
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
592
588
|
end
|
593
589
|
|
594
590
|
it 'should index the id of the select tag' do
|
595
|
-
output_buffer.
|
591
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_name")
|
596
592
|
end
|
597
593
|
|
598
594
|
it 'should index the name of the select' do
|
599
|
-
output_buffer.
|
595
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][name]']")
|
600
596
|
end
|
601
597
|
|
602
598
|
end
|
@@ -607,7 +603,7 @@ describe 'select input' do
|
|
607
603
|
concat(semantic_form_for(@new_post) do |builder|
|
608
604
|
concat(builder.input(:author, :as => :select, :required => true))
|
609
605
|
end)
|
610
|
-
output_buffer.
|
606
|
+
expect(output_buffer).to have_tag("select[@required]")
|
611
607
|
end
|
612
608
|
end
|
613
609
|
end
|