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,32 +1,33 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'InputAction::Base' do
5
-
6
+
6
7
  # Most basic Action class to test Base
7
8
  class ::GenericAction
8
9
  include ::Formtastic::Actions::Base
9
-
10
+
10
11
  def supported_methods
11
12
  [:submit, :reset, :cancel]
12
13
  end
13
-
14
+
14
15
  def to_html
15
16
  wrapper do
16
17
  builder.submit(text, button_html)
17
18
  end
18
19
  end
19
20
  end
20
-
21
+
21
22
  include FormtasticSpecHelper
22
23
 
23
24
  before do
24
- @output_buffer = ''
25
+ @output_buffer = ActionView::OutputBuffer.new ''
25
26
  mock_everything
26
27
  end
27
-
28
+
28
29
  describe 'wrapping HTML' do
29
-
30
+
30
31
  before do
31
32
  concat(semantic_form_for(@new_post) do |builder|
32
33
  concat(builder.action(:submit, :as => :generic,
@@ -34,117 +35,117 @@ RSpec.describe 'InputAction::Base' do
34
35
  ))
35
36
  end)
36
37
  end
37
-
38
+
38
39
  it 'should add the #foo id to the li' do
39
- expect(output_buffer).to have_tag('li#post_submit_action')
40
+ expect(output_buffer.to_str).to have_tag('li#post_submit_action')
40
41
  end
41
-
42
+
42
43
  it 'should add the .action and .generic_action classes to the li' do
43
- expect(output_buffer).to have_tag('li.action.generic_action')
44
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action')
44
45
  end
45
46
 
46
47
  it 'should pass :wrapper_html HTML attributes to the wrapper' do
47
- expect(output_buffer).to have_tag('li.action.generic_action[@foo="bah"]')
48
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action[@foo="bah"]')
48
49
  end
49
-
50
+
50
51
  context "when a custom :id is provided" do
51
-
52
+
52
53
  before do
53
54
  concat(semantic_form_for(@new_post) do |builder|
54
- concat(builder.action(:submit, :as => :generic,
55
+ concat(builder.action(:submit, :as => :generic,
55
56
  :wrapper_html => { :id => 'foo_bah_bing' }
56
57
  ))
57
58
  end)
58
59
  end
59
-
60
+
60
61
  it "should use the custom id" do
61
- expect(output_buffer).to have_tag('li#foo_bah_bing')
62
+ expect(output_buffer.to_str).to have_tag('li#foo_bah_bing')
62
63
  end
63
-
64
+
64
65
  end
65
-
66
- context "when a custom class is provided as a string" do
67
-
66
+
67
+ context "when a custom class is provided as a string" do
68
+
68
69
  before do
69
70
  concat(semantic_form_for(@new_post) do |builder|
70
- concat(builder.action(:submit, :as => :generic,
71
+ concat(builder.action(:submit, :as => :generic,
71
72
  :wrapper_html => { :class => 'foo_bah_bing' }
72
73
  ))
73
74
  end)
74
75
  end
75
-
76
+
76
77
  it "should add the custom class strng to the existing classes" do
77
- expect(output_buffer).to have_tag('li.action.generic_action.foo_bah_bing')
78
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing')
78
79
  end
79
-
80
+
80
81
  end
81
-
82
- context "when a custom class is provided as an array" do
83
-
82
+
83
+ context "when a custom class is provided as an array" do
84
+
84
85
  before do
85
86
  concat(semantic_form_for(@new_post) do |builder|
86
- concat(builder.action(:submit, :as => :generic,
87
+ concat(builder.action(:submit, :as => :generic,
87
88
  :wrapper_html => { :class => ['foo_bah_bing', 'zing_boo'] }
88
89
  ))
89
90
  end)
90
91
  end
91
-
92
+
92
93
  it "should add the custom class strng to the existing classes" do
93
- expect(output_buffer).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
94
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
94
95
  end
95
-
96
+
96
97
  end
97
-
98
+
98
99
  end
99
-
100
+
100
101
  describe 'button HTML' do
101
-
102
+
102
103
  before do
103
104
  concat(semantic_form_for(@new_post) do |builder|
104
- concat(builder.action(:submit, :as => :generic,
105
+ concat(builder.action(:submit, :as => :generic,
105
106
  :button_html => { :foo => 'bah' }
106
107
  ))
107
108
  end)
108
109
  end
109
-
110
+
110
111
  it 'should pass :button_html HTML attributes to the button' do
111
- expect(output_buffer).to have_tag('li.action.generic_action input[@foo="bah"]')
112
+ expect(output_buffer.to_str).to have_tag('li.action.generic_action input[@foo="bah"]')
112
113
  end
113
-
114
+
114
115
  it 'should respect a default_commit_button_accesskey configuration with nil' do
115
116
  with_config :default_commit_button_accesskey, nil do
116
117
  concat(semantic_form_for(@new_post) do |builder|
117
118
  concat(builder.action(:submit, :as => :generic))
118
119
  end)
119
- expect(output_buffer).not_to have_tag('li.action input[@accesskey]')
120
+ expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey]')
120
121
  end
121
122
  end
122
-
123
+
123
124
  it 'should respect a default_commit_button_accesskey configuration with a String' do
124
125
  with_config :default_commit_button_accesskey, 's' do
125
126
  concat(semantic_form_for(@new_post) do |builder|
126
127
  concat(builder.action(:submit, :as => :generic))
127
128
  end)
128
- expect(output_buffer).to have_tag('li.action input[@accesskey="s"]')
129
+ expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="s"]')
129
130
  end
130
131
  end
131
-
132
+
132
133
  it 'should respect an accesskey through options over configration' do
133
134
  with_config :default_commit_button_accesskey, 's' do
134
135
  concat(semantic_form_for(@new_post) do |builder|
135
136
  concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
136
137
  end)
137
- expect(output_buffer).not_to have_tag('li.action input[@accesskey="s"]')
138
- expect(output_buffer).to have_tag('li.action input[@accesskey="o"]')
138
+ expect(output_buffer.to_str).not_to have_tag('li.action input[@accesskey="s"]')
139
+ expect(output_buffer.to_str).to have_tag('li.action input[@accesskey="o"]')
139
140
  end
140
141
  end
141
-
142
+
142
143
  end
143
-
144
+
144
145
  describe 'labelling' do
145
-
146
+
146
147
  describe 'when used without object' do
147
-
148
+
148
149
  describe 'when explicit label is provided' do
149
150
  it 'should render an input with the explicitly specified label' do
150
151
  concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
@@ -152,12 +153,12 @@ RSpec.describe 'InputAction::Base' do
152
153
  concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
153
154
  concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
154
155
  end)
155
- expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
156
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
157
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
156
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
157
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
158
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
158
159
  end
159
160
  end
160
-
161
+
161
162
  describe 'when no explicit label is provided' do
162
163
  describe 'when no I18n-localized label is provided' do
163
164
  before do
@@ -174,20 +175,20 @@ RSpec.describe 'InputAction::Base' do
174
175
  }
175
176
  }
176
177
  end
177
-
178
+
178
179
  after do
179
180
  ::I18n.backend.reload!
180
181
  end
181
-
182
+
182
183
  it 'should render an input with default I18n-localized label (fallback)' do
183
184
  concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
184
185
  concat(builder.action(:submit, :as => :generic))
185
186
  concat(builder.action(:reset, :as => :generic))
186
187
  concat(builder.action(:cancel, :as => :generic))
187
188
  end)
188
- expect(output_buffer).to have_tag('li.generic_action input[@value="Submit Post"]')
189
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
190
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
189
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit Post"]')
190
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
191
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
191
192
  end
192
193
 
193
194
  it 'should render an input with custom resource name localized label' do
@@ -196,14 +197,14 @@ RSpec.describe 'InputAction::Base' do
196
197
  concat(builder.action(:reset, :as => :generic))
197
198
  concat(builder.action(:cancel, :as => :generic))
198
199
  end)
199
- expect(output_buffer).to have_tag('li.generic_action input[@value="Submit message"]')
200
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel message"]')
201
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset message"]')
200
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
201
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
202
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
202
203
  end
203
204
  end
204
-
205
+
205
206
  describe 'when I18n-localized label is provided' do
206
-
207
+
207
208
  before do
208
209
  ::I18n.backend.store_translations :en,
209
210
  :formtastic => {
@@ -214,11 +215,11 @@ RSpec.describe 'InputAction::Base' do
214
215
  }
215
216
  }
216
217
  end
217
-
218
+
218
219
  after do
219
220
  ::I18n.backend.reload!
220
221
  end
221
-
222
+
222
223
  it 'should render an input with localized label (I18n)' do
223
224
  with_config :i18n_lookups_by_default, true do
224
225
  ::I18n.backend.store_translations :en,
@@ -237,12 +238,12 @@ RSpec.describe 'InputAction::Base' do
237
238
  concat(builder.action(:reset, :as => :generic))
238
239
  concat(builder.action(:cancel, :as => :generic))
239
240
  end)
240
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
241
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
242
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
241
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
242
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
243
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
243
244
  end
244
245
  end
245
-
246
+
246
247
  it 'should render an input with anoptional localized label (I18n) - if first is not set' do
247
248
  with_config :i18n_lookups_by_default, true do
248
249
  concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
@@ -250,21 +251,21 @@ RSpec.describe 'InputAction::Base' do
250
251
  concat(builder.action(:reset, :as => :generic))
251
252
  concat(builder.action(:cancel, :as => :generic))
252
253
  end)
253
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
254
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
255
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
254
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
255
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
256
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
256
257
  end
257
258
  end
258
-
259
+
259
260
  end
260
261
  end
261
262
  end
262
-
263
+
263
264
  describe 'when used on a new record' do
264
265
  before do
265
266
  allow(@new_post).to receive(:new_record?).and_return(true)
266
267
  end
267
-
268
+
268
269
  describe 'when explicit label is provided' do
269
270
  it 'should render an input with the explicitly specified label' do
270
271
  concat(semantic_form_for(@new_post) do |builder|
@@ -272,12 +273,12 @@ RSpec.describe 'InputAction::Base' do
272
273
  concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
273
274
  concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
274
275
  end)
275
- expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
276
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
277
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
276
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
277
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
278
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
278
279
  end
279
280
  end
280
-
281
+
281
282
  describe 'when no explicit label is provided' do
282
283
  describe 'when no I18n-localized label is provided' do
283
284
  before do
@@ -287,23 +288,23 @@ RSpec.describe 'InputAction::Base' do
287
288
  :cancel => 'Cancel %{model}'
288
289
  }
289
290
  end
290
-
291
+
291
292
  after do
292
293
  ::I18n.backend.reload!
293
294
  end
294
-
295
+
295
296
  it 'should render an input with default I18n-localized label (fallback)' do
296
297
  concat(semantic_form_for(@new_post) do |builder|
297
298
  concat(builder.action(:submit, :as => :generic))
298
299
  concat(builder.action(:reset, :as => :generic))
299
300
  concat(builder.action(:cancel, :as => :generic))
300
301
  end)
301
- expect(output_buffer).to have_tag('li.generic_action input[@value="Create Post"]')
302
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
303
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
302
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Create Post"]')
303
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
304
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
304
305
  end
305
306
  end
306
-
307
+
307
308
  describe 'when I18n-localized label is provided' do
308
309
  before do
309
310
  ::I18n.backend.store_translations :en,
@@ -315,11 +316,11 @@ RSpec.describe 'InputAction::Base' do
315
316
  }
316
317
  }
317
318
  end
318
-
319
+
319
320
  after do
320
321
  ::I18n.backend.reload!
321
322
  end
322
-
323
+
323
324
  it 'should render an input with localized label (I18n)' do
324
325
  with_config :i18n_lookups_by_default, true do
325
326
  ::I18n.backend.store_translations :en,
@@ -337,12 +338,12 @@ RSpec.describe 'InputAction::Base' do
337
338
  concat(builder.action(:reset, :as => :generic))
338
339
  concat(builder.action(:cancel, :as => :generic))
339
340
  end)
340
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
341
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
342
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
341
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
342
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
343
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
343
344
  end
344
345
  end
345
-
346
+
346
347
  it 'should render an input with anoptional localized label (I18n) - if first is not set' do
347
348
  with_config :i18n_lookups_by_default, true do
348
349
  concat(semantic_form_for(@new_post) do |builder|
@@ -350,21 +351,21 @@ RSpec.describe 'InputAction::Base' do
350
351
  concat(builder.action(:reset, :as => :generic))
351
352
  concat(builder.action(:cancel, :as => :generic))
352
353
  end)
353
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Create"]})
354
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
355
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
354
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Create"]})
355
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
356
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
356
357
  end
357
358
  end
358
-
359
+
359
360
  end
360
361
  end
361
362
  end
362
-
363
+
363
364
  describe 'when used on an existing record' do
364
365
  before do
365
366
  allow(@new_post).to receive(:persisted?).and_return(true)
366
367
  end
367
-
368
+
368
369
  describe 'when explicit label is provided' do
369
370
  it 'should render an input with the explicitly specified label' do
370
371
  concat(semantic_form_for(@new_post) do |builder|
@@ -372,12 +373,12 @@ RSpec.describe 'InputAction::Base' do
372
373
  concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
373
374
  concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
374
375
  end)
375
- expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
376
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
377
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
376
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Click!"]')
377
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset!"]')
378
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel!"]')
378
379
  end
379
380
  end
380
-
381
+
381
382
  describe 'when no explicit label is provided' do
382
383
  describe 'when no I18n-localized label is provided' do
383
384
  before do
@@ -394,20 +395,20 @@ RSpec.describe 'InputAction::Base' do
394
395
  }
395
396
  }
396
397
  end
397
-
398
+
398
399
  after do
399
400
  ::I18n.backend.reload!
400
401
  end
401
-
402
+
402
403
  it 'should render an input with default I18n-localized label (fallback)' do
403
404
  concat(semantic_form_for(@new_post) do |builder|
404
405
  concat(builder.action(:submit, :as => :generic))
405
406
  concat(builder.action(:reset, :as => :generic))
406
407
  concat(builder.action(:cancel, :as => :generic))
407
408
  end)
408
- expect(output_buffer).to have_tag('li.generic_action input[@value="Save Post"]')
409
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
410
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
409
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Save Post"]')
410
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset Post"]')
411
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel Post"]')
411
412
  end
412
413
 
413
414
  it 'should render an input with custom resource name localized label' do
@@ -416,12 +417,12 @@ RSpec.describe 'InputAction::Base' do
416
417
  concat(builder.action(:reset, :as => :generic))
417
418
  concat(builder.action(:cancel, :as => :generic))
418
419
  end)
419
- expect(output_buffer).to have_tag('li.generic_action input[@value="Submit message"]')
420
- expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel message"]')
421
- expect(output_buffer).to have_tag('li.generic_action input[@value="Reset message"]')
420
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Submit message"]')
421
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Cancel message"]')
422
+ expect(output_buffer.to_str).to have_tag('li.generic_action input[@value="Reset message"]')
422
423
  end
423
424
  end
424
-
425
+
425
426
  describe 'when I18n-localized label is provided' do
426
427
  before do
427
428
  ::I18n.backend.reload!
@@ -434,11 +435,11 @@ RSpec.describe 'InputAction::Base' do
434
435
  }
435
436
  }
436
437
  end
437
-
438
+
438
439
  after do
439
440
  ::I18n.backend.reload!
440
441
  end
441
-
442
+
442
443
  it 'should render an input with localized label (I18n)' do
443
444
  with_config :i18n_lookups_by_default, true do
444
445
  ::I18n.backend.store_translations :en,
@@ -456,12 +457,12 @@ RSpec.describe 'InputAction::Base' do
456
457
  concat(builder.action(:reset, :as => :generic))
457
458
  concat(builder.action(:cancel, :as => :generic))
458
459
  end)
459
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
460
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
461
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
460
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
461
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
462
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
462
463
  end
463
464
  end
464
-
465
+
465
466
  it 'should render an input with anoptional localized label (I18n) - if first is not set' do
466
467
  with_config :i18n_lookups_by_default, true do
467
468
  concat(semantic_form_for(@new_post) do |builder|
@@ -469,13 +470,13 @@ RSpec.describe 'InputAction::Base' do
469
470
  concat(builder.action(:reset, :as => :generic))
470
471
  concat(builder.action(:cancel, :as => :generic))
471
472
  end)
472
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Save"]})
473
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
474
- expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
473
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Save"]})
474
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
475
+ expect(output_buffer.to_str).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
475
476
  ::I18n.backend.store_translations :en, :formtastic => {}
476
477
  end
477
478
  end
478
-
479
+
479
480
  end
480
481
  end
481
482
  end
@@ -484,24 +485,24 @@ RSpec.describe 'InputAction::Base' do
484
485
  describe 'when the model is two words' do
485
486
 
486
487
  before do
487
- output_buffer = ''
488
+ output_buffer = ActionView::OutputBuffer.new ''
488
489
  class ::UserPost
489
490
  extend ActiveModel::Naming if defined?(ActiveModel::Naming)
490
491
  include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
491
-
492
+
492
493
  def id
493
494
  end
494
-
495
+
495
496
  def persisted?
496
497
  end
497
-
498
+
498
499
  # Rails does crappy human_name
499
500
  def self.human_name
500
501
  "User post"
501
502
  end
502
503
  end
503
504
  @new_user_post = ::UserPost.new
504
-
505
+
505
506
  allow(@new_user_post).to receive(:new_record?).and_return(true)
506
507
  concat(semantic_form_for(@new_user_post, :url => '') do |builder|
507
508
  concat(builder.action(:submit, :as => :generic))
@@ -509,11 +510,11 @@ RSpec.describe 'InputAction::Base' do
509
510
  concat(builder.action(:cancel, :as => :generic))
510
511
  end)
511
512
  end
512
-
513
+
513
514
  it "should render the string as the value of the button" do
514
- expect(output_buffer).to have_tag('li input[@value="Create User post"]')
515
- expect(output_buffer).to have_tag('li input[@value="Reset User post"]')
516
- expect(output_buffer).to have_tag('li input[@value="Cancel User post"]')
515
+ expect(output_buffer.to_str).to have_tag('li input[@value="Create User post"]')
516
+ expect(output_buffer.to_str).to have_tag('li input[@value="Reset User post"]')
517
+ expect(output_buffer.to_str).to have_tag('li input[@value="Cancel User post"]')
517
518
  end
518
519
 
519
520
  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 'InputAction', 'when submitting' do
@@ -6,16 +7,16 @@ RSpec.describe 'InputAction', 'when submitting' 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
+
12
13
  concat(semantic_form_for(@new_post) do |builder|
13
14
  concat(builder.action(:submit, :as => :input))
14
15
  end)
15
16
  end
16
-
17
+
17
18
  it 'should render a submit type of input' do
18
- expect(output_buffer).to have_tag('li.action.input_action input[@type="submit"]')
19
+ expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="submit"]')
19
20
  end
20
21
 
21
22
  end
@@ -23,37 +24,37 @@ end
23
24
  RSpec.describe 'InputAction', 'when resetting' do
24
25
 
25
26
  include FormtasticSpecHelper
26
-
27
+
27
28
  before do
28
- @output_buffer = ''
29
+ @output_buffer = ActionView::OutputBuffer.new ''
29
30
  mock_everything
30
-
31
+
31
32
  concat(semantic_form_for(@new_post) do |builder|
32
33
  concat(builder.action(:reset, :as => :input))
33
34
  end)
34
35
  end
35
-
36
+
36
37
  it 'should render a reset type of input' do
37
- expect(output_buffer).to have_tag('li.action.input_action input[@type="reset"]')
38
+ expect(output_buffer.to_str).to have_tag('li.action.input_action input[@type="reset"]')
38
39
  end
39
-
40
+
40
41
  end
41
42
 
42
43
  RSpec.describe 'InputAction', 'when cancelling' do
43
44
 
44
45
  include FormtasticSpecHelper
45
-
46
+
46
47
  before do
47
- @output_buffer = ''
48
+ @output_buffer = ActionView::OutputBuffer.new ''
48
49
  mock_everything
49
50
  end
50
-
51
+
51
52
  it 'should raise an error' do
52
- expect {
53
+ expect {
53
54
  concat(semantic_form_for(@new_post) do |builder|
54
55
  concat(builder.action(:cancel, :as => :input))
55
56
  end)
56
57
  }.to raise_error(Formtastic::UnsupportedMethodForAction)
57
58
  end
58
-
59
+
59
60
  end