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,505 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'range input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@bob) do |builder|
16
+ concat(builder.input(:age, :as => :range))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:range)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:numeric)
23
+ it_should_have_input_wrapper_with_class(:stringish)
24
+ it_should_have_input_wrapper_with_id("author_age_input")
25
+ it_should_have_label_with_text(/Age/)
26
+ it_should_have_label_for("author_age")
27
+ it_should_have_input_with_id("author_age")
28
+ it_should_have_input_with_type(:range)
29
+ it_should_have_input_with_name("author[age]")
30
+
31
+ end
32
+
33
+ describe "when namespace is provided" do
34
+
35
+ before do
36
+ concat(semantic_form_for(@james, :namespace => "context2") do |builder|
37
+ concat(builder.input(:age, :as => :range))
38
+ end)
39
+ end
40
+
41
+ it_should_have_input_wrapper_with_id("context2_author_age_input")
42
+ it_should_have_label_and_input_with_id("context2_author_age")
43
+
44
+ end
45
+
46
+ describe "when index is provided" do
47
+
48
+ before do
49
+ @output_buffer = ActionView::OutputBuffer.new ''
50
+ mock_everything
51
+
52
+ concat(semantic_form_for(@new_post) do |builder|
53
+ concat(builder.fields_for(:author, :index => 3) do |author|
54
+ concat(author.input(:name, :as => :range))
55
+ end)
56
+ end)
57
+ end
58
+
59
+ it 'should index the id of the wrapper' do
60
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
61
+ end
62
+
63
+ it 'should index the id of the select tag' do
64
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
65
+ end
66
+
67
+ it 'should index the name of the select tag' do
68
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
69
+ end
70
+
71
+ end
72
+
73
+
74
+ describe "when validations require a minimum value (:greater_than)" do
75
+ before do
76
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
77
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
78
+ ])
79
+ end
80
+
81
+ it "should allow :input_html to override :min" do
82
+ concat(semantic_form_for(@new_post) do |builder|
83
+ builder.input(:title, :as => :range, :input_html => { :min => 5 })
84
+ end)
85
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
86
+ end
87
+
88
+ it "should allow :input_html to override :min through :in" do
89
+ concat(semantic_form_for(@new_post) do |builder|
90
+ builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
91
+ end)
92
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
93
+ end
94
+
95
+ it "should allow options to override :min" do
96
+ concat(semantic_form_for(@new_post) do |builder|
97
+ builder.input(:title, :as => :range, :min => 5)
98
+ end)
99
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
100
+ end
101
+
102
+ it "should allow options to override :min through :in" do
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ builder.input(:title, :as => :range, :in => 5..102)
105
+ end)
106
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
107
+ end
108
+
109
+ describe "and the column is an integer" do
110
+ before do
111
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
112
+ end
113
+
114
+ it "should add a min attribute to the input one greater than the validation" do
115
+ concat(semantic_form_for(@new_post) do |builder|
116
+ builder.input(:title, :as => :range)
117
+ end)
118
+ expect(output_buffer.to_str).to have_tag('input[@min="3"]')
119
+ end
120
+ end
121
+
122
+ describe "and the column is a float" do
123
+ before do
124
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
125
+ end
126
+
127
+ it "should raise an error" do
128
+ expect {
129
+ concat(semantic_form_for(@new_post) do |builder|
130
+ builder.input(:title, :as => :range)
131
+ end)
132
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
133
+ end
134
+ end
135
+
136
+ describe "and the column is a big decimal" do
137
+ before do
138
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
139
+ end
140
+
141
+ it "should raise an error" do
142
+ expect {
143
+ concat(semantic_form_for(@new_post) do |builder|
144
+ builder.input(:title, :as => :range)
145
+ end)
146
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ describe "when validations require a minimum value (:greater_than_or_equal_to)" do
153
+ before do
154
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
155
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
156
+ ])
157
+ end
158
+
159
+ it "should allow :input_html to override :min" do
160
+ concat(semantic_form_for(@new_post) do |builder|
161
+ builder.input(:title, :as => :range, :input_html => { :min => 5 })
162
+ end)
163
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
164
+ end
165
+
166
+ it "should allow options to override :min" do
167
+ concat(semantic_form_for(@new_post) do |builder|
168
+ builder.input(:title, :as => :range, :min => 5)
169
+ end)
170
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
171
+ end
172
+
173
+ it "should allow :input_html to override :min with :in" do
174
+ concat(semantic_form_for(@new_post) do |builder|
175
+ builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
176
+ end)
177
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
178
+ end
179
+
180
+ it "should allow options to override :min with :in" do
181
+ concat(semantic_form_for(@new_post) do |builder|
182
+ builder.input(:title, :as => :range, :in => 5..102)
183
+ end)
184
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
185
+ end
186
+
187
+
188
+ [:integer, :decimal, :float].each do |column_type|
189
+ describe "and the column is a #{column_type}" do
190
+ before do
191
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
192
+ end
193
+
194
+ it "should add a max attribute to the input equal to the validation" do
195
+ concat(semantic_form_for(@new_post) do |builder|
196
+ builder.input(:title, :as => :range)
197
+ end)
198
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
199
+ end
200
+ end
201
+ end
202
+
203
+ describe "and there is no column" do
204
+ before do
205
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
206
+ end
207
+
208
+ it "should add a max attribute to the input equal to the validation" do
209
+ concat(semantic_form_for(@new_post) do |builder|
210
+ builder.input(:title, :as => :range)
211
+ end)
212
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "when validations do not require a minimum value" do
218
+
219
+ it "should default to 1" do
220
+ concat(semantic_form_for(@new_post) do |builder|
221
+ builder.input(:title, :as => :range)
222
+ end)
223
+ expect(output_buffer.to_str).to have_tag('input[@min="1"]')
224
+ end
225
+
226
+ end
227
+
228
+ describe "when validations require a maximum value (:less_than)" do
229
+ before do
230
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
231
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
232
+ ])
233
+ end
234
+
235
+ it "should allow :input_html to override :max" do
236
+ concat(semantic_form_for(@new_post) do |builder|
237
+ builder.input(:title, :as => :range, :input_html => { :max => 102 })
238
+ end)
239
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
240
+ end
241
+
242
+ it "should allow option to override :max" do
243
+ concat(semantic_form_for(@new_post) do |builder|
244
+ builder.input(:title, :as => :range, :max => 102)
245
+ end)
246
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
247
+ end
248
+
249
+ it "should allow :input_html to override :max with :in" do
250
+ concat(semantic_form_for(@new_post) do |builder|
251
+ builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
252
+ end)
253
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
254
+ end
255
+
256
+ it "should allow option to override :max with :in" do
257
+ concat(semantic_form_for(@new_post) do |builder|
258
+ builder.input(:title, :as => :range, :in => 1..102)
259
+ end)
260
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
261
+ end
262
+
263
+ describe "and the column is an integer" do
264
+ before do
265
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
266
+ end
267
+
268
+ it "should add a max attribute to the input one greater than the validation" do
269
+ concat(semantic_form_for(@new_post) do |builder|
270
+ builder.input(:title, :as => :range)
271
+ end)
272
+ expect(output_buffer.to_str).to have_tag('input[@max="19"]')
273
+ end
274
+ end
275
+
276
+ describe "and the column is a float" do
277
+ before do
278
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
279
+ end
280
+
281
+ it "should raise an error" do
282
+ expect {
283
+ concat(semantic_form_for(@new_post) do |builder|
284
+ builder.input(:title, :as => :range)
285
+ end)
286
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
287
+ end
288
+ end
289
+
290
+ describe "and the column is a big decimal" do
291
+ before do
292
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
293
+ end
294
+
295
+ it "should raise an error" do
296
+ expect {
297
+ concat(semantic_form_for(@new_post) do |builder|
298
+ builder.input(:title, :as => :range)
299
+ end)
300
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
301
+ end
302
+ end
303
+
304
+ end
305
+
306
+ describe "when validations require a maximum value (:less_than_or_equal_to)" do
307
+ before do
308
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
309
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
310
+ ])
311
+ end
312
+
313
+ it "should allow :input_html to override :max" do
314
+ concat(semantic_form_for(@new_post) do |builder|
315
+ builder.input(:title, :as => :range, :input_html => { :max => 102 })
316
+ end)
317
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
318
+ end
319
+
320
+ it "should allow options to override :max" do
321
+ concat(semantic_form_for(@new_post) do |builder|
322
+ builder.input(:title, :as => :range, :max => 102)
323
+ end)
324
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
325
+ end
326
+
327
+ it "should allow :input_html to override :max with :in" do
328
+ concat(semantic_form_for(@new_post) do |builder|
329
+ builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
330
+ end)
331
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
332
+ end
333
+
334
+ it "should allow options to override :max with :in" do
335
+ concat(semantic_form_for(@new_post) do |builder|
336
+ builder.input(:title, :as => :range, :in => 1..102)
337
+ end)
338
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
339
+ end
340
+
341
+ [:integer, :decimal, :float].each do |column_type|
342
+ describe "and the column is a #{column_type}" do
343
+ before do
344
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
345
+ end
346
+
347
+ it "should add a max attribute to the input equal to the validation" do
348
+ concat(semantic_form_for(@new_post) do |builder|
349
+ builder.input(:title, :as => :range)
350
+ end)
351
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
352
+ end
353
+ end
354
+ end
355
+
356
+ describe "and there is no column" do
357
+ before do
358
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
359
+ end
360
+
361
+ it "should add a max attribute to the input equal to the validation" do
362
+ concat(semantic_form_for(@new_post) do |builder|
363
+ builder.input(:title, :as => :range)
364
+ end)
365
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
366
+ end
367
+ end
368
+ end
369
+
370
+ describe "when validations do not require a maximum value" do
371
+
372
+ it "should default to 1" do
373
+ concat(semantic_form_for(@new_post) do |builder|
374
+ builder.input(:title, :as => :range)
375
+ end)
376
+ expect(output_buffer.to_str).to have_tag('input[@max="100"]')
377
+ end
378
+
379
+ end
380
+
381
+ describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
382
+ before do
383
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
384
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
385
+ ])
386
+ end
387
+
388
+ it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
389
+ concat(semantic_form_for(@new_post) do |builder|
390
+ builder.input(:title, :as => :range)
391
+ end)
392
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
393
+ end
394
+ end
395
+
396
+ describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
397
+ before do
398
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
399
+ active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
400
+ ])
401
+ end
402
+
403
+ it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
404
+ concat(semantic_form_for(@new_post) do |builder|
405
+ builder.input(:title, :as => :range)
406
+ end)
407
+ expect(output_buffer.to_str).to have_tag('input[@max="2"]')
408
+ end
409
+ end
410
+
411
+ describe "when validations require only an integer (:only_integer)" do
412
+
413
+ before do
414
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
415
+ active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
416
+ ])
417
+ end
418
+
419
+ it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
420
+ concat(semantic_form_for(@new_post) do |builder|
421
+ builder.input(:title, :as => :range)
422
+ end)
423
+ expect(output_buffer.to_str).to have_tag('input[@step="1"]')
424
+ end
425
+
426
+ it "should let input_html override :step" do
427
+ concat(semantic_form_for(@new_post) do |builder|
428
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
429
+ end)
430
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
431
+ end
432
+
433
+ it "should let options override :step" do
434
+ concat(semantic_form_for(@new_post) do |builder|
435
+ builder.input(:title, :as => :range, :step => 3)
436
+ end)
437
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
438
+ end
439
+
440
+ end
441
+
442
+ describe "when validations require a :step (non standard)" do
443
+
444
+ before do
445
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
446
+ active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
447
+ ])
448
+ end
449
+
450
+ it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
451
+ concat(semantic_form_for(@new_post) do |builder|
452
+ builder.input(:title, :as => :range)
453
+ end)
454
+ expect(output_buffer.to_str).to have_tag('input[@step="2"]')
455
+ end
456
+
457
+ it "should let input_html override :step" do
458
+ concat(semantic_form_for(@new_post) do |builder|
459
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
460
+ end)
461
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
462
+ end
463
+
464
+ it "should let options override :step" do
465
+ concat(semantic_form_for(@new_post) do |builder|
466
+ builder.input(:title, :as => :range, :step => 3)
467
+ end)
468
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
469
+ end
470
+
471
+ end
472
+
473
+ describe "when validations do not specify :step (non standard) or :only_integer" do
474
+
475
+ before do
476
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
477
+ active_model_numericality_validator([:title], {:allow_nil=>false})
478
+ ])
479
+ end
480
+
481
+ it "should default step to 1" do
482
+ concat(semantic_form_for(@new_post) do |builder|
483
+ builder.input(:title, :as => :range)
484
+ end)
485
+ expect(output_buffer.to_str).to have_tag('input[@step="1"]')
486
+ end
487
+
488
+ it "should let input_html set :step" do
489
+ concat(semantic_form_for(@new_post) do |builder|
490
+ builder.input(:title, :as => :range, :input_html => { :step => 3 })
491
+ end)
492
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
493
+ end
494
+
495
+ it "should let options set :step" do
496
+ concat(semantic_form_for(@new_post) do |builder|
497
+ builder.input(:title, :as => :range, :step => 3)
498
+ end)
499
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
500
+ end
501
+
502
+ end
503
+
504
+ end
505
+
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'readonly option' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "placeholder text" do
14
+ [:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
15
+
16
+ describe "for #{type} inputs" do
17
+
18
+ describe "when readonly is found in input_html" do
19
+ it "sets readonly attribute" do
20
+ concat(semantic_form_for(@new_post) do |builder|
21
+ concat(builder.input(:title, :as => type, input_html: {readonly: true}))
22
+ end)
23
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
24
+ end
25
+ end
26
+
27
+ describe "when readonly not found in input_html" do
28
+ describe "when column is not readonly attribute" do
29
+ it "doesn't set readonly attribute" do
30
+ concat(semantic_form_for(@new_post) do |builder|
31
+ concat(builder.input(:title, :as => type))
32
+ end)
33
+ expect(output_buffer.to_str).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
34
+ end
35
+ end
36
+ describe "when column is readonly attribute" do
37
+ it "sets readonly attribute" do
38
+ input_class = "Formtastic::Inputs::#{type.to_s.camelize}Input".constantize
39
+ expect_any_instance_of(input_class).to receive(:readonly_attribute?).at_least(1).and_return(true)
40
+ concat(semantic_form_for(@new_post) do |builder|
41
+ concat(builder.input(:title, :as => type))
42
+ end)
43
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'search input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ActionView::OutputBuffer.new ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:search))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:search)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:stringish)
23
+ it_should_have_input_wrapper_with_id("post_search_input")
24
+ it_should_have_label_with_text(/Search/)
25
+ it_should_have_label_for("post_search")
26
+ it_should_have_input_with_id("post_search")
27
+ it_should_have_input_with_type(:search)
28
+ it_should_have_input_with_name("post[search]")
29
+
30
+ end
31
+
32
+ describe "when namespace is provided" do
33
+
34
+ before do
35
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
36
+ concat(builder.input(:search))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_search_input")
41
+ it_should_have_label_and_input_with_id("context2_post_search")
42
+
43
+ end
44
+
45
+ describe "when index is provided" do
46
+
47
+ before do
48
+ @output_buffer = ActionView::OutputBuffer.new ''
49
+ mock_everything
50
+
51
+ concat(semantic_form_for(@new_post) do |builder|
52
+ concat(builder.fields_for(:author, :index => 3) do |author|
53
+ concat(author.input(:name, :as => :search))
54
+ end)
55
+ end)
56
+ end
57
+
58
+ it 'should index the id of the wrapper' do
59
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
60
+ end
61
+
62
+ it 'should index the id of the select tag' do
63
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
64
+ end
65
+
66
+ it 'should index the name of the select tag' do
67
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
68
+ end
69
+
70
+ end
71
+
72
+ describe "when required" do
73
+ it "should add the required attribute to the input's html options" do
74
+ with_config :use_required_attribute, true do
75
+ concat(semantic_form_for(@new_post) do |builder|
76
+ concat(builder.input(:title, :as => :search, :required => true))
77
+ end)
78
+ expect(output_buffer.to_str).to have_tag("input[@required]")
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+