formtastic 2.1.1 → 2.2.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +19 -1
- data/Appraisals +7 -0
- data/CHANGELOG +18 -0
- data/README.textile +14 -16
- data/formtastic.gemspec +1 -1
- data/gemfiles/rails-4.gemfile +8 -0
- data/lib/formtastic/form_builder.rb +0 -1
- data/lib/formtastic/helpers/input_helper.rb +12 -26
- data/lib/formtastic/inputs.rb +6 -0
- data/lib/formtastic/inputs/base.rb +16 -4
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +17 -17
- data/lib/formtastic/inputs/base/wrapping.rb +25 -20
- data/lib/formtastic/inputs/boolean_input.rb +24 -1
- data/lib/formtastic/inputs/date_input.rb +5 -29
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_input.rb +6 -8
- data/lib/formtastic/inputs/datetime_picker_input.rb +100 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/select_input.rb +2 -5
- data/lib/formtastic/inputs/time_input.rb +4 -28
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +34 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +0 -8
- data/sample/basic_inputs.html +21 -1
- data/spec/builder/semantic_fields_for_spec.rb +1 -1
- data/spec/generators/formtastic/install/install_generator_spec.rb +1 -1
- data/spec/helpers/input_helper_spec.rb +20 -16
- data/spec/helpers/semantic_errors_helper_spec.rb +10 -10
- data/spec/inputs/custom_input_spec.rb +5 -2
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/{date_input_spec.rb → date_select_input_spec.rb} +34 -34
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/{datetime_input_spec.rb → datetime_select_input_spec.rb} +33 -33
- data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
- data/spec/inputs/hidden_input_spec.rb +21 -17
- data/spec/inputs/include_blank_spec.rb +3 -3
- data/spec/inputs/label_spec.rb +1 -1
- data/spec/inputs/placeholder_spec.rb +1 -1
- data/spec/inputs/select_input_spec.rb +22 -14
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/{time_input_spec.rb → time_select_input_spec.rb} +35 -35
- data/spec/spec_helper.rb +25 -1
- data/spec/support/custom_macros.rb +2 -2
- metadata +32 -21
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'date input' do
|
4
|
+
describe 'date select input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -15,43 +15,43 @@ describe 'date input' do
|
|
15
15
|
before do
|
16
16
|
output_buffer.replace ''
|
17
17
|
concat(semantic_form_for(@new_post) do |builder|
|
18
|
-
concat(builder.input(:publish_at, :as => :
|
18
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
|
19
19
|
end)
|
20
20
|
end
|
21
21
|
|
22
|
-
it_should_have_input_wrapper_with_class("
|
22
|
+
it_should_have_input_wrapper_with_class("date_select")
|
23
23
|
it_should_have_input_wrapper_with_class(:input)
|
24
24
|
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
25
25
|
it_should_have_a_nested_fieldset
|
26
26
|
it_should_have_a_nested_fieldset_with_class('fragments')
|
27
27
|
it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
28
|
-
it_should_apply_error_logic_for_input_type(:
|
28
|
+
it_should_apply_error_logic_for_input_type(:date_select)
|
29
29
|
|
30
30
|
it 'should have a legend and label with the label text inside the fieldset' do
|
31
|
-
output_buffer.should have_tag('form li.
|
31
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label label', /Publish at/)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should associate the legend label with the first select' do
|
35
|
-
output_buffer.should have_tag('form li.
|
36
|
-
output_buffer.should have_tag('form li.
|
37
|
-
output_buffer.should have_tag('form li.
|
38
|
-
output_buffer.should have_tag('form li.
|
35
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label')
|
36
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label label')
|
37
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for]')
|
38
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for="post_publish_at_1i"]')
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should have an ordered list of three items inside the fieldset' do
|
42
|
-
output_buffer.should have_tag('form li.
|
43
|
-
output_buffer.should have_tag('form li.
|
42
|
+
output_buffer.should have_tag('form li.date_select fieldset ol.fragments-group')
|
43
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li.fragment', :count => 3)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should have three labels for year, month and day' do
|
47
|
-
output_buffer.should have_tag('form li.
|
48
|
-
output_buffer.should have_tag('form li.
|
49
|
-
output_buffer.should have_tag('form li.
|
50
|
-
output_buffer.should have_tag('form li.
|
47
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => 3)
|
48
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', /year/i)
|
49
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', /month/i)
|
50
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', /day/i)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should have three selects for year, month and day' do
|
54
|
-
output_buffer.should have_tag('form li.
|
54
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li select', :count => 3)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -60,7 +60,7 @@ describe 'date input' do
|
|
60
60
|
before do
|
61
61
|
output_buffer.replace ''
|
62
62
|
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
63
|
-
concat(builder.input(:publish_at, :as => :
|
63
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
|
64
64
|
end)
|
65
65
|
end
|
66
66
|
|
@@ -79,7 +79,7 @@ describe 'date input' do
|
|
79
79
|
|
80
80
|
concat(semantic_form_for(@new_post) do |builder|
|
81
81
|
concat(builder.fields_for(:author, :index => 3) do |author|
|
82
|
-
concat(author.input(:created_at, :as => :
|
82
|
+
concat(author.input(:created_at, :as => :date_select))
|
83
83
|
end)
|
84
84
|
end)
|
85
85
|
end
|
@@ -108,40 +108,40 @@ describe 'date input' do
|
|
108
108
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
109
109
|
output_buffer.replace ''
|
110
110
|
concat(semantic_form_for(@new_post) do |builder|
|
111
|
-
concat(builder.input(:created_at, :as => :
|
111
|
+
concat(builder.input(:created_at, :as => :date_select, :labels => { field => "another #{field} label" }))
|
112
112
|
end)
|
113
|
-
output_buffer.should have_tag('form li.
|
113
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length)
|
114
114
|
fields.each do |f|
|
115
|
-
output_buffer.should have_tag('form li.
|
115
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
120
120
|
output_buffer.replace ''
|
121
121
|
concat(semantic_form_for(@new_post) do |builder|
|
122
|
-
concat(builder.input(:created_at, :as => :
|
122
|
+
concat(builder.input(:created_at, :as => :date_select, :labels => { field => "" }))
|
123
123
|
end)
|
124
|
-
output_buffer.should have_tag('form li.
|
124
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length-1)
|
125
125
|
fields.each do |f|
|
126
|
-
output_buffer.should have_tag('form li.
|
126
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', /#{f}/i) unless field == f
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
131
131
|
output_buffer.replace ''
|
132
132
|
concat(semantic_form_for(@new_post) do |builder|
|
133
|
-
concat(builder.input(:created_at, :as => :
|
133
|
+
concat(builder.input(:created_at, :as => :date_select, :labels => { field => false }))
|
134
134
|
end)
|
135
|
-
output_buffer.should have_tag('form li.
|
135
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length-1)
|
136
136
|
fields.each do |f|
|
137
|
-
output_buffer.should have_tag('form li.
|
137
|
+
output_buffer.should have_tag('form li.date_select fieldset ol li label', /#{f}/i) unless field == f
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
142
142
|
output_buffer.replace ''
|
143
143
|
concat(semantic_form_for(@new_post) do |builder|
|
144
|
-
concat(builder.input(:created_at, :as => :
|
144
|
+
concat(builder.input(:created_at, :as => :date_select, :include_seconds => true, :labels => { field => false }))
|
145
145
|
end)
|
146
146
|
output_buffer.should_not include(">")
|
147
147
|
end
|
@@ -153,7 +153,7 @@ describe 'date input' do
|
|
153
153
|
it "should add the required attribute to the input's html options" do
|
154
154
|
with_config :use_required_attribute, true do
|
155
155
|
concat(semantic_form_for(@new_post) do |builder|
|
156
|
-
concat(builder.input(:title, :as => :
|
156
|
+
concat(builder.input(:title, :as => :date_select, :required => true))
|
157
157
|
end)
|
158
158
|
output_buffer.should have_tag("select[@required]", :count => 3)
|
159
159
|
end
|
@@ -164,7 +164,7 @@ describe 'date input' do
|
|
164
164
|
before do
|
165
165
|
output_buffer.replace ''
|
166
166
|
concat(semantic_form_for(@new_post) do |builder|
|
167
|
-
concat(builder.input(:publish_at, :as => :
|
167
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month]))
|
168
168
|
end)
|
169
169
|
end
|
170
170
|
|
@@ -181,7 +181,7 @@ describe 'date input' do
|
|
181
181
|
before do
|
182
182
|
output_buffer.replace ''
|
183
183
|
concat(semantic_form_for(@new_post) do |builder|
|
184
|
-
concat(builder.input(:publish_at, :as => :
|
184
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :day]))
|
185
185
|
end)
|
186
186
|
end
|
187
187
|
|
@@ -198,7 +198,7 @@ describe 'date input' do
|
|
198
198
|
before do
|
199
199
|
output_buffer.replace ''
|
200
200
|
concat(semantic_form_for(@new_post) do |builder|
|
201
|
-
concat(builder.input(:publish_at, :as => :
|
201
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:month, :day]))
|
202
202
|
end)
|
203
203
|
end
|
204
204
|
|
@@ -215,12 +215,12 @@ describe 'date input' do
|
|
215
215
|
before do
|
216
216
|
output_buffer.replace ''
|
217
217
|
concat(semantic_form_for(@new_post) do |builder|
|
218
|
-
concat(builder.input(:publish_at, :as => :
|
218
|
+
concat(builder.input(:publish_at, :as => :date_select, :order => [:day, :month, :year]))
|
219
219
|
end)
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'should associate the legend label with the new first select' do
|
223
|
-
output_buffer.should have_tag('form li.
|
223
|
+
output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for="post_publish_at_3i"]')
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
@@ -0,0 +1,490 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'datetime_picker input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
::I18n.backend.reload!
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with an object" do
|
18
|
+
before do
|
19
|
+
concat(semantic_form_for(@new_post) do |builder|
|
20
|
+
concat(builder.input(:publish_at, :as => :datetime_picker))
|
21
|
+
end)
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_have_input_wrapper_with_class(:datetime_picker)
|
25
|
+
it_should_have_input_wrapper_with_class(:input)
|
26
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
27
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
28
|
+
it_should_have_label_with_text(/Publish at/)
|
29
|
+
it_should_have_label_for("post_publish_at")
|
30
|
+
it_should_have_input_with_id("post_publish_at")
|
31
|
+
it_should_have_input_with_type("datetime-local")
|
32
|
+
it_should_have_input_with_name("post[publish_at]")
|
33
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:datetime_picker)
|
34
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:datetime_picker)
|
35
|
+
# TODO why does this blow-up it_should_apply_error_logic_for_input_type(:datetime_picker)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe ":local option for UTC or local time" do
|
40
|
+
|
41
|
+
it "should default to a datetime-local input (true)" do
|
42
|
+
concat(
|
43
|
+
semantic_form_for(@new_post) do |f|
|
44
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
45
|
+
end
|
46
|
+
)
|
47
|
+
output_buffer.should have_tag "input[type='datetime-local']"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can be set to true for a datetime-local" do
|
51
|
+
concat(
|
52
|
+
semantic_form_for(@new_post) do |f|
|
53
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :local => true))
|
54
|
+
end
|
55
|
+
)
|
56
|
+
output_buffer.should have_tag "input[type='datetime-local']"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can be set to false for a datetime" do
|
60
|
+
concat(
|
61
|
+
semantic_form_for(@new_post) do |f|
|
62
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :local => false))
|
63
|
+
end
|
64
|
+
)
|
65
|
+
output_buffer.should have_tag "input[type='datetime']"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "size attribute" do
|
71
|
+
|
72
|
+
it "defaults to 10 chars (YYYY-YY-YY HH:MM)" do
|
73
|
+
concat(
|
74
|
+
semantic_form_for(@new_post) do |f|
|
75
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
76
|
+
end
|
77
|
+
)
|
78
|
+
output_buffer.should have_tag "input[size='16']"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "can be set from :input_html options" do
|
82
|
+
concat(
|
83
|
+
semantic_form_for(@new_post) do |f|
|
84
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :size => "11" }))
|
85
|
+
end
|
86
|
+
)
|
87
|
+
output_buffer.should have_tag "input[size='11']"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can be set from options (ignoring input_html)" do
|
91
|
+
concat(
|
92
|
+
semantic_form_for(@new_post) do |f|
|
93
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :size => '12', :input_html => { :size => "11" }))
|
94
|
+
end
|
95
|
+
)
|
96
|
+
output_buffer.should have_tag "input[size='12']"
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "maxlength attribute" do
|
102
|
+
|
103
|
+
it "defaults to 10 chars (YYYY-YY-YY HH:MM)" do
|
104
|
+
concat(
|
105
|
+
semantic_form_for(@new_post) do |f|
|
106
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
107
|
+
end
|
108
|
+
)
|
109
|
+
output_buffer.should have_tag "input[maxlength='16']"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "can be set from :input_html options" do
|
113
|
+
concat(
|
114
|
+
semantic_form_for(@new_post) do |f|
|
115
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :maxlength => "11" }))
|
116
|
+
end
|
117
|
+
)
|
118
|
+
output_buffer.should have_tag "input[maxlength='11']"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "can be set from options (ignoring input_html)" do
|
122
|
+
concat(
|
123
|
+
semantic_form_for(@new_post) do |f|
|
124
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :maxlength => 12, :input_html => { :maxlength => "11" }))
|
125
|
+
end
|
126
|
+
)
|
127
|
+
output_buffer.should have_tag "input[maxlength='12']"
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "value attribute" do
|
133
|
+
|
134
|
+
context "when method returns nil" do
|
135
|
+
|
136
|
+
it "has no value" do
|
137
|
+
concat(
|
138
|
+
semantic_form_for(@new_post) do |f|
|
139
|
+
concat(f.input(:publish_at, :as => :datetime_picker ))
|
140
|
+
end
|
141
|
+
)
|
142
|
+
output_buffer.should_not have_tag "li input[value]"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "can be set from :input_html options" do
|
146
|
+
concat(
|
147
|
+
semantic_form_for(@new_post) do |f|
|
148
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :value => "1111-11-11 23:00" }))
|
149
|
+
end
|
150
|
+
)
|
151
|
+
output_buffer.should have_tag "input[value='1111-11-11 23:00']"
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when method returns a Date" do
|
157
|
+
|
158
|
+
before do
|
159
|
+
@date = Date.new(2000, 11, 11)
|
160
|
+
@new_post.stub!(:publish_at).and_return(@date)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "renders the date as YYYY-MM-DD 00:00" do
|
164
|
+
concat(
|
165
|
+
semantic_form_for(@new_post) do |f|
|
166
|
+
concat(f.input(:publish_at, :as => :datetime_picker ))
|
167
|
+
end
|
168
|
+
)
|
169
|
+
output_buffer.should have_tag "input[value='#{@date.to_s} 00:00']"
|
170
|
+
end
|
171
|
+
|
172
|
+
it "can be set from :input_html options" do
|
173
|
+
concat(
|
174
|
+
semantic_form_for(@new_post) do |f|
|
175
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :value => "1111-11-11 00:00" }))
|
176
|
+
end
|
177
|
+
)
|
178
|
+
output_buffer.should have_tag "input[value='1111-11-11 00:00']"
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
context "when method returns a Time" do
|
184
|
+
|
185
|
+
before do
|
186
|
+
@time = Time.utc(2000,11,11,11,11,11)
|
187
|
+
@new_post.stub!(:publish_at).and_return(@time)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "renders the time as a YYYY-MM-DD HH:MM" do
|
191
|
+
concat(
|
192
|
+
semantic_form_for(@new_post) do |f|
|
193
|
+
concat(f.input(:publish_at, :as => :datetime_picker ))
|
194
|
+
end
|
195
|
+
)
|
196
|
+
output_buffer.should have_tag "input[value='2000-11-11 11:11']"
|
197
|
+
end
|
198
|
+
|
199
|
+
it "can be set from :input_html options" do
|
200
|
+
concat(
|
201
|
+
semantic_form_for(@new_post) do |f|
|
202
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :value => "1111-11-11 11:11" }))
|
203
|
+
end
|
204
|
+
)
|
205
|
+
output_buffer.should have_tag "input[value='1111-11-11 11:11']"
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
context "when method returns an empty String" do
|
211
|
+
|
212
|
+
before do
|
213
|
+
@new_post.stub!(:publish_at).and_return("")
|
214
|
+
end
|
215
|
+
|
216
|
+
it "will be empty" do
|
217
|
+
concat(
|
218
|
+
semantic_form_for(@new_post) do |f|
|
219
|
+
concat(f.input(:publish_at, :as => :datetime_picker ))
|
220
|
+
end
|
221
|
+
)
|
222
|
+
output_buffer.should have_tag "input[value='']"
|
223
|
+
end
|
224
|
+
|
225
|
+
it "can be set from :input_html options" do
|
226
|
+
concat(
|
227
|
+
semantic_form_for(@new_post) do |f|
|
228
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :value => "1111-11-11 11:11" }))
|
229
|
+
end
|
230
|
+
)
|
231
|
+
output_buffer.should have_tag "input[value='1111-11-11 11:11']"
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
context "when method returns a String" do
|
237
|
+
|
238
|
+
before do
|
239
|
+
@new_post.stub!(:publish_at).and_return("yeah")
|
240
|
+
end
|
241
|
+
|
242
|
+
it "will be the string" do
|
243
|
+
concat(
|
244
|
+
semantic_form_for(@new_post) do |f|
|
245
|
+
concat(f.input(:publish_at, :as => :datetime_picker ))
|
246
|
+
end
|
247
|
+
)
|
248
|
+
output_buffer.should have_tag "input[value='yeah']"
|
249
|
+
end
|
250
|
+
|
251
|
+
it "can be set from :input_html options" do
|
252
|
+
concat(
|
253
|
+
semantic_form_for(@new_post) do |f|
|
254
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :value => "1111-11-11 11:11" }))
|
255
|
+
end
|
256
|
+
)
|
257
|
+
output_buffer.should have_tag "input[value='1111-11-11 11:11']"
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "min attribute" do
|
265
|
+
|
266
|
+
it "will be omitted by default" do
|
267
|
+
concat(
|
268
|
+
semantic_form_for(@new_post) do |f|
|
269
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
270
|
+
end
|
271
|
+
)
|
272
|
+
output_buffer.should_not have_tag "input[min]"
|
273
|
+
end
|
274
|
+
|
275
|
+
it "can be set from :input_html options" do
|
276
|
+
concat(
|
277
|
+
semantic_form_for(@new_post) do |f|
|
278
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :min => "1970-01-01 12:00" }))
|
279
|
+
end
|
280
|
+
)
|
281
|
+
output_buffer.should have_tag "input[min='1970-01-01 12:00']"
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "max attribute" do
|
287
|
+
|
288
|
+
it "will be omitted by default" do
|
289
|
+
concat(
|
290
|
+
semantic_form_for(@new_post) do |f|
|
291
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
292
|
+
end
|
293
|
+
)
|
294
|
+
output_buffer.should_not have_tag "input[max]"
|
295
|
+
end
|
296
|
+
|
297
|
+
it "can be set from :input_html options" do
|
298
|
+
concat(
|
299
|
+
semantic_form_for(@new_post) do |f|
|
300
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :max => "1970-01-01 12:00" }))
|
301
|
+
end
|
302
|
+
)
|
303
|
+
output_buffer.should have_tag "input[max='1970-01-01 12:00']"
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "step attribute" do
|
309
|
+
|
310
|
+
it "defaults to 1" do
|
311
|
+
concat(
|
312
|
+
semantic_form_for(@new_post) do |f|
|
313
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
314
|
+
end
|
315
|
+
)
|
316
|
+
output_buffer.should have_tag "input[step='1']"
|
317
|
+
end
|
318
|
+
|
319
|
+
it "can be set from :input_html options" do
|
320
|
+
concat(
|
321
|
+
semantic_form_for(@new_post) do |f|
|
322
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :step => "5" }))
|
323
|
+
end
|
324
|
+
)
|
325
|
+
output_buffer.should have_tag "input[step='5']"
|
326
|
+
end
|
327
|
+
|
328
|
+
describe "macros" do
|
329
|
+
before do
|
330
|
+
concat(
|
331
|
+
semantic_form_for(@new_post) do |f|
|
332
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :step => step }))
|
333
|
+
end
|
334
|
+
)
|
335
|
+
end
|
336
|
+
|
337
|
+
context ":second" do
|
338
|
+
let(:step) { :second }
|
339
|
+
it "uses 1" do
|
340
|
+
output_buffer.should have_tag "input[step='1']"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context ":minute" do
|
345
|
+
let(:step) { :minute }
|
346
|
+
it "uses 60" do
|
347
|
+
output_buffer.should have_tag "input[step='60']"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context ":fifteen_minutes" do
|
352
|
+
let(:step) { :fifteen_minutes }
|
353
|
+
it "uses 900" do
|
354
|
+
output_buffer.should have_tag "input[step='900']"
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
context ":quarter_hour" do
|
359
|
+
let(:step) { :quarter_hour }
|
360
|
+
it "uses 900" do
|
361
|
+
output_buffer.should have_tag "input[step='900']"
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
context ":thirty_minutes" do
|
366
|
+
let(:step) { :thirty_minutes }
|
367
|
+
it "uses 1800" do
|
368
|
+
output_buffer.should have_tag "input[step='1800']"
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
context ":half_hour" do
|
373
|
+
let(:step) { :half_hour }
|
374
|
+
it "uses 1800" do
|
375
|
+
output_buffer.should have_tag "input[step='1800']"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context ":hour" do
|
380
|
+
let(:step) { :hour }
|
381
|
+
it "uses 3600" do
|
382
|
+
output_buffer.should have_tag "input[step='3600']"
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
context ":sixty_minutes" do
|
387
|
+
let(:step) { :sixty_minutes }
|
388
|
+
it "uses 3600" do
|
389
|
+
output_buffer.should have_tag "input[step='3600']"
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "placeholder attribute" do
|
398
|
+
|
399
|
+
it "will be omitted" do
|
400
|
+
concat(
|
401
|
+
semantic_form_for(@new_post) do |f|
|
402
|
+
concat(f.input(:publish_at, :as => :datetime_picker))
|
403
|
+
end
|
404
|
+
)
|
405
|
+
output_buffer.should_not have_tag "input[placeholder]"
|
406
|
+
end
|
407
|
+
|
408
|
+
it "can be set from :input_html options" do
|
409
|
+
concat(
|
410
|
+
semantic_form_for(@new_post) do |f|
|
411
|
+
concat(f.input(:publish_at, :as => :datetime_picker, :input_html => { :placeholder => "1970-01-01 00:00" }))
|
412
|
+
end
|
413
|
+
)
|
414
|
+
output_buffer.should have_tag "input[placeholder='1970-01-01 00:00']"
|
415
|
+
end
|
416
|
+
|
417
|
+
context "with i18n set" do
|
418
|
+
before do
|
419
|
+
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :publish_at => 'YYYY-MM-DD HH:MM' }}
|
420
|
+
end
|
421
|
+
|
422
|
+
it "can be set with i18n" do
|
423
|
+
with_config :i18n_lookups_by_default, true do
|
424
|
+
concat(semantic_form_for(@new_post) do |builder|
|
425
|
+
concat(builder.input(:publish_at, :as => :datetime_picker))
|
426
|
+
end)
|
427
|
+
output_buffer.should have_tag('input[@placeholder="YYYY-MM-DD HH:MM"]')
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
it "can be set with input_html, trumping i18n" do
|
432
|
+
with_config :i18n_lookups_by_default, true do
|
433
|
+
concat(semantic_form_for(@new_post) do |builder|
|
434
|
+
concat(builder.input(:publish_at, :as => :datetime_picker, :input_html => { :placeholder => "Something" }))
|
435
|
+
end)
|
436
|
+
output_buffer.should have_tag('input[@placeholder="Something"]')
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
describe "when namespace is provided" do
|
444
|
+
before do
|
445
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
446
|
+
concat(builder.input(:publish_at, :as => :datetime_picker))
|
447
|
+
end)
|
448
|
+
end
|
449
|
+
|
450
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
451
|
+
it_should_have_label_and_input_with_id("context2_post_publish_at")
|
452
|
+
end
|
453
|
+
|
454
|
+
describe "when index is provided" do
|
455
|
+
before do
|
456
|
+
@output_buffer = ''
|
457
|
+
mock_everything
|
458
|
+
|
459
|
+
concat(semantic_form_for(@new_post) do |builder|
|
460
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
461
|
+
concat(author.input(:created_at, :as => :datetime_picker))
|
462
|
+
end)
|
463
|
+
end)
|
464
|
+
end
|
465
|
+
|
466
|
+
it 'should index the id of the wrapper' do
|
467
|
+
output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
|
468
|
+
end
|
469
|
+
|
470
|
+
it 'should index the id of the select tag' do
|
471
|
+
output_buffer.should have_tag("input#post_author_attributes_3_created_at")
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'should index the name of the select tag' do
|
475
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][created_at]']")
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
describe "when required" do
|
480
|
+
it "should add the required attribute to the input's html options" do
|
481
|
+
with_config :use_required_attribute, true do
|
482
|
+
concat(semantic_form_for(@new_post) do |builder|
|
483
|
+
concat(builder.input(:publish_at, :as => :datetime_picker, :required => true))
|
484
|
+
end)
|
485
|
+
output_buffer.should have_tag("input[@required]")
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
end
|