formtastic 3.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,22 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'date_picker input' do
|
5
|
+
RSpec.describe 'date_picker 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
|
context "with an object" do
|
14
15
|
before do
|
15
16
|
concat(semantic_form_for(@new_post) do |builder|
|
16
17
|
concat(builder.input(:publish_at, :as => :date_picker))
|
17
18
|
end)
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
it_should_have_input_wrapper_with_class(:date_picker)
|
21
22
|
it_should_have_input_wrapper_with_class(:input)
|
22
23
|
it_should_have_input_wrapper_with_class(:stringish)
|
@@ -29,36 +30,36 @@ describe 'date_picker input' do
|
|
29
30
|
it_should_apply_custom_input_attributes_when_input_html_provided(:date_picker)
|
30
31
|
it_should_apply_custom_for_to_label_when_input_html_id_provided(:date_picker)
|
31
32
|
# TODO why does this blow-up it_should_apply_error_logic_for_input_type(:date_picker)
|
32
|
-
|
33
|
+
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
describe "size attribute" do
|
36
|
-
|
37
|
+
|
37
38
|
it "defaults to 10 chars (YYYY-YY-YY)" do
|
38
39
|
concat(
|
39
40
|
semantic_form_for(@new_post) do |f|
|
40
41
|
concat(f.input(:publish_at, :as => :date_picker))
|
41
42
|
end
|
42
43
|
)
|
43
|
-
output_buffer.
|
44
|
+
expect(output_buffer.to_str).to have_tag "input[size='10']"
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
it "can be set from :input_html options" do
|
47
48
|
concat(
|
48
49
|
semantic_form_for(@new_post) do |f|
|
49
50
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :size => "11" }))
|
50
51
|
end
|
51
52
|
)
|
52
|
-
output_buffer.
|
53
|
+
expect(output_buffer.to_str).to have_tag "input[size='11']"
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
it "can be set from options (ignoring input_html)" do
|
56
57
|
concat(
|
57
58
|
semantic_form_for(@new_post) do |f|
|
58
59
|
concat(f.input(:publish_at, :as => :date_picker, :size => '12', :input_html => { :size => "11" }))
|
59
60
|
end
|
60
61
|
)
|
61
|
-
output_buffer.
|
62
|
+
expect(output_buffer.to_str).to have_tag "input[size='12']"
|
62
63
|
end
|
63
64
|
|
64
65
|
end
|
@@ -71,7 +72,7 @@ describe 'date_picker input' do
|
|
71
72
|
concat(f.input(:publish_at, :as => :date_picker))
|
72
73
|
end
|
73
74
|
)
|
74
|
-
output_buffer.
|
75
|
+
expect(output_buffer.to_str).to have_tag "input[maxlength='10']"
|
75
76
|
end
|
76
77
|
|
77
78
|
it "can be set from :input_html options" do
|
@@ -80,58 +81,58 @@ describe 'date_picker input' do
|
|
80
81
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :maxlength => "11" }))
|
81
82
|
end
|
82
83
|
)
|
83
|
-
output_buffer.
|
84
|
+
expect(output_buffer.to_str).to have_tag "input[maxlength='11']"
|
84
85
|
end
|
85
|
-
|
86
|
+
|
86
87
|
it "can be set from options (ignoring input_html)" do
|
87
88
|
concat(
|
88
89
|
semantic_form_for(@new_post) do |f|
|
89
90
|
concat(f.input(:publish_at, :as => :date_picker, :maxlength => 12, :input_html => { :maxlength => "11" }))
|
90
91
|
end
|
91
92
|
)
|
92
|
-
output_buffer.
|
93
|
+
expect(output_buffer.to_str).to have_tag "input[maxlength='12']"
|
93
94
|
end
|
94
|
-
|
95
|
+
|
95
96
|
end
|
96
|
-
|
97
|
+
|
97
98
|
describe "value attribute" do
|
98
|
-
|
99
|
+
|
99
100
|
context "when method returns nil" do
|
100
|
-
|
101
|
+
|
101
102
|
it "has no value" do
|
102
103
|
concat(
|
103
104
|
semantic_form_for(@new_post) do |f|
|
104
105
|
concat(f.input(:publish_at, :as => :date_picker ))
|
105
106
|
end
|
106
107
|
)
|
107
|
-
output_buffer.
|
108
|
+
expect(output_buffer.to_str).not_to have_tag "li input[value]"
|
108
109
|
end
|
109
|
-
|
110
|
+
|
110
111
|
it "can be set from :input_html options" do
|
111
112
|
concat(
|
112
113
|
semantic_form_for(@new_post) do |f|
|
113
114
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
114
115
|
end
|
115
116
|
)
|
116
|
-
output_buffer.
|
117
|
+
expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
end
|
120
|
-
|
121
|
+
|
121
122
|
context "when method returns a Date" do
|
122
|
-
|
123
|
+
|
123
124
|
before do
|
124
125
|
@date = Date.new(2000, 11, 11)
|
125
|
-
@new_post.
|
126
|
+
allow(@new_post).to receive(:publish_at).and_return(@date)
|
126
127
|
end
|
127
|
-
|
128
|
+
|
128
129
|
it "renders the date as YYYY-MM-DD" do
|
129
130
|
concat(
|
130
131
|
semantic_form_for(@new_post) do |f|
|
131
132
|
concat(f.input(:publish_at, :as => :date_picker ))
|
132
133
|
end
|
133
134
|
)
|
134
|
-
output_buffer.
|
135
|
+
expect(output_buffer.to_str).to have_tag "input[value='#{@date.to_s}']"
|
135
136
|
end
|
136
137
|
|
137
138
|
it "can be set from :input_html options" do
|
@@ -140,114 +141,114 @@ describe 'date_picker input' do
|
|
140
141
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
141
142
|
end
|
142
143
|
)
|
143
|
-
output_buffer.
|
144
|
+
expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
|
144
145
|
end
|
145
|
-
|
146
|
+
|
146
147
|
end
|
147
|
-
|
148
|
+
|
148
149
|
context "when method returns a Time" do
|
149
|
-
|
150
|
+
|
150
151
|
before do
|
151
152
|
@time = Time.utc(2000,11,11,11,11,11)
|
152
|
-
@new_post.
|
153
|
+
allow(@new_post).to receive(:publish_at).and_return(@time)
|
153
154
|
end
|
154
|
-
|
155
|
+
|
155
156
|
it "renders the time as a YYYY-MM-DD" do
|
156
157
|
concat(
|
157
158
|
semantic_form_for(@new_post) do |f|
|
158
159
|
concat(f.input(:publish_at, :as => :date_picker ))
|
159
160
|
end
|
160
161
|
)
|
161
|
-
output_buffer.
|
162
|
+
expect(output_buffer.to_str).to have_tag "input[value='2000-11-11']"
|
162
163
|
end
|
163
|
-
|
164
|
+
|
164
165
|
it "can be set from :input_html options" do
|
165
166
|
concat(
|
166
167
|
semantic_form_for(@new_post) do |f|
|
167
168
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
168
169
|
end
|
169
170
|
)
|
170
|
-
output_buffer.
|
171
|
+
expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
|
171
172
|
end
|
172
|
-
|
173
|
+
|
173
174
|
end
|
174
|
-
|
175
|
+
|
175
176
|
context "when method returns an empty String" do
|
176
|
-
|
177
|
+
|
177
178
|
before do
|
178
|
-
@new_post.
|
179
|
+
allow(@new_post).to receive(:publish_at).and_return("")
|
179
180
|
end
|
180
|
-
|
181
|
+
|
181
182
|
it "will be empty" do
|
182
183
|
concat(
|
183
184
|
semantic_form_for(@new_post) do |f|
|
184
185
|
concat(f.input(:publish_at, :as => :date_picker ))
|
185
186
|
end
|
186
187
|
)
|
187
|
-
output_buffer.
|
188
|
+
expect(output_buffer.to_str).to have_tag "input[value='']"
|
188
189
|
end
|
189
|
-
|
190
|
+
|
190
191
|
it "can be set from :input_html options" do
|
191
192
|
concat(
|
192
193
|
semantic_form_for(@new_post) do |f|
|
193
194
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
194
195
|
end
|
195
196
|
)
|
196
|
-
output_buffer.
|
197
|
+
expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
|
197
198
|
end
|
198
|
-
|
199
|
+
|
199
200
|
end
|
200
|
-
|
201
|
+
|
201
202
|
context "when method returns a String" do
|
202
|
-
|
203
|
+
|
203
204
|
before do
|
204
|
-
@new_post.
|
205
|
+
allow(@new_post).to receive(:publish_at).and_return("yeah")
|
205
206
|
end
|
206
|
-
|
207
|
+
|
207
208
|
it "will be the string" do
|
208
209
|
concat(
|
209
210
|
semantic_form_for(@new_post) do |f|
|
210
211
|
concat(f.input(:publish_at, :as => :date_picker ))
|
211
212
|
end
|
212
213
|
)
|
213
|
-
output_buffer.
|
214
|
+
expect(output_buffer.to_str).to have_tag "input[value='yeah']"
|
214
215
|
end
|
215
|
-
|
216
|
+
|
216
217
|
it "can be set from :input_html options" do
|
217
218
|
concat(
|
218
219
|
semantic_form_for(@new_post) do |f|
|
219
220
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :value => "1111-11-11" }))
|
220
221
|
end
|
221
222
|
)
|
222
|
-
output_buffer.
|
223
|
+
expect(output_buffer.to_str).to have_tag "input[value='1111-11-11']"
|
223
224
|
end
|
224
|
-
|
225
|
+
|
225
226
|
end
|
226
227
|
|
227
228
|
end
|
228
|
-
|
229
|
+
|
229
230
|
describe "min attribute" do
|
230
|
-
|
231
|
+
|
231
232
|
it "will be omitted by default" do
|
232
233
|
concat(
|
233
234
|
semantic_form_for(@new_post) do |f|
|
234
235
|
concat(f.input(:publish_at, :as => :date_picker))
|
235
236
|
end
|
236
237
|
)
|
237
|
-
output_buffer.
|
238
|
+
expect(output_buffer.to_str).not_to have_tag "input[min]"
|
238
239
|
end
|
239
|
-
|
240
|
+
|
240
241
|
it "can be set from :input_html options" do
|
241
242
|
concat(
|
242
243
|
semantic_form_for(@new_post) do |f|
|
243
244
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :min => "1970-01-01" }))
|
244
245
|
end
|
245
246
|
)
|
246
|
-
output_buffer.
|
247
|
+
expect(output_buffer.to_str).to have_tag "input[min='1970-01-01']"
|
247
248
|
end
|
248
|
-
|
249
|
+
|
249
250
|
end
|
250
|
-
|
251
|
+
|
251
252
|
describe "max attribute" do
|
252
253
|
|
253
254
|
it "will be omitted by default" do
|
@@ -256,29 +257,29 @@ describe 'date_picker input' do
|
|
256
257
|
concat(f.input(:publish_at, :as => :date_picker))
|
257
258
|
end
|
258
259
|
)
|
259
|
-
output_buffer.
|
260
|
+
expect(output_buffer.to_str).not_to have_tag "input[max]"
|
260
261
|
end
|
261
|
-
|
262
|
+
|
262
263
|
it "can be set from :input_html options" do
|
263
264
|
concat(
|
264
265
|
semantic_form_for(@new_post) do |f|
|
265
266
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :max => "1970-01-01" }))
|
266
267
|
end
|
267
268
|
)
|
268
|
-
output_buffer.
|
269
|
+
expect(output_buffer.to_str).to have_tag "input[max='1970-01-01']"
|
269
270
|
end
|
270
|
-
|
271
|
+
|
271
272
|
end
|
272
|
-
|
273
|
+
|
273
274
|
describe "step attribute" do
|
274
|
-
|
275
|
+
|
275
276
|
it "defaults to 1" do
|
276
277
|
concat(
|
277
278
|
semantic_form_for(@new_post) do |f|
|
278
279
|
concat(f.input(:publish_at, :as => :date_picker))
|
279
280
|
end
|
280
281
|
)
|
281
|
-
output_buffer.
|
282
|
+
expect(output_buffer.to_str).to have_tag "input[step='1']"
|
282
283
|
end
|
283
284
|
|
284
285
|
it "can be set from :input_html options" do
|
@@ -287,118 +288,118 @@ describe 'date_picker input' do
|
|
287
288
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => "5" }))
|
288
289
|
end
|
289
290
|
)
|
290
|
-
output_buffer.
|
291
|
+
expect(output_buffer.to_str).to have_tag "input[step='5']"
|
291
292
|
end
|
292
|
-
|
293
|
+
|
293
294
|
describe "macros" do
|
294
|
-
|
295
|
-
before do
|
295
|
+
|
296
|
+
before do
|
296
297
|
concat(
|
297
298
|
semantic_form_for(@new_post) do |f|
|
298
299
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :step => step }))
|
299
300
|
end
|
300
301
|
)
|
301
302
|
end
|
302
|
-
|
303
|
+
|
303
304
|
context ":day" do
|
304
305
|
let(:step) { :day }
|
305
306
|
it "uses 1" do
|
306
|
-
output_buffer.
|
307
|
+
expect(output_buffer.to_str).to have_tag "input[step='1']"
|
307
308
|
end
|
308
309
|
end
|
309
|
-
|
310
|
+
|
310
311
|
context ":seven_days" do
|
311
312
|
let(:step) { :seven_days }
|
312
313
|
it "uses 7" do
|
313
|
-
output_buffer.
|
314
|
+
expect(output_buffer.to_str).to have_tag "input[step='7']"
|
314
315
|
end
|
315
316
|
end
|
316
|
-
|
317
|
+
|
317
318
|
context ":week" do
|
318
319
|
let(:step) { :week }
|
319
320
|
it "uses 7" do
|
320
|
-
output_buffer.
|
321
|
+
expect(output_buffer.to_str).to have_tag "input[step='7']"
|
321
322
|
end
|
322
323
|
end
|
323
|
-
|
324
|
+
|
324
325
|
context ":fortnight" do
|
325
326
|
let(:step) { :fortnight }
|
326
327
|
it "uses 14" do
|
327
|
-
output_buffer.
|
328
|
+
expect(output_buffer.to_str).to have_tag "input[step='14']"
|
328
329
|
end
|
329
330
|
end
|
330
|
-
|
331
|
+
|
331
332
|
context ":two_weeks" do
|
332
333
|
let(:step) { :two_weeks }
|
333
334
|
it "uses 14" do
|
334
|
-
output_buffer.
|
335
|
+
expect(output_buffer.to_str).to have_tag "input[step='14']"
|
335
336
|
end
|
336
337
|
end
|
337
|
-
|
338
|
+
|
338
339
|
context ":four_weeks" do
|
339
340
|
let(:step) { :four_weeks }
|
340
341
|
it "uses 28" do
|
341
|
-
output_buffer.
|
342
|
+
expect(output_buffer.to_str).to have_tag "input[step='28']"
|
342
343
|
end
|
343
344
|
end
|
344
|
-
|
345
|
+
|
345
346
|
context ":thirty_days" do
|
346
347
|
let(:step) { :thirty_days }
|
347
348
|
it "uses 30" do
|
348
|
-
output_buffer.
|
349
|
+
expect(output_buffer.to_str).to have_tag "input[step='30']"
|
349
350
|
end
|
350
351
|
end
|
351
|
-
|
352
|
+
|
352
353
|
end
|
353
|
-
|
354
|
+
|
354
355
|
end
|
355
|
-
|
356
|
+
|
356
357
|
describe "placeholder attribute" do
|
357
|
-
|
358
|
+
|
358
359
|
it "will be omitted" do
|
359
360
|
concat(
|
360
361
|
semantic_form_for(@new_post) do |f|
|
361
362
|
concat(f.input(:publish_at, :as => :date_picker))
|
362
363
|
end
|
363
364
|
)
|
364
|
-
output_buffer.
|
365
|
+
expect(output_buffer.to_str).not_to have_tag "input[placeholder]"
|
365
366
|
end
|
366
|
-
|
367
|
+
|
367
368
|
it "can be set from :input_html options" do
|
368
369
|
concat(
|
369
370
|
semantic_form_for(@new_post) do |f|
|
370
371
|
concat(f.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "1970-01-01" }))
|
371
372
|
end
|
372
373
|
)
|
373
|
-
output_buffer.
|
374
|
+
expect(output_buffer.to_str).to have_tag "input[placeholder='1970-01-01']"
|
374
375
|
end
|
375
|
-
|
376
|
+
|
376
377
|
context "with i18n set" do
|
377
378
|
before do
|
378
379
|
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :publish_at => 'YYYY-MM-DD' }}
|
379
380
|
end
|
380
|
-
|
381
|
+
|
381
382
|
it "can be set with i18n" do
|
382
383
|
with_config :i18n_lookups_by_default, true do
|
383
384
|
concat(semantic_form_for(@new_post) do |builder|
|
384
385
|
concat(builder.input(:publish_at, :as => :date_picker))
|
385
386
|
end)
|
386
|
-
output_buffer.
|
387
|
+
expect(output_buffer.to_str).to have_tag('input[@placeholder="YYYY-MM-DD"]')
|
387
388
|
end
|
388
389
|
end
|
389
|
-
|
390
|
+
|
390
391
|
it "can be set with input_html, trumping i18n" do
|
391
392
|
with_config :i18n_lookups_by_default, true do
|
392
393
|
concat(semantic_form_for(@new_post) do |builder|
|
393
394
|
concat(builder.input(:publish_at, :as => :date_picker, :input_html => { :placeholder => "Something" }))
|
394
395
|
end)
|
395
|
-
output_buffer.
|
396
|
+
expect(output_buffer.to_str).to have_tag('input[@placeholder="Something"]')
|
396
397
|
end
|
397
398
|
end
|
398
399
|
end
|
399
|
-
|
400
|
+
|
400
401
|
end
|
401
|
-
|
402
|
+
|
402
403
|
describe "when namespace is provided" do
|
403
404
|
before do
|
404
405
|
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
@@ -409,10 +410,10 @@ describe 'date_picker input' do
|
|
409
410
|
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
410
411
|
it_should_have_label_and_input_with_id("context2_post_publish_at")
|
411
412
|
end
|
412
|
-
|
413
|
+
|
413
414
|
describe "when index is provided" do
|
414
415
|
before do
|
415
|
-
@output_buffer = ''
|
416
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
416
417
|
mock_everything
|
417
418
|
|
418
419
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -421,29 +422,29 @@ describe 'date_picker input' do
|
|
421
422
|
end)
|
422
423
|
end)
|
423
424
|
end
|
424
|
-
|
425
|
+
|
425
426
|
it 'should index the id of the wrapper' do
|
426
|
-
output_buffer.
|
427
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
|
427
428
|
end
|
428
|
-
|
429
|
+
|
429
430
|
it 'should index the id of the select tag' do
|
430
|
-
output_buffer.
|
431
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at")
|
431
432
|
end
|
432
|
-
|
433
|
+
|
433
434
|
it 'should index the name of the select tag' do
|
434
|
-
output_buffer.
|
435
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at]']")
|
435
436
|
end
|
436
437
|
end
|
437
|
-
|
438
|
+
|
438
439
|
describe "when required" do
|
439
440
|
it "should add the required attribute to the input's html options" do
|
440
|
-
with_config :use_required_attribute, true do
|
441
|
+
with_config :use_required_attribute, true do
|
441
442
|
concat(semantic_form_for(@new_post) do |builder|
|
442
443
|
concat(builder.input(:publish_at, :as => :date_picker, :required => true))
|
443
444
|
end)
|
444
|
-
output_buffer.
|
445
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
445
446
|
end
|
446
447
|
end
|
447
448
|
end
|
448
|
-
|
449
|
+
|
449
450
|
end
|