formtastic 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 'LinkAction', 'when cancelling' do
@@ -6,49 +7,49 @@ RSpec.describe 'LinkAction', 'when cancelling' 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
  context 'without a :url' do
14
15
  before do
15
16
  concat(semantic_form_for(@new_post) do |builder|
16
17
  concat(builder.action(:cancel, :as => :link))
17
18
  end)
18
19
  end
19
-
20
+
20
21
  it 'should render a submit type of input' do
21
- expect(output_buffer).to have_tag('li.action.link_action a[@href="javascript:history.back()"]')
22
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="javascript:history.back()"]')
22
23
  end
23
-
24
+
24
25
  end
25
-
26
+
26
27
  context 'with a :url as String' do
27
-
28
+
28
29
  before do
29
30
  concat(semantic_form_for(@new_post) do |builder|
30
31
  concat(builder.action(:cancel, :as => :link, :url => "http://foo.bah/baz"))
31
32
  end)
32
33
  end
33
-
34
+
34
35
  it 'should render a submit type of input' do
35
- expect(output_buffer).to have_tag('li.action.link_action a[@href="http://foo.bah/baz"]')
36
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="http://foo.bah/baz"]')
36
37
  end
37
-
38
+
38
39
  end
39
40
 
40
41
  context 'with a :url as Hash' do
41
-
42
+
42
43
  before do
43
44
  concat(semantic_form_for(@new_post) do |builder|
44
45
  concat(builder.action(:cancel, :as => :link, :url => { :action => "foo" }))
45
46
  end)
46
47
  end
47
-
48
+
48
49
  it 'should render a submit type of input' do
49
- expect(output_buffer).to have_tag('li.action.link_action a[@href="/mock/path"]')
50
+ expect(output_buffer.to_str).to have_tag('li.action.link_action a[@href="/mock/path"]')
50
51
  end
51
-
52
+
52
53
  end
53
54
 
54
55
  end
@@ -56,37 +57,37 @@ end
56
57
  RSpec.describe 'LinkAction', 'when submitting' do
57
58
 
58
59
  include FormtasticSpecHelper
59
-
60
+
60
61
  before do
61
- @output_buffer = ''
62
+ @output_buffer = ActionView::OutputBuffer.new ''
62
63
  mock_everything
63
64
  end
64
-
65
+
65
66
  it 'should raise an error' do
66
- expect {
67
+ expect {
67
68
  concat(semantic_form_for(@new_post) do |builder|
68
69
  concat(builder.action(:submit, :as => :link))
69
70
  end)
70
71
  }.to raise_error(Formtastic::UnsupportedMethodForAction)
71
72
  end
72
-
73
+
73
74
  end
74
75
 
75
76
  RSpec.describe 'LinkAction', 'when submitting' do
76
77
 
77
78
  include FormtasticSpecHelper
78
-
79
+
79
80
  before do
80
- @output_buffer = ''
81
+ @output_buffer = ActionView::OutputBuffer.new ''
81
82
  mock_everything
82
83
  end
83
-
84
+
84
85
  it 'should raise an error' do
85
- expect {
86
+ expect {
86
87
  concat(semantic_form_for(@new_post) do |builder|
87
88
  concat(builder.action(:reset, :as => :link))
88
89
  end)
89
90
  }.to raise_error(Formtastic::UnsupportedMethodForAction)
90
91
  end
91
-
92
+
92
93
  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 'Formtastic::Helpers::FormHelper.builder' do
@@ -17,7 +18,7 @@ RSpec.describe 'Formtastic::Helpers::FormHelper.builder' do
17
18
  end
18
19
 
19
20
  before do
20
- @output_buffer = ''
21
+ @output_buffer = ActionView::OutputBuffer.new ''
21
22
  mock_everything
22
23
  end
23
24
 
@@ -87,9 +88,9 @@ RSpec.describe 'Formtastic::Helpers::FormHelper.builder' do
87
88
  concat(builder.inputs)
88
89
  end)
89
90
 
90
- expect(output_buffer).to_not have_tag('input#post_title')
91
- expect(output_buffer).to_not have_tag('li#post_created_at_input')
92
- expect(output_buffer).to have_tag('textarea#post_body')
91
+ expect(output_buffer.to_str).to_not have_tag('input#post_title')
92
+ expect(output_buffer.to_str).to_not have_tag('li#post_created_at_input')
93
+ expect(output_buffer.to_str).to have_tag('textarea#post_body')
93
94
  end
94
95
  end
95
96
 
@@ -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 'Rails field_error_proc' do
@@ -6,7 +7,7 @@ RSpec.describe 'Rails field_error_proc' 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
 
@@ -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 'Formtastic::FormBuilder#fields_for' do
@@ -6,7 +7,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' 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
  allow(@new_post).to receive(:author).and_return(::Author.new)
12
13
  end
@@ -26,7 +27,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
26
27
  expect(nested_builder.class).to eq(Formtastic::Helpers::FormHelper.builder)
27
28
  end
28
29
  end
29
-
30
+
30
31
  it 'should respond to input' do
31
32
  semantic_fields_for(@new_post) do |nested_builder|
32
33
  expect(nested_builder.respond_to?(:input)).to be_truthy
@@ -42,7 +43,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
42
43
  end
43
44
  end
44
45
  end
45
-
46
+
46
47
  context 'within a form_for block' do
47
48
  it 'yields an instance of FormHelper.builder' do
48
49
  semantic_form_for(@new_post) do |builder|
@@ -51,7 +52,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
51
52
  end
52
53
  end
53
54
  end
54
-
55
+
55
56
  it 'yields an instance of FormHelper.builder with hash-like model' do
56
57
  semantic_form_for(:user) do |builder|
57
58
  builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
@@ -59,7 +60,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
59
60
  end
60
61
  end
61
62
  end
62
-
63
+
63
64
  it 'nests the object name' do
64
65
  semantic_form_for(@new_post) do |builder|
65
66
  builder.semantic_fields_for(@bob) do |nested_builder|
@@ -67,7 +68,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
67
68
  end
68
69
  end
69
70
  end
70
-
71
+
71
72
  it 'supports passing collection as second parameter' do
72
73
  semantic_form_for(@new_post) do |builder|
73
74
  builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
@@ -75,7 +76,7 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
75
76
  end
76
77
  end
77
78
  end
78
-
79
+
79
80
  it 'should sanitize html id for li tag' do
80
81
  allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
81
82
  concat(semantic_form_for(@new_post) do |builder|
@@ -83,12 +84,12 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
83
84
  concat(nested_builder.inputs(:login))
84
85
  end)
85
86
  end)
86
- expect(output_buffer).to have_tag('form fieldset.inputs #post_author_1_login_input')
87
+ expect(output_buffer.to_str).to have_tag('form fieldset.inputs #post_author_1_login_input')
87
88
  # Not valid selector, so using good ol' regex
88
- expect(output_buffer).not_to match(/id="post\[author\]_1_login_input"/)
89
+ expect(output_buffer.to_str).not_to match(/id="post\[author\]_1_login_input"/)
89
90
  # <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
90
91
  end
91
-
92
+
92
93
  it 'should use namespace provided in nested fields' do
93
94
  allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
94
95
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
@@ -96,29 +97,29 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
96
97
  concat(nested_builder.inputs(:login))
97
98
  end)
98
99
  end)
99
- expect(output_buffer).to have_tag('form fieldset.inputs #context2_post_author_1_login_input')
100
+ expect(output_buffer.to_str).to have_tag('form fieldset.inputs #context2_post_author_1_login_input')
100
101
  end
101
-
102
+
102
103
  it 'should render errors on the nested inputs' do
103
104
  @errors = double('errors')
104
- allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
105
+ allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
105
106
  allow(@bob).to receive(:errors).and_return(@errors)
106
-
107
+
107
108
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
108
109
  concat(builder.semantic_fields_for(@bob) do |nested_builder|
109
110
  concat(nested_builder.inputs(:login))
110
111
  end)
111
112
  end)
112
- expect(output_buffer).to match(/oh noes/)
113
+ expect(output_buffer.to_str).to match(/oh noes/)
113
114
  end
114
-
115
+
115
116
  end
116
-
117
- context "when I rendered my own hidden id input" do
118
-
117
+
118
+ context "when I rendered my own hidden id input" do
119
+
119
120
  before do
120
- output_buffer.replace ''
121
-
121
+ @output_buffer = ActionView::OutputBuffer.new ''
122
+
122
123
  expect(@fred.posts.size).to eq(1)
123
124
  allow(@fred.posts.first).to receive(:persisted?).and_return(true)
124
125
  allow(@fred).to receive(:posts_attributes=)
@@ -129,13 +130,13 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
129
130
  end)
130
131
  end)
131
132
  end
132
-
133
+
133
134
  it "should only render one hidden input (my one)" do
134
- expect(output_buffer).to have_tag 'input#author_posts_attributes_0_id', :count => 1
135
+ expect(output_buffer.to_str).to have_tag 'input#author_posts_attributes_0_id', :count => 1
135
136
  end
136
-
137
+
137
138
  it "should render the hidden input inside an li.hidden" do
138
- expect(output_buffer).to have_tag 'li.hidden input#author_posts_attributes_0_id'
139
+ expect(output_buffer.to_str).to have_tag 'li.hidden input#author_posts_attributes_0_id'
139
140
  end
140
141
  end
141
142
 
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  $LOAD_PATH << 'lib/formtastic'
3
4
  require 'active_support/all'
4
5
  require 'localized_string'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  # Generators are not automatically loaded by Rails
@@ -11,7 +12,7 @@ RSpec.describe Formtastic::FormGenerator do
11
12
  destination File.expand_path("../../../../../tmp", __FILE__)
12
13
 
13
14
  before do
14
- @output_buffer = ''
15
+ @output_buffer = ActionView::OutputBuffer.new ''
15
16
  prepare_destination
16
17
  mock_everything
17
18
  allow(::Post).to receive(:reflect_on_all_associations).with(:belongs_to).and_return([
@@ -21,7 +22,7 @@ RSpec.describe Formtastic::FormGenerator do
21
22
  double('reflection', :name => :attachment, :options => {:polymorphic => true}, :macro => :belongs_to),
22
23
  ])
23
24
  end
24
-
25
+
25
26
  after do
26
27
  FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
27
28
  end
@@ -82,14 +83,14 @@ RSpec.describe Formtastic::FormGenerator do
82
83
  end
83
84
 
84
85
  describe 'haml' do
85
-
86
+
86
87
  describe 'app/views/posts/_form.html.haml' do
87
88
  before { run_generator %w(Post --template-engine haml) }
88
89
  subject { file('app/views/posts/_form.html.haml') }
89
90
  it { is_expected.to exist }
90
91
  it { is_expected.to contain "= semantic_form_for @post do |f|" }
91
92
  end
92
-
93
+
93
94
  context 'with copy option' do
94
95
  describe 'app/views/posts/_form.html.haml' do
95
96
  before { run_generator %w(Post --copy --template-engine haml) }
@@ -97,7 +98,7 @@ RSpec.describe Formtastic::FormGenerator do
97
98
  it { is_expected.not_to exist }
98
99
  end
99
100
  end
100
-
101
+
101
102
  end
102
103
 
103
104
  describe 'slim' do
@@ -110,10 +111,10 @@ RSpec.describe Formtastic::FormGenerator do
110
111
  end
111
112
  end
112
113
  end
113
-
114
+
114
115
  describe 'with copy option' do
115
116
  before { run_generator %w(Post --copy) }
116
-
117
+
117
118
  describe 'app/views/posts/_form.html.erb' do
118
119
  subject { file('app/views/posts/_form.html.erb') }
119
120
  it { is_expected.not_to exist }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  require 'generators/formtastic/input/input_generator'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  # Generators are not automatically loaded by Rails
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe 'with action class finder' do
@@ -21,21 +22,21 @@ RSpec.describe 'with action class finder' do
21
22
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
22
23
  concat(builder.action(:submit))
23
24
  end)
24
- expect(output_buffer).to 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)
25
26
  end
26
27
 
27
28
  it 'should default to a button for reset' do
28
29
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
29
30
  concat(builder.action(:reset))
30
31
  end)
31
- expect(output_buffer).to 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)
32
33
  end
33
34
 
34
35
  it 'should default to a link for cancel' do
35
36
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
36
37
  concat(builder.action(:cancel))
37
38
  end)
38
- expect(output_buffer).to 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)
39
40
  end
40
41
  end
41
42
 
@@ -202,26 +203,26 @@ RSpec.describe 'with action class finder' do
202
203
  concat(semantic_form_for(@new_post) do |builder|
203
204
  concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
204
205
  end)
205
- expect(output_buffer).to have_tag("form li#another_id")
206
+ expect(output_buffer.to_str).to have_tag("form li#another_id")
206
207
  end
207
208
 
208
209
  it 'should append given classes to li default classes' do
209
210
  concat(semantic_form_for(@new_post) do |builder|
210
211
  concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
211
212
  end)
212
- expect(output_buffer).to have_tag("form li.action")
213
- expect(output_buffer).to have_tag("form li.input_action")
214
- expect(output_buffer).to 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")
215
216
  end
216
217
 
217
218
  it 'should allow classes to be an array' do
218
219
  concat(semantic_form_for(@new_post) do |builder|
219
220
  concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
220
221
  end)
221
- expect(output_buffer).to have_tag("form li.action")
222
- expect(output_buffer).to have_tag("form li.input_action")
223
- expect(output_buffer).to have_tag("form li.my_class")
224
- expect(output_buffer).to 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")
225
226
  end
226
227
  end
227
228
 
@@ -230,9 +231,9 @@ RSpec.describe 'with action class finder' do
230
231
  concat(semantic_form_for(@new_post) do |builder|
231
232
  concat(builder.action(:submit))
232
233
  end)
233
- expect(output_buffer).to have_tag("form li#post_submit_action")
234
- expect(output_buffer).to have_tag("form li.action")
235
- expect(output_buffer).to 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")
236
237
  end
237
238
  end
238
239
 
@@ -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 'Formtastic::FormBuilder#actions' do
@@ -6,7 +7,7 @@ RSpec.describe 'Formtastic::FormBuilder#actions' 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
 
@@ -21,123 +22,123 @@ RSpec.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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to have_tag("form fieldset.actions ol", :text => /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
- expect(output_buffer).not_to 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
- expect(output_buffer).to have_tag("form fieldset.actions legend", :text => /#{@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
- expect(output_buffer).to have_tag("form fieldset##{@id_option}")
66
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).not_to 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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to 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
- expect(output_buffer).to have_tag('form > fieldset#my-id.actions > legend', :text => /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