formtastic 2.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +4 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +105 -0
  8. data/MIT-LICENSE +1 -1
  9. data/{README.textile → README.md} +204 -219
  10. data/RELEASE_PROCESS +3 -1
  11. data/Rakefile +27 -29
  12. data/app/assets/stylesheets/formtastic.css +3 -2
  13. data/bin/appraisal +8 -0
  14. data/formtastic.gemspec +11 -14
  15. data/gemfiles/rails_5.2/Gemfile +5 -0
  16. data/gemfiles/rails_6.0/Gemfile +5 -0
  17. data/gemfiles/rails_6.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +18 -0
  20. data/lib/formtastic/actions/button_action.rb +55 -60
  21. data/lib/formtastic/actions/input_action.rb +59 -57
  22. data/lib/formtastic/actions/link_action.rb +68 -67
  23. data/lib/formtastic/actions.rb +6 -3
  24. data/lib/formtastic/deprecation.rb +5 -0
  25. data/lib/formtastic/engine.rb +3 -1
  26. data/lib/formtastic/form_builder.rb +35 -16
  27. data/lib/formtastic/helpers/action_helper.rb +34 -28
  28. data/lib/formtastic/helpers/enum.rb +13 -0
  29. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  30. data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
  31. data/lib/formtastic/helpers/form_helper.rb +19 -16
  32. data/lib/formtastic/helpers/input_helper.rb +69 -97
  33. data/lib/formtastic/helpers/inputs_helper.rb +35 -25
  34. data/lib/formtastic/helpers/reflection.rb +4 -4
  35. data/lib/formtastic/helpers.rb +1 -2
  36. data/lib/formtastic/html_attributes.rb +12 -1
  37. data/lib/formtastic/i18n.rb +1 -1
  38. data/lib/formtastic/input_class_finder.rb +18 -0
  39. data/lib/formtastic/inputs/base/choices.rb +2 -2
  40. data/lib/formtastic/inputs/base/collections.rb +46 -14
  41. data/lib/formtastic/inputs/base/database.rb +7 -2
  42. data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
  43. data/lib/formtastic/inputs/base/errors.rb +7 -7
  44. data/lib/formtastic/inputs/base/hints.rb +2 -2
  45. data/lib/formtastic/inputs/base/html.rb +10 -9
  46. data/lib/formtastic/inputs/base/labelling.rb +5 -8
  47. data/lib/formtastic/inputs/base/naming.rb +4 -4
  48. data/lib/formtastic/inputs/base/numeric.rb +1 -1
  49. data/lib/formtastic/inputs/base/options.rb +3 -4
  50. data/lib/formtastic/inputs/base/stringish.rb +10 -2
  51. data/lib/formtastic/inputs/base/timeish.rb +34 -22
  52. data/lib/formtastic/inputs/base/validations.rb +41 -13
  53. data/lib/formtastic/inputs/base/wrapping.rb +29 -26
  54. data/lib/formtastic/inputs/base.rb +22 -15
  55. data/lib/formtastic/inputs/boolean_input.rb +26 -12
  56. data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
  57. data/lib/formtastic/inputs/color_input.rb +41 -0
  58. data/lib/formtastic/inputs/country_input.rb +24 -5
  59. data/lib/formtastic/inputs/datalist_input.rb +41 -0
  60. data/lib/formtastic/inputs/date_picker_input.rb +93 -0
  61. data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
  62. data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
  63. data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
  64. data/lib/formtastic/inputs/file_input.rb +2 -2
  65. data/lib/formtastic/inputs/hidden_input.rb +2 -6
  66. data/lib/formtastic/inputs/radio_input.rb +28 -22
  67. data/lib/formtastic/inputs/select_input.rb +36 -39
  68. data/lib/formtastic/inputs/time_picker_input.rb +99 -0
  69. data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
  70. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  71. data/lib/formtastic/inputs.rb +32 -21
  72. data/lib/formtastic/localized_string.rb +1 -1
  73. data/lib/formtastic/localizer.rb +24 -24
  74. data/lib/formtastic/namespaced_class_finder.rb +99 -0
  75. data/lib/formtastic/version.rb +1 -1
  76. data/lib/formtastic.rb +20 -10
  77. data/lib/generators/formtastic/form/form_generator.rb +10 -4
  78. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  79. data/lib/generators/formtastic/install/install_generator.rb +5 -19
  80. data/lib/generators/templates/_form.html.slim +2 -2
  81. data/lib/generators/templates/formtastic.rb +46 -25
  82. data/lib/generators/templates/input.rb +19 -0
  83. data/sample/basic_inputs.html +23 -3
  84. data/script/integration-template.rb +74 -0
  85. data/script/integration.sh +19 -0
  86. data/spec/action_class_finder_spec.rb +12 -0
  87. data/spec/actions/button_action_spec.rb +8 -8
  88. data/spec/actions/generic_action_spec.rb +92 -56
  89. data/spec/actions/input_action_spec.rb +7 -7
  90. data/spec/actions/link_action_spec.rb +10 -10
  91. data/spec/builder/custom_builder_spec.rb +36 -20
  92. data/spec/builder/error_proc_spec.rb +4 -4
  93. data/spec/builder/semantic_fields_for_spec.rb +28 -29
  94. data/spec/fast_spec_helper.rb +12 -0
  95. data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
  96. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  97. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  98. data/spec/helpers/action_helper_spec.rb +75 -103
  99. data/spec/helpers/actions_helper_spec.rb +17 -17
  100. data/spec/helpers/form_helper_spec.rb +84 -33
  101. data/spec/helpers/input_helper_spec.rb +333 -285
  102. data/spec/helpers/inputs_helper_spec.rb +167 -121
  103. data/spec/helpers/reflection_helper_spec.rb +3 -3
  104. data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
  105. data/spec/i18n_spec.rb +26 -26
  106. data/spec/input_class_finder_spec.rb +10 -0
  107. data/spec/inputs/base/collections_spec.rb +76 -0
  108. data/spec/inputs/base/validations_spec.rb +480 -0
  109. data/spec/inputs/boolean_input_spec.rb +100 -65
  110. data/spec/inputs/check_boxes_input_spec.rb +200 -101
  111. data/spec/inputs/color_input_spec.rb +85 -0
  112. data/spec/inputs/country_input_spec.rb +20 -20
  113. data/spec/inputs/custom_input_spec.rb +3 -4
  114. data/spec/inputs/datalist_input_spec.rb +61 -0
  115. data/spec/inputs/date_picker_input_spec.rb +449 -0
  116. data/spec/inputs/date_select_input_spec.rb +249 -0
  117. data/spec/inputs/datetime_picker_input_spec.rb +490 -0
  118. data/spec/inputs/datetime_select_input_spec.rb +209 -0
  119. data/spec/inputs/email_input_spec.rb +5 -5
  120. data/spec/inputs/file_input_spec.rb +6 -6
  121. data/spec/inputs/hidden_input_spec.rb +22 -35
  122. data/spec/inputs/include_blank_spec.rb +11 -11
  123. data/spec/inputs/label_spec.rb +62 -25
  124. data/spec/inputs/number_input_spec.rb +112 -112
  125. data/spec/inputs/password_input_spec.rb +5 -5
  126. data/spec/inputs/phone_input_spec.rb +5 -5
  127. data/spec/inputs/placeholder_spec.rb +6 -6
  128. data/spec/inputs/radio_input_spec.rb +99 -55
  129. data/spec/inputs/range_input_spec.rb +66 -66
  130. data/spec/inputs/readonly_spec.rb +50 -0
  131. data/spec/inputs/search_input_spec.rb +5 -5
  132. data/spec/inputs/select_input_spec.rb +170 -170
  133. data/spec/inputs/string_input_spec.rb +68 -16
  134. data/spec/inputs/text_input_spec.rb +16 -16
  135. data/spec/inputs/time_picker_input_spec.rb +455 -0
  136. data/spec/inputs/time_select_input_spec.rb +261 -0
  137. data/spec/inputs/time_zone_input_spec.rb +54 -28
  138. data/spec/inputs/url_input_spec.rb +5 -5
  139. data/spec/inputs/with_options_spec.rb +7 -7
  140. data/spec/localizer_spec.rb +39 -17
  141. data/spec/namespaced_class_finder_spec.rb +79 -0
  142. data/spec/schema.rb +21 -0
  143. data/spec/spec_helper.rb +254 -221
  144. data/spec/support/custom_macros.rb +128 -95
  145. data/spec/support/shared_examples.rb +12 -0
  146. data/spec/support/specialized_class_finder_shared_example.rb +27 -0
  147. data/spec/support/test_environment.rb +26 -10
  148. metadata +177 -238
  149. data/.travis.yml +0 -8
  150. data/Appraisals +0 -11
  151. data/CHANGELOG +0 -371
  152. data/gemfiles/rails-3.0.gemfile +0 -7
  153. data/gemfiles/rails-3.1.gemfile +0 -7
  154. data/gemfiles/rails-3.2.gemfile +0 -7
  155. data/lib/formtastic/helpers/buttons_helper.rb +0 -310
  156. data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
  157. data/lib/formtastic/util.rb +0 -25
  158. data/lib/tasks/verify_rcov.rb +0 -44
  159. data/spec/helpers/buttons_helper_spec.rb +0 -166
  160. data/spec/helpers/commit_button_helper_spec.rb +0 -530
  161. data/spec/inputs/date_input_spec.rb +0 -227
  162. data/spec/inputs/datetime_input_spec.rb +0 -185
  163. data/spec/inputs/time_input_spec.rb +0 -267
  164. data/spec/support/deferred_garbage_collection.rb +0 -21
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'range input' do
4
+ RSpec.describe 'range input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -57,15 +57,15 @@ describe 'range input' do
57
57
  end
58
58
 
59
59
  it 'should index the id of the wrapper' do
60
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
60
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
61
61
  end
62
62
 
63
63
  it 'should index the id of the select tag' do
64
- output_buffer.should have_tag("input#post_author_attributes_3_name")
64
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
65
65
  end
66
66
 
67
67
  it 'should index the name of the select tag' do
68
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
68
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
69
69
  end
70
70
 
71
71
  end
@@ -73,7 +73,7 @@ describe 'range input' do
73
73
 
74
74
  describe "when validations require a minimum value (:greater_than)" do
75
75
  before do
76
- @new_post.class.stub!(:validators_on).with(:title).and_return([
76
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
77
77
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
78
78
  ])
79
79
  end
@@ -82,68 +82,68 @@ describe 'range input' do
82
82
  concat(semantic_form_for(@new_post) do |builder|
83
83
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
84
84
  end)
85
- output_buffer.should have_tag('input[@min="5"]')
85
+ expect(output_buffer).to have_tag('input[@min="5"]')
86
86
  end
87
87
 
88
88
  it "should allow :input_html to override :min through :in" do
89
89
  concat(semantic_form_for(@new_post) do |builder|
90
90
  builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
91
91
  end)
92
- output_buffer.should have_tag('input[@min="5"]')
92
+ expect(output_buffer).to have_tag('input[@min="5"]')
93
93
  end
94
94
 
95
95
  it "should allow options to override :min" do
96
96
  concat(semantic_form_for(@new_post) do |builder|
97
97
  builder.input(:title, :as => :range, :min => 5)
98
98
  end)
99
- output_buffer.should have_tag('input[@min="5"]')
99
+ expect(output_buffer).to have_tag('input[@min="5"]')
100
100
  end
101
101
 
102
102
  it "should allow options to override :min through :in" do
103
103
  concat(semantic_form_for(@new_post) do |builder|
104
104
  builder.input(:title, :as => :range, :in => 5..102)
105
105
  end)
106
- output_buffer.should have_tag('input[@min="5"]')
106
+ expect(output_buffer).to have_tag('input[@min="5"]')
107
107
  end
108
108
 
109
109
  describe "and the column is an integer" do
110
110
  before do
111
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
111
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
112
112
  end
113
113
 
114
114
  it "should add a min attribute to the input one greater than the validation" do
115
115
  concat(semantic_form_for(@new_post) do |builder|
116
116
  builder.input(:title, :as => :range)
117
117
  end)
118
- output_buffer.should have_tag('input[@min="3"]')
118
+ expect(output_buffer).to have_tag('input[@min="3"]')
119
119
  end
120
120
  end
121
121
 
122
122
  describe "and the column is a float" do
123
123
  before do
124
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
124
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
125
125
  end
126
126
 
127
127
  it "should raise an error" do
128
- lambda {
128
+ expect {
129
129
  concat(semantic_form_for(@new_post) do |builder|
130
130
  builder.input(:title, :as => :range)
131
131
  end)
132
- }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
132
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
133
133
  end
134
134
  end
135
135
 
136
136
  describe "and the column is a big decimal" do
137
137
  before do
138
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
138
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
139
139
  end
140
140
 
141
141
  it "should raise an error" do
142
- lambda {
142
+ expect {
143
143
  concat(semantic_form_for(@new_post) do |builder|
144
144
  builder.input(:title, :as => :range)
145
145
  end)
146
- }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
146
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
147
147
  end
148
148
  end
149
149
 
@@ -151,7 +151,7 @@ describe 'range input' do
151
151
 
152
152
  describe "when validations require a minimum value (:greater_than_or_equal_to)" do
153
153
  before do
154
- @new_post.class.stub!(:validators_on).with(:title).and_return([
154
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
155
155
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
156
156
  ])
157
157
  end
@@ -160,56 +160,56 @@ describe 'range input' do
160
160
  concat(semantic_form_for(@new_post) do |builder|
161
161
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
162
162
  end)
163
- output_buffer.should have_tag('input[@min="5"]')
163
+ expect(output_buffer).to have_tag('input[@min="5"]')
164
164
  end
165
165
 
166
166
  it "should allow options to override :min" do
167
167
  concat(semantic_form_for(@new_post) do |builder|
168
168
  builder.input(:title, :as => :range, :min => 5)
169
169
  end)
170
- output_buffer.should have_tag('input[@min="5"]')
170
+ expect(output_buffer).to have_tag('input[@min="5"]')
171
171
  end
172
172
 
173
173
  it "should allow :input_html to override :min with :in" do
174
174
  concat(semantic_form_for(@new_post) do |builder|
175
175
  builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
176
176
  end)
177
- output_buffer.should have_tag('input[@min="5"]')
177
+ expect(output_buffer).to have_tag('input[@min="5"]')
178
178
  end
179
179
 
180
180
  it "should allow options to override :min with :in" do
181
181
  concat(semantic_form_for(@new_post) do |builder|
182
182
  builder.input(:title, :as => :range, :in => 5..102)
183
183
  end)
184
- output_buffer.should have_tag('input[@min="5"]')
184
+ expect(output_buffer).to have_tag('input[@min="5"]')
185
185
  end
186
186
 
187
187
 
188
188
  [:integer, :decimal, :float].each do |column_type|
189
189
  describe "and the column is a #{column_type}" do
190
190
  before do
191
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
191
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
192
192
  end
193
193
 
194
194
  it "should add a max attribute to the input equal to the validation" do
195
195
  concat(semantic_form_for(@new_post) do |builder|
196
196
  builder.input(:title, :as => :range)
197
197
  end)
198
- output_buffer.should have_tag('input[@min="2"]')
198
+ expect(output_buffer).to have_tag('input[@min="2"]')
199
199
  end
200
200
  end
201
201
  end
202
202
 
203
203
  describe "and there is no column" do
204
204
  before do
205
- @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
205
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
206
206
  end
207
207
 
208
208
  it "should add a max attribute to the input equal to the validation" do
209
209
  concat(semantic_form_for(@new_post) do |builder|
210
210
  builder.input(:title, :as => :range)
211
211
  end)
212
- output_buffer.should have_tag('input[@min="2"]')
212
+ expect(output_buffer).to have_tag('input[@min="2"]')
213
213
  end
214
214
  end
215
215
  end
@@ -220,14 +220,14 @@ describe 'range input' do
220
220
  concat(semantic_form_for(@new_post) do |builder|
221
221
  builder.input(:title, :as => :range)
222
222
  end)
223
- output_buffer.should have_tag('input[@min="1"]')
223
+ expect(output_buffer).to have_tag('input[@min="1"]')
224
224
  end
225
225
 
226
226
  end
227
227
 
228
228
  describe "when validations require a maximum value (:less_than)" do
229
229
  before do
230
- @new_post.class.stub!(:validators_on).with(:title).and_return([
230
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
231
231
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
232
232
  ])
233
233
  end
@@ -236,68 +236,68 @@ describe 'range input' do
236
236
  concat(semantic_form_for(@new_post) do |builder|
237
237
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
238
238
  end)
239
- output_buffer.should have_tag('input[@max="102"]')
239
+ expect(output_buffer).to have_tag('input[@max="102"]')
240
240
  end
241
241
 
242
242
  it "should allow option to override :max" do
243
243
  concat(semantic_form_for(@new_post) do |builder|
244
244
  builder.input(:title, :as => :range, :max => 102)
245
245
  end)
246
- output_buffer.should have_tag('input[@max="102"]')
246
+ expect(output_buffer).to have_tag('input[@max="102"]')
247
247
  end
248
248
 
249
249
  it "should allow :input_html to override :max with :in" do
250
250
  concat(semantic_form_for(@new_post) do |builder|
251
251
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
252
252
  end)
253
- output_buffer.should have_tag('input[@max="102"]')
253
+ expect(output_buffer).to have_tag('input[@max="102"]')
254
254
  end
255
255
 
256
256
  it "should allow option to override :max with :in" do
257
257
  concat(semantic_form_for(@new_post) do |builder|
258
258
  builder.input(:title, :as => :range, :in => 1..102)
259
259
  end)
260
- output_buffer.should have_tag('input[@max="102"]')
260
+ expect(output_buffer).to have_tag('input[@max="102"]')
261
261
  end
262
262
 
263
263
  describe "and the column is an integer" do
264
264
  before do
265
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
265
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
266
266
  end
267
267
 
268
268
  it "should add a max attribute to the input one greater than the validation" do
269
269
  concat(semantic_form_for(@new_post) do |builder|
270
270
  builder.input(:title, :as => :range)
271
271
  end)
272
- output_buffer.should have_tag('input[@max="19"]')
272
+ expect(output_buffer).to have_tag('input[@max="19"]')
273
273
  end
274
274
  end
275
275
 
276
276
  describe "and the column is a float" do
277
277
  before do
278
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
278
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
279
279
  end
280
280
 
281
281
  it "should raise an error" do
282
- lambda {
282
+ expect {
283
283
  concat(semantic_form_for(@new_post) do |builder|
284
284
  builder.input(:title, :as => :range)
285
285
  end)
286
- }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
286
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
287
287
  end
288
288
  end
289
289
 
290
290
  describe "and the column is a big decimal" do
291
291
  before do
292
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
292
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
293
293
  end
294
294
 
295
295
  it "should raise an error" do
296
- lambda {
296
+ expect {
297
297
  concat(semantic_form_for(@new_post) do |builder|
298
298
  builder.input(:title, :as => :range)
299
299
  end)
300
- }.should raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
300
+ }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
301
301
  end
302
302
  end
303
303
 
@@ -305,7 +305,7 @@ describe 'range input' do
305
305
 
306
306
  describe "when validations require a maximum value (:less_than_or_equal_to)" do
307
307
  before do
308
- @new_post.class.stub!(:validators_on).with(:title).and_return([
308
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
309
309
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
310
310
  ])
311
311
  end
@@ -314,55 +314,55 @@ describe 'range input' do
314
314
  concat(semantic_form_for(@new_post) do |builder|
315
315
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
316
316
  end)
317
- output_buffer.should have_tag('input[@max="102"]')
317
+ expect(output_buffer).to have_tag('input[@max="102"]')
318
318
  end
319
319
 
320
320
  it "should allow options to override :max" do
321
321
  concat(semantic_form_for(@new_post) do |builder|
322
322
  builder.input(:title, :as => :range, :max => 102)
323
323
  end)
324
- output_buffer.should have_tag('input[@max="102"]')
324
+ expect(output_buffer).to have_tag('input[@max="102"]')
325
325
  end
326
326
 
327
327
  it "should allow :input_html to override :max with :in" do
328
328
  concat(semantic_form_for(@new_post) do |builder|
329
329
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
330
330
  end)
331
- output_buffer.should have_tag('input[@max="102"]')
331
+ expect(output_buffer).to have_tag('input[@max="102"]')
332
332
  end
333
333
 
334
334
  it "should allow options to override :max with :in" do
335
335
  concat(semantic_form_for(@new_post) do |builder|
336
336
  builder.input(:title, :as => :range, :in => 1..102)
337
337
  end)
338
- output_buffer.should have_tag('input[@max="102"]')
338
+ expect(output_buffer).to have_tag('input[@max="102"]')
339
339
  end
340
340
 
341
341
  [:integer, :decimal, :float].each do |column_type|
342
342
  describe "and the column is a #{column_type}" do
343
343
  before do
344
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
344
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
345
345
  end
346
346
 
347
347
  it "should add a max attribute to the input equal to the validation" do
348
348
  concat(semantic_form_for(@new_post) do |builder|
349
349
  builder.input(:title, :as => :range)
350
350
  end)
351
- output_buffer.should have_tag('input[@max="20"]')
351
+ expect(output_buffer).to have_tag('input[@max="20"]')
352
352
  end
353
353
  end
354
354
  end
355
355
 
356
356
  describe "and there is no column" do
357
357
  before do
358
- @new_post.stub!(:column_for_attribute).with(:title).and_return(nil)
358
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
359
359
  end
360
360
 
361
361
  it "should add a max attribute to the input equal to the validation" do
362
362
  concat(semantic_form_for(@new_post) do |builder|
363
363
  builder.input(:title, :as => :range)
364
364
  end)
365
- output_buffer.should have_tag('input[@max="20"]')
365
+ expect(output_buffer).to have_tag('input[@max="20"]')
366
366
  end
367
367
  end
368
368
  end
@@ -373,14 +373,14 @@ describe 'range input' do
373
373
  concat(semantic_form_for(@new_post) do |builder|
374
374
  builder.input(:title, :as => :range)
375
375
  end)
376
- output_buffer.should have_tag('input[@max="100"]')
376
+ expect(output_buffer).to have_tag('input[@max="100"]')
377
377
  end
378
378
 
379
379
  end
380
380
 
381
381
  describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
382
382
  before do
383
- @new_post.class.stub!(:validators_on).with(:title).and_return([
383
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
384
384
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
385
385
  ])
386
386
  end
@@ -389,13 +389,13 @@ describe 'range input' do
389
389
  concat(semantic_form_for(@new_post) do |builder|
390
390
  builder.input(:title, :as => :range)
391
391
  end)
392
- output_buffer.should have_tag('input[@min="2"]')
392
+ expect(output_buffer).to have_tag('input[@min="2"]')
393
393
  end
394
394
  end
395
395
 
396
396
  describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
397
397
  before do
398
- @new_post.class.stub!(:validators_on).with(:title).and_return([
398
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
399
399
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
400
400
  ])
401
401
  end
@@ -404,14 +404,14 @@ describe 'range input' do
404
404
  concat(semantic_form_for(@new_post) do |builder|
405
405
  builder.input(:title, :as => :range)
406
406
  end)
407
- output_buffer.should have_tag('input[@max="2"]')
407
+ expect(output_buffer).to have_tag('input[@max="2"]')
408
408
  end
409
409
  end
410
410
 
411
411
  describe "when validations require only an integer (:only_integer)" do
412
412
 
413
413
  before do
414
- @new_post.class.stub!(:validators_on).with(:title).and_return([
414
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
415
415
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
416
416
  ])
417
417
  end
@@ -420,21 +420,21 @@ describe 'range input' do
420
420
  concat(semantic_form_for(@new_post) do |builder|
421
421
  builder.input(:title, :as => :range)
422
422
  end)
423
- output_buffer.should have_tag('input[@step="1"]')
423
+ expect(output_buffer).to have_tag('input[@step="1"]')
424
424
  end
425
425
 
426
426
  it "should let input_html override :step" do
427
427
  concat(semantic_form_for(@new_post) do |builder|
428
428
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
429
429
  end)
430
- output_buffer.should have_tag('input[@step="3"]')
430
+ expect(output_buffer).to have_tag('input[@step="3"]')
431
431
  end
432
432
 
433
433
  it "should let options override :step" do
434
434
  concat(semantic_form_for(@new_post) do |builder|
435
435
  builder.input(:title, :as => :range, :step => 3)
436
436
  end)
437
- output_buffer.should have_tag('input[@step="3"]')
437
+ expect(output_buffer).to have_tag('input[@step="3"]')
438
438
  end
439
439
 
440
440
  end
@@ -442,7 +442,7 @@ describe 'range input' do
442
442
  describe "when validations require a :step (non standard)" do
443
443
 
444
444
  before do
445
- @new_post.class.stub!(:validators_on).with(:title).and_return([
445
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
446
446
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
447
447
  ])
448
448
  end
@@ -451,21 +451,21 @@ describe 'range input' do
451
451
  concat(semantic_form_for(@new_post) do |builder|
452
452
  builder.input(:title, :as => :range)
453
453
  end)
454
- output_buffer.should have_tag('input[@step="2"]')
454
+ expect(output_buffer).to have_tag('input[@step="2"]')
455
455
  end
456
456
 
457
457
  it "should let input_html override :step" do
458
458
  concat(semantic_form_for(@new_post) do |builder|
459
459
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
460
460
  end)
461
- output_buffer.should have_tag('input[@step="3"]')
461
+ expect(output_buffer).to have_tag('input[@step="3"]')
462
462
  end
463
463
 
464
464
  it "should let options override :step" do
465
465
  concat(semantic_form_for(@new_post) do |builder|
466
466
  builder.input(:title, :as => :range, :step => 3)
467
467
  end)
468
- output_buffer.should have_tag('input[@step="3"]')
468
+ expect(output_buffer).to have_tag('input[@step="3"]')
469
469
  end
470
470
 
471
471
  end
@@ -473,7 +473,7 @@ describe 'range input' do
473
473
  describe "when validations do not specify :step (non standard) or :only_integer" do
474
474
 
475
475
  before do
476
- @new_post.class.stub!(:validators_on).with(:title).and_return([
476
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
477
477
  active_model_numericality_validator([:title], {:allow_nil=>false})
478
478
  ])
479
479
  end
@@ -482,21 +482,21 @@ describe 'range input' do
482
482
  concat(semantic_form_for(@new_post) do |builder|
483
483
  builder.input(:title, :as => :range)
484
484
  end)
485
- output_buffer.should have_tag('input[@step="1"]')
485
+ expect(output_buffer).to have_tag('input[@step="1"]')
486
486
  end
487
487
 
488
488
  it "should let input_html set :step" do
489
489
  concat(semantic_form_for(@new_post) do |builder|
490
490
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
491
491
  end)
492
- output_buffer.should have_tag('input[@step="3"]')
492
+ expect(output_buffer).to have_tag('input[@step="3"]')
493
493
  end
494
494
 
495
495
  it "should let options set :step" do
496
496
  concat(semantic_form_for(@new_post) do |builder|
497
497
  builder.input(:title, :as => :range, :step => 3)
498
498
  end)
499
- output_buffer.should have_tag('input[@step="3"]')
499
+ expect(output_buffer).to have_tag('input[@step="3"]')
500
500
  end
501
501
 
502
502
  end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'readonly option' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
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 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).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 have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'search input' do
4
+ RSpec.describe 'search input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -56,15 +56,15 @@ describe 'search input' do
56
56
  end
57
57
 
58
58
  it 'should index the id of the wrapper' do
59
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
59
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
60
60
  end
61
61
 
62
62
  it 'should index the id of the select tag' do
63
- output_buffer.should have_tag("input#post_author_attributes_3_name")
63
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
64
64
  end
65
65
 
66
66
  it 'should index the name of the select tag' do
67
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
67
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
68
68
  end
69
69
 
70
70
  end
@@ -75,7 +75,7 @@ describe 'search input' do
75
75
  concat(semantic_form_for(@new_post) do |builder|
76
76
  concat(builder.input(:title, :as => :search, :required => true))
77
77
  end)
78
- output_buffer.should have_tag("input[@required]")
78
+ expect(output_buffer).to have_tag("input[@required]")
79
79
  end
80
80
  end
81
81
  end