formtastic 3.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +5 -13
  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} +191 -168
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +24 -8
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +13 -17
  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 +19 -0
  20. data/lib/formtastic/actions/base.rb +1 -0
  21. data/lib/formtastic/actions/button_action.rb +56 -53
  22. data/lib/formtastic/actions/buttonish.rb +1 -0
  23. data/lib/formtastic/actions/input_action.rb +60 -57
  24. data/lib/formtastic/actions/link_action.rb +69 -67
  25. data/lib/formtastic/actions.rb +7 -3
  26. data/lib/formtastic/deprecation.rb +6 -0
  27. data/lib/formtastic/engine.rb +4 -1
  28. data/lib/formtastic/form_builder.rb +32 -25
  29. data/lib/formtastic/helpers/action_helper.rb +22 -31
  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 +16 -11
  34. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  35. data/lib/formtastic/helpers/form_helper.rb +4 -3
  36. data/lib/formtastic/helpers/input_helper.rb +59 -80
  37. data/lib/formtastic/helpers/inputs_helper.rb +33 -27
  38. data/lib/formtastic/helpers/reflection.rb +5 -4
  39. data/lib/formtastic/helpers.rb +2 -2
  40. data/lib/formtastic/html_attributes.rb +13 -1
  41. data/lib/formtastic/i18n.rb +2 -1
  42. data/lib/formtastic/input_class_finder.rb +19 -0
  43. data/lib/formtastic/inputs/base/associations.rb +1 -0
  44. data/lib/formtastic/inputs/base/choices.rb +4 -3
  45. data/lib/formtastic/inputs/base/collections.rb +47 -11
  46. data/lib/formtastic/inputs/base/database.rb +8 -5
  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 +12 -10
  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 +2 -3
  61. data/lib/formtastic/inputs/base.rb +17 -12
  62. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  63. data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
  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 +42 -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 +3 -2
  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 +26 -21
  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 +32 -10
  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 -28
  88. data/lib/formtastic/localized_string.rb +2 -1
  89. data/lib/formtastic/localizer.rb +23 -24
  90. data/lib/formtastic/namespaced_class_finder.rb +98 -0
  91. data/lib/formtastic/version.rb +2 -1
  92. data/lib/formtastic.rb +19 -14
  93. data/lib/generators/formtastic/form/form_generator.rb +8 -2
  94. data/lib/generators/formtastic/input/input_generator.rb +47 -0
  95. data/lib/generators/formtastic/install/install_generator.rb +2 -0
  96. data/lib/generators/templates/formtastic.rb +29 -7
  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 +13 -0
  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 +70 -97
  114. data/spec/helpers/actions_helper_spec.rb +43 -42
  115. data/spec/helpers/form_helper_spec.rb +56 -39
  116. data/spec/helpers/input_helper_spec.rb +314 -255
  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 +11 -0
  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 +174 -123
  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 +62 -0
  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 +36 -31
  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 +91 -0
  157. data/spec/schema.rb +22 -0
  158. data/spec/spec_helper.rb +180 -249
  159. data/spec/support/custom_macros.rb +128 -98
  160. data/spec/support/deprecation.rb +2 -1
  161. data/spec/support/shared_examples.rb +13 -0
  162. data/spec/support/specialized_class_finder_shared_example.rb +28 -0
  163. data/spec/support/test_environment.rb +25 -10
  164. metadata +95 -136
  165. data/.travis.yml +0 -28
  166. data/Appraisals +0 -25
  167. data/CHANGELOG +0 -27
  168. data/gemfiles/rails_3.2.gemfile +0 -7
  169. data/gemfiles/rails_4.0.4.gemfile +0 -7
  170. data/gemfiles/rails_4.1.gemfile +0 -7
  171. data/gemfiles/rails_4.gemfile +0 -7
  172. data/gemfiles/rails_edge.gemfile +0 -10
  173. data/lib/formtastic/util.rb +0 -53
  174. data/spec/support/deferred_garbage_collection.rb +0 -21
  175. data/spec/util_spec.rb +0 -52
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ require 'generators/formtastic/input/input_generator'
5
+
6
+ RSpec.describe Formtastic::InputGenerator do
7
+ include FormtasticSpecHelper
8
+
9
+ destination File.expand_path("../../../../../tmp", __FILE__)
10
+
11
+ before do
12
+ prepare_destination
13
+ end
14
+
15
+ after do
16
+ FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
17
+ end
18
+
19
+ describe 'without file name' do
20
+ it 'should raise Thor::RequiredArgumentMissingError' do
21
+ expect { run_generator }.to raise_error(Thor::RequiredArgumentMissingError)
22
+ end
23
+ end
24
+
25
+ describe "input generator with underscore definition" do
26
+ before { run_generator %w(hat_size)}
27
+
28
+ describe 'generate an input in its respective folder' do
29
+ subject{ file('app/inputs/hat_size_input.rb')}
30
+ it { is_expected.to exist}
31
+ it { is_expected.to contain "class HatSizeInput"}
32
+ it { is_expected.to contain "def to_html"}
33
+ it { is_expected.to contain "include Formtastic::Inputs::Base"}
34
+ it { is_expected.not_to contain "super"}
35
+ end
36
+ end
37
+
38
+ describe "input generator with camelcase definition" do
39
+ before { run_generator %w(HatSize)}
40
+
41
+ describe 'generate an input in its respective folder' do
42
+ subject{ file('app/inputs/hat_size_input.rb')}
43
+ it { is_expected.to exist}
44
+ it { is_expected.to contain "class HatSizeInput"}
45
+ end
46
+ end
47
+
48
+ describe "input generator with camelcase Input name sufixed" do
49
+ before { run_generator %w(HatSizeInput)}
50
+
51
+ describe 'generate an input in its respective folder' do
52
+ subject{ file('app/inputs/hat_size_input.rb')}
53
+ it { is_expected.to exist}
54
+ it { is_expected.to contain "class HatSizeInput"}
55
+ end
56
+ end
57
+
58
+ describe "input generator with underscore _input name sufixed" do
59
+ before { run_generator %w(hat_size_input)}
60
+
61
+ describe 'generate an input in its respective folder' do
62
+ subject{ file('app/inputs/hat_size_input.rb')}
63
+ it { is_expected.to exist}
64
+ it { is_expected.to contain "class HatSizeInput"}
65
+ end
66
+ end
67
+
68
+ describe "input generator with underscore input name sufixed" do
69
+ before { run_generator %w(hat_sizeinput)}
70
+
71
+ describe 'generate an input in its respective folder' do
72
+ subject{ file('app/inputs/hat_size_input.rb')}
73
+ it { is_expected.to exist}
74
+ it { is_expected.to contain "class HatSizeInput"}
75
+ end
76
+ end
77
+
78
+ describe "override an existing input using extend" do
79
+ before { run_generator %w(string --extend)}
80
+
81
+ describe 'app/inputs/string_input.rb' do
82
+ subject{ file('app/inputs/string_input.rb')}
83
+ it { is_expected.to exist }
84
+ it { is_expected.to contain "class StringInput < Formtastic::Inputs::StringInput" }
85
+ it { is_expected.to contain "def to_html" }
86
+ it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
87
+ it { is_expected.to contain "super" }
88
+ it { is_expected.not_to contain "def input_html_options" }
89
+ end
90
+ end
91
+
92
+ describe "extend an existing input" do
93
+ before { run_generator %w(FlexibleText --extend string)}
94
+
95
+ describe 'app/inputs/flexible_text_input.rb' do
96
+ subject{ file('app/inputs/flexible_text_input.rb')}
97
+ it { is_expected.to contain "class FlexibleTextInput < Formtastic::Inputs::StringInput" }
98
+ it { is_expected.to contain "def input_html_options" }
99
+ it { is_expected.not_to contain "include Formtastic::Inputs::Base" }
100
+ it { is_expected.not_to contain "def to_html" }
101
+ end
102
+ end
103
+
104
+ describe "provide a slashed namespace" do
105
+ before { run_generator %w(stuff/foo)}
106
+
107
+ describe 'app/inputs/stuff/foo_input.rb' do
108
+ subject{ file('app/inputs/stuff/foo_input.rb')}
109
+ it {is_expected.to exist}
110
+ it { is_expected.to contain "class Stuff::FooInput" }
111
+ it { is_expected.to contain "include Formtastic::Inputs::Base" }
112
+ end
113
+ end
114
+
115
+ describe "provide a camelized namespace" do
116
+ before { run_generator %w(Stuff::Foo)}
117
+
118
+ describe 'app/inputs/stuff/foo_input.rb' do
119
+ subject{ file('app/inputs/stuff/foo_input.rb')}
120
+ it {is_expected.to exist}
121
+ it { is_expected.to contain "class Stuff::FooInput" }
122
+ it { is_expected.to contain "include Formtastic::Inputs::Base" }
123
+ end
124
+ end
125
+ end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  # Generators are not automatically loaded by Rails
4
5
  require 'generators/formtastic/install/install_generator'
5
6
 
6
- describe Formtastic::InstallGenerator do
7
+ RSpec.describe Formtastic::InstallGenerator do
7
8
  # Tell the generator where to put its output (what it thinks of as Rails.root)
8
9
  destination File.expand_path("../../../../../tmp", __FILE__)
9
10
 
@@ -14,14 +15,14 @@ describe Formtastic::InstallGenerator do
14
15
 
15
16
  describe 'config/initializers/formtastic.rb' do
16
17
  subject { file('config/initializers/formtastic.rb') }
17
- it { should exist }
18
- it { should contain "#" }
18
+ it { is_expected.to exist }
19
+ it { is_expected.to contain "#" }
19
20
  end
20
21
 
21
22
  describe 'lib/templates/erb/scaffold/_form.html.erb' do
22
23
  subject { file('lib/templates/erb/scaffold/_form.html.erb') }
23
- it { should exist }
24
- it { should contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
24
+ it { is_expected.to exist }
25
+ it { is_expected.to contain "<%%= semantic_form_for @<%= singular_name %> do |f| %>" }
25
26
  end
26
27
  end
27
28
 
@@ -30,8 +31,8 @@ describe Formtastic::InstallGenerator do
30
31
 
31
32
  describe 'lib/templates/erb/scaffold/_form.html.haml' do
32
33
  subject { file('lib/templates/haml/scaffold/_form.html.haml') }
33
- it { should exist }
34
- it { should contain "= semantic_form_for @<%= singular_name %> do |f|" }
34
+ it { is_expected.to exist }
35
+ it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
35
36
  end
36
37
  end
37
38
 
@@ -40,8 +41,8 @@ describe Formtastic::InstallGenerator do
40
41
 
41
42
  describe 'lib/templates/erb/scaffold/_form.html.slim' do
42
43
  subject { file('lib/templates/slim/scaffold/_form.html.slim') }
43
- it { should exist }
44
- it { should contain "= semantic_form_for @<%= singular_name %> do |f|" }
44
+ it { is_expected.to exist }
45
+ it { is_expected.to contain "= semantic_form_for @<%= singular_name %> do |f|" }
45
46
  end
46
47
  end
47
48
  end
@@ -1,72 +1,62 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Formtastic::FormBuilder#action' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ''
10
- mock_everything
11
- end
12
-
13
- after do
14
- ::I18n.backend.reload!
15
- end
4
+ RSpec.describe 'with action class finder' do
5
+ include_context 'form builder'
16
6
 
17
7
  describe 'arguments and options' do
18
8
 
19
9
  it 'should require the first argument (the action method)' do
20
- lambda {
10
+ expect {
21
11
  concat(semantic_form_for(@new_post) do |builder|
22
12
  concat(builder.action()) # no args passed in at all
23
13
  end)
24
- }.should raise_error(ArgumentError)
14
+ }.to raise_error(ArgumentError)
25
15
  end
26
16
 
27
17
  describe ':as option' do
28
-
18
+
29
19
  describe 'when not provided' do
30
-
20
+
31
21
  it 'should default to a commit for commit' do
32
22
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
33
23
  concat(builder.action(:submit))
34
24
  end)
35
- output_buffer.should have_tag('form li.action.input_action', :count => 1)
25
+ expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
36
26
  end
37
-
27
+
38
28
  it 'should default to a button for reset' do
39
29
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
40
30
  concat(builder.action(:reset))
41
31
  end)
42
- output_buffer.should have_tag('form li.action.input_action', :count => 1)
32
+ expect(output_buffer.to_str).to have_tag('form li.action.input_action', :count => 1)
43
33
  end
44
34
 
45
35
  it 'should default to a link for cancel' do
46
36
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
47
37
  concat(builder.action(:cancel))
48
38
  end)
49
- output_buffer.should have_tag('form li.action.link_action', :count => 1)
39
+ expect(output_buffer.to_str).to have_tag('form li.action.link_action', :count => 1)
50
40
  end
51
41
  end
52
-
42
+
53
43
  it 'should call the corresponding action class with .to_html' do
54
44
  [:input, :button, :link].each do |action_style|
55
45
  semantic_form_for(:project, :url => "http://test.host") do |builder|
56
46
  action_instance = double('Action instance')
57
47
  action_class = "#{action_style.to_s}_action".classify
58
48
  action_constant = "Formtastic::Actions::#{action_class}".constantize
59
-
60
- action_constant.should_receive(:new).and_return(action_instance)
61
- action_instance.should_receive(:to_html).and_return("some HTML")
62
-
49
+
50
+ expect(action_constant).to receive(:new).and_return(action_instance)
51
+ expect(action_instance).to receive(:to_html).and_return("some HTML")
52
+
63
53
  concat(builder.action(:submit, :as => action_style))
64
54
  end
65
55
  end
66
56
  end
67
-
57
+
68
58
  end
69
-
59
+
70
60
  #describe ':label option' do
71
61
  #
72
62
  # describe 'when provided' do
@@ -207,159 +197,142 @@ describe 'Formtastic::FormBuilder#action' do
207
197
  #end
208
198
  #
209
199
  describe ':wrapper_html option' do
210
-
200
+
211
201
  describe 'when provided' do
212
202
  it 'should be passed down to the li tag' do
213
203
  concat(semantic_form_for(@new_post) do |builder|
214
204
  concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
215
205
  end)
216
- output_buffer.should have_tag("form li#another_id")
206
+ expect(output_buffer.to_str).to have_tag("form li#another_id")
217
207
  end
218
-
208
+
219
209
  it 'should append given classes to li default classes' do
220
210
  concat(semantic_form_for(@new_post) do |builder|
221
211
  concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
222
212
  end)
223
- output_buffer.should have_tag("form li.action")
224
- output_buffer.should have_tag("form li.input_action")
225
- output_buffer.should have_tag("form li.another_class")
213
+ expect(output_buffer.to_str).to have_tag("form li.action")
214
+ expect(output_buffer.to_str).to have_tag("form li.input_action")
215
+ expect(output_buffer.to_str).to have_tag("form li.another_class")
226
216
  end
227
-
217
+
228
218
  it 'should allow classes to be an array' do
229
219
  concat(semantic_form_for(@new_post) do |builder|
230
220
  concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
231
221
  end)
232
- output_buffer.should have_tag("form li.action")
233
- output_buffer.should have_tag("form li.input_action")
234
- output_buffer.should have_tag("form li.my_class")
235
- output_buffer.should have_tag("form li.another_class")
222
+ expect(output_buffer.to_str).to have_tag("form li.action")
223
+ expect(output_buffer.to_str).to have_tag("form li.input_action")
224
+ expect(output_buffer.to_str).to have_tag("form li.my_class")
225
+ expect(output_buffer.to_str).to have_tag("form li.another_class")
236
226
  end
237
227
  end
238
-
228
+
239
229
  describe 'when not provided' do
240
230
  it 'should use default id and class' do
241
231
  concat(semantic_form_for(@new_post) do |builder|
242
232
  concat(builder.action(:submit))
243
233
  end)
244
- output_buffer.should have_tag("form li#post_submit_action")
245
- output_buffer.should have_tag("form li.action")
246
- output_buffer.should have_tag("form li.input_action")
234
+ expect(output_buffer.to_str).to have_tag("form li#post_submit_action")
235
+ expect(output_buffer.to_str).to have_tag("form li.action")
236
+ expect(output_buffer.to_str).to have_tag("form li.input_action")
247
237
  end
248
238
  end
249
-
239
+
250
240
  end
251
-
241
+
252
242
  end
253
243
 
254
244
  describe 'instantiating an action class' do
255
-
256
245
  context 'when a class does not exist' do
257
246
  it "should raise an error" do
258
- lambda {
247
+ expect {
259
248
  concat(semantic_form_for(@new_post) do |builder|
260
249
  builder.action(:submit, :as => :non_existant)
261
250
  end)
262
- }.should raise_error(Formtastic::UnknownActionError)
251
+ }.to raise_error(Formtastic::UnknownActionError)
263
252
  end
264
253
  end
265
-
254
+
266
255
  context 'when a customized top-level class does not exist' do
267
-
268
256
  it 'should instantiate the Formtastic action' do
269
257
  action = double('action', :to_html => 'some HTML')
270
- Formtastic::Actions::ButtonAction.should_receive(:new).and_return(action)
258
+ expect(Formtastic::Actions::ButtonAction).to receive(:new).and_return(action)
271
259
  concat(semantic_form_for(@new_post) do |builder|
272
260
  builder.action(:commit, :as => :button)
273
261
  end)
274
262
  end
275
-
276
263
  end
277
-
264
+
278
265
  describe 'when a top-level (custom) action class exists' do
279
266
  it "should instantiate the top-level action instead of the Formtastic one" do
280
267
  class ::ButtonAction < Formtastic::Actions::ButtonAction
281
268
  end
282
-
269
+
283
270
  action = double('action', :to_html => 'some HTML')
284
- Formtastic::Actions::ButtonAction.should_not_receive(:new)
285
- ::ButtonAction.should_receive(:new).and_return(action)
286
-
271
+ expect(Formtastic::Actions::ButtonAction).not_to receive(:new)
272
+ expect(::ButtonAction).to receive(:new).and_return(action)
273
+
287
274
  concat(semantic_form_for(@new_post) do |builder|
288
275
  builder.action(:commit, :as => :button)
289
276
  end)
290
277
  end
291
278
  end
292
-
293
- describe 'when instantiated multiple times with the same action type' do
294
-
295
- it "should be cached (not calling the internal methods)" do
296
- # TODO this is really tied to the underlying implementation
297
- concat(semantic_form_for(@new_post) do |builder|
298
- builder.should_receive(:custom_action_class_name).with(:button).once.and_return(::Formtastic::Actions::ButtonAction)
299
- builder.action(:submit, :as => :button)
300
- builder.action(:submit, :as => :button)
301
- end)
302
- end
303
-
304
- end
305
-
279
+
306
280
  describe 'support for :as on each action' do
307
-
281
+
308
282
  it "should raise an error when the action does not support the :as" do
309
- lambda {
283
+ expect {
310
284
  concat(semantic_form_for(@new_post) do |builder|
311
285
  concat(builder.action(:submit, :as => :link))
312
286
  end)
313
- }.should raise_error(Formtastic::UnsupportedMethodForAction)
314
-
315
- lambda {
287
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
288
+
289
+ expect {
316
290
  concat(semantic_form_for(@new_post) do |builder|
317
291
  concat(builder.action(:cancel, :as => :input))
318
292
  end)
319
- }.should raise_error(Formtastic::UnsupportedMethodForAction)
320
-
321
- lambda {
293
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
294
+
295
+ expect {
322
296
  concat(semantic_form_for(@new_post) do |builder|
323
297
  concat(builder.action(:cancel, :as => :button))
324
298
  end)
325
- }.should raise_error(Formtastic::UnsupportedMethodForAction)
299
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
326
300
  end
327
-
301
+
328
302
  it "should not raise an error when the action does not support the :as" do
329
- lambda {
303
+ expect {
330
304
  concat(semantic_form_for(@new_post) do |builder|
331
305
  concat(builder.action(:cancel, :as => :link))
332
306
  end)
333
- }.should_not raise_error
334
-
335
- lambda {
307
+ }.not_to raise_error
308
+
309
+ expect {
336
310
  concat(semantic_form_for(@new_post) do |builder|
337
311
  concat(builder.action(:submit, :as => :input))
338
312
  end)
339
- }.should_not raise_error
313
+ }.not_to raise_error
340
314
 
341
- lambda {
315
+ expect {
342
316
  concat(semantic_form_for(@new_post) do |builder|
343
317
  concat(builder.action(:submit, :as => :button))
344
318
  end)
345
- }.should_not raise_error
346
-
347
- lambda {
319
+ }.not_to raise_error
320
+
321
+ expect {
348
322
  concat(semantic_form_for(@new_post) do |builder|
349
323
  concat(builder.action(:reset, :as => :input))
350
324
  end)
351
- }.should_not raise_error
352
-
353
- lambda {
325
+ }.not_to raise_error
326
+
327
+ expect {
354
328
  concat(semantic_form_for(@new_post) do |builder|
355
329
  concat(builder.action(:reset, :as => :button))
356
330
  end)
357
- }.should_not raise_error
331
+ }.not_to raise_error
358
332
  end
359
-
333
+
360
334
  end
361
-
335
+
362
336
  end
363
337
 
364
338
  end
365
-
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
- describe 'Formtastic::FormBuilder#actions' do
5
+ RSpec.describe 'Formtastic::FormBuilder#actions' do
5
6
 
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
 
@@ -21,123 +22,123 @@ describe 'Formtastic::FormBuilder#actions' do
21
22
  end
22
23
 
23
24
  it 'should render a fieldset inside the form, with a class of "actions"' do
24
- output_buffer.should have_tag("form fieldset.actions")
25
+ expect(output_buffer.to_str).to have_tag("form fieldset.actions")
25
26
  end
26
27
 
27
28
  it 'should render an ol inside the fieldset' do
28
- output_buffer.should have_tag("form fieldset.actions ol")
29
+ expect(output_buffer.to_str).to have_tag("form fieldset.actions ol")
29
30
  end
30
31
 
31
32
  it 'should render the contents of the block inside the ol' do
32
- output_buffer.should have_tag("form fieldset.actions ol", /hello/)
33
+ expect(output_buffer.to_str).to have_tag("form fieldset.actions ol", :text => /hello/)
33
34
  end
34
35
 
35
36
  it 'should not render a legend inside the fieldset' do
36
- output_buffer.should_not have_tag("form fieldset.actions legend")
37
+ expect(output_buffer.to_str).not_to have_tag("form fieldset.actions legend")
37
38
  end
38
39
  end
39
40
 
40
41
  describe 'when a :name option is provided' do
41
42
  before do
42
43
  @legend_text = "Advanced options"
43
-
44
+
44
45
  concat(semantic_form_for(@new_post) do |builder|
45
46
  builder.actions :name => @legend_text do
46
47
  end
47
48
  end)
48
49
  end
49
50
  it 'should render a fieldset inside the form' do
50
- output_buffer.should have_tag("form fieldset.actions legend", /#{@legend_text}/)
51
+ expect(output_buffer.to_str).to have_tag("form fieldset.actions legend", :text => /#{@legend_text}/)
51
52
  end
52
53
  end
53
-
54
+
54
55
  describe 'when other options are provided' do
55
56
  before do
56
57
  @id_option = 'advanced'
57
58
  @class_option = 'wide'
58
-
59
+
59
60
  concat(semantic_form_for(@new_post) do |builder|
60
61
  builder.actions :id => @id_option, :class => @class_option do
61
62
  end
62
63
  end)
63
64
  end
64
65
  it 'should pass the options into the fieldset tag as attributes' do
65
- output_buffer.should have_tag("form fieldset##{@id_option}")
66
- output_buffer.should have_tag("form fieldset.#{@class_option}")
66
+ expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
67
+ expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
67
68
  end
68
69
  end
69
-
70
+
70
71
  end
71
72
 
72
73
  describe 'without a block' do
73
-
74
+
74
75
  describe 'with no args (default buttons)' do
75
-
76
+
76
77
  before do
77
78
  concat(semantic_form_for(@new_post) do |builder|
78
79
  concat(builder.actions)
79
80
  end)
80
81
  end
81
-
82
+
82
83
  it 'should render a form' do
83
- output_buffer.should have_tag('form')
84
+ expect(output_buffer.to_str).to have_tag('form')
84
85
  end
85
-
86
+
86
87
  it 'should render an actions fieldset inside the form' do
87
- output_buffer.should have_tag('form fieldset.actions')
88
+ expect(output_buffer.to_str).to have_tag('form fieldset.actions')
88
89
  end
89
-
90
+
90
91
  it 'should not render a legend in the fieldset' do
91
- output_buffer.should_not have_tag('form fieldset.actions legend')
92
+ expect(output_buffer.to_str).not_to have_tag('form fieldset.actions legend')
92
93
  end
93
-
94
+
94
95
  it 'should render an ol in the fieldset' do
95
- output_buffer.should have_tag('form fieldset.actions ol')
96
+ expect(output_buffer.to_str).to have_tag('form fieldset.actions ol')
96
97
  end
97
-
98
+
98
99
  it 'should render a list item in the ol for each default action' do
99
- output_buffer.should have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
100
+ expect(output_buffer.to_str).to have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
100
101
  end
101
-
102
+
102
103
  end
103
-
104
+
104
105
  describe 'with button names as args' do
105
-
106
+
106
107
  before do
107
108
  concat(semantic_form_for(@new_post) do |builder|
108
109
  concat(builder.actions(:submit, :cancel, :reset))
109
110
  end)
110
111
  end
111
-
112
+
112
113
  it 'should render a form with a fieldset containing a list item for each button arg' do
113
- output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
114
+ expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
114
115
  end
115
-
116
+
116
117
  end
117
-
118
+
118
119
  describe 'with button names as args and an options hash' do
119
-
120
+
120
121
  before do
121
122
  concat(semantic_form_for(@new_post) do |builder|
122
123
  concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
123
124
  end)
124
125
  end
125
-
126
+
126
127
  it 'should render a form with a fieldset containing a list item for each button arg' do
127
- output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
128
+ expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
128
129
  end
129
-
130
+
130
131
  it 'should pass the options down to the fieldset' do
131
- output_buffer.should have_tag('form > fieldset#my-id.actions')
132
+ expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions')
132
133
  end
133
-
134
+
134
135
  it 'should use the special :name option as a text for the legend tag' do
135
- output_buffer.should have_tag('form > fieldset#my-id.actions > legend', /Now click a button/)
136
+ expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions > legend', :text => /Now click a button/)
136
137
  end
137
-
138
+
138
139
  end
139
-
140
+
140
141
  end
141
-
142
+
142
143
  end
143
144