formtastic 3.1.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +3 -2
  5. data/CHANGELOG.md +61 -0
  6. data/Gemfile.lock +140 -0
  7. data/MIT-LICENSE +1 -1
  8. data/{README.textile → README.md} +183 -167
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +20 -1
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +12 -16
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_6.1/Gemfile +5 -0
  16. data/gemfiles/rails_7.0/Gemfile +5 -0
  17. data/gemfiles/rails_7.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +1 -0
  20. data/lib/formtastic/actions/base.rb +1 -0
  21. data/lib/formtastic/actions/button_action.rb +1 -0
  22. data/lib/formtastic/actions/buttonish.rb +1 -0
  23. data/lib/formtastic/actions/input_action.rb +1 -0
  24. data/lib/formtastic/actions/link_action.rb +1 -0
  25. data/lib/formtastic/actions.rb +7 -3
  26. data/lib/formtastic/deprecation.rb +2 -38
  27. data/lib/formtastic/engine.rb +4 -1
  28. data/lib/formtastic/form_builder.rb +12 -24
  29. data/lib/formtastic/helpers/action_helper.rb +2 -48
  30. data/lib/formtastic/helpers/actions_helper.rb +1 -0
  31. data/lib/formtastic/helpers/enum.rb +14 -0
  32. data/lib/formtastic/helpers/errors_helper.rb +3 -2
  33. data/lib/formtastic/helpers/fieldset_wrapper.rb +14 -9
  34. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  35. data/lib/formtastic/helpers/form_helper.rb +2 -1
  36. data/lib/formtastic/helpers/input_helper.rb +20 -76
  37. data/lib/formtastic/helpers/inputs_helper.rb +29 -23
  38. data/lib/formtastic/helpers/reflection.rb +1 -0
  39. data/lib/formtastic/helpers.rb +2 -2
  40. data/lib/formtastic/html_attributes.rb +1 -0
  41. data/lib/formtastic/i18n.rb +2 -1
  42. data/lib/formtastic/input_class_finder.rb +1 -0
  43. data/lib/formtastic/inputs/base/associations.rb +1 -0
  44. data/lib/formtastic/inputs/base/choices.rb +3 -2
  45. data/lib/formtastic/inputs/base/collections.rb +46 -10
  46. data/lib/formtastic/inputs/base/database.rb +5 -7
  47. data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
  48. data/lib/formtastic/inputs/base/errors.rb +7 -6
  49. data/lib/formtastic/inputs/base/fileish.rb +1 -0
  50. data/lib/formtastic/inputs/base/hints.rb +2 -1
  51. data/lib/formtastic/inputs/base/html.rb +9 -7
  52. data/lib/formtastic/inputs/base/labelling.rb +3 -2
  53. data/lib/formtastic/inputs/base/naming.rb +5 -4
  54. data/lib/formtastic/inputs/base/numeric.rb +1 -0
  55. data/lib/formtastic/inputs/base/options.rb +3 -3
  56. data/lib/formtastic/inputs/base/placeholder.rb +1 -0
  57. data/lib/formtastic/inputs/base/stringish.rb +1 -0
  58. data/lib/formtastic/inputs/base/timeish.rb +9 -4
  59. data/lib/formtastic/inputs/base/validations.rb +39 -12
  60. data/lib/formtastic/inputs/base/wrapping.rb +1 -0
  61. data/lib/formtastic/inputs/base.rb +3 -2
  62. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  63. data/lib/formtastic/inputs/check_boxes_input.rb +15 -6
  64. data/lib/formtastic/inputs/color_input.rb +1 -1
  65. data/lib/formtastic/inputs/country_input.rb +4 -1
  66. data/lib/formtastic/inputs/datalist_input.rb +1 -0
  67. data/lib/formtastic/inputs/date_picker_input.rb +1 -0
  68. data/lib/formtastic/inputs/date_select_input.rb +1 -0
  69. data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
  70. data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
  71. data/lib/formtastic/inputs/email_input.rb +1 -0
  72. data/lib/formtastic/inputs/file_input.rb +1 -0
  73. data/lib/formtastic/inputs/hidden_input.rb +3 -2
  74. data/lib/formtastic/inputs/number_input.rb +1 -0
  75. data/lib/formtastic/inputs/password_input.rb +1 -0
  76. data/lib/formtastic/inputs/phone_input.rb +1 -0
  77. data/lib/formtastic/inputs/radio_input.rb +21 -0
  78. data/lib/formtastic/inputs/range_input.rb +1 -0
  79. data/lib/formtastic/inputs/search_input.rb +1 -0
  80. data/lib/formtastic/inputs/select_input.rb +30 -1
  81. data/lib/formtastic/inputs/string_input.rb +1 -0
  82. data/lib/formtastic/inputs/text_input.rb +1 -0
  83. data/lib/formtastic/inputs/time_picker_input.rb +1 -0
  84. data/lib/formtastic/inputs/time_select_input.rb +1 -0
  85. data/lib/formtastic/inputs/time_zone_input.rb +17 -6
  86. data/lib/formtastic/inputs/url_input.rb +1 -0
  87. data/lib/formtastic/inputs.rb +33 -29
  88. data/lib/formtastic/localized_string.rb +1 -0
  89. data/lib/formtastic/localizer.rb +21 -22
  90. data/lib/formtastic/namespaced_class_finder.rb +8 -9
  91. data/lib/formtastic/version.rb +2 -1
  92. data/lib/formtastic.rb +10 -11
  93. data/lib/generators/formtastic/form/form_generator.rb +2 -1
  94. data/lib/generators/formtastic/input/input_generator.rb +47 -0
  95. data/lib/generators/formtastic/install/install_generator.rb +1 -0
  96. data/lib/generators/templates/formtastic.rb +15 -13
  97. data/lib/generators/templates/input.rb +19 -0
  98. data/sample/basic_inputs.html +1 -1
  99. data/script/integration-template.rb +73 -0
  100. data/script/integration.sh +19 -0
  101. data/spec/action_class_finder_spec.rb +2 -1
  102. data/spec/actions/button_action_spec.rb +21 -20
  103. data/spec/actions/generic_action_spec.rb +134 -133
  104. data/spec/actions/input_action_spec.rb +20 -19
  105. data/spec/actions/link_action_spec.rb +30 -29
  106. data/spec/builder/custom_builder_spec.rb +39 -22
  107. data/spec/builder/error_proc_spec.rb +6 -5
  108. data/spec/builder/semantic_fields_for_spec.rb +46 -45
  109. data/spec/fast_spec_helper.rb +13 -0
  110. data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
  111. data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  112. data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
  113. data/spec/helpers/action_helper_spec.rb +329 -10
  114. data/spec/helpers/actions_helper_spec.rb +43 -42
  115. data/spec/helpers/form_helper_spec.rb +45 -38
  116. data/spec/helpers/input_helper_spec.rb +976 -2
  117. data/spec/helpers/inputs_helper_spec.rb +217 -202
  118. data/spec/helpers/reflection_helper_spec.rb +7 -6
  119. data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
  120. data/spec/i18n_spec.rb +30 -29
  121. data/spec/input_class_finder_spec.rb +2 -1
  122. data/spec/inputs/base/collections_spec.rb +78 -0
  123. data/spec/inputs/base/validations_spec.rb +481 -0
  124. data/spec/inputs/boolean_input_spec.rb +73 -72
  125. data/spec/inputs/check_boxes_input_spec.rb +169 -121
  126. data/spec/inputs/color_input_spec.rb +53 -64
  127. data/spec/inputs/country_input_spec.rb +23 -22
  128. data/spec/inputs/custom_input_spec.rb +3 -6
  129. data/spec/inputs/datalist_input_spec.rb +3 -2
  130. data/spec/inputs/date_picker_input_spec.rb +114 -113
  131. data/spec/inputs/date_select_input_spec.rb +76 -61
  132. data/spec/inputs/datetime_picker_input_spec.rb +123 -122
  133. data/spec/inputs/datetime_select_input_spec.rb +85 -68
  134. data/spec/inputs/email_input_spec.rb +17 -16
  135. data/spec/inputs/file_input_spec.rb +18 -17
  136. data/spec/inputs/hidden_input_spec.rb +32 -31
  137. data/spec/inputs/include_blank_spec.rb +10 -9
  138. data/spec/inputs/label_spec.rb +26 -25
  139. data/spec/inputs/number_input_spec.rb +212 -211
  140. data/spec/inputs/password_input_spec.rb +17 -16
  141. data/spec/inputs/phone_input_spec.rb +17 -16
  142. data/spec/inputs/placeholder_spec.rb +18 -17
  143. data/spec/inputs/radio_input_spec.rb +92 -65
  144. data/spec/inputs/range_input_spec.rb +136 -135
  145. data/spec/inputs/readonly_spec.rb +51 -0
  146. data/spec/inputs/search_input_spec.rb +16 -15
  147. data/spec/inputs/select_input_spec.rb +209 -102
  148. data/spec/inputs/string_input_spec.rb +51 -50
  149. data/spec/inputs/text_input_spec.rb +34 -33
  150. data/spec/inputs/time_picker_input_spec.rb +115 -114
  151. data/spec/inputs/time_select_input_spec.rb +84 -70
  152. data/spec/inputs/time_zone_input_spec.rb +58 -31
  153. data/spec/inputs/url_input_spec.rb +17 -16
  154. data/spec/inputs/with_options_spec.rb +9 -8
  155. data/spec/localizer_spec.rb +18 -17
  156. data/spec/namespaced_class_finder_spec.rb +18 -6
  157. data/spec/schema.rb +22 -0
  158. data/spec/spec_helper.rb +172 -260
  159. data/spec/support/custom_macros.rb +74 -76
  160. data/spec/support/deprecation.rb +2 -1
  161. data/spec/support/shared_examples.rb +2 -1233
  162. data/spec/support/specialized_class_finder_shared_example.rb +1 -0
  163. data/spec/support/test_environment.rb +24 -9
  164. metadata +78 -170
  165. data/.travis.yml +0 -29
  166. data/Appraisals +0 -29
  167. data/CHANGELOG +0 -39
  168. data/DEPRECATIONS +0 -49
  169. data/gemfiles/rails_3.2.gemfile +0 -7
  170. data/gemfiles/rails_4.0.4.gemfile +0 -7
  171. data/gemfiles/rails_4.1.gemfile +0 -7
  172. data/gemfiles/rails_4.2.gemfile +0 -7
  173. data/gemfiles/rails_4.gemfile +0 -7
  174. data/gemfiles/rails_edge.gemfile +0 -10
  175. data/lib/formtastic/util.rb +0 -57
  176. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  177. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  178. data/spec/support/deferred_garbage_collection.rb +0 -21
  179. data/spec/util_spec.rb +0 -66
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module CustomMacros
4
5
 
@@ -10,67 +11,67 @@ module CustomMacros
10
11
 
11
12
  def it_should_have_input_wrapper_with_class(class_name)
12
13
  it "should have input wrapper with class '#{class_name}'" do
13
- output_buffer.should have_tag("form li.#{class_name}")
14
+ expect(output_buffer.to_str).to have_tag("form li.#{class_name}")
14
15
  end
15
16
  end
16
17
 
17
18
  def it_should_have_input_wrapper_with_id(id_string)
18
19
  it "should have input wrapper with id '#{id_string}'" do
19
- output_buffer.should have_tag("form li##{id_string}")
20
+ expect(output_buffer.to_str).to have_tag("form li##{id_string}")
20
21
  end
21
22
  end
22
23
 
23
24
  def it_should_not_have_a_label
24
25
  it "should not have a label" do
25
- output_buffer.should_not have_tag("form li label")
26
+ expect(output_buffer.to_str).not_to have_tag("form li label")
26
27
  end
27
28
  end
28
29
 
29
30
  def it_should_have_a_nested_fieldset
30
31
  it "should have a nested_fieldset" do
31
- output_buffer.should have_tag("form li fieldset")
32
+ expect(output_buffer.to_str).to have_tag("form li fieldset")
32
33
  end
33
34
  end
34
35
 
35
36
  def it_should_have_a_nested_fieldset_with_class(klass)
36
37
  it "should have a nested_fieldset with class #{klass}" do
37
- output_buffer.should have_tag("form li fieldset.#{klass}")
38
+ expect(output_buffer.to_str).to have_tag("form li fieldset.#{klass}")
38
39
  end
39
40
  end
40
41
 
41
42
  def it_should_have_a_nested_ordered_list_with_class(klass)
42
43
  it "should have a nested fieldset with class #{klass}" do
43
- output_buffer.should have_tag("form li ol.#{klass}")
44
+ expect(output_buffer.to_str).to have_tag("form li ol.#{klass}")
44
45
  end
45
46
  end
46
47
 
47
48
  def it_should_have_label_with_text(string_or_regex)
48
49
  it "should have a label with text '#{string_or_regex}'" do
49
- output_buffer.should have_tag("form li label", string_or_regex)
50
+ expect(output_buffer.to_str).to have_tag("form li label", :text => string_or_regex)
50
51
  end
51
52
  end
52
53
 
53
54
  def it_should_have_label_for(element_id)
54
55
  it "should have a label for ##{element_id}" do
55
- output_buffer.should have_tag("form li label.label[@for='#{element_id}']")
56
+ expect(output_buffer.to_str).to have_tag("form li label.label[@for='#{element_id}']")
56
57
  end
57
58
  end
58
59
 
59
60
  def it_should_have_an_inline_label_for(element_id)
60
61
  it "should have a label for ##{element_id}" do
61
- output_buffer.should have_tag("form li label[@for='#{element_id}']")
62
+ expect(output_buffer.to_str).to have_tag("form li label[@for='#{element_id}']")
62
63
  end
63
64
  end
64
65
 
65
66
  def it_should_have_input_with_id(element_id)
66
67
  it "should have an input with id '#{element_id}'" do
67
- output_buffer.should have_tag("form li input##{element_id}")
68
+ expect(output_buffer.to_str).to have_tag("form li input##{element_id}")
68
69
  end
69
70
  end
70
71
 
71
72
  def it_should_have_select_with_id(element_id)
72
73
  it "should have a select box with id '#{element_id}'" do
73
- output_buffer.should have_tag("form li select##{element_id}")
74
+ expect(output_buffer.to_str).to have_tag("form li select##{element_id}")
74
75
  end
75
76
  end
76
77
 
@@ -78,7 +79,7 @@ module CustomMacros
78
79
  def it_should_have_tag_with(type, attribute_value_hash)
79
80
  attribute_value_hash.each do |attribute, value|
80
81
  it "should have a #{type} box with #{attribute} '#{value}'" do
81
- output_buffer.should have_tag("form li #{type}[@#{attribute}=\"#{value}\"]")
82
+ expect(output_buffer.to_str).to have_tag("form li #{type}[@#{attribute}=\"#{value}\"]")
82
83
  end
83
84
  end
84
85
  end
@@ -88,44 +89,44 @@ module CustomMacros
88
89
 
89
90
  def it_should_have_many_tags(type, count)
90
91
  it "should have #{count} #{type} tags" do
91
- output_buffer.should have_tag("form li #{type}", count: count)
92
+ expect(output_buffer.to_str).to have_tag("form li #{type}", count: count)
92
93
  end
93
94
  end
94
95
 
95
96
  def it_should_have_input_with_type(input_type)
96
97
  it "should have a #{input_type} input" do
97
- output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
98
+ expect(output_buffer.to_str).to have_tag("form li input[@type=\"#{input_type}\"]")
98
99
  end
99
100
  end
100
101
 
101
102
  def it_should_have_input_with_name(name)
102
103
  it "should have an input named #{name}" do
103
- output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
104
+ expect(output_buffer.to_str).to have_tag("form li input[@name=\"#{name}\"]")
104
105
  end
105
106
  end
106
107
 
107
108
  def it_should_have_select_with_name(name)
108
109
  it "should have an input named #{name}" do
109
- output_buffer.should have_tag("form li select[@name=\"#{name}\"]")
110
+ expect(output_buffer.to_str).to have_tag("form li select[@name=\"#{name}\"]")
110
111
  end
111
112
  end
112
113
 
113
114
  def it_should_have_textarea_with_name(name)
114
115
  it "should have an input named #{name}" do
115
- output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
116
+ expect(output_buffer.to_str).to have_tag("form li textarea[@name=\"#{name}\"]")
116
117
  end
117
118
  end
118
119
 
119
120
  def it_should_have_textarea_with_id(element_id)
120
121
  it "should have an input with id '#{element_id}'" do
121
- output_buffer.should have_tag("form li textarea##{element_id}")
122
+ expect(output_buffer.to_str).to have_tag("form li textarea##{element_id}")
122
123
  end
123
124
  end
124
125
 
125
126
  def it_should_have_label_and_input_with_id(element_id)
126
127
  it "should have an input with id '#{element_id}'" do
127
- output_buffer.should have_tag("form li input##{element_id}")
128
- output_buffer.should have_tag("form li label[@for='#{element_id}']")
128
+ expect(output_buffer.to_str).to have_tag("form li input##{element_id}")
129
+ expect(output_buffer.to_str).to have_tag("form li label[@for='#{element_id}']")
129
130
  end
130
131
  end
131
132
 
@@ -135,7 +136,7 @@ module CustomMacros
135
136
  concat(semantic_form_for(@new_post) do |builder|
136
137
  concat(builder.input(:title, :as => as))
137
138
  end)
138
- output_buffer.should have_tag("form li input[@size='#{Formtastic::FormBuilder.default_text_field_size}']")
139
+ expect(output_buffer.to_str).to have_tag("form li input[@size='#{Formtastic::FormBuilder.default_text_field_size}']")
139
140
  end
140
141
  end
141
142
  end
@@ -146,8 +147,8 @@ module CustomMacros
146
147
  concat(semantic_form_for(@new_post) do |builder|
147
148
  concat(builder.input(:title, :as => as))
148
149
  end)
149
- output_buffer.should have_tag("form li input")
150
- output_buffer.should_not have_tag("form li input[@size]")
150
+ expect(output_buffer.to_str).to have_tag("form li input")
151
+ expect(output_buffer.to_str).not_to have_tag("form li input[@size]")
151
152
  end
152
153
  end
153
154
  end
@@ -157,7 +158,7 @@ module CustomMacros
157
158
  concat(semantic_form_for(@new_post) do |builder|
158
159
  concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
159
160
  end)
160
- output_buffer.should have_tag("form li input.myclass")
161
+ expect(output_buffer.to_str).to have_tag("form li input.myclass")
161
162
  end
162
163
  end
163
164
 
@@ -166,27 +167,28 @@ module CustomMacros
166
167
  concat(semantic_form_for(@new_post) do |builder|
167
168
  concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
168
169
  end)
169
- output_buffer.should have_tag('form li label[@for="myid"]')
170
+ expect(output_buffer.to_str).to have_tag('form li label[@for="myid"]')
170
171
  end
171
172
  end
172
173
 
173
174
  def it_should_have_maxlength_matching_column_limit
174
175
  it 'should have a maxlength matching column limit' do
175
- @new_post.column_for_attribute(:title).limit.should == 50
176
- output_buffer.should have_tag("form li input[@maxlength='50']")
176
+ expect(@new_post.column_for_attribute(:title).limit).to eq(50)
177
+ expect(output_buffer.to_str).to have_tag("form li input[@maxlength='50']")
177
178
  end
178
179
  end
179
180
 
180
181
  def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
181
182
  it 'should use the column size for columns shorter than default_text_field_size' do
182
183
  column_limit_shorted_than_default = 1
183
- @new_post.stub(:column_for_attribute).and_return(double('column', :type => as, :limit => column_limit_shorted_than_default))
184
+ allow(@new_post).to receive(:column_for_attribute)
185
+ .and_return(double('column', :type => as, :limit => column_limit_shorted_than_default))
184
186
 
185
187
  concat(semantic_form_for(@new_post) do |builder|
186
188
  concat(builder.input(:title, :as => as))
187
189
  end)
188
190
 
189
- output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
191
+ expect(output_buffer.to_str).to have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
190
192
  end
191
193
  end
192
194
 
@@ -195,25 +197,25 @@ module CustomMacros
195
197
  before do
196
198
  @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
197
199
  @errors = double('errors')
198
- @errors.stub(:[]).with(errors_matcher(:title)).and_return(@title_errors)
200
+ allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
199
201
  Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
200
- @errors.stub(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
202
+ allow(@errors).to receive(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
201
203
  end
202
- @new_post.stub(:errors).and_return(@errors)
204
+ allow(@new_post).to receive(:errors).and_return(@errors)
203
205
  end
204
206
 
205
207
  it 'should apply an errors class to the list item' do
206
208
  concat(semantic_form_for(@new_post) do |builder|
207
209
  concat(builder.input(:title, :as => type))
208
210
  end)
209
- output_buffer.should have_tag('form li.error')
211
+ expect(output_buffer.to_str).to have_tag('form li.error')
210
212
  end
211
213
 
212
214
  it 'should not wrap the input with the Rails default error wrapping' do
213
215
  concat(semantic_form_for(@new_post) do |builder|
214
216
  concat(builder.input(:title, :as => type))
215
217
  end)
216
- output_buffer.should_not have_tag('div.fieldWithErrors')
218
+ expect(output_buffer.to_str).not_to have_tag('div.fieldWithErrors')
217
219
  end
218
220
 
219
221
  it 'should render a paragraph for the errors' do
@@ -221,7 +223,7 @@ module CustomMacros
221
223
  concat(semantic_form_for(@new_post) do |builder|
222
224
  concat(builder.input(:title, :as => type))
223
225
  end)
224
- output_buffer.should have_tag('form li.error p.inline-errors')
226
+ expect(output_buffer.to_str).to have_tag('form li.error p.inline-errors')
225
227
  end
226
228
 
227
229
  it 'should not display an error list' do
@@ -229,7 +231,7 @@ module CustomMacros
229
231
  concat(semantic_form_for(@new_post) do |builder|
230
232
  concat(builder.input(:title, :as => type))
231
233
  end)
232
- output_buffer.should have_tag('form li.error ul.errors')
234
+ expect(output_buffer.to_str).to have_tag('form li.error ul.errors')
233
235
  end
234
236
  end
235
237
 
@@ -241,15 +243,15 @@ module CustomMacros
241
243
  end
242
244
 
243
245
  it 'should not apply an errors class to the list item' do
244
- output_buffer.should_not have_tag('form li.error')
246
+ expect(output_buffer.to_str).not_to have_tag('form li.error')
245
247
  end
246
248
 
247
249
  it 'should not render a paragraph for the errors' do
248
- output_buffer.should_not have_tag('form li.error p.inline-errors')
250
+ expect(output_buffer.to_str).not_to have_tag('form li.error p.inline-errors')
249
251
  end
250
252
 
251
253
  it 'should not display an error list' do
252
- output_buffer.should_not have_tag('form li.error ul.errors')
254
+ expect(output_buffer.to_str).not_to have_tag('form li.error ul.errors')
253
255
  end
254
256
  end
255
257
 
@@ -261,26 +263,22 @@ module CustomMacros
261
263
  end
262
264
 
263
265
  it 'should not apply an errors class to the list item' do
264
- output_buffer.should_not have_tag('form li.error')
266
+ expect(output_buffer.to_str).not_to have_tag('form li.error')
265
267
  end
266
268
 
267
269
  it 'should not render a paragraph for the errors' do
268
- output_buffer.should_not have_tag('form li.error p.inline-errors')
270
+ expect(output_buffer.to_str).not_to have_tag('form li.error p.inline-errors')
269
271
  end
270
272
 
271
273
  it 'should not display an error list' do
272
- output_buffer.should_not have_tag('form li.error ul.errors')
274
+ expect(output_buffer.to_str).not_to have_tag('form li.error ul.errors')
273
275
  end
274
276
  end
275
277
  end
276
278
 
277
279
  def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
278
280
  it "should call find on the association class when no collection is provided" do
279
- if Formtastic::Util.rails3?
280
- ::Author.should_receive(:scoped)
281
- else
282
- ::Author.should_receive(:where)
283
- end
281
+ expect(::Author).to receive(:where)
284
282
  concat(semantic_form_for(@new_post) do |builder|
285
283
  concat(builder.input(:author, :as => as))
286
284
  end)
@@ -292,14 +290,14 @@ module CustomMacros
292
290
 
293
291
  before do
294
292
  @authors = ([::Author.all] * 2).flatten
295
- output_buffer.replace ''
293
+ @output_buffer = ActionView::OutputBuffer.new ''
296
294
  end
297
295
 
298
296
  it 'should use the provided collection' do
299
297
  concat(semantic_form_for(@new_post) do |builder|
300
298
  concat(builder.input(:author, :as => as, :collection => @authors))
301
299
  end)
302
- output_buffer.should have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
300
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
303
301
  end
304
302
 
305
303
  describe 'and the :collection is an array of strings' do
@@ -313,24 +311,24 @@ module CustomMacros
313
311
  end)
314
312
 
315
313
  @categories.each do |value|
316
- output_buffer.should have_tag("form li.#{as}", /#{value}/)
317
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
314
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{value}/)
315
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{value}']")
318
316
  end
319
317
  end
320
318
 
321
319
  if as == :radio
322
320
  it 'should generate a sanitized label for attribute' do
323
- @bob.stub(:category_name).and_return(@categories)
321
+ allow(@bob).to receive(:category_name).and_return(@categories)
324
322
  concat(semantic_form_for(@new_post) do |builder|
325
323
  fields = builder.semantic_fields_for(@bob) do |bob_builder|
326
324
  concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
327
325
  end
328
326
  concat(fields)
329
327
  end)
330
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
331
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
332
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
333
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_quasi-serious_inventions']")
328
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
329
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
330
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
331
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_category_name_quasi-serious_inventions']")
334
332
  end
335
333
  end
336
334
  end
@@ -346,8 +344,8 @@ module CustomMacros
346
344
  end)
347
345
 
348
346
  @categories.each do |label, value|
349
- output_buffer.should have_tag("form li.#{as}", /#{label}/)
350
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
347
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{label}/)
348
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{value}']")
351
349
  end
352
350
  end
353
351
  end
@@ -364,9 +362,9 @@ module CustomMacros
364
362
 
365
363
  @categories.each do |text, value|
366
364
  label = as == :select ? :option : :label
367
- output_buffer.should have_tag("form li.#{as} #{label}", /#{text}/i)
368
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
369
- output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
365
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{label}", :text => /#{text}/i)
366
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
367
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
370
368
  end
371
369
  end
372
370
  end
@@ -382,8 +380,8 @@ module CustomMacros
382
380
  concat(builder.input(:category_name, :as => as, :collection => @choices))
383
381
  end)
384
382
 
385
- output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
386
- output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
383
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}#post_category_name_true")
384
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}#post_category_name_false")
387
385
  end
388
386
  end
389
387
  end
@@ -400,8 +398,8 @@ module CustomMacros
400
398
 
401
399
  @categories.each do |value|
402
400
  label = as == :select ? :option : :label
403
- output_buffer.should have_tag("form li.#{as} #{label}", /#{value}/i)
404
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
401
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{label}", :text => /#{value}/i)
402
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
405
403
  end
406
404
  end
407
405
  end
@@ -417,8 +415,8 @@ module CustomMacros
417
415
  end)
418
416
 
419
417
  @categories.each do |label, value|
420
- output_buffer.should have_tag("form li.#{as}", /#{label}/)
421
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
418
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{label}/)
419
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{value}']")
422
420
  end
423
421
  end
424
422
 
@@ -437,7 +435,7 @@ module CustomMacros
437
435
 
438
436
  it 'should have options with text content from the specified method' do
439
437
  ::Author.all.each do |author|
440
- output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
438
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{author.login}/)
441
439
  end
442
440
  end
443
441
  end
@@ -453,7 +451,7 @@ module CustomMacros
453
451
 
454
452
  it 'should have options with the proc applied to each' do
455
453
  ::Author.all.each do |author|
456
- output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
454
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{author.login.reverse}/)
457
455
  end
458
456
  end
459
457
  end
@@ -472,7 +470,7 @@ module CustomMacros
472
470
 
473
471
  it 'should have options with the proc applied to each' do
474
472
  ::Author.all.each do |author|
475
- output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
473
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /#{author.login.reverse}/)
476
474
  end
477
475
  end
478
476
  end
@@ -483,8 +481,8 @@ module CustomMacros
483
481
 
484
482
  describe "when the collection objects respond to #{label_method}" do
485
483
  before do
486
- @fred.stub(:respond_to?) { |m| m.to_s == label_method || m.to_s == 'id' }
487
- [@fred, @bob].each { |a| a.stub(label_method).and_return('The Label Text') }
484
+ allow(@fred).to receive(:respond_to?) { |m| m.to_s == label_method || m.to_s == 'id' }
485
+ [@fred, @bob].each { |a| allow(a).to receive(label_method).and_return('The Label Text') }
488
486
 
489
487
  with_deprecation_silenced do
490
488
  concat(semantic_form_for(@new_post) do |builder|
@@ -495,7 +493,7 @@ module CustomMacros
495
493
 
496
494
  it "should render the options with #{label_method} as the label" do
497
495
  ::Author.all.each do |author|
498
- output_buffer.should have_tag("form li.#{as}", /The Label Text/)
496
+ expect(output_buffer.to_str).to have_tag("form li.#{as}", :text => /The Label Text/)
499
497
  end
500
498
  end
501
499
  end
@@ -516,7 +514,7 @@ module CustomMacros
516
514
 
517
515
  it 'should have options with values from specified method' do
518
516
  ::Author.all.each do |author|
519
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
517
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
520
518
  end
521
519
  end
522
520
  end
@@ -532,7 +530,7 @@ module CustomMacros
532
530
 
533
531
  it 'should have options with the proc applied to each value' do
534
532
  ::Author.all.each do |author|
535
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
533
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
536
534
  end
537
535
  end
538
536
  end
@@ -551,7 +549,7 @@ module CustomMacros
551
549
 
552
550
  it 'should have options with the proc applied to each value' do
553
551
  ::Author.all.each do |author|
554
- output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
552
+ expect(output_buffer.to_str).to have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
555
553
  end
556
554
  end
557
555
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  def with_deprecation_silenced(&block)
2
- ::ActiveSupport::Deprecation.silence do
3
+ ::Formtastic::Deprecation.silence do
3
4
  yield
4
5
  end
5
6
  end