formtastic 3.0.0 → 5.0.0
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.
- checksums.yaml +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'number input' do
|
|
5
|
+
RSpec.describe 'number input' do
|
|
5
6
|
|
|
6
7
|
include FormtasticSpecHelper
|
|
7
8
|
|
|
8
9
|
before do
|
|
9
|
-
@output_buffer = ''
|
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
10
11
|
mock_everything
|
|
11
|
-
|
|
12
|
-
@new_post.class.
|
|
12
|
+
|
|
13
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
13
14
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
|
|
14
15
|
])
|
|
15
16
|
end
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
describe "all cases" do
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
before do
|
|
20
21
|
concat(
|
|
21
22
|
semantic_form_for(@new_post) do |builder|
|
|
@@ -40,7 +41,7 @@ describe 'number input' do
|
|
|
40
41
|
# it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
|
41
42
|
# it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
|
42
43
|
it_should_apply_error_logic_for_input_type(:number)
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
describe "when no object is provided" do
|
|
@@ -49,7 +50,7 @@ describe 'number input' do
|
|
|
49
50
|
concat(builder.input(:title, :as => :number, :input_html => { :min => 1, :max => 2 }))
|
|
50
51
|
end)
|
|
51
52
|
end
|
|
52
|
-
|
|
53
|
+
|
|
53
54
|
it_should_have_label_with_text(/Title/)
|
|
54
55
|
it_should_have_label_for("project_title")
|
|
55
56
|
it_should_have_input_with_id("project_title")
|
|
@@ -63,15 +64,15 @@ describe 'number input' do
|
|
|
63
64
|
concat(builder.input(:title, :as => :number))
|
|
64
65
|
end)
|
|
65
66
|
end
|
|
66
|
-
|
|
67
|
+
|
|
67
68
|
it_should_have_input_wrapper_with_id("context2_post_title_input")
|
|
68
69
|
it_should_have_label_and_input_with_id("context2_post_title")
|
|
69
70
|
end
|
|
70
|
-
|
|
71
|
+
|
|
71
72
|
describe "when index is provided" do
|
|
72
73
|
|
|
73
74
|
before do
|
|
74
|
-
@output_buffer = ''
|
|
75
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
75
76
|
mock_everything
|
|
76
77
|
|
|
77
78
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -80,257 +81,257 @@ describe 'number input' do
|
|
|
80
81
|
end)
|
|
81
82
|
end)
|
|
82
83
|
end
|
|
83
|
-
|
|
84
|
+
|
|
84
85
|
it 'should index the id of the wrapper' do
|
|
85
|
-
output_buffer.
|
|
86
|
+
expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
|
|
86
87
|
end
|
|
87
|
-
|
|
88
|
+
|
|
88
89
|
it 'should index the id of the select tag' do
|
|
89
|
-
output_buffer.
|
|
90
|
+
expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
|
|
90
91
|
end
|
|
91
|
-
|
|
92
|
+
|
|
92
93
|
it 'should index the name of the select tag' do
|
|
93
|
-
output_buffer.
|
|
94
|
+
expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
94
95
|
end
|
|
95
|
-
|
|
96
|
+
|
|
96
97
|
end
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
|
|
99
|
+
|
|
99
100
|
describe "when required" do
|
|
100
101
|
it "should add the required attribute to the input's html options" do
|
|
101
|
-
with_config :use_required_attribute, true do
|
|
102
|
+
with_config :use_required_attribute, true do
|
|
102
103
|
concat(semantic_form_for(@new_post) do |builder|
|
|
103
104
|
concat(builder.input(:title, :as => :number, :required => true))
|
|
104
105
|
end)
|
|
105
|
-
output_buffer.
|
|
106
|
+
expect(output_buffer.to_str).to have_tag("input[@required]")
|
|
106
107
|
end
|
|
107
108
|
end
|
|
108
109
|
end
|
|
109
|
-
|
|
110
|
+
|
|
110
111
|
describe "when validations require a minimum value (:greater_than)" do
|
|
111
112
|
before do
|
|
112
|
-
@new_post.class.
|
|
113
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
113
114
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
|
|
114
115
|
])
|
|
115
116
|
end
|
|
116
|
-
|
|
117
|
+
|
|
117
118
|
it "should allow :input_html to override :min" do
|
|
118
119
|
concat(semantic_form_for(@new_post) do |builder|
|
|
119
120
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
|
120
121
|
end)
|
|
121
|
-
output_buffer.
|
|
122
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
122
123
|
end
|
|
123
|
-
|
|
124
|
+
|
|
124
125
|
it "should allow :input_html to override :min through :in" do
|
|
125
126
|
concat(semantic_form_for(@new_post) do |builder|
|
|
126
127
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
|
127
128
|
end)
|
|
128
|
-
output_buffer.
|
|
129
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
129
130
|
end
|
|
130
|
-
|
|
131
|
+
|
|
131
132
|
it "should allow options to override :min" do
|
|
132
133
|
concat(semantic_form_for(@new_post) do |builder|
|
|
133
134
|
builder.input(:title, :as => :number, :min => 5)
|
|
134
135
|
end)
|
|
135
|
-
output_buffer.
|
|
136
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
136
137
|
end
|
|
137
|
-
|
|
138
|
+
|
|
138
139
|
it "should allow options to override :min through :in" do
|
|
139
140
|
concat(semantic_form_for(@new_post) do |builder|
|
|
140
141
|
builder.input(:title, :as => :number, :in => 5..102)
|
|
141
142
|
end)
|
|
142
|
-
output_buffer.
|
|
143
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
143
144
|
end
|
|
144
|
-
|
|
145
|
+
|
|
145
146
|
describe "and the column is an integer" do
|
|
146
147
|
before do
|
|
147
|
-
@new_post.
|
|
148
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
|
148
149
|
end
|
|
149
|
-
|
|
150
|
+
|
|
150
151
|
it "should add a min attribute to the input one greater than the validation" do
|
|
151
152
|
concat(semantic_form_for(@new_post) do |builder|
|
|
152
153
|
builder.input(:title, :as => :number)
|
|
153
154
|
end)
|
|
154
|
-
output_buffer.
|
|
155
|
+
expect(output_buffer.to_str).to have_tag('input[@min="3"]')
|
|
155
156
|
end
|
|
156
157
|
end
|
|
157
|
-
|
|
158
|
+
|
|
158
159
|
describe "and the column is a float" do
|
|
159
160
|
before do
|
|
160
|
-
@new_post.
|
|
161
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
|
161
162
|
end
|
|
162
|
-
|
|
163
|
+
|
|
163
164
|
it "should raise an error" do
|
|
164
|
-
|
|
165
|
+
expect {
|
|
165
166
|
concat(semantic_form_for(@new_post) do |builder|
|
|
166
167
|
builder.input(:title, :as => :number)
|
|
167
168
|
end)
|
|
168
|
-
}.
|
|
169
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
|
169
170
|
end
|
|
170
171
|
end
|
|
171
|
-
|
|
172
|
+
|
|
172
173
|
describe "and the column is a big decimal" do
|
|
173
174
|
before do
|
|
174
|
-
@new_post.
|
|
175
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
175
176
|
end
|
|
176
|
-
|
|
177
|
+
|
|
177
178
|
it "should raise an error" do
|
|
178
|
-
|
|
179
|
+
expect {
|
|
179
180
|
concat(semantic_form_for(@new_post) do |builder|
|
|
180
181
|
builder.input(:title, :as => :number)
|
|
181
182
|
end)
|
|
182
|
-
}.
|
|
183
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
|
183
184
|
end
|
|
184
185
|
end
|
|
185
|
-
|
|
186
|
+
|
|
186
187
|
end
|
|
187
|
-
|
|
188
|
+
|
|
188
189
|
describe "when validations require a minimum value (:greater_than) that takes a proc" do
|
|
189
190
|
before do
|
|
190
|
-
@new_post.class.
|
|
191
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
191
192
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=> Proc.new {|post| 2}})
|
|
192
193
|
])
|
|
193
194
|
end
|
|
194
|
-
|
|
195
|
+
|
|
195
196
|
it "should allow :input_html to override :min" do
|
|
196
197
|
concat(semantic_form_for(@new_post) do |builder|
|
|
197
198
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
|
198
199
|
end)
|
|
199
|
-
output_buffer.
|
|
200
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
200
201
|
end
|
|
201
|
-
|
|
202
|
+
|
|
202
203
|
it "should allow :input_html to override :min through :in" do
|
|
203
204
|
concat(semantic_form_for(@new_post) do |builder|
|
|
204
205
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
|
205
206
|
end)
|
|
206
|
-
output_buffer.
|
|
207
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
207
208
|
end
|
|
208
|
-
|
|
209
|
+
|
|
209
210
|
it "should allow options to override :min" do
|
|
210
211
|
concat(semantic_form_for(@new_post) do |builder|
|
|
211
212
|
builder.input(:title, :as => :number, :min => 5)
|
|
212
213
|
end)
|
|
213
|
-
output_buffer.
|
|
214
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
214
215
|
end
|
|
215
|
-
|
|
216
|
+
|
|
216
217
|
it "should allow options to override :min through :in" do
|
|
217
218
|
concat(semantic_form_for(@new_post) do |builder|
|
|
218
219
|
builder.input(:title, :as => :number, :in => 5..102)
|
|
219
220
|
end)
|
|
220
|
-
output_buffer.
|
|
221
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
221
222
|
end
|
|
222
|
-
|
|
223
|
+
|
|
223
224
|
describe "and the column is an integer" do
|
|
224
225
|
before do
|
|
225
|
-
@new_post.
|
|
226
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
|
226
227
|
end
|
|
227
|
-
|
|
228
|
+
|
|
228
229
|
it "should add a min attribute to the input one greater than the validation" do
|
|
229
230
|
concat(semantic_form_for(@new_post) do |builder|
|
|
230
231
|
builder.input(:title, :as => :number)
|
|
231
232
|
end)
|
|
232
|
-
output_buffer.
|
|
233
|
+
expect(output_buffer.to_str).to have_tag('input[@min="3"]')
|
|
233
234
|
end
|
|
234
235
|
end
|
|
235
|
-
|
|
236
|
+
|
|
236
237
|
describe "and the column is a float" do
|
|
237
238
|
before do
|
|
238
|
-
@new_post.
|
|
239
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
|
239
240
|
end
|
|
240
|
-
|
|
241
|
+
|
|
241
242
|
it "should raise an error" do
|
|
242
|
-
|
|
243
|
+
expect {
|
|
243
244
|
concat(semantic_form_for(@new_post) do |builder|
|
|
244
245
|
builder.input(:title, :as => :number)
|
|
245
246
|
end)
|
|
246
|
-
}.
|
|
247
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
|
247
248
|
end
|
|
248
249
|
end
|
|
249
|
-
|
|
250
|
+
|
|
250
251
|
describe "and the column is a big decimal" do
|
|
251
252
|
before do
|
|
252
|
-
@new_post.
|
|
253
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
253
254
|
end
|
|
254
|
-
|
|
255
|
+
|
|
255
256
|
it "should raise an error" do
|
|
256
|
-
|
|
257
|
+
expect {
|
|
257
258
|
concat(semantic_form_for(@new_post) do |builder|
|
|
258
259
|
builder.input(:title, :as => :number)
|
|
259
260
|
end)
|
|
260
|
-
}.
|
|
261
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
|
|
261
262
|
end
|
|
262
263
|
end
|
|
263
|
-
|
|
264
|
+
|
|
264
265
|
end
|
|
265
|
-
|
|
266
|
+
|
|
266
267
|
describe "when validations require a minimum value (:greater_than_or_equal_to)" do
|
|
267
268
|
before do
|
|
268
|
-
@new_post.class.
|
|
269
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
269
270
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
|
|
270
271
|
])
|
|
271
272
|
end
|
|
272
|
-
|
|
273
|
+
|
|
273
274
|
it "should allow :input_html to override :min" do
|
|
274
275
|
concat(semantic_form_for(@new_post) do |builder|
|
|
275
276
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
|
276
277
|
end)
|
|
277
|
-
output_buffer.
|
|
278
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
278
279
|
end
|
|
279
|
-
|
|
280
|
+
|
|
280
281
|
it "should allow options to override :min" do
|
|
281
282
|
concat(semantic_form_for(@new_post) do |builder|
|
|
282
283
|
builder.input(:title, :as => :number, :min => 5)
|
|
283
284
|
end)
|
|
284
|
-
output_buffer.
|
|
285
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
285
286
|
end
|
|
286
287
|
|
|
287
288
|
it "should allow :input_html to override :min with :in" do
|
|
288
289
|
concat(semantic_form_for(@new_post) do |builder|
|
|
289
290
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
|
290
291
|
end)
|
|
291
|
-
output_buffer.
|
|
292
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
292
293
|
end
|
|
293
|
-
|
|
294
|
+
|
|
294
295
|
it "should allow options to override :min with :in" do
|
|
295
296
|
concat(semantic_form_for(@new_post) do |builder|
|
|
296
297
|
builder.input(:title, :as => :number, :in => 5..102)
|
|
297
298
|
end)
|
|
298
|
-
output_buffer.
|
|
299
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
299
300
|
end
|
|
300
|
-
|
|
301
|
+
|
|
301
302
|
|
|
302
303
|
[:integer, :decimal, :float].each do |column_type|
|
|
303
304
|
describe "and the column is a #{column_type}" do
|
|
304
305
|
before do
|
|
305
|
-
@new_post.
|
|
306
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
|
306
307
|
end
|
|
307
308
|
|
|
308
309
|
it "should add a max attribute to the input equal to the validation" do
|
|
309
310
|
concat(semantic_form_for(@new_post) do |builder|
|
|
310
311
|
builder.input(:title, :as => :number)
|
|
311
312
|
end)
|
|
312
|
-
output_buffer.
|
|
313
|
+
expect(output_buffer.to_str).to have_tag('input[@min="2"]')
|
|
313
314
|
end
|
|
314
315
|
end
|
|
315
316
|
end
|
|
316
317
|
|
|
317
318
|
describe "and there is no column" do
|
|
318
319
|
before do
|
|
319
|
-
@new_post.
|
|
320
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
|
|
320
321
|
end
|
|
321
|
-
|
|
322
|
+
|
|
322
323
|
it "should add a max attribute to the input equal to the validation" do
|
|
323
324
|
concat(semantic_form_for(@new_post) do |builder|
|
|
324
325
|
builder.input(:title, :as => :number)
|
|
325
326
|
end)
|
|
326
|
-
output_buffer.
|
|
327
|
+
expect(output_buffer.to_str).to have_tag('input[@min="2"]')
|
|
327
328
|
end
|
|
328
329
|
end
|
|
329
330
|
end
|
|
330
|
-
|
|
331
|
+
|
|
331
332
|
describe "when validations require a minimum value (:greater_than_or_equal_to) that takes a Proc" do
|
|
332
333
|
before do
|
|
333
|
-
@new_post.class.
|
|
334
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
334
335
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=> Proc.new { |post| 2}})
|
|
335
336
|
])
|
|
336
337
|
end
|
|
@@ -339,294 +340,294 @@ describe 'number input' do
|
|
|
339
340
|
concat(semantic_form_for(@new_post) do |builder|
|
|
340
341
|
builder.input(:title, :as => :number, :input_html => { :min => 5 })
|
|
341
342
|
end)
|
|
342
|
-
output_buffer.
|
|
343
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
343
344
|
end
|
|
344
345
|
|
|
345
346
|
it "should allow options to override :min" do
|
|
346
347
|
concat(semantic_form_for(@new_post) do |builder|
|
|
347
348
|
builder.input(:title, :as => :number, :min => 5)
|
|
348
349
|
end)
|
|
349
|
-
output_buffer.
|
|
350
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
350
351
|
end
|
|
351
352
|
|
|
352
353
|
it "should allow :input_html to override :min with :in" do
|
|
353
354
|
concat(semantic_form_for(@new_post) do |builder|
|
|
354
355
|
builder.input(:title, :as => :number, :input_html => { :in => 5..102 })
|
|
355
356
|
end)
|
|
356
|
-
output_buffer.
|
|
357
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
357
358
|
end
|
|
358
359
|
|
|
359
360
|
it "should allow options to override :min with :in" do
|
|
360
361
|
concat(semantic_form_for(@new_post) do |builder|
|
|
361
362
|
builder.input(:title, :as => :number, :in => 5..102)
|
|
362
363
|
end)
|
|
363
|
-
output_buffer.
|
|
364
|
+
expect(output_buffer.to_str).to have_tag('input[@min="5"]')
|
|
364
365
|
end
|
|
365
366
|
|
|
366
367
|
|
|
367
368
|
[:integer, :decimal, :float].each do |column_type|
|
|
368
369
|
describe "and the column is a #{column_type}" do
|
|
369
370
|
before do
|
|
370
|
-
@new_post.
|
|
371
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
|
371
372
|
end
|
|
372
373
|
|
|
373
374
|
it "should add a max attribute to the input equal to the validation" do
|
|
374
375
|
concat(semantic_form_for(@new_post) do |builder|
|
|
375
376
|
builder.input(:title, :as => :number)
|
|
376
377
|
end)
|
|
377
|
-
output_buffer.
|
|
378
|
+
expect(output_buffer.to_str).to have_tag('input[@min="2"]')
|
|
378
379
|
end
|
|
379
380
|
end
|
|
380
381
|
end
|
|
381
382
|
|
|
382
383
|
describe "and there is no column" do
|
|
383
384
|
before do
|
|
384
|
-
@new_post.
|
|
385
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
|
|
385
386
|
end
|
|
386
387
|
|
|
387
388
|
it "should add a max attribute to the input equal to the validation" do
|
|
388
389
|
concat(semantic_form_for(@new_post) do |builder|
|
|
389
390
|
builder.input(:title, :as => :number)
|
|
390
391
|
end)
|
|
391
|
-
output_buffer.
|
|
392
|
+
expect(output_buffer.to_str).to have_tag('input[@min="2"]')
|
|
392
393
|
end
|
|
393
394
|
end
|
|
394
395
|
end
|
|
395
396
|
|
|
396
397
|
describe "when validations require a maximum value (:less_than)" do
|
|
397
|
-
|
|
398
|
+
|
|
398
399
|
before do
|
|
399
|
-
@new_post.class.
|
|
400
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
400
401
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
|
|
401
402
|
])
|
|
402
403
|
end
|
|
403
|
-
|
|
404
|
+
|
|
404
405
|
it "should allow :input_html to override :max" do
|
|
405
406
|
concat(semantic_form_for(@new_post) do |builder|
|
|
406
407
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
|
407
408
|
end)
|
|
408
|
-
output_buffer.
|
|
409
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
409
410
|
end
|
|
410
|
-
|
|
411
|
+
|
|
411
412
|
it "should allow option to override :max" do
|
|
412
413
|
concat(semantic_form_for(@new_post) do |builder|
|
|
413
414
|
builder.input(:title, :as => :number, :max => 102)
|
|
414
415
|
end)
|
|
415
|
-
output_buffer.
|
|
416
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
416
417
|
end
|
|
417
|
-
|
|
418
|
+
|
|
418
419
|
it "should allow :input_html to override :max with :in" do
|
|
419
420
|
concat(semantic_form_for(@new_post) do |builder|
|
|
420
421
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
|
421
422
|
end)
|
|
422
|
-
output_buffer.
|
|
423
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
423
424
|
end
|
|
424
425
|
|
|
425
426
|
it "should allow option to override :max with :in" do
|
|
426
427
|
concat(semantic_form_for(@new_post) do |builder|
|
|
427
428
|
builder.input(:title, :as => :number, :in => 1..102)
|
|
428
429
|
end)
|
|
429
|
-
output_buffer.
|
|
430
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
430
431
|
end
|
|
431
|
-
|
|
432
|
+
|
|
432
433
|
describe "and the column is an integer" do
|
|
433
434
|
before do
|
|
434
|
-
@new_post.
|
|
435
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
|
435
436
|
end
|
|
436
|
-
|
|
437
|
+
|
|
437
438
|
it "should add a max attribute to the input one greater than the validation" do
|
|
438
439
|
concat(semantic_form_for(@new_post) do |builder|
|
|
439
440
|
builder.input(:title, :as => :number)
|
|
440
441
|
end)
|
|
441
|
-
output_buffer.
|
|
442
|
+
expect(output_buffer.to_str).to have_tag('input[@max="19"]')
|
|
442
443
|
end
|
|
443
444
|
end
|
|
444
|
-
|
|
445
|
+
|
|
445
446
|
describe "and the column is a float" do
|
|
446
447
|
before do
|
|
447
|
-
@new_post.
|
|
448
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
|
448
449
|
end
|
|
449
|
-
|
|
450
|
+
|
|
450
451
|
it "should raise an error" do
|
|
451
|
-
|
|
452
|
+
expect {
|
|
452
453
|
concat(semantic_form_for(@new_post) do |builder|
|
|
453
454
|
builder.input(:title, :as => :number)
|
|
454
455
|
end)
|
|
455
|
-
}.
|
|
456
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
|
456
457
|
end
|
|
457
458
|
end
|
|
458
|
-
|
|
459
|
+
|
|
459
460
|
describe "and the column is a big decimal" do
|
|
460
461
|
before do
|
|
461
|
-
@new_post.
|
|
462
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
462
463
|
end
|
|
463
|
-
|
|
464
|
+
|
|
464
465
|
it "should raise an error" do
|
|
465
|
-
|
|
466
|
+
expect {
|
|
466
467
|
concat(semantic_form_for(@new_post) do |builder|
|
|
467
468
|
builder.input(:title, :as => :number)
|
|
468
469
|
end)
|
|
469
|
-
}.
|
|
470
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
|
470
471
|
end
|
|
471
472
|
end
|
|
472
473
|
describe "and the validator takes a proc" do
|
|
473
474
|
before do
|
|
474
|
-
@new_post.
|
|
475
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
475
476
|
end
|
|
476
477
|
end
|
|
477
478
|
end
|
|
478
|
-
|
|
479
|
+
|
|
479
480
|
describe "when validations require a maximum value (:less_than) that takes a Proc" do
|
|
480
|
-
|
|
481
|
+
|
|
481
482
|
before do
|
|
482
|
-
@new_post.class.
|
|
483
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
483
484
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=> Proc.new {|post| 20 }})
|
|
484
485
|
])
|
|
485
486
|
end
|
|
486
|
-
|
|
487
|
+
|
|
487
488
|
it "should allow :input_html to override :max" do
|
|
488
489
|
concat(semantic_form_for(@new_post) do |builder|
|
|
489
490
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
|
490
491
|
end)
|
|
491
|
-
output_buffer.
|
|
492
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
492
493
|
end
|
|
493
|
-
|
|
494
|
+
|
|
494
495
|
it "should allow option to override :max" do
|
|
495
496
|
concat(semantic_form_for(@new_post) do |builder|
|
|
496
497
|
builder.input(:title, :as => :number, :max => 102)
|
|
497
498
|
end)
|
|
498
|
-
output_buffer.
|
|
499
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
499
500
|
end
|
|
500
|
-
|
|
501
|
+
|
|
501
502
|
it "should allow :input_html to override :max with :in" do
|
|
502
503
|
concat(semantic_form_for(@new_post) do |builder|
|
|
503
504
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
|
504
505
|
end)
|
|
505
|
-
output_buffer.
|
|
506
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
506
507
|
end
|
|
507
508
|
|
|
508
509
|
it "should allow option to override :max with :in" do
|
|
509
510
|
concat(semantic_form_for(@new_post) do |builder|
|
|
510
511
|
builder.input(:title, :as => :number, :in => 1..102)
|
|
511
512
|
end)
|
|
512
|
-
output_buffer.
|
|
513
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
513
514
|
end
|
|
514
|
-
|
|
515
|
+
|
|
515
516
|
describe "and the column is an integer" do
|
|
516
517
|
before do
|
|
517
|
-
@new_post.
|
|
518
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
|
518
519
|
end
|
|
519
|
-
|
|
520
|
+
|
|
520
521
|
it "should add a max attribute to the input one greater than the validation" do
|
|
521
522
|
concat(semantic_form_for(@new_post) do |builder|
|
|
522
523
|
builder.input(:title, :as => :number)
|
|
523
524
|
end)
|
|
524
|
-
output_buffer.
|
|
525
|
+
expect(output_buffer.to_str).to have_tag('input[@max="19"]')
|
|
525
526
|
end
|
|
526
527
|
end
|
|
527
|
-
|
|
528
|
+
|
|
528
529
|
describe "and the column is a float" do
|
|
529
530
|
before do
|
|
530
|
-
@new_post.
|
|
531
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
|
531
532
|
end
|
|
532
|
-
|
|
533
|
+
|
|
533
534
|
it "should raise an error" do
|
|
534
|
-
|
|
535
|
+
expect {
|
|
535
536
|
concat(semantic_form_for(@new_post) do |builder|
|
|
536
537
|
builder.input(:title, :as => :number)
|
|
537
538
|
end)
|
|
538
|
-
}.
|
|
539
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
|
539
540
|
end
|
|
540
541
|
end
|
|
541
|
-
|
|
542
|
+
|
|
542
543
|
describe "and the column is a big decimal" do
|
|
543
544
|
before do
|
|
544
|
-
@new_post.
|
|
545
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
545
546
|
end
|
|
546
|
-
|
|
547
|
+
|
|
547
548
|
it "should raise an error" do
|
|
548
|
-
|
|
549
|
+
expect {
|
|
549
550
|
concat(semantic_form_for(@new_post) do |builder|
|
|
550
551
|
builder.input(:title, :as => :number)
|
|
551
552
|
end)
|
|
552
|
-
}.
|
|
553
|
+
}.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
|
|
553
554
|
end
|
|
554
555
|
end
|
|
555
556
|
describe "and the validator takes a proc" do
|
|
556
557
|
before do
|
|
557
|
-
@new_post.
|
|
558
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
|
558
559
|
end
|
|
559
560
|
end
|
|
560
561
|
end
|
|
561
|
-
|
|
562
|
-
|
|
562
|
+
|
|
563
|
+
|
|
563
564
|
describe "when validations require a maximum value (:less_than_or_equal_to)" do
|
|
564
565
|
before do
|
|
565
|
-
@new_post.class.
|
|
566
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
566
567
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
|
|
567
568
|
])
|
|
568
569
|
end
|
|
569
|
-
|
|
570
|
+
|
|
570
571
|
it "should allow :input_html to override :max" do
|
|
571
572
|
concat(semantic_form_for(@new_post) do |builder|
|
|
572
573
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
|
573
574
|
end)
|
|
574
|
-
output_buffer.
|
|
575
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
575
576
|
end
|
|
576
|
-
|
|
577
|
+
|
|
577
578
|
it "should allow options to override :max" do
|
|
578
579
|
concat(semantic_form_for(@new_post) do |builder|
|
|
579
580
|
builder.input(:title, :as => :number, :max => 102)
|
|
580
581
|
end)
|
|
581
|
-
output_buffer.
|
|
582
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
582
583
|
end
|
|
583
|
-
|
|
584
|
+
|
|
584
585
|
it "should allow :input_html to override :max with :in" do
|
|
585
586
|
concat(semantic_form_for(@new_post) do |builder|
|
|
586
587
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
|
587
588
|
end)
|
|
588
|
-
output_buffer.
|
|
589
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
589
590
|
end
|
|
590
|
-
|
|
591
|
+
|
|
591
592
|
it "should allow options to override :max with :in" do
|
|
592
593
|
concat(semantic_form_for(@new_post) do |builder|
|
|
593
594
|
builder.input(:title, :as => :number, :in => 1..102)
|
|
594
595
|
end)
|
|
595
|
-
output_buffer.
|
|
596
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
596
597
|
end
|
|
597
598
|
|
|
598
599
|
[:integer, :decimal, :float].each do |column_type|
|
|
599
600
|
describe "and the column is a #{column_type}" do
|
|
600
601
|
before do
|
|
601
|
-
@new_post.
|
|
602
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
|
602
603
|
end
|
|
603
604
|
|
|
604
605
|
it "should add a max attribute to the input equal to the validation" do
|
|
605
606
|
concat(semantic_form_for(@new_post) do |builder|
|
|
606
607
|
builder.input(:title, :as => :number)
|
|
607
608
|
end)
|
|
608
|
-
output_buffer.
|
|
609
|
+
expect(output_buffer.to_str).to have_tag('input[@max="20"]')
|
|
609
610
|
end
|
|
610
611
|
end
|
|
611
612
|
end
|
|
612
613
|
|
|
613
614
|
describe "and there is no column" do
|
|
614
615
|
before do
|
|
615
|
-
@new_post.
|
|
616
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
|
|
616
617
|
end
|
|
617
|
-
|
|
618
|
+
|
|
618
619
|
it "should add a max attribute to the input equal to the validation" do
|
|
619
620
|
concat(semantic_form_for(@new_post) do |builder|
|
|
620
621
|
builder.input(:title, :as => :number)
|
|
621
622
|
end)
|
|
622
|
-
output_buffer.
|
|
623
|
+
expect(output_buffer.to_str).to have_tag('input[@max="20"]')
|
|
623
624
|
end
|
|
624
625
|
end
|
|
625
626
|
end
|
|
626
|
-
|
|
627
|
+
|
|
627
628
|
describe "when validations require a maximum value (:less_than_or_equal_to) that takes a proc" do
|
|
628
629
|
before do
|
|
629
|
-
@new_post.class.
|
|
630
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
630
631
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=> Proc.new { |post| 20 }})
|
|
631
632
|
])
|
|
632
633
|
end
|
|
@@ -635,181 +636,181 @@ describe 'number input' do
|
|
|
635
636
|
concat(semantic_form_for(@new_post) do |builder|
|
|
636
637
|
builder.input(:title, :as => :number, :input_html => { :max => 102 })
|
|
637
638
|
end)
|
|
638
|
-
output_buffer.
|
|
639
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
639
640
|
end
|
|
640
641
|
|
|
641
642
|
it "should allow options to override :max" do
|
|
642
643
|
concat(semantic_form_for(@new_post) do |builder|
|
|
643
644
|
builder.input(:title, :as => :number, :max => 102)
|
|
644
645
|
end)
|
|
645
|
-
output_buffer.
|
|
646
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
646
647
|
end
|
|
647
648
|
|
|
648
649
|
it "should allow :input_html to override :max with :in" do
|
|
649
650
|
concat(semantic_form_for(@new_post) do |builder|
|
|
650
651
|
builder.input(:title, :as => :number, :input_html => { :in => 1..102 })
|
|
651
652
|
end)
|
|
652
|
-
output_buffer.
|
|
653
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
653
654
|
end
|
|
654
655
|
|
|
655
656
|
it "should allow options to override :max with :in" do
|
|
656
657
|
concat(semantic_form_for(@new_post) do |builder|
|
|
657
658
|
builder.input(:title, :as => :number, :in => 1..102)
|
|
658
659
|
end)
|
|
659
|
-
output_buffer.
|
|
660
|
+
expect(output_buffer.to_str).to have_tag('input[@max="102"]')
|
|
660
661
|
end
|
|
661
662
|
|
|
662
663
|
[:integer, :decimal, :float].each do |column_type|
|
|
663
664
|
describe "and the column is a #{column_type}" do
|
|
664
665
|
before do
|
|
665
|
-
@new_post.
|
|
666
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
|
666
667
|
end
|
|
667
668
|
|
|
668
669
|
it "should add a max attribute to the input equal to the validation" do
|
|
669
670
|
concat(semantic_form_for(@new_post) do |builder|
|
|
670
671
|
builder.input(:title, :as => :number)
|
|
671
672
|
end)
|
|
672
|
-
output_buffer.
|
|
673
|
+
expect(output_buffer.to_str).to have_tag('input[@max="20"]')
|
|
673
674
|
end
|
|
674
675
|
end
|
|
675
676
|
end
|
|
676
677
|
|
|
677
678
|
describe "and there is no column" do
|
|
678
679
|
before do
|
|
679
|
-
@new_post.
|
|
680
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
|
|
680
681
|
end
|
|
681
682
|
|
|
682
683
|
it "should add a max attribute to the input equal to the validation" do
|
|
683
684
|
concat(semantic_form_for(@new_post) do |builder|
|
|
684
685
|
builder.input(:title, :as => :number)
|
|
685
686
|
end)
|
|
686
|
-
output_buffer.
|
|
687
|
+
expect(output_buffer.to_str).to have_tag('input[@max="20"]')
|
|
687
688
|
end
|
|
688
689
|
end
|
|
689
690
|
end
|
|
690
|
-
|
|
691
|
+
|
|
691
692
|
describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
|
|
692
693
|
before do
|
|
693
|
-
@new_post.class.
|
|
694
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
694
695
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
|
|
695
696
|
])
|
|
696
697
|
end
|
|
697
|
-
|
|
698
|
+
|
|
698
699
|
it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
|
|
699
700
|
concat(semantic_form_for(@new_post) do |builder|
|
|
700
701
|
builder.input(:title, :as => :number)
|
|
701
702
|
end)
|
|
702
|
-
output_buffer.
|
|
703
|
+
expect(output_buffer.to_str).to have_tag('input[@min="2"]')
|
|
703
704
|
end
|
|
704
705
|
end
|
|
705
|
-
|
|
706
|
+
|
|
706
707
|
describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
|
|
707
708
|
before do
|
|
708
|
-
@new_post.class.
|
|
709
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
709
710
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
|
|
710
711
|
])
|
|
711
712
|
end
|
|
712
|
-
|
|
713
|
+
|
|
713
714
|
it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
|
|
714
715
|
concat(semantic_form_for(@new_post) do |builder|
|
|
715
716
|
builder.input(:title, :as => :number)
|
|
716
717
|
end)
|
|
717
|
-
output_buffer.
|
|
718
|
+
expect(output_buffer.to_str).to have_tag('input[@max="2"]')
|
|
718
719
|
end
|
|
719
720
|
end
|
|
720
|
-
|
|
721
|
+
|
|
721
722
|
describe "when validations require only an integer (:only_integer)" do
|
|
722
|
-
|
|
723
|
+
|
|
723
724
|
before do
|
|
724
|
-
@new_post.class.
|
|
725
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
725
726
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
|
|
726
727
|
])
|
|
727
728
|
end
|
|
728
|
-
|
|
729
|
+
|
|
729
730
|
it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
|
|
730
731
|
concat(semantic_form_for(@new_post) do |builder|
|
|
731
732
|
builder.input(:title, :as => :number)
|
|
732
733
|
end)
|
|
733
|
-
output_buffer.
|
|
734
|
+
expect(output_buffer.to_str).to have_tag('input[@step="1"]')
|
|
734
735
|
end
|
|
735
|
-
|
|
736
|
+
|
|
736
737
|
it "should let input_html override :step" do
|
|
737
738
|
concat(semantic_form_for(@new_post) do |builder|
|
|
738
739
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
|
739
740
|
end)
|
|
740
|
-
output_buffer.
|
|
741
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
741
742
|
end
|
|
742
|
-
|
|
743
|
+
|
|
743
744
|
it "should let options override :step" do
|
|
744
745
|
concat(semantic_form_for(@new_post) do |builder|
|
|
745
746
|
builder.input(:title, :as => :number, :step => 3)
|
|
746
747
|
end)
|
|
747
|
-
output_buffer.
|
|
748
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
748
749
|
end
|
|
749
|
-
|
|
750
|
+
|
|
750
751
|
end
|
|
751
|
-
|
|
752
|
+
|
|
752
753
|
describe "when validations require a :step (non standard)" do
|
|
753
|
-
|
|
754
|
+
|
|
754
755
|
before do
|
|
755
|
-
@new_post.class.
|
|
756
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
756
757
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
|
|
757
758
|
])
|
|
758
759
|
end
|
|
759
|
-
|
|
760
|
+
|
|
760
761
|
it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
|
|
761
762
|
concat(semantic_form_for(@new_post) do |builder|
|
|
762
763
|
builder.input(:title, :as => :number)
|
|
763
764
|
end)
|
|
764
|
-
output_buffer.
|
|
765
|
+
expect(output_buffer.to_str).to have_tag('input[@step="2"]')
|
|
765
766
|
end
|
|
766
|
-
|
|
767
|
+
|
|
767
768
|
it "should let input_html override :step" do
|
|
768
769
|
concat(semantic_form_for(@new_post) do |builder|
|
|
769
770
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
|
770
771
|
end)
|
|
771
|
-
output_buffer.
|
|
772
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
772
773
|
end
|
|
773
|
-
|
|
774
|
+
|
|
774
775
|
it "should let options override :step" do
|
|
775
776
|
concat(semantic_form_for(@new_post) do |builder|
|
|
776
777
|
builder.input(:title, :as => :number, :step => 3)
|
|
777
778
|
end)
|
|
778
|
-
output_buffer.
|
|
779
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
779
780
|
end
|
|
780
|
-
|
|
781
|
+
|
|
781
782
|
end
|
|
782
|
-
|
|
783
|
+
|
|
783
784
|
describe "when validations do not specify :step (non standard) or :only_integer" do
|
|
784
|
-
|
|
785
|
+
|
|
785
786
|
before do
|
|
786
|
-
@new_post.class.
|
|
787
|
+
allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
|
|
787
788
|
active_model_numericality_validator([:title], {:allow_nil=>false})
|
|
788
789
|
])
|
|
789
790
|
end
|
|
790
|
-
|
|
791
|
+
|
|
791
792
|
it "should default step to 'any'" do
|
|
792
793
|
concat(semantic_form_for(@new_post) do |builder|
|
|
793
794
|
builder.input(:title, :as => :number)
|
|
794
795
|
end)
|
|
795
|
-
output_buffer.
|
|
796
|
+
expect(output_buffer.to_str).to have_tag('input[@step="any"]')
|
|
796
797
|
end
|
|
797
|
-
|
|
798
|
+
|
|
798
799
|
it "should let input_html set :step" do
|
|
799
800
|
concat(semantic_form_for(@new_post) do |builder|
|
|
800
801
|
builder.input(:title, :as => :number, :input_html => { :step => 3 })
|
|
801
802
|
end)
|
|
802
|
-
output_buffer.
|
|
803
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
803
804
|
end
|
|
804
|
-
|
|
805
|
+
|
|
805
806
|
it "should let options set :step" do
|
|
806
807
|
concat(semantic_form_for(@new_post) do |builder|
|
|
807
808
|
builder.input(:title, :as => :number, :step => 3)
|
|
808
809
|
end)
|
|
809
|
-
output_buffer.
|
|
810
|
+
expect(output_buffer.to_str).to have_tag('input[@step="3"]')
|
|
810
811
|
end
|
|
811
|
-
|
|
812
|
+
|
|
812
813
|
end
|
|
813
|
-
|
|
814
|
+
|
|
814
815
|
end
|
|
815
816
|
|