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