formtastic 2.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +4 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +204 -219
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +27 -29
- data/app/assets/stylesheets/formtastic.css +3 -2
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +11 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions/button_action.rb +55 -60
- data/lib/formtastic/actions/input_action.rb +59 -57
- data/lib/formtastic/actions/link_action.rb +68 -67
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +5 -0
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +35 -16
- data/lib/formtastic/helpers/action_helper.rb +34 -28
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
- data/lib/formtastic/helpers/form_helper.rb +19 -16
- data/lib/formtastic/helpers/input_helper.rb +69 -97
- data/lib/formtastic/helpers/inputs_helper.rb +35 -25
- data/lib/formtastic/helpers/reflection.rb +4 -4
- data/lib/formtastic/helpers.rb +1 -2
- data/lib/formtastic/html_attributes.rb +12 -1
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs/base/choices.rb +2 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -14
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -7
- data/lib/formtastic/inputs/base/hints.rb +2 -2
- data/lib/formtastic/inputs/base/html.rb +10 -9
- data/lib/formtastic/inputs/base/labelling.rb +5 -8
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -1
- data/lib/formtastic/inputs/base/options.rb +3 -4
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +34 -22
- data/lib/formtastic/inputs/base/validations.rb +41 -13
- data/lib/formtastic/inputs/base/wrapping.rb +29 -26
- data/lib/formtastic/inputs/base.rb +22 -15
- data/lib/formtastic/inputs/boolean_input.rb +26 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
- data/lib/formtastic/inputs/color_input.rb +41 -0
- data/lib/formtastic/inputs/country_input.rb +24 -5
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
- data/lib/formtastic/inputs/file_input.rb +2 -2
- data/lib/formtastic/inputs/hidden_input.rb +2 -6
- data/lib/formtastic/inputs/radio_input.rb +28 -22
- data/lib/formtastic/inputs/select_input.rb +36 -39
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/inputs.rb +32 -21
- data/lib/formtastic/localized_string.rb +1 -1
- data/lib/formtastic/localizer.rb +24 -24
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/formtastic.rb +20 -10
- data/lib/generators/formtastic/form/form_generator.rb +10 -4
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +5 -19
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +46 -25
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +23 -3
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +92 -56
- 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 +28 -29
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +75 -103
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +84 -33
- data/spec/helpers/input_helper_spec.rb +333 -285
- data/spec/helpers/inputs_helper_spec.rb +167 -121
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +100 -65
- data/spec/inputs/check_boxes_input_spec.rb +200 -101
- data/spec/inputs/color_input_spec.rb +85 -0
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +3 -4
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +249 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +209 -0
- 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 +22 -35
- data/spec/inputs/include_blank_spec.rb +11 -11
- data/spec/inputs/label_spec.rb +62 -25
- 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 +6 -6
- data/spec/inputs/radio_input_spec.rb +99 -55
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +170 -170
- data/spec/inputs/string_input_spec.rb +68 -16
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +261 -0
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +39 -17
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +254 -221
- data/spec/support/custom_macros.rb +128 -95
- data/spec/support/shared_examples.rb +12 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +26 -10
- metadata +177 -238
- data/.travis.yml +0 -8
- data/Appraisals +0 -11
- data/CHANGELOG +0 -371
- data/gemfiles/rails-3.0.gemfile +0 -7
- data/gemfiles/rails-3.1.gemfile +0 -7
- data/gemfiles/rails-3.2.gemfile +0 -7
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
- data/lib/formtastic/util.rb +0 -25
- data/lib/tasks/verify_rcov.rb +0 -44
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
- data/spec/inputs/date_input_spec.rb +0 -227
- data/spec/inputs/datetime_input_spec.rb +0 -185
- data/spec/inputs/time_input_spec.rb +0 -267
- data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -0,0 +1,455 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe 'time_picker input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with an object" do
|
14
|
+
before do
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:publish_at, :as => :time_picker))
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class(:time_picker)
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
22
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
23
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
24
|
+
it_should_have_label_with_text(/Publish at/)
|
25
|
+
it_should_have_label_for("post_publish_at")
|
26
|
+
it_should_have_input_with_id("post_publish_at")
|
27
|
+
it_should_have_input_with_type(:time)
|
28
|
+
it_should_have_input_with_name("post[publish_at]")
|
29
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:date_picker)
|
30
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:date_picker)
|
31
|
+
# TODO why does this blow-up it_should_apply_error_logic_for_input_type(:date_picker)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "size attribute" do
|
36
|
+
|
37
|
+
it "defaults to 5 chars (HH:MM)" do
|
38
|
+
concat(
|
39
|
+
semantic_form_for(@new_post) do |f|
|
40
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
41
|
+
end
|
42
|
+
)
|
43
|
+
expect(output_buffer).to have_tag "input[size='5']"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can be set from :input_html options" do
|
47
|
+
concat(
|
48
|
+
semantic_form_for(@new_post) do |f|
|
49
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :size => "11" }))
|
50
|
+
end
|
51
|
+
)
|
52
|
+
expect(output_buffer).to have_tag "input[size='11']"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can be set from options (ignoring input_html)" do
|
56
|
+
concat(
|
57
|
+
semantic_form_for(@new_post) do |f|
|
58
|
+
concat(f.input(:publish_at, :as => :time_picker, :size => '12', :input_html => { :size => "11" }))
|
59
|
+
end
|
60
|
+
)
|
61
|
+
expect(output_buffer).to have_tag "input[size='12']"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "maxlength attribute" do
|
67
|
+
|
68
|
+
it "defaults to 5 chars (HH:MM:SS)" do
|
69
|
+
concat(
|
70
|
+
semantic_form_for(@new_post) do |f|
|
71
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
72
|
+
end
|
73
|
+
)
|
74
|
+
expect(output_buffer).to have_tag "input[maxlength='5']"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can be set from :input_html options" do
|
78
|
+
concat(
|
79
|
+
semantic_form_for(@new_post) do |f|
|
80
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :maxlength => "11" }))
|
81
|
+
end
|
82
|
+
)
|
83
|
+
expect(output_buffer).to have_tag "input[maxlength='11']"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "can be set from options (ignoring input_html)" do
|
87
|
+
concat(
|
88
|
+
semantic_form_for(@new_post) do |f|
|
89
|
+
concat(f.input(:publish_at, :as => :time_picker, :maxlength => 12, :input_html => { :maxlength => "11" }))
|
90
|
+
end
|
91
|
+
)
|
92
|
+
expect(output_buffer).to have_tag "input[maxlength='12']"
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "value attribute" do
|
98
|
+
|
99
|
+
context "when method returns nil" do
|
100
|
+
|
101
|
+
it "has no value" do
|
102
|
+
concat(
|
103
|
+
semantic_form_for(@new_post) do |f|
|
104
|
+
concat(f.input(:publish_at, :as => :time_picker ))
|
105
|
+
end
|
106
|
+
)
|
107
|
+
expect(output_buffer).not_to have_tag "li input[value]"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can be set from :input_html options" do
|
111
|
+
concat(
|
112
|
+
semantic_form_for(@new_post) do |f|
|
113
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :value => "12:00" }))
|
114
|
+
end
|
115
|
+
)
|
116
|
+
expect(output_buffer).to have_tag "input[value='12:00']"
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when method returns a Date" do
|
122
|
+
|
123
|
+
before do
|
124
|
+
@date = Date.new(2000, 11, 11)
|
125
|
+
allow(@new_post).to receive(:publish_at).and_return(@date)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "renders 00:00" do
|
129
|
+
concat(
|
130
|
+
semantic_form_for(@new_post) do |f|
|
131
|
+
concat(f.input(:publish_at, :as => :time_picker ))
|
132
|
+
end
|
133
|
+
)
|
134
|
+
expect(output_buffer).to have_tag "input[value='00:00']"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "can be set from :input_html options" do
|
138
|
+
concat(
|
139
|
+
semantic_form_for(@new_post) do |f|
|
140
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :value => "23:59" }))
|
141
|
+
end
|
142
|
+
)
|
143
|
+
expect(output_buffer).to have_tag "input[value='23:59']"
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when method returns a Time" do
|
149
|
+
|
150
|
+
before do
|
151
|
+
@time = Time.utc(2000,11,11,11,11,11)
|
152
|
+
allow(@new_post).to receive(:publish_at).and_return(@time)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "renders the time as a HH:MM" do
|
156
|
+
concat(
|
157
|
+
semantic_form_for(@new_post) do |f|
|
158
|
+
concat(f.input(:publish_at, :as => :time_picker ))
|
159
|
+
end
|
160
|
+
)
|
161
|
+
expect(output_buffer).to have_tag "input[value='11:11']"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "can be set from :input_html options" do
|
165
|
+
concat(
|
166
|
+
semantic_form_for(@new_post) do |f|
|
167
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :value => "12:12" }))
|
168
|
+
end
|
169
|
+
)
|
170
|
+
expect(output_buffer).to have_tag "input[value='12:12']"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when method returns an empty String" do
|
176
|
+
|
177
|
+
before do
|
178
|
+
allow(@new_post).to receive(:publish_at).and_return("")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "will be empty" do
|
182
|
+
concat(
|
183
|
+
semantic_form_for(@new_post) do |f|
|
184
|
+
concat(f.input(:publish_at, :as => :time_picker ))
|
185
|
+
end
|
186
|
+
)
|
187
|
+
expect(output_buffer).to have_tag "input[value='']"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "can be set from :input_html options" do
|
191
|
+
concat(
|
192
|
+
semantic_form_for(@new_post) do |f|
|
193
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :value => "12:12:12" }))
|
194
|
+
end
|
195
|
+
)
|
196
|
+
expect(output_buffer).to have_tag "input[value='12:12:12']"
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
context "when method returns a String" do
|
202
|
+
|
203
|
+
before do
|
204
|
+
allow(@new_post).to receive(:publish_at).and_return("yeah")
|
205
|
+
end
|
206
|
+
|
207
|
+
it "will be the string" do
|
208
|
+
concat(
|
209
|
+
semantic_form_for(@new_post) do |f|
|
210
|
+
concat(f.input(:publish_at, :as => :time_picker ))
|
211
|
+
end
|
212
|
+
)
|
213
|
+
expect(output_buffer).to have_tag "input[value='yeah']"
|
214
|
+
end
|
215
|
+
|
216
|
+
it "can be set from :input_html options" do
|
217
|
+
concat(
|
218
|
+
semantic_form_for(@new_post) do |f|
|
219
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :value => "12:12:12" }))
|
220
|
+
end
|
221
|
+
)
|
222
|
+
expect(output_buffer).to have_tag "input[value='12:12:12']"
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "min attribute" do
|
230
|
+
|
231
|
+
it "will be omitted by default" do
|
232
|
+
concat(
|
233
|
+
semantic_form_for(@new_post) do |f|
|
234
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
235
|
+
end
|
236
|
+
)
|
237
|
+
expect(output_buffer).not_to have_tag "input[min]"
|
238
|
+
end
|
239
|
+
|
240
|
+
it "can be set from :input_html options" do
|
241
|
+
concat(
|
242
|
+
semantic_form_for(@new_post) do |f|
|
243
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :min => "13:00" }))
|
244
|
+
end
|
245
|
+
)
|
246
|
+
expect(output_buffer).to have_tag "input[min='13:00']"
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "max attribute" do
|
252
|
+
|
253
|
+
it "will be omitted by default" do
|
254
|
+
concat(
|
255
|
+
semantic_form_for(@new_post) do |f|
|
256
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
257
|
+
end
|
258
|
+
)
|
259
|
+
expect(output_buffer).not_to have_tag "input[max]"
|
260
|
+
end
|
261
|
+
|
262
|
+
it "can be set from :input_html options" do
|
263
|
+
concat(
|
264
|
+
semantic_form_for(@new_post) do |f|
|
265
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :max => "13:00" }))
|
266
|
+
end
|
267
|
+
)
|
268
|
+
expect(output_buffer).to have_tag "input[max='13:00']"
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
describe "step attribute" do
|
274
|
+
|
275
|
+
it "defaults to 60 (seconds)" do
|
276
|
+
concat(
|
277
|
+
semantic_form_for(@new_post) do |f|
|
278
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
279
|
+
end
|
280
|
+
)
|
281
|
+
expect(output_buffer).to have_tag "input[step='60']"
|
282
|
+
end
|
283
|
+
|
284
|
+
it "can be set from :input_html options" do
|
285
|
+
concat(
|
286
|
+
semantic_form_for(@new_post) do |f|
|
287
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :step => "3600" }))
|
288
|
+
end
|
289
|
+
)
|
290
|
+
expect(output_buffer).to have_tag "input[step='3600']"
|
291
|
+
end
|
292
|
+
|
293
|
+
describe "macros" do
|
294
|
+
before do
|
295
|
+
concat(
|
296
|
+
semantic_form_for(@new_post) do |f|
|
297
|
+
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => step }))
|
298
|
+
end
|
299
|
+
)
|
300
|
+
end
|
301
|
+
|
302
|
+
context ":second" do
|
303
|
+
let(:step) { :second }
|
304
|
+
it "uses 1" do
|
305
|
+
expect(output_buffer).to have_tag "input[step='1']"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context ":minute" do
|
310
|
+
let(:step) { :minute }
|
311
|
+
it "uses 60" do
|
312
|
+
expect(output_buffer).to have_tag "input[step='60']"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context ":fifteen_minutes" do
|
317
|
+
let(:step) { :fifteen_minutes }
|
318
|
+
it "uses 900" do
|
319
|
+
expect(output_buffer).to have_tag "input[step='900']"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context ":quarter_hour" do
|
324
|
+
let(:step) { :quarter_hour }
|
325
|
+
it "uses 900" do
|
326
|
+
expect(output_buffer).to have_tag "input[step='900']"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context ":thirty_minutes" do
|
331
|
+
let(:step) { :thirty_minutes }
|
332
|
+
it "uses 1800" do
|
333
|
+
expect(output_buffer).to have_tag "input[step='1800']"
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context ":half_hour" do
|
338
|
+
let(:step) { :half_hour }
|
339
|
+
it "uses 1800" do
|
340
|
+
expect(output_buffer).to have_tag "input[step='1800']"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context ":hour" do
|
345
|
+
let(:step) { :hour }
|
346
|
+
it "uses 3600" do
|
347
|
+
expect(output_buffer).to have_tag "input[step='3600']"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context ":sixty_minutes" do
|
352
|
+
let(:step) { :sixty_minutes }
|
353
|
+
it "uses 3600" do
|
354
|
+
expect(output_buffer).to have_tag "input[step='3600']"
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
describe "placeholder attribute" do
|
363
|
+
|
364
|
+
it "will be omitted" do
|
365
|
+
concat(
|
366
|
+
semantic_form_for(@new_post) do |f|
|
367
|
+
concat(f.input(:publish_at, :as => :time_picker))
|
368
|
+
end
|
369
|
+
)
|
370
|
+
expect(output_buffer).not_to have_tag "input[placeholder]"
|
371
|
+
end
|
372
|
+
|
373
|
+
it "can be set from :input_html options" do
|
374
|
+
concat(
|
375
|
+
semantic_form_for(@new_post) do |f|
|
376
|
+
concat(f.input(:publish_at, :as => :time_picker, :input_html => { :placeholder => "HH:MM" }))
|
377
|
+
end
|
378
|
+
)
|
379
|
+
expect(output_buffer).to have_tag "input[placeholder='HH:MM']"
|
380
|
+
end
|
381
|
+
|
382
|
+
context "with i18n set" do
|
383
|
+
before do
|
384
|
+
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :publish_at => 'HH:MM' }}
|
385
|
+
end
|
386
|
+
|
387
|
+
it "can be set with i18n" do
|
388
|
+
with_config :i18n_lookups_by_default, true do
|
389
|
+
concat(semantic_form_for(@new_post) do |builder|
|
390
|
+
concat(builder.input(:publish_at, :as => :time_picker))
|
391
|
+
end)
|
392
|
+
expect(output_buffer).to have_tag('input[@placeholder="HH:MM"]')
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
it "can be set with input_html, trumping i18n" do
|
397
|
+
with_config :i18n_lookups_by_default, true do
|
398
|
+
concat(semantic_form_for(@new_post) do |builder|
|
399
|
+
concat(builder.input(:publish_at, :as => :time_picker, :input_html => { :placeholder => "Something" }))
|
400
|
+
end)
|
401
|
+
expect(output_buffer).to have_tag('input[@placeholder="Something"]')
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
407
|
+
|
408
|
+
describe "when namespace is provided" do
|
409
|
+
before do
|
410
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
411
|
+
concat(builder.input(:publish_at, :as => :time_picker))
|
412
|
+
end)
|
413
|
+
end
|
414
|
+
|
415
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
416
|
+
it_should_have_label_and_input_with_id("context2_post_publish_at")
|
417
|
+
end
|
418
|
+
|
419
|
+
describe "when index is provided" do
|
420
|
+
before do
|
421
|
+
@output_buffer = ''
|
422
|
+
mock_everything
|
423
|
+
|
424
|
+
concat(semantic_form_for(@new_post) do |builder|
|
425
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
426
|
+
concat(author.input(:created_at, :as => :time_picker))
|
427
|
+
end)
|
428
|
+
end)
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'should index the id of the wrapper' do
|
432
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_created_at_input")
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'should index the id of the select tag' do
|
436
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at")
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'should index the name of the select tag' do
|
440
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at]']")
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "when required" do
|
445
|
+
it "should add the required attribute to the input's html options" do
|
446
|
+
with_config :use_required_attribute, true do
|
447
|
+
concat(semantic_form_for(@new_post) do |builder|
|
448
|
+
concat(builder.input(:publish_at, :as => :time_picker, :required => true))
|
449
|
+
end)
|
450
|
+
expect(output_buffer).to have_tag("input[@required]")
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|