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,19 +1,20 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'time select input' do
|
|
5
|
+
RSpec.describe 'time select 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
|
|
|
13
14
|
describe "general" do
|
|
14
15
|
before do
|
|
15
16
|
::I18n.backend.reload!
|
|
16
|
-
output_buffer.
|
|
17
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
describe "with :ignore_date => true" do
|
|
@@ -24,42 +25,42 @@ describe 'time select input' do
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
it 'should not have hidden inputs for day, month and year' do
|
|
27
|
-
output_buffer.
|
|
28
|
-
output_buffer.
|
|
29
|
-
output_buffer.
|
|
28
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_1i')
|
|
29
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_2i')
|
|
30
|
+
expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_3i')
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
it 'should have an input for hour and minute' do
|
|
33
|
-
output_buffer.
|
|
34
|
-
output_buffer.
|
|
34
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
|
|
35
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
end
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
describe "with :ignore_date => false" do
|
|
40
41
|
before do
|
|
41
|
-
@new_post.
|
|
42
|
+
allow(@new_post).to receive(:publish_at).and_return(Time.parse('2010-11-07'))
|
|
42
43
|
concat(semantic_form_for(@new_post) do |builder|
|
|
43
44
|
concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
|
|
44
45
|
end)
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
it 'should have a hidden input for day, month and year' do
|
|
48
|
-
output_buffer.
|
|
49
|
-
output_buffer.
|
|
50
|
-
output_buffer.
|
|
51
|
-
output_buffer.
|
|
52
|
-
output_buffer.
|
|
53
|
-
output_buffer.
|
|
49
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i')
|
|
50
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i')
|
|
51
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i')
|
|
52
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i[@value="2010"]')
|
|
53
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i[@value="11"]')
|
|
54
|
+
expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i[@value="7"]')
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
it 'should have an select for hour and minute' do
|
|
57
|
-
output_buffer.
|
|
58
|
-
output_buffer.
|
|
58
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
|
|
59
|
+
expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
it 'should associate the legend label with the hour select' do
|
|
62
|
-
output_buffer.
|
|
63
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
end
|
|
@@ -80,26 +81,26 @@ describe 'time select input' do
|
|
|
80
81
|
it_should_apply_error_logic_for_input_type(:time_select)
|
|
81
82
|
|
|
82
83
|
it 'should have a legend and label with the label text inside the fieldset' do
|
|
83
|
-
output_buffer.
|
|
84
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
it 'should associate the legend label with the first select' do
|
|
87
|
-
output_buffer.
|
|
88
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
it 'should have an ordered list of two items inside the fieldset' do
|
|
91
|
-
output_buffer.
|
|
92
|
-
output_buffer.
|
|
92
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol.fragments-group')
|
|
93
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
it 'should have five labels for hour and minute' do
|
|
96
|
-
output_buffer.
|
|
97
|
-
output_buffer.
|
|
98
|
-
output_buffer.
|
|
97
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 2)
|
|
98
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
|
99
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
it 'should have two selects for hour and minute' do
|
|
102
|
-
output_buffer.
|
|
103
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 2)
|
|
103
104
|
end
|
|
104
105
|
end
|
|
105
106
|
|
|
@@ -111,20 +112,20 @@ describe 'time select input' do
|
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
it 'should have five labels for hour and minute' do
|
|
114
|
-
output_buffer.
|
|
115
|
-
output_buffer.
|
|
116
|
-
output_buffer.
|
|
117
|
-
output_buffer.
|
|
115
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 3)
|
|
116
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
|
|
117
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
|
|
118
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
it 'should have three selects for hour, minute and seconds' do
|
|
121
|
-
output_buffer.
|
|
122
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 3)
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
it 'should generate a sanitized label and matching ids for attribute' do
|
|
125
126
|
4.upto(6) do |i|
|
|
126
|
-
output_buffer.
|
|
127
|
-
output_buffer.
|
|
127
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
|
128
|
+
expect(output_buffer.to_str).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
|
128
129
|
end
|
|
129
130
|
end
|
|
130
131
|
end
|
|
@@ -134,54 +135,67 @@ describe 'time select input' do
|
|
|
134
135
|
fields = [:hour, :minute, :second]
|
|
135
136
|
fields.each do |field|
|
|
136
137
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
|
137
|
-
output_buffer.
|
|
138
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
138
139
|
concat(semantic_form_for(@new_post) do |builder|
|
|
139
140
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
|
140
141
|
end)
|
|
141
|
-
output_buffer.
|
|
142
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
|
|
142
143
|
fields.each do |f|
|
|
143
|
-
output_buffer.
|
|
144
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
|
|
144
145
|
end
|
|
145
146
|
end
|
|
146
147
|
|
|
147
148
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
|
148
|
-
output_buffer.
|
|
149
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
149
150
|
concat(semantic_form_for(@new_post) do |builder|
|
|
150
151
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
|
|
151
152
|
end)
|
|
152
|
-
output_buffer.
|
|
153
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
|
153
154
|
fields.each do |f|
|
|
154
|
-
output_buffer.
|
|
155
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
|
155
156
|
end
|
|
156
157
|
end
|
|
157
|
-
|
|
158
|
-
it "should not render the label when :labels[:#{field}] is false" do
|
|
159
|
-
output_buffer.
|
|
158
|
+
|
|
159
|
+
it "should not render the label when :labels[:#{field}] is false" do
|
|
160
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
160
161
|
concat(semantic_form_for(@new_post) do |builder|
|
|
161
162
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
|
162
163
|
end)
|
|
163
|
-
output_buffer.
|
|
164
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
|
164
165
|
fields.each do |f|
|
|
165
|
-
output_buffer.
|
|
166
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
|
|
166
167
|
end
|
|
167
168
|
end
|
|
168
169
|
|
|
169
|
-
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
|
170
|
-
output_buffer.
|
|
170
|
+
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
|
171
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
171
172
|
concat(semantic_form_for(@new_post) do |builder|
|
|
172
173
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
|
173
174
|
end)
|
|
174
|
-
output_buffer.
|
|
175
|
+
expect(output_buffer.to_str).not_to include(">")
|
|
175
176
|
end
|
|
176
|
-
|
|
177
|
+
|
|
177
178
|
end
|
|
178
179
|
|
|
179
180
|
it "should not render labels when :labels is falsy" do
|
|
180
|
-
output_buffer.
|
|
181
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
181
182
|
concat(semantic_form_for(@new_post) do |builder|
|
|
182
183
|
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
|
|
183
184
|
end)
|
|
184
|
-
output_buffer.
|
|
185
|
+
expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 0)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
describe ":selected option for setting a value" do
|
|
190
|
+
it "should set the selected value for the form" do
|
|
191
|
+
concat(
|
|
192
|
+
semantic_form_for(@new_post) do |f|
|
|
193
|
+
concat(f.input(:created_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)))
|
|
194
|
+
end
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
expect(output_buffer.to_str).to have_tag "option[value='12'][selected='selected']"
|
|
198
|
+
expect(output_buffer.to_str).to have_tag "option[value='00'][selected='selected']"
|
|
185
199
|
end
|
|
186
200
|
end
|
|
187
201
|
|
|
@@ -193,23 +207,23 @@ describe 'time select input' do
|
|
|
193
207
|
end
|
|
194
208
|
|
|
195
209
|
it 'should have a tag matching the namespace' do
|
|
196
|
-
output_buffer.
|
|
197
|
-
output_buffer.
|
|
198
|
-
output_buffer.
|
|
210
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_input')
|
|
211
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_4i')
|
|
212
|
+
expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_5i')
|
|
199
213
|
end
|
|
200
214
|
end
|
|
201
|
-
|
|
215
|
+
|
|
202
216
|
describe "when required" do
|
|
203
217
|
it "should add the required attribute to the input's html options" do
|
|
204
|
-
with_config :use_required_attribute, true do
|
|
218
|
+
with_config :use_required_attribute, true do
|
|
205
219
|
concat(semantic_form_for(@new_post) do |builder|
|
|
206
220
|
concat(builder.input(:title, :as => :time_select, :required => true))
|
|
207
221
|
end)
|
|
208
|
-
output_buffer.
|
|
222
|
+
expect(output_buffer.to_str).to have_tag("select[@required]", :count => 2)
|
|
209
223
|
end
|
|
210
224
|
end
|
|
211
225
|
end
|
|
212
|
-
|
|
226
|
+
|
|
213
227
|
describe "when index is provided" do
|
|
214
228
|
|
|
215
229
|
before do
|
|
@@ -221,27 +235,27 @@ describe 'time select input' do
|
|
|
221
235
|
end
|
|
222
236
|
|
|
223
237
|
it 'should index the id of the wrapper' do
|
|
224
|
-
output_buffer.
|
|
238
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
|
|
225
239
|
end
|
|
226
240
|
|
|
227
241
|
it 'should index the id of the select tag' do
|
|
228
|
-
output_buffer.
|
|
229
|
-
output_buffer.
|
|
230
|
-
output_buffer.
|
|
231
|
-
output_buffer.
|
|
232
|
-
output_buffer.
|
|
242
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_1i")
|
|
243
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_2i")
|
|
244
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_3i")
|
|
245
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_4i")
|
|
246
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_5i")
|
|
233
247
|
end
|
|
234
248
|
|
|
235
249
|
it 'should index the name of the select tag' do
|
|
236
|
-
output_buffer.
|
|
237
|
-
output_buffer.
|
|
238
|
-
output_buffer.
|
|
239
|
-
output_buffer.
|
|
240
|
-
output_buffer.
|
|
250
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
|
|
251
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
|
|
252
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
|
|
253
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
|
254
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
|
241
255
|
end
|
|
242
256
|
|
|
243
257
|
end
|
|
244
|
-
|
|
258
|
+
|
|
245
259
|
end
|
|
246
260
|
|
|
247
261
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'time_zone input' do
|
|
5
|
+
RSpec.describe 'time_zone 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
|
|
|
12
13
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -20,28 +21,28 @@ describe 'time_zone input' do
|
|
|
20
21
|
it_should_apply_error_logic_for_input_type(:time_zone)
|
|
21
22
|
|
|
22
23
|
it 'should generate a label for the input' do
|
|
23
|
-
output_buffer.
|
|
24
|
-
output_buffer.
|
|
25
|
-
output_buffer.
|
|
24
|
+
expect(output_buffer.to_str).to have_tag('form li label')
|
|
25
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="post_time_zone"]')
|
|
26
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
it "should generate a select" do
|
|
29
|
-
output_buffer.
|
|
30
|
-
output_buffer.
|
|
31
|
-
output_buffer.
|
|
30
|
+
expect(output_buffer.to_str).to have_tag("form li select")
|
|
31
|
+
expect(output_buffer.to_str).to have_tag("form li select#post_time_zone")
|
|
32
|
+
expect(output_buffer.to_str).to have_tag("form li select[@name=\"post[time_zone]\"]")
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
it 'should use input_html to style inputs' do
|
|
35
36
|
concat(semantic_form_for(@new_post) do |builder|
|
|
36
37
|
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
|
37
38
|
end)
|
|
38
|
-
output_buffer.
|
|
39
|
+
expect(output_buffer.to_str).to have_tag("form li select.myclass")
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
describe "when namespace is provided" do
|
|
42
43
|
|
|
43
44
|
before do
|
|
44
|
-
@output_buffer = ''
|
|
45
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
45
46
|
mock_everything
|
|
46
47
|
|
|
47
48
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
|
@@ -54,11 +55,11 @@ describe 'time_zone input' do
|
|
|
54
55
|
it_should_have_label_for("context2_post_time_zone")
|
|
55
56
|
|
|
56
57
|
end
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
describe "when index is provided" do
|
|
59
60
|
|
|
60
61
|
before do
|
|
61
|
-
@output_buffer = ''
|
|
62
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
62
63
|
mock_everything
|
|
63
64
|
|
|
64
65
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -67,51 +68,77 @@ describe 'time_zone input' do
|
|
|
67
68
|
end)
|
|
68
69
|
end)
|
|
69
70
|
end
|
|
70
|
-
|
|
71
|
+
|
|
71
72
|
it 'should index the id of the wrapper' do
|
|
72
|
-
output_buffer.
|
|
73
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
73
74
|
end
|
|
74
|
-
|
|
75
|
+
|
|
75
76
|
it 'should index the id of the select tag' do
|
|
76
|
-
output_buffer.
|
|
77
|
+
expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_name")
|
|
77
78
|
end
|
|
78
|
-
|
|
79
|
+
|
|
79
80
|
it 'should index the name of the select tag' do
|
|
80
|
-
output_buffer.
|
|
81
|
+
expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][name]']")
|
|
81
82
|
end
|
|
82
|
-
|
|
83
|
+
|
|
83
84
|
end
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
|
|
86
87
|
describe 'when no object is given' do
|
|
87
|
-
before(:
|
|
88
|
+
before(:example) do
|
|
88
89
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
89
90
|
concat(builder.input(:time_zone, :as => :time_zone))
|
|
90
91
|
end)
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
it 'should generate labels' do
|
|
94
|
-
output_buffer.
|
|
95
|
-
output_buffer.
|
|
96
|
-
output_buffer.
|
|
95
|
+
expect(output_buffer.to_str).to have_tag('form li label')
|
|
96
|
+
expect(output_buffer.to_str).to have_tag('form li label[@for="project_time_zone"]')
|
|
97
|
+
expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
|
|
97
98
|
end
|
|
98
99
|
|
|
99
100
|
it 'should generate select inputs' do
|
|
100
|
-
output_buffer.
|
|
101
|
-
output_buffer.
|
|
102
|
-
output_buffer.
|
|
101
|
+
expect(output_buffer.to_str).to have_tag("form li select")
|
|
102
|
+
expect(output_buffer.to_str).to have_tag("form li select#project_time_zone")
|
|
103
|
+
expect(output_buffer.to_str).to have_tag("form li select[@name=\"project[time_zone]\"]")
|
|
103
104
|
end
|
|
104
105
|
end
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
context "when required" do
|
|
107
108
|
it "should add the required attribute to the input's html options" do
|
|
108
|
-
with_config :use_required_attribute, true do
|
|
109
|
+
with_config :use_required_attribute, true do
|
|
109
110
|
concat(semantic_form_for(@new_post) do |builder|
|
|
110
111
|
concat(builder.input(:title, :as => :time_zone, :required => true))
|
|
111
112
|
end)
|
|
112
|
-
output_buffer.
|
|
113
|
+
expect(output_buffer.to_str).to have_tag("select[@required]")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "when priority time zone is provided" do
|
|
119
|
+
let(:time_zones) { [ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii']] }
|
|
120
|
+
let(:input_html_options) do
|
|
121
|
+
{ id: "post_title", required: false, autofocus: false, readonly: false }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "by priority_zone option" do
|
|
125
|
+
it "passes right time_zones" do
|
|
126
|
+
expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
|
|
127
|
+
semantic_form_for(@new_post) do |builder|
|
|
128
|
+
builder.input(:title, as: :time_zone, priority_zones: time_zones)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "by configuration" do
|
|
134
|
+
it "passes right time_zones" do
|
|
135
|
+
expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
|
|
136
|
+
with_config :priority_time_zones, time_zones do
|
|
137
|
+
semantic_form_for(@new_post) do |builder|
|
|
138
|
+
builder.input(:title, as: :time_zone)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
113
141
|
end
|
|
114
142
|
end
|
|
115
143
|
end
|
|
116
|
-
|
|
117
144
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'url input' do
|
|
5
|
+
RSpec.describe 'url 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
|
|
|
@@ -41,11 +42,11 @@ describe 'url input' do
|
|
|
41
42
|
it_should_have_label_and_input_with_id("context2_post_url")
|
|
42
43
|
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
describe "when index is provided" do
|
|
46
47
|
|
|
47
48
|
before do
|
|
48
|
-
@output_buffer = ''
|
|
49
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
49
50
|
mock_everything
|
|
50
51
|
|
|
51
52
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -54,32 +55,32 @@ describe 'url input' do
|
|
|
54
55
|
end)
|
|
55
56
|
end)
|
|
56
57
|
end
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
it 'should index the id of the wrapper' do
|
|
59
|
-
output_buffer.
|
|
60
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
60
61
|
end
|
|
61
|
-
|
|
62
|
+
|
|
62
63
|
it 'should index the id of the select tag' do
|
|
63
|
-
output_buffer.
|
|
64
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
64
65
|
end
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
it 'should index the name of the select tag' do
|
|
67
|
-
output_buffer.
|
|
68
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
end
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
|
|
73
74
|
describe "when required" do
|
|
74
75
|
it "should add the required attribute to the input's html options" do
|
|
75
|
-
with_config :use_required_attribute, true do
|
|
76
|
+
with_config :use_required_attribute, true do
|
|
76
77
|
concat(semantic_form_for(@new_post) do |builder|
|
|
77
78
|
concat(builder.input(:title, :as => :url, :required => true))
|
|
78
79
|
end)
|
|
79
|
-
output_buffer.
|
|
80
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
80
81
|
end
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
|
-
|
|
84
|
+
|
|
84
85
|
end
|
|
85
86
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'string input' do
|
|
5
|
+
RSpec.describe 'string 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
|
|
|
@@ -21,23 +22,23 @@ describe 'string input' do
|
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
it "should have extra class on title" do
|
|
24
|
-
output_buffer.
|
|
25
|
+
expect(output_buffer.to_str).to have_tag("form li#post_title_input.extra")
|
|
25
26
|
end
|
|
26
27
|
it "should have title as string" do
|
|
27
|
-
output_buffer.
|
|
28
|
+
expect(output_buffer.to_str).to have_tag("form li#post_title_input.string")
|
|
28
29
|
end
|
|
29
30
|
it "should not have title as radio" do
|
|
30
|
-
output_buffer.
|
|
31
|
+
expect(output_buffer.to_str).not_to have_tag("form li#post_title_input.radio")
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
it "should have extra class on author" do
|
|
34
|
-
output_buffer.
|
|
35
|
+
expect(output_buffer.to_str).to have_tag("form li#post_author_input.extra")
|
|
35
36
|
end
|
|
36
37
|
it "should not have author as string" do
|
|
37
|
-
output_buffer.
|
|
38
|
+
expect(output_buffer.to_str).not_to have_tag("form li#post_author_input.string")
|
|
38
39
|
end
|
|
39
40
|
it "should have author as radio" do
|
|
40
|
-
output_buffer.
|
|
41
|
+
expect(output_buffer.to_str).to have_tag("form li#post_author_input.radio")
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|