formtastic 4.0.0 → 5.0.0

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +13 -13
  3. data/CHANGELOG.md +10 -1
  4. data/Gemfile.lock +99 -64
  5. data/README.md +7 -2
  6. data/formtastic.gemspec +5 -3
  7. data/gemfiles/{rails_5.2 → rails_7.0}/Gemfile +1 -1
  8. data/gemfiles/rails_7.1/Gemfile +5 -0
  9. data/gemfiles/rails_edge/Gemfile +1 -1
  10. data/lib/formtastic/action_class_finder.rb +1 -0
  11. data/lib/formtastic/actions/base.rb +1 -0
  12. data/lib/formtastic/actions/button_action.rb +1 -0
  13. data/lib/formtastic/actions/buttonish.rb +1 -0
  14. data/lib/formtastic/actions/input_action.rb +1 -0
  15. data/lib/formtastic/actions/link_action.rb +1 -0
  16. data/lib/formtastic/actions.rb +1 -0
  17. data/lib/formtastic/deprecation.rb +2 -1
  18. data/lib/formtastic/engine.rb +1 -0
  19. data/lib/formtastic/form_builder.rb +1 -0
  20. data/lib/formtastic/helpers/action_helper.rb +1 -0
  21. data/lib/formtastic/helpers/actions_helper.rb +1 -0
  22. data/lib/formtastic/helpers/enum.rb +1 -0
  23. data/lib/formtastic/helpers/errors_helper.rb +1 -0
  24. data/lib/formtastic/helpers/fieldset_wrapper.rb +1 -0
  25. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  26. data/lib/formtastic/helpers/form_helper.rb +1 -0
  27. data/lib/formtastic/helpers/input_helper.rb +2 -4
  28. data/lib/formtastic/helpers/inputs_helper.rb +2 -1
  29. data/lib/formtastic/helpers/reflection.rb +1 -0
  30. data/lib/formtastic/helpers.rb +1 -1
  31. data/lib/formtastic/html_attributes.rb +1 -0
  32. data/lib/formtastic/i18n.rb +1 -0
  33. data/lib/formtastic/input_class_finder.rb +1 -0
  34. data/lib/formtastic/inputs/base/associations.rb +1 -0
  35. data/lib/formtastic/inputs/base/choices.rb +2 -1
  36. data/lib/formtastic/inputs/base/collections.rb +4 -1
  37. data/lib/formtastic/inputs/base/database.rb +5 -7
  38. data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
  39. data/lib/formtastic/inputs/base/errors.rb +3 -2
  40. data/lib/formtastic/inputs/base/fileish.rb +1 -0
  41. data/lib/formtastic/inputs/base/hints.rb +1 -0
  42. data/lib/formtastic/inputs/base/html.rb +2 -1
  43. data/lib/formtastic/inputs/base/labelling.rb +3 -2
  44. data/lib/formtastic/inputs/base/naming.rb +1 -0
  45. data/lib/formtastic/inputs/base/numeric.rb +1 -0
  46. data/lib/formtastic/inputs/base/options.rb +1 -0
  47. data/lib/formtastic/inputs/base/placeholder.rb +1 -0
  48. data/lib/formtastic/inputs/base/stringish.rb +1 -0
  49. data/lib/formtastic/inputs/base/timeish.rb +4 -3
  50. data/lib/formtastic/inputs/base/validations.rb +2 -1
  51. data/lib/formtastic/inputs/base/wrapping.rb +1 -0
  52. data/lib/formtastic/inputs/base.rb +3 -2
  53. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  54. data/lib/formtastic/inputs/check_boxes_input.rb +2 -1
  55. data/lib/formtastic/inputs/color_input.rb +1 -0
  56. data/lib/formtastic/inputs/country_input.rb +1 -0
  57. data/lib/formtastic/inputs/datalist_input.rb +1 -0
  58. data/lib/formtastic/inputs/date_picker_input.rb +1 -0
  59. data/lib/formtastic/inputs/date_select_input.rb +1 -0
  60. data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
  61. data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
  62. data/lib/formtastic/inputs/email_input.rb +1 -0
  63. data/lib/formtastic/inputs/file_input.rb +1 -0
  64. data/lib/formtastic/inputs/hidden_input.rb +3 -2
  65. data/lib/formtastic/inputs/number_input.rb +1 -0
  66. data/lib/formtastic/inputs/password_input.rb +1 -0
  67. data/lib/formtastic/inputs/phone_input.rb +1 -0
  68. data/lib/formtastic/inputs/radio_input.rb +1 -0
  69. data/lib/formtastic/inputs/range_input.rb +1 -0
  70. data/lib/formtastic/inputs/search_input.rb +1 -0
  71. data/lib/formtastic/inputs/select_input.rb +1 -0
  72. data/lib/formtastic/inputs/string_input.rb +1 -0
  73. data/lib/formtastic/inputs/text_input.rb +1 -0
  74. data/lib/formtastic/inputs/time_picker_input.rb +1 -0
  75. data/lib/formtastic/inputs/time_select_input.rb +1 -0
  76. data/lib/formtastic/inputs/time_zone_input.rb +1 -0
  77. data/lib/formtastic/inputs/url_input.rb +1 -0
  78. data/lib/formtastic/inputs.rb +1 -0
  79. data/lib/formtastic/localized_string.rb +1 -0
  80. data/lib/formtastic/localizer.rb +1 -0
  81. data/lib/formtastic/namespaced_class_finder.rb +7 -8
  82. data/lib/formtastic/version.rb +2 -1
  83. data/lib/formtastic.rb +1 -0
  84. data/lib/generators/formtastic/form/form_generator.rb +1 -0
  85. data/lib/generators/formtastic/input/input_generator.rb +1 -0
  86. data/lib/generators/formtastic/install/install_generator.rb +1 -0
  87. data/lib/generators/templates/formtastic.rb +1 -0
  88. data/script/integration-template.rb +2 -3
  89. data/spec/action_class_finder_spec.rb +1 -0
  90. data/spec/actions/button_action_spec.rb +17 -16
  91. data/spec/actions/generic_action_spec.rb +130 -129
  92. data/spec/actions/input_action_spec.rb +16 -15
  93. data/spec/actions/link_action_spec.rb +25 -24
  94. data/spec/builder/custom_builder_spec.rb +5 -4
  95. data/spec/builder/error_proc_spec.rb +2 -1
  96. data/spec/builder/semantic_fields_for_spec.rb +26 -25
  97. data/spec/fast_spec_helper.rb +1 -0
  98. data/spec/generators/formtastic/form/form_generator_spec.rb +8 -7
  99. data/spec/generators/formtastic/input/input_generator_spec.rb +1 -0
  100. data/spec/generators/formtastic/install/install_generator_spec.rb +1 -0
  101. data/spec/helpers/action_helper_spec.rb +15 -14
  102. data/spec/helpers/actions_helper_spec.rb +42 -41
  103. data/spec/helpers/form_helper_spec.rb +26 -19
  104. data/spec/helpers/input_helper_spec.rb +70 -69
  105. data/spec/helpers/inputs_helper_spec.rb +179 -179
  106. data/spec/helpers/reflection_helper_spec.rb +4 -3
  107. data/spec/helpers/semantic_errors_helper_spec.rb +4 -3
  108. data/spec/i18n_spec.rb +13 -12
  109. data/spec/input_class_finder_spec.rb +1 -0
  110. data/spec/inputs/base/collections_spec.rb +2 -0
  111. data/spec/inputs/base/validations_spec.rb +1 -0
  112. data/spec/inputs/boolean_input_spec.rb +66 -65
  113. data/spec/inputs/check_boxes_input_spec.rb +89 -88
  114. data/spec/inputs/color_input_spec.rb +7 -6
  115. data/spec/inputs/country_input_spec.rb +10 -9
  116. data/spec/inputs/custom_input_spec.rb +1 -0
  117. data/spec/inputs/datalist_input_spec.rb +2 -1
  118. data/spec/inputs/date_picker_input_spec.rb +109 -108
  119. data/spec/inputs/date_select_input_spec.rb +63 -62
  120. data/spec/inputs/datetime_picker_input_spec.rb +118 -117
  121. data/spec/inputs/datetime_select_input_spec.rb +72 -71
  122. data/spec/inputs/email_input_spec.rb +16 -15
  123. data/spec/inputs/file_input_spec.rb +17 -16
  124. data/spec/inputs/hidden_input_spec.rb +29 -28
  125. data/spec/inputs/include_blank_spec.rb +7 -6
  126. data/spec/inputs/label_spec.rb +25 -24
  127. data/spec/inputs/number_input_spec.rb +159 -158
  128. data/spec/inputs/password_input_spec.rb +16 -15
  129. data/spec/inputs/phone_input_spec.rb +16 -15
  130. data/spec/inputs/placeholder_spec.rb +17 -16
  131. data/spec/inputs/radio_input_spec.rb +58 -57
  132. data/spec/inputs/range_input_spec.rb +108 -107
  133. data/spec/inputs/readonly_spec.rb +5 -4
  134. data/spec/inputs/search_input_spec.rb +15 -14
  135. data/spec/inputs/select_input_spec.rb +144 -93
  136. data/spec/inputs/string_input_spec.rb +36 -35
  137. data/spec/inputs/text_input_spec.rb +32 -31
  138. data/spec/inputs/time_picker_input_spec.rb +110 -109
  139. data/spec/inputs/time_select_input_spec.rb +71 -70
  140. data/spec/inputs/time_zone_input_spec.rb +21 -20
  141. data/spec/inputs/url_input_spec.rb +16 -15
  142. data/spec/inputs/with_options_spec.rb +8 -7
  143. data/spec/localizer_spec.rb +1 -0
  144. data/spec/namespaced_class_finder_spec.rb +17 -5
  145. data/spec/schema.rb +1 -0
  146. data/spec/spec_helper.rb +8 -8
  147. data/spec/support/custom_macros.rb +64 -63
  148. data/spec/support/deprecation.rb +2 -1
  149. data/spec/support/shared_examples.rb +2 -1
  150. data/spec/support/specialized_class_finder_shared_example.rb +1 -0
  151. data/spec/support/test_environment.rb +1 -0
  152. metadata +29 -14
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'check_boxes input' do
@@ -6,13 +7,13 @@ RSpec.describe 'check_boxes input' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  end
12
13
 
13
14
  describe 'for a has_many association' do
14
15
  before do
15
- @output_buffer = ''
16
+ @output_buffer = ActionView::OutputBuffer.new ''
16
17
  mock_everything
17
18
 
18
19
  concat(semantic_form_for(@fred) do |builder|
@@ -31,127 +32,127 @@ RSpec.describe 'check_boxes input' do
31
32
  it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
32
33
 
33
34
  it 'should generate a legend containing a label with text for the input' do
34
- expect(output_buffer).to have_tag('form li fieldset legend.label label')
35
- expect(output_buffer).to have_tag('form li fieldset legend.label label', :text => /Posts/)
35
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label')
36
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend.label label', :text => /Posts/)
36
37
  end
37
38
 
38
39
  it 'should not link the label within the legend to any input' do
39
- expect(output_buffer).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
40
+ expect(output_buffer.to_str).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
40
41
  end
41
42
 
42
43
  it 'should generate an ordered list with an li.choice for each choice' do
43
- expect(output_buffer).to have_tag('form li fieldset ol')
44
- expect(output_buffer).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
44
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol')
45
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
45
46
  end
46
47
 
47
48
  it 'should have one option with a "checked" attribute' do
48
- expect(output_buffer).to have_tag('form li input[@checked]', :count => 1)
49
+ expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 1)
49
50
  end
50
51
 
51
52
  it 'should not generate hidden inputs with default value blank' do
52
- expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
53
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
53
54
  end
54
55
 
55
56
  it 'should not render hidden inputs inside the ol' do
56
- expect(output_buffer).not_to have_tag("form li fieldset ol li input[@type='hidden']")
57
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li input[@type='hidden']")
57
58
  end
58
59
 
59
60
  it 'should render one hidden input for each choice outside the ol' do
60
- expect(output_buffer).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
61
+ expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
61
62
  end
62
63
 
63
64
  describe "each choice" do
64
65
 
65
66
  it 'should not give the choice label the .label class' do
66
- expect(output_buffer).not_to have_tag('li.choice label.label')
67
+ expect(output_buffer.to_str).not_to have_tag('li.choice label.label')
67
68
  end
68
69
 
69
70
  it 'should not be marked as required' do
70
- expect(output_buffer).not_to have_tag('li.choice input[@required]')
71
+ expect(output_buffer.to_str).not_to have_tag('li.choice input[@required]')
71
72
  end
72
73
 
73
74
  it 'should contain a label for the radio input with a nested input and label text' do
74
75
  ::Post.all.each do |post|
75
- expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
76
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
76
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
77
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
77
78
  end
78
79
  end
79
80
 
80
81
  it 'should use values as li.class when value_as_class is true' do
81
82
  ::Post.all.each do |post|
82
- expect(output_buffer).to have_tag("form li fieldset ol li.post_#{post.id} label")
83
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li.post_#{post.id} label")
83
84
  end
84
85
  end
85
86
 
86
87
  it 'should have a checkbox input but no hidden field for each post' do
87
88
  ::Post.all.each do |post|
88
- expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
89
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
89
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
90
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
90
91
  end
91
92
  end
92
93
 
93
94
  it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
94
- expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
95
+ expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
95
96
  end
96
97
 
97
98
  it 'the hidden field with an empty array value should be followed by the ol' do
98
- expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
99
+ expect(output_buffer.to_str).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
99
100
  end
100
101
 
101
102
  it 'should not have a hidden field with an empty string value for the collection' do
102
- expect(output_buffer).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
103
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
103
104
  end
104
105
 
105
106
  it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
106
- output_buffer.replace ''
107
+ @output_buffer = ActionView::OutputBuffer.new ''
107
108
 
108
109
  concat(semantic_form_for(@fred) do |builder|
109
110
  concat(builder.input(:posts, :as => :check_boxes, :hidden_fields => true, :value_as_class => true))
110
111
  end)
111
112
 
112
113
  ::Post.all.each do |post|
113
- expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
114
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
115
- expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
114
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
115
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
116
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
116
117
  end
117
118
 
118
119
  end
119
120
 
120
121
  it "should mark input as checked if it's the the existing choice" do
121
122
  expect(::Post.all.include?(@fred.posts.first)).to be_truthy
122
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
123
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
123
124
  end
124
125
  end
125
126
 
126
127
  describe 'and no object is given' do
127
128
  before(:example) do
128
- output_buffer.replace ''
129
+ @output_buffer = ActionView::OutputBuffer.new ''
129
130
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
130
131
  concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
131
132
  end)
132
133
  end
133
134
 
134
135
  it 'should generate a fieldset with legend' do
135
- expect(output_buffer).to have_tag('form li fieldset legend', :text => /Author/)
136
+ expect(output_buffer.to_str).to have_tag('form li fieldset legend', :text => /Author/)
136
137
  end
137
138
 
138
139
  it 'shold generate an li tag for each item in the collection' do
139
- expect(output_buffer).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
140
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
140
141
  end
141
142
 
142
143
  it 'should generate labels for each item' do
143
144
  ::Author.all.each do |author|
144
- expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
145
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
145
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
146
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
146
147
  end
147
148
  end
148
149
 
149
150
  it 'should generate inputs for each item' do
150
151
  ::Author.all.each do |author|
151
- expect(output_buffer).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
152
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@type='checkbox']")
153
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
154
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
152
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
153
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@type='checkbox']")
154
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
155
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
155
156
  end
156
157
  end
157
158
 
@@ -160,7 +161,7 @@ RSpec.describe 'check_boxes input' do
160
161
  concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
161
162
  end)
162
163
 
163
- expect(output_buffer).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
164
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
164
165
  expect(label).to have_text('<b>Item 1</b>', count: 1)
165
166
  expect(label).to have_text('<b>Item 2</b>', count: 1)
166
167
  end
@@ -169,7 +170,7 @@ RSpec.describe 'check_boxes input' do
169
170
 
170
171
  describe 'when :hidden_fields is set to false' do
171
172
  before do
172
- @output_buffer = ''
173
+ @output_buffer = ActionView::OutputBuffer.new ''
173
174
  mock_everything
174
175
 
175
176
  concat(semantic_form_for(@fred) do |builder|
@@ -179,24 +180,24 @@ RSpec.describe 'check_boxes input' do
179
180
 
180
181
  it 'should have a checkbox input for each post' do
181
182
  ::Post.all.each do |post|
182
- expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
183
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
183
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
184
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
184
185
  end
185
186
  end
186
187
 
187
188
  it "should mark input as checked if it's the the existing choice" do
188
189
  expect(::Post.all.include?(@fred.posts.first)).to be_truthy
189
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
190
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@checked='checked']")
190
191
  end
191
192
 
192
193
  it 'should not generate empty hidden inputs' do
193
- expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
194
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
194
195
  end
195
196
  end
196
197
 
197
198
  describe 'when :disabled is set' do
198
199
  before do
199
- @output_buffer = ''
200
+ @output_buffer = ActionView::OutputBuffer.new ''
200
201
  end
201
202
 
202
203
  describe "no disabled items" do
@@ -209,7 +210,7 @@ RSpec.describe 'check_boxes input' do
209
210
  end
210
211
 
211
212
  it 'should not have any disabled item(s)' do
212
- expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
213
+ expect(output_buffer.to_str).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
213
214
  end
214
215
  end
215
216
 
@@ -223,9 +224,9 @@ RSpec.describe 'check_boxes input' do
223
224
  end
224
225
 
225
226
  it "should have one item disabled; the specified one" do
226
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
227
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
228
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
227
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
228
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
229
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
229
230
  end
230
231
  end
231
232
 
@@ -239,11 +240,11 @@ RSpec.describe 'check_boxes input' do
239
240
  end
240
241
 
241
242
  it "should have multiple items disabled; the specified ones" do
242
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
243
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
244
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
245
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
246
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
243
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
244
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
245
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
246
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
247
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
247
248
  end
248
249
  end
249
250
 
@@ -266,7 +267,7 @@ RSpec.describe 'check_boxes input' do
266
267
  end
267
268
 
268
269
  it "should do foo" do
269
- expect(output_buffer).to have_tag("legend.label label", :text => /Translated/)
270
+ expect(output_buffer.to_str).to have_tag("legend.label label", :text => /Translated/)
270
271
  end
271
272
 
272
273
  end
@@ -280,13 +281,13 @@ RSpec.describe 'check_boxes input' do
280
281
  end
281
282
 
282
283
  it "should output the correct label title" do
283
- expect(output_buffer).to have_tag("legend.label label", :text => /The authors/)
284
+ expect(output_buffer.to_str).to have_tag("legend.label label", :text => /The authors/)
284
285
  end
285
286
  end
286
287
 
287
288
  describe "when :label option is false" do
288
289
  before do
289
- @output_buffer = ''
290
+ @output_buffer = ActionView::OutputBuffer.new ''
290
291
  allow(@new_post).to receive(:author_ids).and_return(nil)
291
292
  concat(semantic_form_for(@new_post) do |builder|
292
293
  concat(builder.input(:authors, :as => :check_boxes, :label => false))
@@ -294,11 +295,11 @@ RSpec.describe 'check_boxes input' do
294
295
  end
295
296
 
296
297
  it "should not output the legend" do
297
- expect(output_buffer).not_to have_tag("legend.label")
298
+ expect(output_buffer.to_str).not_to have_tag("legend.label")
298
299
  end
299
300
 
300
301
  it "should not cause escaped HTML" do
301
- expect(output_buffer).not_to include("&gt;")
302
+ expect(output_buffer.to_str).not_to include("&gt;")
302
303
  end
303
304
 
304
305
  end
@@ -312,7 +313,7 @@ RSpec.describe 'check_boxes input' do
312
313
  end
313
314
 
314
315
  it "should output the correct label title" do
315
- expect(output_buffer).to have_tag("legend.label label abbr")
316
+ expect(output_buffer.to_str).to have_tag("legend.label label abbr")
316
317
  end
317
318
  end
318
319
  end
@@ -337,7 +338,7 @@ RSpec.describe 'check_boxes input' do
337
338
  describe 'for a has_and_belongs_to_many association' do
338
339
 
339
340
  before do
340
- @output_buffer = ''
341
+ @output_buffer = ActionView::OutputBuffer.new ''
341
342
  mock_everything
342
343
 
343
344
  concat(semantic_form_for(@freds_post) do |builder|
@@ -347,14 +348,14 @@ RSpec.describe 'check_boxes input' do
347
348
 
348
349
  it 'should render checkboxes' do
349
350
  # I'm aware these two lines test the same thing
350
- expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
351
- expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
351
+ expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
352
+ expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
352
353
  end
353
354
 
354
355
  it 'should only select checkboxes that are present in the association' do
355
356
  # I'm aware these two lines test the same thing
356
- expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
357
- expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
357
+ expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
358
+ expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
358
359
  end
359
360
 
360
361
  end
@@ -362,7 +363,7 @@ RSpec.describe 'check_boxes input' do
362
363
  describe ':collection for a has_and_belongs_to_many association' do
363
364
 
364
365
  before do
365
- @output_buffer = ''
366
+ @output_buffer = ActionView::OutputBuffer.new ''
366
367
  mock_everything
367
368
 
368
369
  concat(semantic_form_for(@freds_post) do |builder|
@@ -372,14 +373,14 @@ RSpec.describe 'check_boxes input' do
372
373
 
373
374
  it 'should render checkboxes' do
374
375
  # I'm aware these two lines test the same thing
375
- expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
376
- expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
376
+ expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => 2)
377
+ expect(output_buffer.to_str).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
377
378
  end
378
379
 
379
380
  it 'should only select checkboxes that are present in the association' do
380
381
  # I'm aware these two lines test the same thing
381
- expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
382
- expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
382
+ expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => 1)
383
+ expect(output_buffer.to_str).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
383
384
  end
384
385
 
385
386
  end
@@ -387,7 +388,7 @@ RSpec.describe 'check_boxes input' do
387
388
  describe 'for an association when a :collection is provided' do
388
389
  describe 'it should use the specified :member_value option' do
389
390
  before do
390
- @output_buffer = ''
391
+ @output_buffer = ActionView::OutputBuffer.new ''
391
392
  mock_everything
392
393
  end
393
394
 
@@ -403,14 +404,14 @@ RSpec.describe 'check_boxes input' do
403
404
  concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
404
405
  end)
405
406
  end
406
- expect(output_buffer).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
407
+ expect(output_buffer.to_str).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
407
408
  end
408
409
  end
409
410
  end
410
411
 
411
412
  describe 'when :collection is provided as an array of arrays' do
412
413
  before do
413
- @output_buffer = ''
414
+ @output_buffer = ActionView::OutputBuffer.new ''
414
415
  mock_everything
415
416
  allow(@fred).to receive(:genres) { ['fiction', 'biography'] }
416
417
 
@@ -420,14 +421,14 @@ RSpec.describe 'check_boxes input' do
420
421
  end
421
422
 
422
423
  it 'should check the correct checkboxes' do
423
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
424
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
424
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
425
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
425
426
  end
426
427
  end
427
428
 
428
429
  describe 'when :collection is a set' do
429
430
  before do
430
- @output_buffer = ''
431
+ @output_buffer = ActionView::OutputBuffer.new ''
431
432
  mock_everything
432
433
  allow(@fred).to receive(:roles) { Set.new([:reviewer, :admin]) }
433
434
 
@@ -437,16 +438,16 @@ RSpec.describe 'check_boxes input' do
437
438
  end
438
439
 
439
440
  it 'should check the correct checkboxes' do
440
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='user']")
441
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
442
- expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
441
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='user']")
442
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
443
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
443
444
  end
444
445
  end
445
446
 
446
447
  describe "when namespace is provided" do
447
448
 
448
449
  before do
449
- @output_buffer = ''
450
+ @output_buffer = ActionView::OutputBuffer.new ''
450
451
  mock_everything
451
452
 
452
453
  concat(semantic_form_for(@fred, :namespace => "context2") do |builder|
@@ -455,7 +456,7 @@ RSpec.describe 'check_boxes input' do
455
456
  end
456
457
 
457
458
  it "should have a label for #context2_author_post_ids_19" do
458
- expect(output_buffer).to have_tag("form li label[@for='context2_author_post_ids_19']")
459
+ expect(output_buffer.to_str).to have_tag("form li label[@for='context2_author_post_ids_19']")
459
460
  end
460
461
 
461
462
  it_should_have_input_with_id('context2_author_post_ids_19')
@@ -465,7 +466,7 @@ RSpec.describe 'check_boxes input' do
465
466
  describe "when index is provided" do
466
467
 
467
468
  before do
468
- @output_buffer = ''
469
+ @output_buffer = ActionView::OutputBuffer.new ''
469
470
  mock_everything
470
471
 
471
472
  concat(semantic_form_for(@fred) do |builder|
@@ -476,15 +477,15 @@ RSpec.describe 'check_boxes input' do
476
477
  end
477
478
 
478
479
  it 'should index the id of the wrapper' do
479
- expect(output_buffer).to have_tag("li#author_post_3_authors_input")
480
+ expect(output_buffer.to_str).to have_tag("li#author_post_3_authors_input")
480
481
  end
481
482
 
482
483
  it 'should index the id of the input tag' do
483
- expect(output_buffer).to have_tag("input#author_post_3_author_ids_42")
484
+ expect(output_buffer.to_str).to have_tag("input#author_post_3_author_ids_42")
484
485
  end
485
486
 
486
487
  it 'should index the name of the checkbox input' do
487
- expect(output_buffer).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
488
+ expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
488
489
  end
489
490
 
490
491
  end
@@ -492,7 +493,7 @@ RSpec.describe 'check_boxes input' do
492
493
 
493
494
  describe "when collection is an array" do
494
495
  before do
495
- @output_buffer = ''
496
+ @output_buffer = ActionView::OutputBuffer.new ''
496
497
  @_collection = [["First", 1], ["Second", 2]]
497
498
  mock_everything
498
499
 
@@ -503,13 +504,13 @@ RSpec.describe 'check_boxes input' do
503
504
 
504
505
  it "should use array items for labels and values" do
505
506
  @_collection.each do |post|
506
- expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
507
- expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
507
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
508
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
508
509
  end
509
510
  end
510
511
 
511
512
  it "should not check any items" do
512
- expect(output_buffer).to have_tag('form li input[@checked]', :count => 0)
513
+ expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 0)
513
514
  end
514
515
 
515
516
  describe "and the attribute has values" do
@@ -522,7 +523,7 @@ RSpec.describe 'check_boxes input' do
522
523
  end
523
524
 
524
525
  it "should check the appropriate items" do
525
- expect(output_buffer).to have_tag("form li input[@value='1'][@checked]")
526
+ expect(output_buffer.to_str).to have_tag("form li input[@value='1'][@checked]")
526
527
  end
527
528
  end
528
529
 
@@ -537,7 +538,7 @@ RSpec.describe 'check_boxes input' do
537
538
 
538
539
  it "should have injected the html attributes" do
539
540
  @_collection.each do |v|
540
- expect(output_buffer).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
541
+ expect(output_buffer.to_str).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
541
542
  end
542
543
  end
543
544
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'color input' do
@@ -6,7 +7,7 @@ RSpec.describe 'color input' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  end
12
13
 
@@ -45,7 +46,7 @@ RSpec.describe 'color input' do
45
46
  describe "when index is provided" do
46
47
 
47
48
  before do
48
- @output_buffer = ''
49
+ @output_buffer = ActionView::OutputBuffer.new ''
49
50
  mock_everything
50
51
 
51
52
  concat(semantic_form_for(@new_post) do |builder|
@@ -56,15 +57,15 @@ RSpec.describe 'color input' do
56
57
  end
57
58
 
58
59
  it 'should index the id of the wrapper' do
59
- expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
60
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
60
61
  end
61
62
 
62
63
  it 'should index the id of the select tag' do
63
- expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
64
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
64
65
  end
65
66
 
66
67
  it 'should index the name of the select tag' do
67
- expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
68
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
68
69
  end
69
70
 
70
71
  end
@@ -76,7 +77,7 @@ RSpec.describe 'color input' do
76
77
  concat(semantic_form_for(@new_post) do |builder|
77
78
  concat(builder.input(:title, :as => :color, :required => true))
78
79
  end)
79
- expect(output_buffer).to have_tag("input[@required]")
80
+ expect(output_buffer.to_str).to have_tag("input[@required]")
80
81
  end
81
82
  end
82
83
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'country input' do
@@ -6,7 +7,7 @@ RSpec.describe 'country input' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  end
12
13
 
@@ -39,13 +40,13 @@ RSpec.describe 'country input' do
39
40
  #it_should_apply_error_logic_for_input_type(:country)
40
41
 
41
42
  it 'should generate a label for the input' do
42
- expect(output_buffer).to have_tag('form li label')
43
- expect(output_buffer).to have_tag('form li label[@for="post_country"]')
44
- expect(output_buffer).to have_tag('form li label', :text => /Country/)
43
+ expect(output_buffer.to_str).to have_tag('form li label')
44
+ expect(output_buffer.to_str).to have_tag('form li label[@for="post_country"]')
45
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Country/)
45
46
  end
46
47
 
47
48
  it "should generate a select" do
48
- expect(output_buffer).to have_tag("form li select")
49
+ expect(output_buffer.to_str).to have_tag("form li select")
49
50
  end
50
51
 
51
52
  end
@@ -80,7 +81,7 @@ RSpec.describe 'country input' do
80
81
  describe "when namespace is provided" do
81
82
 
82
83
  before do
83
- @output_buffer = ''
84
+ @output_buffer = ActionView::OutputBuffer.new ''
84
85
  mock_everything
85
86
 
86
87
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
@@ -107,7 +108,7 @@ RSpec.describe 'country input' do
107
108
  end
108
109
 
109
110
  it "should render a country input" do
110
- expect(output_buffer).to have_tag "form li.country"
111
+ expect(output_buffer.to_str).to have_tag "form li.country"
111
112
  end
112
113
  end
113
114
 
@@ -121,8 +122,8 @@ RSpec.describe 'country input' do
121
122
  end
122
123
 
123
124
  it "should render a country input" do
124
- expect(output_buffer).not_to have_tag "form li.country"
125
- expect(output_buffer).to have_tag "form li.string", :count => 2
125
+ expect(output_buffer.to_str).not_to have_tag "form li.country"
126
+ expect(output_buffer.to_str).to have_tag "form li.string", :count => 2
126
127
  end
127
128
 
128
129
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  # TODO extract out
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe "datalist inputs" do
5
6
  include FormtasticSpecHelper
6
7
 
7
8
  before do
8
- @output_buffer = ''
9
+ @output_buffer = ActionView::OutputBuffer.new ''
9
10
  mock_everything
10
11
  end
11
12