mega-safe-tool 0.0.1

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.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/formtastic-6.0.0/Appraisals +23 -0
  3. data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
  4. data/formtastic-6.0.0/Gemfile +8 -0
  5. data/formtastic-6.0.0/MIT-LICENSE +20 -0
  6. data/formtastic-6.0.0/README.md +600 -0
  7. data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
  8. data/formtastic-6.0.0/Rakefile +54 -0
  9. data/formtastic-6.0.0/bin/appraisal +8 -0
  10. data/formtastic-6.0.0/formtastic.gemspec +45 -0
  11. data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
  12. data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
  13. data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
  14. data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
  15. data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
  16. data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
  17. data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
  18. data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
  19. data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
  20. data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
  21. data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
  22. data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
  23. data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
  24. data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
  25. data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
  26. data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
  27. data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
  28. data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
  29. data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
  30. data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
  31. data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
  32. data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
  33. data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
  34. data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
  35. data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
  36. data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
  37. data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
  38. data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
  39. data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
  40. data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
  41. data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
  42. data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
  43. data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
  44. data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
  45. data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
  46. data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
  47. data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
  48. data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
  49. data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
  50. data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
  51. data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
  52. data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
  53. data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
  54. data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
  55. data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
  56. data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
  57. data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
  58. data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
  59. data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
  60. data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
  61. data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
  62. data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
  63. data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
  64. data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
  65. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
  66. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
  67. data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
  68. data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
  69. data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
  70. data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
  71. data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
  72. data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
  73. data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
  74. data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
  75. data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
  76. data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
  77. data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
  78. data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
  79. data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
  80. data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
  81. data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
  82. data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
  83. data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
  84. data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
  85. data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
  86. data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
  87. data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
  88. data/formtastic-6.0.0/lib/formtastic.rb +48 -0
  89. data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
  90. data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
  91. data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
  92. data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  93. data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
  94. data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
  95. data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
  96. data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
  97. data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
  98. data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
  99. data/formtastic-6.0.0/lib/locale/en.yml +10 -0
  100. data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
  101. data/formtastic-6.0.0/sample/config.ru +69 -0
  102. data/formtastic-6.0.0/sample/index.html +14 -0
  103. data/formtastic-6.0.0/script/integration-template.rb +76 -0
  104. data/formtastic-6.0.0/script/integration.sh +32 -0
  105. data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
  106. data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
  107. data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
  108. data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
  109. data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
  110. data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
  111. data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
  112. data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
  113. data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
  114. data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
  115. data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  116. data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
  117. data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  118. data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
  119. data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
  120. data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
  121. data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
  122. data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
  123. data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
  124. data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
  125. data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
  126. data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
  127. data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
  128. data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
  129. data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
  130. data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
  131. data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
  132. data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
  133. data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
  134. data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
  135. data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
  136. data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
  137. data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
  138. data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
  139. data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
  140. data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
  141. data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
  142. data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
  143. data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
  144. data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
  145. data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
  146. data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
  147. data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
  148. data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
  149. data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
  150. data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
  151. data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
  152. data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
  153. data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
  154. data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
  155. data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
  156. data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
  157. data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
  158. data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
  159. data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
  160. data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
  161. data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
  162. data/formtastic-6.0.0/spec/schema.rb +22 -0
  163. data/formtastic-6.0.0/spec/spec.opts +2 -0
  164. data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
  165. data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
  166. data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
  167. data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
  168. data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
  169. data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
  170. data/mega-safe-tool.gemspec +11 -0
  171. metadata +209 -0
@@ -0,0 +1,815 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'number input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+
12
+ allow(@new_post.class).to receive(: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 = ActionView::OutputBuffer.new ''
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
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
86
+ end
87
+
88
+ it 'should index the id of the select tag' do
89
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
90
+ end
91
+
92
+ it 'should index the name of the select tag' do
93
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
143
+ end
144
+
145
+ describe "and the column is an integer" do
146
+ before do
147
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@min="3"]')
155
+ end
156
+ end
157
+
158
+ describe "and the column is a float" do
159
+ before do
160
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
161
+ end
162
+
163
+ it "should raise an error" do
164
+ expect {
165
+ concat(semantic_form_for(@new_post) do |builder|
166
+ builder.input(:title, :as => :number)
167
+ end)
168
+ }.to 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
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
175
+ end
176
+
177
+ it "should raise an error" do
178
+ expect {
179
+ concat(semantic_form_for(@new_post) do |builder|
180
+ builder.input(:title, :as => :number)
181
+ end)
182
+ }.to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
221
+ end
222
+
223
+ describe "and the column is an integer" do
224
+ before do
225
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@min="3"]')
233
+ end
234
+ end
235
+
236
+ describe "and the column is a float" do
237
+ before do
238
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
239
+ end
240
+
241
+ it "should raise an error" do
242
+ expect {
243
+ concat(semantic_form_for(@new_post) do |builder|
244
+ builder.input(:title, :as => :number)
245
+ end)
246
+ }.to 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
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
253
+ end
254
+
255
+ it "should raise an error" do
256
+ expect {
257
+ concat(semantic_form_for(@new_post) do |builder|
258
+ builder.input(:title, :as => :number)
259
+ end)
260
+ }.to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
313
+ end
314
+ end
315
+ end
316
+
317
+ describe "and there is no column" do
318
+ before do
319
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
378
+ end
379
+ end
380
+ end
381
+
382
+ describe "and there is no column" do
383
+ before do
384
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
430
+ end
431
+
432
+ describe "and the column is an integer" do
433
+ before do
434
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@max="19"]')
442
+ end
443
+ end
444
+
445
+ describe "and the column is a float" do
446
+ before do
447
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
448
+ end
449
+
450
+ it "should raise an error" do
451
+ expect {
452
+ concat(semantic_form_for(@new_post) do |builder|
453
+ builder.input(:title, :as => :number)
454
+ end)
455
+ }.to 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
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
462
+ end
463
+
464
+ it "should raise an error" do
465
+ expect {
466
+ concat(semantic_form_for(@new_post) do |builder|
467
+ builder.input(:title, :as => :number)
468
+ end)
469
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
470
+ end
471
+ end
472
+ describe "and the validator takes a proc" do
473
+ before do
474
+ allow(@new_post).to receive(: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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
513
+ end
514
+
515
+ describe "and the column is an integer" do
516
+ before do
517
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@max="19"]')
525
+ end
526
+ end
527
+
528
+ describe "and the column is a float" do
529
+ before do
530
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
531
+ end
532
+
533
+ it "should raise an error" do
534
+ expect {
535
+ concat(semantic_form_for(@new_post) do |builder|
536
+ builder.input(:title, :as => :number)
537
+ end)
538
+ }.to 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
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
545
+ end
546
+
547
+ it "should raise an error" do
548
+ expect {
549
+ concat(semantic_form_for(@new_post) do |builder|
550
+ builder.input(:title, :as => :number)
551
+ end)
552
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
553
+ end
554
+ end
555
+ describe "and the validator takes a proc" do
556
+ before do
557
+ allow(@new_post).to receive(: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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
609
+ end
610
+ end
611
+ end
612
+
613
+ describe "and there is no column" do
614
+ before do
615
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
673
+ end
674
+ end
675
+ end
676
+
677
+ describe "and there is no column" do
678
+ before do
679
+ allow(@new_post).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ allow(@new_post.class).to receive(: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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to 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
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
810
+ end
811
+
812
+ end
813
+
814
+ end
815
+