speedo-formstrap 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +42 -40
- data/README.md +8 -15
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/formtastic-bootstrap.gemspec +133 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/engine.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/form_builder.rb +9 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/buttons_helper.rb +10 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/fieldset_wrapper.rb +7 -12
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/input_helper.rb +2 -2
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/inputs_helper.rb +6 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers.rb +6 -8
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/errors.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/hints.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/html.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +18 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/stringish.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/timeish.rb +13 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/wrapping.rb +15 -33
- data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/check_boxes_input.rb +10 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/date_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/datetime_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/email_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/file_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/number_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/password_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/phone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/radio_input.rb +13 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/range_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/search_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/select_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/string_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/text_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_zone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/url_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs.rb +29 -0
- data/lib/formtastic-bootstrap.rb +6 -0
- data/spec/builder/errors_spec.rb +214 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- data/spec/helpers/buttons_helper_spec.rb +45 -55
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +102 -116
- data/spec/inputs/boolean_input_spec.rb +44 -72
- data/spec/inputs/check_boxes_input_spec.rb +80 -108
- data/spec/inputs/date_input_spec.rb +14 -80
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +5 -33
- data/spec/inputs/file_input_spec.rb +5 -33
- data/spec/inputs/hidden_input_spec.rb +12 -40
- data/spec/inputs/number_input_spec.rb +96 -126
- data/spec/inputs/password_input_spec.rb +5 -33
- data/spec/inputs/phone_input_spec.rb +5 -33
- data/spec/inputs/radio_input_spec.rb +44 -72
- data/spec/inputs/range_input_spec.rb +65 -93
- data/spec/inputs/search_input_spec.rb +5 -32
- data/spec/inputs/select_input_spec.rb +77 -123
- data/spec/inputs/string_input_spec.rb +21 -66
- data/spec/inputs/text_input_spec.rb +13 -40
- data/spec/inputs/time_input_spec.rb +22 -22
- data/spec/inputs/time_zone_input_spec.rb +17 -17
- data/spec/inputs/url_input_spec.rb +5 -33
- data/spec/spec_helper.rb +1 -1
- data/spec/support/custom_macros.rb +188 -59
- data/spec/support/formtastic_spec_helper.rb +3 -19
- data/vendor/assets/stylesheets/formtastic-bootstrap.css +3 -0
- metadata +62 -74
- data/lib/speedo-formstrap/actions/base.rb +0 -18
- data/lib/speedo-formstrap/actions/button_action.rb +0 -7
- data/lib/speedo-formstrap/actions/input_action.rb +0 -7
- data/lib/speedo-formstrap/actions/link_action.rb +0 -7
- data/lib/speedo-formstrap/actions.rb +0 -4
- data/lib/speedo-formstrap/helpers/action_helper.rb +0 -12
- data/lib/speedo-formstrap/helpers/actions_helper.rb +0 -23
- data/lib/speedo-formstrap/inputs/base/choices.rb +0 -38
- data/lib/speedo-formstrap/inputs/base/labelling.rb +0 -28
- data/lib/speedo-formstrap/inputs/base/numeric.rb +0 -18
- data/lib/speedo-formstrap/inputs/base.rb +0 -23
- data/lib/speedo-formstrap/inputs/boolean_input.rb +0 -29
- data/lib/speedo-formstrap/inputs/hidden_input.rb +0 -14
- data/lib/speedo-formstrap/inputs.rb +0 -29
- data/lib/speedo-formstrap.rb +0 -7
- data/spec/actions/button_action_spec.rb +0 -68
- data/spec/actions/generic_action_spec.rb +0 -486
- data/spec/actions/input_action_spec.rb +0 -64
- data/spec/actions/link_action_spec.rb +0 -93
- data/spec/helpers/action_helper_spec.rb +0 -365
- data/spec/helpers/actions_helper_spec.rb +0 -143
- data/speedo-formstrap.gemspec +0 -145
@@ -20,8 +20,8 @@ describe 'date input' do
|
|
20
20
|
end)
|
21
21
|
end
|
22
22
|
|
23
|
-
it_should_have_input_wrapper_with_class("date
|
24
|
-
it_should_have_input_wrapper_with_class(
|
23
|
+
it_should_have_input_wrapper_with_class("date")
|
24
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
25
25
|
it_should_have_input_wrapper_with_class(:stringish)
|
26
26
|
it_should_have_input_class_in_the_right_place
|
27
27
|
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
@@ -31,7 +31,7 @@ describe 'date input' do
|
|
31
31
|
it_should_apply_error_logic_for_input_type(:date)
|
32
32
|
|
33
33
|
it 'should have a legend and label with the label text inside the fieldset' do
|
34
|
-
output_buffer.should have_tag('form div.
|
34
|
+
output_buffer.should have_tag('form div.clearfix.date label', /Publish at/)
|
35
35
|
end
|
36
36
|
|
37
37
|
# it 'should associate the legend label with the first select' do
|
@@ -42,8 +42,8 @@ describe 'date input' do
|
|
42
42
|
# end
|
43
43
|
|
44
44
|
it 'should (sort of) associate the label with the input' do
|
45
|
-
output_buffer.should have_tag('form div.
|
46
|
-
output_buffer.should have_tag('form div.
|
45
|
+
output_buffer.should have_tag('form div.clearfix.date label[@for="post_publish_at"]')
|
46
|
+
output_buffer.should have_tag('form div.clearfix.date div.input input[@id="post_publish_at[date]"]')
|
47
47
|
end
|
48
48
|
|
49
49
|
# it 'should have an ordered list of three items inside the fieldset' do
|
@@ -58,7 +58,7 @@ describe 'date input' do
|
|
58
58
|
# output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
|
59
59
|
# end
|
60
60
|
it 'should have an text input inside the div' do
|
61
|
-
output_buffer.should have_tag('form div.
|
61
|
+
output_buffer.should have_tag('form div.clearfix.date div.input input[@type="text"]')
|
62
62
|
end
|
63
63
|
|
64
64
|
# it 'should have three selects for year, month and day' do
|
@@ -97,7 +97,7 @@ describe 'date input' do
|
|
97
97
|
# output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
98
98
|
# end
|
99
99
|
# end
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
102
102
|
# output_buffer.replace ''
|
103
103
|
# concat(semantic_form_for(@new_post) do |builder|
|
@@ -108,7 +108,7 @@ describe 'date input' do
|
|
108
108
|
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
109
109
|
# end
|
110
110
|
# end
|
111
|
-
#
|
111
|
+
#
|
112
112
|
# it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
113
113
|
# output_buffer.replace ''
|
114
114
|
# concat(semantic_form_for(@new_post) do |builder|
|
@@ -119,21 +119,21 @@ describe 'date input' do
|
|
119
119
|
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
120
120
|
# end
|
121
121
|
# end
|
122
|
-
#
|
123
|
-
# it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
122
|
+
#
|
123
|
+
# it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
124
124
|
# output_buffer.replace ''
|
125
125
|
# concat(semantic_form_for(@new_post) do |builder|
|
126
126
|
# concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
|
127
127
|
# end)
|
128
128
|
# output_buffer.should_not include(">")
|
129
129
|
# end
|
130
|
-
#
|
130
|
+
#
|
131
131
|
# end
|
132
132
|
# end
|
133
|
-
|
133
|
+
|
134
134
|
describe "when required" do
|
135
135
|
it "should add the required attribute to the input's html options" do
|
136
|
-
with_config :use_required_attribute, true do
|
136
|
+
with_config :use_required_attribute, true do
|
137
137
|
concat(semantic_form_for(@new_post) do |builder|
|
138
138
|
concat(builder.input(:title, :as => :date, :required => true))
|
139
139
|
end)
|
@@ -143,71 +143,5 @@ describe 'date input' do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
146
|
-
|
147
|
-
# We use text field for dates
|
148
|
-
|
149
|
-
# describe "when order does not include day" do
|
150
|
-
# before do
|
151
|
-
# output_buffer.replace ''
|
152
|
-
# concat(semantic_form_for(@new_post) do |builder|
|
153
|
-
# concat(builder.input(:publish_at, :as => :date, :order => [:year, :month]))
|
154
|
-
# end)
|
155
|
-
# end
|
156
|
-
#
|
157
|
-
# it "should include a hidden input for day" do
|
158
|
-
# output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(3i)]"][@value="1"]')
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# it "should not include a select for day" do
|
162
|
-
# output_buffer.should_not have_tag('select[@name="post[publish_at(3i)]"]')
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
#
|
166
|
-
# describe "when order does not include month" do
|
167
|
-
# before do
|
168
|
-
# output_buffer.replace ''
|
169
|
-
# concat(semantic_form_for(@new_post) do |builder|
|
170
|
-
# concat(builder.input(:publish_at, :as => :date, :order => [:year, :day]))
|
171
|
-
# end)
|
172
|
-
# end
|
173
|
-
#
|
174
|
-
# it "should include a hidden input for month" do
|
175
|
-
# output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(2i)]"][@value="1"]')
|
176
|
-
# end
|
177
|
-
#
|
178
|
-
# it "should not include a select for month" do
|
179
|
-
# output_buffer.should_not have_tag('select[@name="post[publish_at(2i)]"]')
|
180
|
-
# end
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# describe "when order does not include year" do
|
184
|
-
# before do
|
185
|
-
# output_buffer.replace ''
|
186
|
-
# concat(semantic_form_for(@new_post) do |builder|
|
187
|
-
# concat(builder.input(:publish_at, :as => :date, :order => [:month, :day]))
|
188
|
-
# end)
|
189
|
-
# end
|
190
|
-
#
|
191
|
-
# it "should include a hidden input for month" do
|
192
|
-
# output_buffer.should have_tag("input[@type=\"hidden\"][@name=\"post[publish_at(1i)]\"][@value=\"#{Time.now.year}\"]")
|
193
|
-
# end
|
194
|
-
#
|
195
|
-
# it "should not include a select for month" do
|
196
|
-
# output_buffer.should_not have_tag('select[@name="post[publish_at(1i)]"]')
|
197
|
-
# end
|
198
|
-
# end
|
199
|
-
#
|
200
|
-
# describe "when order does not have year first" do
|
201
|
-
# before do
|
202
|
-
# output_buffer.replace ''
|
203
|
-
# concat(semantic_form_for(@new_post) do |builder|
|
204
|
-
# concat(builder.input(:publish_at, :as => :date, :order => [:day, :month, :year]))
|
205
|
-
# end)
|
206
|
-
# end
|
207
|
-
#
|
208
|
-
# it 'should associate the legend label with the new first select' do
|
209
|
-
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_3i"]')
|
210
|
-
# end
|
211
|
-
# end
|
212
|
-
|
146
|
+
|
213
147
|
end
|
@@ -21,8 +21,8 @@ describe 'datetime input' do
|
|
21
21
|
end)
|
22
22
|
end
|
23
23
|
|
24
|
-
it_should_have_input_wrapper_with_class("datetime
|
25
|
-
it_should_have_input_wrapper_with_class(
|
24
|
+
it_should_have_input_wrapper_with_class("datetime")
|
25
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
26
26
|
it_should_have_input_wrapper_with_class(:stringish) # Decide about this.
|
27
27
|
it_should_have_input_class_in_the_right_place
|
28
28
|
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
@@ -30,9 +30,9 @@ describe 'datetime input' do
|
|
30
30
|
# it_should_have_a_nested_fieldset_with_class('fragments')
|
31
31
|
# it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
32
32
|
it_should_apply_error_logic_for_input_type(:datetime)
|
33
|
-
|
33
|
+
|
34
34
|
it 'should have a legend and label with the label text inside the fieldset' do
|
35
|
-
output_buffer.should have_tag('form div.
|
35
|
+
output_buffer.should have_tag('form div.clearfix.datetime label', /Publish at/)
|
36
36
|
end
|
37
37
|
|
38
38
|
# it 'should associate the legend label with the first select' do
|
@@ -41,7 +41,7 @@ describe 'datetime input' do
|
|
41
41
|
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for]')
|
42
42
|
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
|
43
43
|
# end
|
44
|
-
|
44
|
+
|
45
45
|
# it 'should have an ordered list of five items inside the fieldset' do
|
46
46
|
# output_buffer.should have_tag('form li.datetime fieldset ol.fragments-group')
|
47
47
|
# output_buffer.should have_tag('form li.datetime fieldset ol li.fragment', :count => 5)
|
@@ -55,26 +55,26 @@ describe 'datetime input' do
|
|
55
55
|
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
|
56
56
|
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /min/i)
|
57
57
|
# end
|
58
|
-
|
58
|
+
|
59
59
|
# it 'should have five selects' do
|
60
60
|
# output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
|
61
61
|
# end
|
62
62
|
|
63
63
|
it 'should have two inputs' do
|
64
|
-
output_buffer.should have_tag('form div.
|
64
|
+
output_buffer.should have_tag('form div.clearfix.datetime div.input input', :count => 2)
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "when namespace is provided" do
|
70
|
-
|
70
|
+
|
71
71
|
before do
|
72
72
|
output_buffer.replace ''
|
73
73
|
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
74
74
|
concat(builder.input(:publish_at, :as => :datetime))
|
75
75
|
end)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
79
79
|
it_should_have_input_with_id("context2_post_publish_at[date]")
|
80
80
|
it_should_have_input_with_id("context2_post_publish_at[time]")
|
@@ -83,12 +83,12 @@ describe 'datetime input' do
|
|
83
83
|
# it_should_have_select_with_id("context2_post_publish_at_3i")
|
84
84
|
# it_should_have_select_with_id("context2_post_publish_at_4i")
|
85
85
|
# it_should_have_select_with_id("context2_post_publish_at_5i")
|
86
|
-
|
86
|
+
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "when required" do
|
90
90
|
it "should add the required attribute to the input's html options" do
|
91
|
-
with_config :use_required_attribute, true do
|
91
|
+
with_config :use_required_attribute, true do
|
92
92
|
concat(semantic_form_for(@new_post) do |builder|
|
93
93
|
concat(builder.input(:title, :as => :datetime, :required => true))
|
94
94
|
end)
|
@@ -97,5 +97,5 @@ describe 'datetime input' do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
end
|
@@ -18,8 +18,8 @@ describe 'email input' do
|
|
18
18
|
end)
|
19
19
|
end
|
20
20
|
|
21
|
-
it_should_have_input_wrapper_with_class(
|
22
|
-
it_should_have_input_wrapper_with_class(
|
21
|
+
it_should_have_input_wrapper_with_class(:email)
|
22
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
23
23
|
it_should_have_input_wrapper_with_class(:stringish)
|
24
24
|
it_should_have_input_class_in_the_right_place
|
25
25
|
it_should_have_input_wrapper_with_id("post_email_input")
|
@@ -43,38 +43,10 @@ describe 'email input' do
|
|
43
43
|
it_should_have_label_and_input_with_id("context2_post_email")
|
44
44
|
|
45
45
|
end
|
46
|
-
|
47
|
-
describe "when index is provided" do
|
48
|
-
|
49
|
-
before do
|
50
|
-
@output_buffer = ''
|
51
|
-
mock_everything
|
52
|
-
|
53
|
-
concat(semantic_form_for(@new_post) do |builder|
|
54
|
-
concat(builder.fields_for(:author, :index => 3) do |author|
|
55
|
-
concat(author.input(:name, :as => :email))
|
56
|
-
end)
|
57
|
-
end)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should index the id of the wrapper' do
|
61
|
-
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should index the id of the select tag' do
|
65
|
-
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should index the name of the select tag' do
|
69
|
-
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
|
46
|
+
|
75
47
|
describe "when required" do
|
76
48
|
it "should add the required attribute to the input's html options" do
|
77
|
-
with_config :use_required_attribute, true do
|
49
|
+
with_config :use_required_attribute, true do
|
78
50
|
concat(semantic_form_for(@new_post) do |builder|
|
79
51
|
concat(builder.input(:title, :as => :email, :required => true))
|
80
52
|
end)
|
@@ -82,6 +54,6 @@ describe 'email input' do
|
|
82
54
|
end
|
83
55
|
end
|
84
56
|
end
|
85
|
-
|
57
|
+
|
86
58
|
end
|
87
59
|
|
@@ -15,8 +15,8 @@ describe 'file input' do
|
|
15
15
|
end)
|
16
16
|
end
|
17
17
|
|
18
|
-
it_should_have_input_wrapper_with_class("file
|
19
|
-
it_should_have_input_wrapper_with_class(
|
18
|
+
it_should_have_input_wrapper_with_class("file")
|
19
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
20
20
|
it_should_have_input_class_in_the_right_place
|
21
21
|
it_should_have_input_wrapper_with_id("post_body_input")
|
22
22
|
it_should_have_label_with_text(/Body/)
|
@@ -29,7 +29,7 @@ describe 'file input' do
|
|
29
29
|
concat(semantic_form_for(@new_post) do |builder|
|
30
30
|
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
31
31
|
end)
|
32
|
-
output_buffer.should have_tag("form div.
|
32
|
+
output_buffer.should have_tag("form div.clearfix div.input input.myclass")
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "when namespace is provided" do
|
@@ -47,35 +47,7 @@ describe 'file input' do
|
|
47
47
|
it_should_have_label_and_input_with_id("context2_post_body")
|
48
48
|
|
49
49
|
end
|
50
|
-
|
51
|
-
describe "when index is provided" do
|
52
|
-
|
53
|
-
before do
|
54
|
-
@output_buffer = ''
|
55
|
-
mock_everything
|
56
|
-
|
57
|
-
concat(semantic_form_for(@new_post) do |builder|
|
58
|
-
concat(builder.fields_for(:author, :index => 3) do |author|
|
59
|
-
concat(author.input(:name, :as => :file))
|
60
|
-
end)
|
61
|
-
end)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should index the id of the wrapper' do
|
65
|
-
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should index the id of the select tag' do
|
69
|
-
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should index the name of the select tag' do
|
73
|
-
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
|
50
|
+
|
79
51
|
context "when required" do
|
80
52
|
it "should add the required attribute to the input's html options" do
|
81
53
|
with_config :use_required_attribute, true do
|
@@ -86,6 +58,6 @@ describe 'file input' do
|
|
86
58
|
end
|
87
59
|
end
|
88
60
|
end
|
89
|
-
|
61
|
+
|
90
62
|
end
|
91
63
|
|
@@ -19,37 +19,37 @@ describe 'hidden input' do
|
|
19
19
|
end)
|
20
20
|
end
|
21
21
|
|
22
|
-
it_should_have_input_wrapper_with_class("hidden
|
23
|
-
it_should_have_input_wrapper_with_class(
|
22
|
+
it_should_have_input_wrapper_with_class("hidden")
|
23
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
24
24
|
it_should_have_input_class_in_the_right_place
|
25
25
|
it_should_have_input_wrapper_with_id("post_secret_input")
|
26
26
|
it_should_not_have_a_label
|
27
27
|
|
28
28
|
it "should generate a input field" do
|
29
|
-
output_buffer.should have_tag("form div.
|
30
|
-
output_buffer.should have_tag("form div.
|
31
|
-
output_buffer.should have_tag("form div.
|
29
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret")
|
30
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"]")
|
31
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@name=\"post[secret]\"]")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should get value from the object" do
|
35
|
-
output_buffer.should have_tag("form div.
|
35
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"][@value=\"1\"]")
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should pass any explicitly specified value - using :value" do
|
39
|
-
output_buffer.should have_tag("form div.
|
39
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
|
40
40
|
end
|
41
41
|
|
42
42
|
# Handle Formtastic :input_html options for consistency.
|
43
43
|
it "should pass any explicitly specified value - using :input_html options" do
|
44
|
-
output_buffer.should have_tag("form div.
|
44
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should pass any option specified using :input_html" do
|
48
|
-
output_buffer.should have_tag("form div.
|
48
|
+
output_buffer.should have_tag("form div.clearfix div.input input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should prefer :input_html over directly supplied options" do
|
52
|
-
output_buffer.should have_tag("form div.
|
52
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not render inline errors" do
|
@@ -99,35 +99,7 @@ describe 'hidden input' do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
102
|
-
|
103
|
-
describe "when index is provided" do
|
104
|
-
|
105
|
-
before do
|
106
|
-
@output_buffer = ''
|
107
|
-
mock_everything
|
108
|
-
|
109
|
-
concat(semantic_form_for(@new_post) do |builder|
|
110
|
-
concat(builder.fields_for(:author, :index => 3) do |author|
|
111
|
-
concat(author.input(:name, :as => :hidden))
|
112
|
-
end)
|
113
|
-
end)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should index the id of the wrapper' do
|
117
|
-
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should index the id of the select tag' do
|
121
|
-
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should index the name of the select tag' do
|
125
|
-
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
|
102
|
+
|
131
103
|
context "when required" do
|
132
104
|
it "should not add the required attribute to the input's html options" do
|
133
105
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -14,9 +14,9 @@ describe 'number input' do
|
|
14
14
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
|
15
15
|
])
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe "all cases" do
|
19
|
-
|
19
|
+
|
20
20
|
before do
|
21
21
|
concat(
|
22
22
|
semantic_form_for(@new_post) do |builder|
|
@@ -25,9 +25,8 @@ describe 'number input' do
|
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
it_should_have_input_wrapper_with_class(
|
29
|
-
it_should_have_input_wrapper_with_class(
|
30
|
-
it_should_have_input_wrapper_with_class(:numeric)
|
28
|
+
it_should_have_input_wrapper_with_class(:number)
|
29
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
31
30
|
it_should_have_input_wrapper_with_class(:stringish)
|
32
31
|
it_should_have_input_class_in_the_right_place
|
33
32
|
it_should_have_input_wrapper_with_id("post_title_input")
|
@@ -36,13 +35,12 @@ describe 'number input' do
|
|
36
35
|
it_should_have_input_with_id("post_title")
|
37
36
|
it_should_have_input_with_type(:number)
|
38
37
|
it_should_have_input_with_name("post[title]")
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
38
|
+
it_should_use_default_text_field_size_when_not_nil(:string)
|
39
|
+
it_should_not_use_default_text_field_size_when_nil(:string)
|
40
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
41
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
44
42
|
it_should_apply_error_logic_for_input_type(:number)
|
45
|
-
|
43
|
+
|
46
44
|
end
|
47
45
|
|
48
46
|
describe "when no object is provided" do
|
@@ -51,7 +49,7 @@ describe 'number input' do
|
|
51
49
|
concat(builder.input(:title, :as => :number, :input_html => { :min => 1, :max => 2 }))
|
52
50
|
end)
|
53
51
|
end
|
54
|
-
|
52
|
+
|
55
53
|
it_should_have_label_with_text(/Title/)
|
56
54
|
it_should_have_label_for("project_title")
|
57
55
|
it_should_have_input_with_id("project_title")
|
@@ -65,42 +63,14 @@ describe 'number input' do
|
|
65
63
|
concat(builder.input(:title, :as => :number))
|
66
64
|
end)
|
67
65
|
end
|
68
|
-
|
66
|
+
|
69
67
|
it_should_have_input_wrapper_with_id("context2_post_title_input")
|
70
68
|
it_should_have_label_and_input_with_id("context2_post_title")
|
71
69
|
end
|
72
|
-
|
73
|
-
describe "when index is provided" do
|
74
|
-
|
75
|
-
before do
|
76
|
-
@output_buffer = ''
|
77
|
-
mock_everything
|
78
|
-
|
79
|
-
concat(semantic_form_for(@new_post) do |builder|
|
80
|
-
concat(builder.fields_for(:author, :index => 3) do |author|
|
81
|
-
concat(author.input(:name, :as => :number))
|
82
|
-
end)
|
83
|
-
end)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should index the id of the wrapper' do
|
87
|
-
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should index the id of the select tag' do
|
91
|
-
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should index the name of the select tag' do
|
95
|
-
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
70
|
+
|
101
71
|
describe "when required" do
|
102
72
|
it "should add the required attribute to the input's html options" do
|
103
|
-
with_config :use_required_attribute, true do
|
73
|
+
with_config :use_required_attribute, true do
|
104
74
|
concat(semantic_form_for(@new_post) do |builder|
|
105
75
|
concat(builder.input(:title, :as => :number, :required => true))
|
106
76
|
end)
|
@@ -108,47 +78,47 @@ describe 'number input' do
|
|
108
78
|
end
|
109
79
|
end
|
110
80
|
end
|
111
|
-
|
81
|
+
|
112
82
|
describe "when validations require a minimum value (:greater_than)" do
|
113
83
|
before do
|
114
84
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
115
85
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
|
116
86
|
])
|
117
87
|
end
|
118
|
-
|
88
|
+
|
119
89
|
it "should allow :input_html to override :min" do
|
120
90
|
concat(semantic_form_for(@new_post) do |builder|
|
121
91
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
122
92
|
end)
|
123
93
|
output_buffer.should have_tag('input[@min="5"]')
|
124
94
|
end
|
125
|
-
|
95
|
+
|
126
96
|
it "should allow :input_html to override :min through :in" do
|
127
97
|
concat(semantic_form_for(@new_post) do |builder|
|
128
98
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
129
99
|
end)
|
130
100
|
output_buffer.should have_tag('input[@min="5"]')
|
131
101
|
end
|
132
|
-
|
102
|
+
|
133
103
|
it "should allow options to override :min" do
|
134
104
|
concat(semantic_form_for(@new_post) do |builder|
|
135
105
|
builder.input(:title, :as => :number, :min => 5)
|
136
106
|
end)
|
137
107
|
output_buffer.should have_tag('input[@min="5"]')
|
138
108
|
end
|
139
|
-
|
109
|
+
|
140
110
|
it "should allow options to override :min through :in" do
|
141
111
|
concat(semantic_form_for(@new_post) do |builder|
|
142
112
|
builder.input(:title, :as => :number, :in => 5..102)
|
143
113
|
end)
|
144
114
|
output_buffer.should have_tag('input[@min="5"]')
|
145
115
|
end
|
146
|
-
|
116
|
+
|
147
117
|
describe "and the column is an integer" do
|
148
118
|
before do
|
149
119
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
|
150
120
|
end
|
151
|
-
|
121
|
+
|
152
122
|
it "should add a min attribute to the input one greater than the validation" do
|
153
123
|
concat(semantic_form_for(@new_post) do |builder|
|
154
124
|
builder.input(:title, :as => :number)
|
@@ -156,12 +126,12 @@ describe 'number input' do
|
|
156
126
|
output_buffer.should have_tag('input[@min="3"]')
|
157
127
|
end
|
158
128
|
end
|
159
|
-
|
129
|
+
|
160
130
|
describe "and the column is a float" do
|
161
131
|
before do
|
162
132
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
|
163
133
|
end
|
164
|
-
|
134
|
+
|
165
135
|
it "should raise an error" do
|
166
136
|
lambda {
|
167
137
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -170,12 +140,12 @@ describe 'number input' do
|
|
170
140
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
171
141
|
end
|
172
142
|
end
|
173
|
-
|
143
|
+
|
174
144
|
describe "and the column is a big decimal" do
|
175
145
|
before do
|
176
146
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
|
177
147
|
end
|
178
|
-
|
148
|
+
|
179
149
|
it "should raise an error" do
|
180
150
|
lambda {
|
181
151
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -184,49 +154,49 @@ describe 'number input' do
|
|
184
154
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
185
155
|
end
|
186
156
|
end
|
187
|
-
|
157
|
+
|
188
158
|
end
|
189
|
-
|
159
|
+
|
190
160
|
describe "when validations require a minimum value (:greater_than) that takes a proc" do
|
191
161
|
before do
|
192
162
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
193
163
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=> Proc.new {|post| 2}})
|
194
164
|
])
|
195
165
|
end
|
196
|
-
|
166
|
+
|
197
167
|
it "should allow :input_html to override :min" do
|
198
168
|
concat(semantic_form_for(@new_post) do |builder|
|
199
169
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
200
170
|
end)
|
201
171
|
output_buffer.should have_tag('input[@min="5"]')
|
202
172
|
end
|
203
|
-
|
173
|
+
|
204
174
|
it "should allow :input_html to override :min through :in" do
|
205
175
|
concat(semantic_form_for(@new_post) do |builder|
|
206
176
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
207
177
|
end)
|
208
178
|
output_buffer.should have_tag('input[@min="5"]')
|
209
179
|
end
|
210
|
-
|
180
|
+
|
211
181
|
it "should allow options to override :min" do
|
212
182
|
concat(semantic_form_for(@new_post) do |builder|
|
213
183
|
builder.input(:title, :as => :number, :min => 5)
|
214
184
|
end)
|
215
185
|
output_buffer.should have_tag('input[@min="5"]')
|
216
186
|
end
|
217
|
-
|
187
|
+
|
218
188
|
it "should allow options to override :min through :in" do
|
219
189
|
concat(semantic_form_for(@new_post) do |builder|
|
220
190
|
builder.input(:title, :as => :number, :in => 5..102)
|
221
191
|
end)
|
222
192
|
output_buffer.should have_tag('input[@min="5"]')
|
223
193
|
end
|
224
|
-
|
194
|
+
|
225
195
|
describe "and the column is an integer" do
|
226
196
|
before do
|
227
197
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
|
228
198
|
end
|
229
|
-
|
199
|
+
|
230
200
|
it "should add a min attribute to the input one greater than the validation" do
|
231
201
|
concat(semantic_form_for(@new_post) do |builder|
|
232
202
|
builder.input(:title, :as => :number)
|
@@ -234,12 +204,12 @@ describe 'number input' do
|
|
234
204
|
output_buffer.should have_tag('input[@min="3"]')
|
235
205
|
end
|
236
206
|
end
|
237
|
-
|
207
|
+
|
238
208
|
describe "and the column is a float" do
|
239
209
|
before do
|
240
210
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
|
241
211
|
end
|
242
|
-
|
212
|
+
|
243
213
|
it "should raise an error" do
|
244
214
|
lambda {
|
245
215
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -248,12 +218,12 @@ describe 'number input' do
|
|
248
218
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
249
219
|
end
|
250
220
|
end
|
251
|
-
|
221
|
+
|
252
222
|
describe "and the column is a big decimal" do
|
253
223
|
before do
|
254
224
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
|
255
225
|
end
|
256
|
-
|
226
|
+
|
257
227
|
it "should raise an error" do
|
258
228
|
lambda {
|
259
229
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -262,23 +232,23 @@ describe 'number input' do
|
|
262
232
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
263
233
|
end
|
264
234
|
end
|
265
|
-
|
235
|
+
|
266
236
|
end
|
267
|
-
|
237
|
+
|
268
238
|
describe "when validations require a minimum value (:greater_than_or_equal_to)" do
|
269
239
|
before do
|
270
240
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
271
241
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
|
272
242
|
])
|
273
243
|
end
|
274
|
-
|
244
|
+
|
275
245
|
it "should allow :input_html to override :min" do
|
276
246
|
concat(semantic_form_for(@new_post) do |builder|
|
277
247
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
278
248
|
end)
|
279
249
|
output_buffer.should have_tag('input[@min="5"]')
|
280
250
|
end
|
281
|
-
|
251
|
+
|
282
252
|
it "should allow options to override :min" do
|
283
253
|
concat(semantic_form_for(@new_post) do |builder|
|
284
254
|
builder.input(:title, :as => :number, :min => 5)
|
@@ -292,14 +262,14 @@ describe 'number input' do
|
|
292
262
|
end)
|
293
263
|
output_buffer.should have_tag('input[@min="5"]')
|
294
264
|
end
|
295
|
-
|
265
|
+
|
296
266
|
it "should allow options to override :min with :in" do
|
297
267
|
concat(semantic_form_for(@new_post) do |builder|
|
298
268
|
builder.input(:title, :as => :number, :in => 5..102)
|
299
269
|
end)
|
300
270
|
output_buffer.should have_tag('input[@min="5"]')
|
301
271
|
end
|
302
|
-
|
272
|
+
|
303
273
|
|
304
274
|
[:integer, :decimal, :float].each do |column_type|
|
305
275
|
describe "and the column is a #{column_type}" do
|
@@ -320,7 +290,7 @@ describe 'number input' do
|
|
320
290
|
before do
|
321
291
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
|
322
292
|
end
|
323
|
-
|
293
|
+
|
324
294
|
it "should add a max attribute to the input equal to the validation" do
|
325
295
|
concat(semantic_form_for(@new_post) do |builder|
|
326
296
|
builder.input(:title, :as => :number)
|
@@ -329,7 +299,7 @@ describe 'number input' do
|
|
329
299
|
end
|
330
300
|
end
|
331
301
|
end
|
332
|
-
|
302
|
+
|
333
303
|
describe "when validations require a minimum value (:greater_than_or_equal_to) that takes a Proc" do
|
334
304
|
before do
|
335
305
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
@@ -396,27 +366,27 @@ describe 'number input' do
|
|
396
366
|
end
|
397
367
|
|
398
368
|
describe "when validations require a maximum value (:less_than)" do
|
399
|
-
|
369
|
+
|
400
370
|
before do
|
401
371
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
402
372
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
|
403
373
|
])
|
404
374
|
end
|
405
|
-
|
375
|
+
|
406
376
|
it "should allow :input_html to override :max" do
|
407
377
|
concat(semantic_form_for(@new_post) do |builder|
|
408
378
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
409
379
|
end)
|
410
380
|
output_buffer.should have_tag('input[@max="102"]')
|
411
381
|
end
|
412
|
-
|
382
|
+
|
413
383
|
it "should allow option to override :max" do
|
414
384
|
concat(semantic_form_for(@new_post) do |builder|
|
415
385
|
builder.input(:title, :as => :number, :max => 102)
|
416
386
|
end)
|
417
387
|
output_buffer.should have_tag('input[@max="102"]')
|
418
388
|
end
|
419
|
-
|
389
|
+
|
420
390
|
it "should allow :input_html to override :max with :in" do
|
421
391
|
concat(semantic_form_for(@new_post) do |builder|
|
422
392
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
@@ -430,12 +400,12 @@ describe 'number input' do
|
|
430
400
|
end)
|
431
401
|
output_buffer.should have_tag('input[@max="102"]')
|
432
402
|
end
|
433
|
-
|
403
|
+
|
434
404
|
describe "and the column is an integer" do
|
435
405
|
before do
|
436
406
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
|
437
407
|
end
|
438
|
-
|
408
|
+
|
439
409
|
it "should add a max attribute to the input one greater than the validation" do
|
440
410
|
concat(semantic_form_for(@new_post) do |builder|
|
441
411
|
builder.input(:title, :as => :number)
|
@@ -443,12 +413,12 @@ describe 'number input' do
|
|
443
413
|
output_buffer.should have_tag('input[@max="19"]')
|
444
414
|
end
|
445
415
|
end
|
446
|
-
|
416
|
+
|
447
417
|
describe "and the column is a float" do
|
448
418
|
before do
|
449
419
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
|
450
420
|
end
|
451
|
-
|
421
|
+
|
452
422
|
it "should raise an error" do
|
453
423
|
lambda {
|
454
424
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -457,12 +427,12 @@ describe 'number input' do
|
|
457
427
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
458
428
|
end
|
459
429
|
end
|
460
|
-
|
430
|
+
|
461
431
|
describe "and the column is a big decimal" do
|
462
432
|
before do
|
463
433
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
|
464
434
|
end
|
465
|
-
|
435
|
+
|
466
436
|
it "should raise an error" do
|
467
437
|
lambda {
|
468
438
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -477,29 +447,29 @@ describe 'number input' do
|
|
477
447
|
end
|
478
448
|
end
|
479
449
|
end
|
480
|
-
|
450
|
+
|
481
451
|
describe "when validations require a maximum value (:less_than) that takes a Proc" do
|
482
|
-
|
452
|
+
|
483
453
|
before do
|
484
454
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
485
455
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=> Proc.new {|post| 20 }})
|
486
456
|
])
|
487
457
|
end
|
488
|
-
|
458
|
+
|
489
459
|
it "should allow :input_html to override :max" do
|
490
460
|
concat(semantic_form_for(@new_post) do |builder|
|
491
461
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
492
462
|
end)
|
493
463
|
output_buffer.should have_tag('input[@max="102"]')
|
494
464
|
end
|
495
|
-
|
465
|
+
|
496
466
|
it "should allow option to override :max" do
|
497
467
|
concat(semantic_form_for(@new_post) do |builder|
|
498
468
|
builder.input(:title, :as => :number, :max => 102)
|
499
469
|
end)
|
500
470
|
output_buffer.should have_tag('input[@max="102"]')
|
501
471
|
end
|
502
|
-
|
472
|
+
|
503
473
|
it "should allow :input_html to override :max with :in" do
|
504
474
|
concat(semantic_form_for(@new_post) do |builder|
|
505
475
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
@@ -513,12 +483,12 @@ describe 'number input' do
|
|
513
483
|
end)
|
514
484
|
output_buffer.should have_tag('input[@max="102"]')
|
515
485
|
end
|
516
|
-
|
486
|
+
|
517
487
|
describe "and the column is an integer" do
|
518
488
|
before do
|
519
489
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
|
520
490
|
end
|
521
|
-
|
491
|
+
|
522
492
|
it "should add a max attribute to the input one greater than the validation" do
|
523
493
|
concat(semantic_form_for(@new_post) do |builder|
|
524
494
|
builder.input(:title, :as => :number)
|
@@ -526,12 +496,12 @@ describe 'number input' do
|
|
526
496
|
output_buffer.should have_tag('input[@max="19"]')
|
527
497
|
end
|
528
498
|
end
|
529
|
-
|
499
|
+
|
530
500
|
describe "and the column is a float" do
|
531
501
|
before do
|
532
502
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
|
533
503
|
end
|
534
|
-
|
504
|
+
|
535
505
|
it "should raise an error" do
|
536
506
|
lambda {
|
537
507
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -540,12 +510,12 @@ describe 'number input' do
|
|
540
510
|
}.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
541
511
|
end
|
542
512
|
end
|
543
|
-
|
513
|
+
|
544
514
|
describe "and the column is a big decimal" do
|
545
515
|
before do
|
546
516
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
|
547
517
|
end
|
548
|
-
|
518
|
+
|
549
519
|
it "should raise an error" do
|
550
520
|
lambda {
|
551
521
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -560,36 +530,36 @@ describe 'number input' do
|
|
560
530
|
end
|
561
531
|
end
|
562
532
|
end
|
563
|
-
|
564
|
-
|
533
|
+
|
534
|
+
|
565
535
|
describe "when validations require a maximum value (:less_than_or_equal_to)" do
|
566
536
|
before do
|
567
537
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
568
538
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
|
569
539
|
])
|
570
540
|
end
|
571
|
-
|
541
|
+
|
572
542
|
it "should allow :input_html to override :max" do
|
573
543
|
concat(semantic_form_for(@new_post) do |builder|
|
574
544
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
575
545
|
end)
|
576
546
|
output_buffer.should have_tag('input[@max="102"]')
|
577
547
|
end
|
578
|
-
|
548
|
+
|
579
549
|
it "should allow options to override :max" do
|
580
550
|
concat(semantic_form_for(@new_post) do |builder|
|
581
551
|
builder.input(:title, :as => :number, :max => 102)
|
582
552
|
end)
|
583
553
|
output_buffer.should have_tag('input[@max="102"]')
|
584
554
|
end
|
585
|
-
|
555
|
+
|
586
556
|
it "should allow :input_html to override :max with :in" do
|
587
557
|
concat(semantic_form_for(@new_post) do |builder|
|
588
558
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
589
559
|
end)
|
590
560
|
output_buffer.should have_tag('input[@max="102"]')
|
591
561
|
end
|
592
|
-
|
562
|
+
|
593
563
|
it "should allow options to override :max with :in" do
|
594
564
|
concat(semantic_form_for(@new_post) do |builder|
|
595
565
|
builder.input(:title, :as => :number, :in => 1..102)
|
@@ -616,7 +586,7 @@ describe 'number input' do
|
|
616
586
|
before do
|
617
587
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
|
618
588
|
end
|
619
|
-
|
589
|
+
|
620
590
|
it "should add a max attribute to the input equal to the validation" do
|
621
591
|
concat(semantic_form_for(@new_post) do |builder|
|
622
592
|
builder.input(:title, :as => :number)
|
@@ -625,7 +595,7 @@ describe 'number input' do
|
|
625
595
|
end
|
626
596
|
end
|
627
597
|
end
|
628
|
-
|
598
|
+
|
629
599
|
describe "when validations require a maximum value (:less_than_or_equal_to) that takes a proc" do
|
630
600
|
before do
|
631
601
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
@@ -689,14 +659,14 @@ describe 'number input' do
|
|
689
659
|
end
|
690
660
|
end
|
691
661
|
end
|
692
|
-
|
662
|
+
|
693
663
|
describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
|
694
664
|
before do
|
695
665
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
696
666
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
|
697
667
|
])
|
698
668
|
end
|
699
|
-
|
669
|
+
|
700
670
|
it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
|
701
671
|
concat(semantic_form_for(@new_post) do |builder|
|
702
672
|
builder.input(:title, :as => :number)
|
@@ -704,14 +674,14 @@ describe 'number input' do
|
|
704
674
|
output_buffer.should have_tag('input[@min="2"]')
|
705
675
|
end
|
706
676
|
end
|
707
|
-
|
677
|
+
|
708
678
|
describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
|
709
679
|
before do
|
710
680
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
711
681
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
|
712
682
|
])
|
713
683
|
end
|
714
|
-
|
684
|
+
|
715
685
|
it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
|
716
686
|
concat(semantic_form_for(@new_post) do |builder|
|
717
687
|
builder.input(:title, :as => :number)
|
@@ -719,99 +689,99 @@ describe 'number input' do
|
|
719
689
|
output_buffer.should have_tag('input[@max="2"]')
|
720
690
|
end
|
721
691
|
end
|
722
|
-
|
692
|
+
|
723
693
|
describe "when validations require only an integer (:only_integer)" do
|
724
|
-
|
694
|
+
|
725
695
|
before do
|
726
696
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
727
697
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
|
728
698
|
])
|
729
699
|
end
|
730
|
-
|
700
|
+
|
731
701
|
it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
|
732
702
|
concat(semantic_form_for(@new_post) do |builder|
|
733
703
|
builder.input(:title, :as => :number)
|
734
704
|
end)
|
735
705
|
output_buffer.should have_tag('input[@step="1"]')
|
736
706
|
end
|
737
|
-
|
707
|
+
|
738
708
|
it "should let input_html override :step" do
|
739
709
|
concat(semantic_form_for(@new_post) do |builder|
|
740
710
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
741
711
|
end)
|
742
712
|
output_buffer.should have_tag('input[@step="3"]')
|
743
713
|
end
|
744
|
-
|
714
|
+
|
745
715
|
it "should let options override :step" do
|
746
716
|
concat(semantic_form_for(@new_post) do |builder|
|
747
717
|
builder.input(:title, :as => :number, :step => 3)
|
748
718
|
end)
|
749
719
|
output_buffer.should have_tag('input[@step="3"]')
|
750
720
|
end
|
751
|
-
|
721
|
+
|
752
722
|
end
|
753
|
-
|
723
|
+
|
754
724
|
describe "when validations require a :step (non standard)" do
|
755
|
-
|
725
|
+
|
756
726
|
before do
|
757
727
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
758
728
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
|
759
729
|
])
|
760
730
|
end
|
761
|
-
|
731
|
+
|
762
732
|
it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
|
763
733
|
concat(semantic_form_for(@new_post) do |builder|
|
764
734
|
builder.input(:title, :as => :number)
|
765
735
|
end)
|
766
736
|
output_buffer.should have_tag('input[@step="2"]')
|
767
737
|
end
|
768
|
-
|
738
|
+
|
769
739
|
it "should let input_html override :step" do
|
770
740
|
concat(semantic_form_for(@new_post) do |builder|
|
771
741
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
772
742
|
end)
|
773
743
|
output_buffer.should have_tag('input[@step="3"]')
|
774
744
|
end
|
775
|
-
|
745
|
+
|
776
746
|
it "should let options override :step" do
|
777
747
|
concat(semantic_form_for(@new_post) do |builder|
|
778
748
|
builder.input(:title, :as => :number, :step => 3)
|
779
749
|
end)
|
780
750
|
output_buffer.should have_tag('input[@step="3"]')
|
781
751
|
end
|
782
|
-
|
752
|
+
|
783
753
|
end
|
784
|
-
|
754
|
+
|
785
755
|
describe "when validations do not specify :step (non standard) or :only_integer" do
|
786
|
-
|
756
|
+
|
787
757
|
before do
|
788
758
|
@new_post.class.stub!(:validators_on).with(:title).and_return([
|
789
759
|
active_model_numericality_validator([:title], {:allow_nil=>false})
|
790
760
|
])
|
791
761
|
end
|
792
|
-
|
762
|
+
|
793
763
|
it "should default step to 'any'" do
|
794
764
|
concat(semantic_form_for(@new_post) do |builder|
|
795
765
|
builder.input(:title, :as => :number)
|
796
766
|
end)
|
797
767
|
output_buffer.should have_tag('input[@step="any"]')
|
798
768
|
end
|
799
|
-
|
769
|
+
|
800
770
|
it "should let input_html set :step" do
|
801
771
|
concat(semantic_form_for(@new_post) do |builder|
|
802
772
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
803
773
|
end)
|
804
774
|
output_buffer.should have_tag('input[@step="3"]')
|
805
775
|
end
|
806
|
-
|
776
|
+
|
807
777
|
it "should let options set :step" do
|
808
778
|
concat(semantic_form_for(@new_post) do |builder|
|
809
779
|
builder.input(:title, :as => :number, :step => 3)
|
810
780
|
end)
|
811
781
|
output_buffer.should have_tag('input[@step="3"]')
|
812
782
|
end
|
813
|
-
|
783
|
+
|
814
784
|
end
|
815
|
-
|
785
|
+
|
816
786
|
end
|
817
787
|
|