formtastic 2.1.1 → 2.2.0.rc
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.
- 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 'datetime input' do
|
4
|
+
describe 'datetime select input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -16,45 +16,45 @@ describe 'datetime input' do
|
|
16
16
|
::I18n.backend.store_translations :en, {}
|
17
17
|
output_buffer.replace ''
|
18
18
|
concat(semantic_form_for(@new_post) do |builder|
|
19
|
-
concat(builder.input(:publish_at, :as => :
|
19
|
+
concat(builder.input(:publish_at, :as => :datetime_select))
|
20
20
|
end)
|
21
21
|
end
|
22
22
|
|
23
|
-
it_should_have_input_wrapper_with_class("
|
23
|
+
it_should_have_input_wrapper_with_class("datetime_select")
|
24
24
|
it_should_have_input_wrapper_with_class(:input)
|
25
25
|
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
26
26
|
it_should_have_a_nested_fieldset
|
27
27
|
it_should_have_a_nested_fieldset_with_class('fragments')
|
28
28
|
it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
29
|
-
it_should_apply_error_logic_for_input_type(:
|
29
|
+
it_should_apply_error_logic_for_input_type(:datetime_select)
|
30
30
|
|
31
31
|
it 'should have a legend and label with the label text inside the fieldset' do
|
32
|
-
output_buffer.should have_tag('form li.
|
32
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label', /Publish at/)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should associate the legend label with the first select' do
|
36
|
-
output_buffer.should have_tag('form li.
|
37
|
-
output_buffer.should have_tag('form li.
|
38
|
-
output_buffer.should have_tag('form li.
|
39
|
-
output_buffer.should have_tag('form li.
|
36
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label')
|
37
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label')
|
38
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for]')
|
39
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_1i"]')
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should have an ordered list of five items inside the fieldset' do
|
43
|
-
output_buffer.should have_tag('form li.
|
44
|
-
output_buffer.should have_tag('form li.
|
43
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol.fragments-group')
|
44
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li.fragment', :count => 5)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should have five labels for year, month and day' do
|
48
|
-
output_buffer.should have_tag('form li.
|
49
|
-
output_buffer.should have_tag('form li.
|
50
|
-
output_buffer.should have_tag('form li.
|
51
|
-
output_buffer.should have_tag('form li.
|
52
|
-
output_buffer.should have_tag('form li.
|
53
|
-
output_buffer.should have_tag('form li.
|
48
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => 5)
|
49
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /year/i)
|
50
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /month/i)
|
51
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /day/i)
|
52
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /hour/i)
|
53
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /min/i)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should have five selects' do
|
57
|
-
output_buffer.should have_tag('form li.
|
57
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li select', :count => 5)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -63,7 +63,7 @@ describe 'datetime input' do
|
|
63
63
|
before do
|
64
64
|
output_buffer.replace ''
|
65
65
|
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
66
|
-
concat(builder.input(:publish_at, :as => :
|
66
|
+
concat(builder.input(:publish_at, :as => :datetime_select))
|
67
67
|
end)
|
68
68
|
end
|
69
69
|
|
@@ -84,7 +84,7 @@ describe 'datetime input' do
|
|
84
84
|
|
85
85
|
concat(semantic_form_for(@new_post) do |builder|
|
86
86
|
concat(builder.fields_for(:author, :index => 3) do |author|
|
87
|
-
concat(author.input(:created_at, :as => :
|
87
|
+
concat(author.input(:created_at, :as => :datetime_select))
|
88
88
|
end)
|
89
89
|
end)
|
90
90
|
end
|
@@ -118,40 +118,40 @@ describe 'datetime input' do
|
|
118
118
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
119
119
|
output_buffer.replace ''
|
120
120
|
concat(semantic_form_for(@new_post) do |builder|
|
121
|
-
concat(builder.input(:created_at, :as => :
|
121
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "another #{field} label" }))
|
122
122
|
end)
|
123
|
-
output_buffer.should have_tag('form li.
|
123
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length)
|
124
124
|
fields.each do |f|
|
125
|
-
output_buffer.should have_tag('form li.
|
125
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
130
130
|
output_buffer.replace ''
|
131
131
|
concat(semantic_form_for(@new_post) do |builder|
|
132
|
-
concat(builder.input(:created_at, :as => :
|
132
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "" }))
|
133
133
|
end)
|
134
|
-
output_buffer.should have_tag('form li.
|
134
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
135
135
|
fields.each do |f|
|
136
|
-
output_buffer.should have_tag('form li.
|
136
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
141
141
|
output_buffer.replace ''
|
142
142
|
concat(semantic_form_for(@new_post) do |builder|
|
143
|
-
concat(builder.input(:created_at, :as => :
|
143
|
+
concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => false }))
|
144
144
|
end)
|
145
|
-
output_buffer.should have_tag('form li.
|
145
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
|
146
146
|
fields.each do |f|
|
147
|
-
output_buffer.should have_tag('form li.
|
147
|
+
output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
152
152
|
output_buffer.replace ''
|
153
153
|
concat(semantic_form_for(@new_post) do |builder|
|
154
|
-
concat(builder.input(:created_at, :as => :
|
154
|
+
concat(builder.input(:created_at, :as => :datetime_select, :include_seconds => true, :labels => { field => false }))
|
155
155
|
end)
|
156
156
|
output_buffer.should_not include(">")
|
157
157
|
end
|
@@ -162,7 +162,7 @@ describe 'datetime input' do
|
|
162
162
|
it "should add the required attribute to the input's html options" do
|
163
163
|
with_config :use_required_attribute, true do
|
164
164
|
concat(semantic_form_for(@new_post) do |builder|
|
165
|
-
concat(builder.input(:title, :as => :
|
165
|
+
concat(builder.input(:title, :as => :datetime_select, :required => true))
|
166
166
|
end)
|
167
167
|
output_buffer.should have_tag("select[@required]", :count => 5)
|
168
168
|
end
|
@@ -173,12 +173,12 @@ describe 'datetime input' do
|
|
173
173
|
before do
|
174
174
|
output_buffer.replace ''
|
175
175
|
concat(semantic_form_for(@new_post) do |builder|
|
176
|
-
concat(builder.input(:publish_at, :as => :
|
176
|
+
concat(builder.input(:publish_at, :as => :datetime_select, :order => [:day, :month, :year]))
|
177
177
|
end)
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'should associate the legend label with the new first select' do
|
181
|
-
output_buffer.should have_tag('form li.
|
181
|
+
output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_3i"]')
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'deprecated time, datetime and date inputs' do
|
4
|
+
include FormtasticSpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@output_buffer = ''
|
8
|
+
mock_everything
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should warn :time is deprecated' do
|
12
|
+
::ActiveSupport::Deprecation.should_receive(:warn)
|
13
|
+
semantic_form_for(@new_post) do |f|
|
14
|
+
concat(f.input :created_at, :as => :time)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should warn :datetime is deprecated' do
|
19
|
+
::ActiveSupport::Deprecation.should_receive(:warn)
|
20
|
+
semantic_form_for(@new_post) do |f|
|
21
|
+
concat(f.input :created_at, :as => :datetime)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should warn :date is deprecated' do
|
26
|
+
::ActiveSupport::Deprecation.should_receive(:warn)
|
27
|
+
semantic_form_for(@new_post) do |f|
|
28
|
+
concat(f.input :created_at, :as => :date)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should use wrapper css class based off :as, not off their parent class' do
|
33
|
+
with_deprecation_silenced do
|
34
|
+
concat(semantic_form_for(@new_post) do |f|
|
35
|
+
concat(f.input :created_at, :as => :time)
|
36
|
+
concat(f.input :created_at, :as => :datetime)
|
37
|
+
concat(f.input :created_at, :as => :date)
|
38
|
+
end)
|
39
|
+
end
|
40
|
+
output_buffer.should have_tag('li.time')
|
41
|
+
output_buffer.should have_tag('li.datetime')
|
42
|
+
output_buffer.should have_tag('li.date')
|
43
|
+
output_buffer.should_not have_tag('li.time_select')
|
44
|
+
output_buffer.should_not have_tag('li.datetime_select')
|
45
|
+
output_buffer.should_not have_tag('li.date_select')
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -8,14 +8,16 @@ describe 'hidden input' do
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
|
12
|
-
|
13
|
-
concat(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
with_deprecation_silenced do
|
13
|
+
concat(semantic_form_for(@new_post) do |builder|
|
14
|
+
concat(builder.input(:secret, :as => :hidden))
|
15
|
+
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
16
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
17
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
18
|
+
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
19
|
+
end)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it_should_have_input_wrapper_with_class("hidden")
|
@@ -52,7 +54,7 @@ describe 'hidden input' do
|
|
52
54
|
|
53
55
|
it "should not render inline errors" do
|
54
56
|
@errors = mock('errors')
|
55
|
-
@errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
|
57
|
+
@errors.stub!(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
|
56
58
|
@new_post.stub!(:errors).and_return(@errors)
|
57
59
|
|
58
60
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -77,14 +79,16 @@ describe 'hidden input' do
|
|
77
79
|
before do
|
78
80
|
@output_buffer = ''
|
79
81
|
mock_everything
|
80
|
-
|
81
|
-
|
82
|
-
concat(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
|
83
|
+
with_deprecation_silenced do
|
84
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
85
|
+
concat(builder.input(:secret, :as => :hidden))
|
86
|
+
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
87
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
88
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
89
|
+
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
90
|
+
end)
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
attributes_to_check = [:secret, :author_id, :published, :reviewer]
|
@@ -15,9 +15,9 @@ describe "*select: options[:include_blank]" do
|
|
15
15
|
|
16
16
|
SELECT_INPUT_TYPES = {
|
17
17
|
:select => :author,
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
:datetime_select => :publish_at,
|
19
|
+
:date_select => :publish_at,
|
20
|
+
:time_select => :publish_at
|
21
21
|
}
|
22
22
|
|
23
23
|
SELECT_INPUT_TYPES.each do |as, attribute|
|
data/spec/inputs/label_spec.rb
CHANGED
@@ -98,7 +98,7 @@ describe 'Formtastic::FormBuilder#label' do
|
|
98
98
|
|
99
99
|
it 'should return nil if label is false for timeish fragments' do
|
100
100
|
concat(semantic_form_for(@new_post) do |builder|
|
101
|
-
builder.input(:title, :as => :
|
101
|
+
builder.input(:title, :as => :time_select, :label => false)
|
102
102
|
end)
|
103
103
|
output_buffer.should_not have_tag('li.time > label')
|
104
104
|
output_buffer.should_not include(">")
|
@@ -16,7 +16,7 @@ describe 'string input' do
|
|
16
16
|
|
17
17
|
describe "placeholder text" do
|
18
18
|
|
19
|
-
[:email, :number, :password, :phone, :search, :string, :url, :text].each do |type|
|
19
|
+
[:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
|
20
20
|
|
21
21
|
describe "for #{type} inputs" do
|
22
22
|
|
@@ -63,7 +63,7 @@ describe 'select input' do
|
|
63
63
|
|
64
64
|
describe 'using a string' do
|
65
65
|
before do
|
66
|
-
@string ="<option value='0'>0</option><option value='1'>1</option>"
|
66
|
+
@string ="<option value='0'>0</option><option value='1'>1</option>".html_safe
|
67
67
|
concat(semantic_form_for(@new_post) do |builder|
|
68
68
|
concat(builder.input(:title, :as => :select, :collection => @string))
|
69
69
|
end)
|
@@ -207,9 +207,11 @@ describe 'select input' do
|
|
207
207
|
[@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
|
208
208
|
@fred.should_receive(:posts)
|
209
209
|
|
210
|
-
|
211
|
-
concat(
|
212
|
-
|
210
|
+
with_deprecation_silenced do
|
211
|
+
concat(semantic_form_for(@new_post) do |builder|
|
212
|
+
concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
|
213
|
+
end)
|
214
|
+
end
|
213
215
|
end
|
214
216
|
end
|
215
217
|
|
@@ -234,8 +236,10 @@ describe 'select input' do
|
|
234
236
|
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
235
237
|
::Author.should_receive(:where).with({:publisher => true})
|
236
238
|
|
237
|
-
|
238
|
-
|
239
|
+
with_deprecation_silenced do
|
240
|
+
semantic_form_for(@new_post) do |builder|
|
241
|
+
concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
|
242
|
+
end
|
239
243
|
end
|
240
244
|
end
|
241
245
|
end
|
@@ -258,12 +262,14 @@ describe 'select input' do
|
|
258
262
|
continent.stub!(:authors).and_return([@authors[i]])
|
259
263
|
end
|
260
264
|
|
261
|
-
|
262
|
-
concat(
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
265
|
+
with_deprecation_silenced do
|
266
|
+
concat(semantic_form_for(@new_post) do |builder|
|
267
|
+
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
|
268
|
+
concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
|
269
|
+
concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
|
270
|
+
concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
|
271
|
+
end)
|
272
|
+
end
|
267
273
|
end
|
268
274
|
|
269
275
|
it_should_have_input_wrapper_with_class("select")
|
@@ -303,8 +309,10 @@ describe 'select input' do
|
|
303
309
|
it 'should call find with :include for more optimized queries' do
|
304
310
|
Author.should_receive(:where).with(:include => :continent)
|
305
311
|
|
306
|
-
|
307
|
-
|
312
|
+
with_deprecation_silenced do
|
313
|
+
semantic_form_for(@new_post) do |builder|
|
314
|
+
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
|
315
|
+
end
|
308
316
|
end
|
309
317
|
end
|
310
318
|
end
|
@@ -0,0 +1,455 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should_not 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
|
+
output_buffer.should 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
|
+
@new_post.stub!(: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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
@new_post.stub!(: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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
@new_post.stub!(: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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
@new_post.stub!(: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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should_not 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
|
+
output_buffer.should 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
|
+
output_buffer.should_not 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should have_tag "input[step='1']"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context ":minute" do
|
310
|
+
let(:step) { :minute }
|
311
|
+
it "uses 60" do
|
312
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should have_tag "input[step='1800']"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context ":hour" do
|
345
|
+
let(:step) { :hour }
|
346
|
+
it "uses 3600" do
|
347
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should_not 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should 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
|
+
output_buffer.should have_tag("input#post_author_attributes_3_created_at")
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'should index the name of the select tag' do
|
440
|
+
output_buffer.should 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
|
+
output_buffer.should have_tag("input[@required]")
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|