formtastic 5.0.0 → 6.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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +0 -1
  3. data/.github/workflows/integration.yaml +36 -0
  4. data/.github/workflows/test.yml +26 -20
  5. data/.gitignore +2 -1
  6. data/Appraisals +23 -0
  7. data/CONTRIBUTING.md +27 -0
  8. data/Gemfile +5 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +14 -46
  11. data/RELEASE_PROCESS +0 -1
  12. data/Rakefile +1 -1
  13. data/formtastic.gemspec +17 -10
  14. data/gemfiles/rails_72.gemfile +9 -0
  15. data/gemfiles/rails_80.gemfile +9 -0
  16. data/gemfiles/rails_81.gemfile +9 -0
  17. data/gemfiles/rails_edge.gemfile +9 -0
  18. data/lib/formtastic/actions/input_action.rb +1 -1
  19. data/lib/formtastic/actions/link_action.rb +1 -1
  20. data/lib/formtastic/form_builder.rb +27 -27
  21. data/lib/formtastic/helpers/action_helper.rb +0 -1
  22. data/lib/formtastic/helpers/actions_helper.rb +1 -1
  23. data/lib/formtastic/helpers/errors_helper.rb +71 -14
  24. data/lib/formtastic/helpers/fieldset_wrapper.rb +1 -1
  25. data/lib/formtastic/helpers/form_helper.rb +3 -3
  26. data/lib/formtastic/helpers/input_helper.rb +5 -3
  27. data/lib/formtastic/i18n.rb +0 -1
  28. data/lib/formtastic/inputs/base/aria.rb +26 -0
  29. data/lib/formtastic/inputs/base/collections.rb +1 -1
  30. data/lib/formtastic/inputs/base/errors.rb +1 -1
  31. data/lib/formtastic/inputs/base/html.rb +1 -1
  32. data/lib/formtastic/inputs/base/labelling.rb +1 -1
  33. data/lib/formtastic/inputs/base/validations.rb +32 -8
  34. data/lib/formtastic/inputs/base.rb +7 -5
  35. data/lib/formtastic/inputs/country_input.rb +9 -6
  36. data/lib/formtastic/inputs/datalist_input.rb +2 -2
  37. data/lib/formtastic/inputs/number_input.rb +1 -1
  38. data/lib/formtastic/inputs/range_input.rb +1 -1
  39. data/lib/formtastic/inputs/time_zone_input.rb +1 -1
  40. data/lib/formtastic/version.rb +1 -1
  41. data/lib/formtastic.rb +6 -2
  42. data/lib/generators/formtastic/form/form_generator.rb +2 -3
  43. data/lib/generators/formtastic/install/install_generator.rb +0 -1
  44. data/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  45. data/{app/assets/stylesheets → lib/generators/templates}/formtastic.css +4 -4
  46. data/lib/generators/templates/formtastic.rb +7 -1
  47. data/script/integration-template.rb +14 -11
  48. data/script/integration.sh +17 -4
  49. data/spec/action_class_finder_spec.rb +0 -1
  50. data/spec/actions/button_action_spec.rb +0 -1
  51. data/spec/actions/generic_action_spec.rb +2 -3
  52. data/spec/actions/input_action_spec.rb +0 -1
  53. data/spec/actions/link_action_spec.rb +0 -1
  54. data/spec/builder/custom_builder_spec.rb +0 -1
  55. data/spec/builder/error_proc_spec.rb +0 -1
  56. data/spec/builder/semantic_fields_for_spec.rb +72 -2
  57. data/spec/fast_spec_helper.rb +0 -1
  58. data/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  59. data/spec/helpers/actions_helper_spec.rb +0 -1
  60. data/spec/helpers/form_helper_spec.rb +0 -1
  61. data/spec/helpers/input_helper_spec.rb +12 -1
  62. data/spec/helpers/inputs_helper_spec.rb +1 -2
  63. data/spec/helpers/reflection_helper_spec.rb +0 -1
  64. data/spec/helpers/semantic_errors_helper_spec.rb +114 -7
  65. data/spec/i18n_spec.rb +1 -2
  66. data/spec/input_class_finder_spec.rb +0 -1
  67. data/spec/inputs/base/collections_spec.rb +41 -0
  68. data/spec/inputs/boolean_input_spec.rb +0 -1
  69. data/spec/inputs/check_boxes_input_spec.rb +1 -2
  70. data/spec/inputs/color_input_spec.rb +0 -1
  71. data/spec/inputs/country_input_spec.rb +5 -6
  72. data/spec/inputs/custom_input_spec.rb +0 -1
  73. data/spec/inputs/datalist_input_spec.rb +0 -1
  74. data/spec/inputs/date_picker_input_spec.rb +0 -1
  75. data/spec/inputs/date_select_input_spec.rb +1 -2
  76. data/spec/inputs/datetime_picker_input_spec.rb +0 -1
  77. data/spec/inputs/datetime_select_input_spec.rb +1 -2
  78. data/spec/inputs/email_input_spec.rb +0 -1
  79. data/spec/inputs/file_input_spec.rb +0 -1
  80. data/spec/inputs/hidden_input_spec.rb +0 -1
  81. data/spec/inputs/include_blank_spec.rb +0 -1
  82. data/spec/inputs/label_spec.rb +32 -1
  83. data/spec/inputs/number_input_spec.rb +0 -1
  84. data/spec/inputs/password_input_spec.rb +1 -2
  85. data/spec/inputs/phone_input_spec.rb +0 -1
  86. data/spec/inputs/placeholder_spec.rb +0 -1
  87. data/spec/inputs/radio_input_spec.rb +0 -1
  88. data/spec/inputs/range_input_spec.rb +0 -1
  89. data/spec/inputs/readonly_spec.rb +0 -1
  90. data/spec/inputs/search_input_spec.rb +0 -1
  91. data/spec/inputs/select_input_spec.rb +0 -1
  92. data/spec/inputs/string_input_spec.rb +67 -2
  93. data/spec/inputs/text_input_spec.rb +0 -1
  94. data/spec/inputs/time_picker_input_spec.rb +0 -1
  95. data/spec/inputs/time_select_input_spec.rb +1 -2
  96. data/spec/inputs/time_zone_input_spec.rb +0 -1
  97. data/spec/inputs/url_input_spec.rb +0 -1
  98. data/spec/inputs/with_options_spec.rb +0 -1
  99. data/spec/localizer_spec.rb +0 -1
  100. data/spec/namespaced_class_finder_spec.rb +0 -1
  101. data/spec/spec_helper.rb +2 -1
  102. data/spec/support/custom_macros.rb +11 -3
  103. data/spec/support/specialized_class_finder_shared_example.rb +0 -1
  104. data/spec/support/test_environment.rb +2 -2
  105. metadata +53 -41
  106. data/CHANGELOG.md +0 -61
  107. data/Gemfile.lock +0 -140
  108. data/app/assets/stylesheets/formtastic_ie6.css +0 -33
  109. data/app/assets/stylesheets/formtastic_ie7.css +0 -23
  110. data/gemfiles/rails_6.0/Gemfile +0 -5
  111. data/gemfiles/rails_6.1/Gemfile +0 -5
  112. data/gemfiles/rails_7.0/Gemfile +0 -5
  113. data/gemfiles/rails_7.1/Gemfile +0 -5
  114. data/gemfiles/rails_edge/Gemfile +0 -13
  115. data/lib/formtastic/engine.rb +0 -14
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
  require 'formtastic/action_class_finder'
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -74,7 +73,7 @@ RSpec.describe 'InputAction::Base' do
74
73
  end)
75
74
  end
76
75
 
77
- it "should add the custom class strng to the existing classes" do
76
+ it "should add the custom class string to the existing classes" do
78
77
  expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing')
79
78
  end
80
79
 
@@ -90,7 +89,7 @@ RSpec.describe 'InputAction::Base' do
90
89
  end)
91
90
  end
92
91
 
93
- it "should add the custom class strng to the existing classes" do
92
+ it "should add the custom class string to the existing classes" do
94
93
  expect(output_buffer.to_str).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
95
94
  end
96
95
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -112,7 +111,6 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
112
111
  end)
113
112
  expect(output_buffer.to_str).to match(/oh noes/)
114
113
  end
115
-
116
114
  end
117
115
 
118
116
  context "when I rendered my own hidden id input" do
@@ -140,4 +138,76 @@ RSpec.describe 'Formtastic::FormBuilder#fields_for' do
140
138
  end
141
139
  end
142
140
 
141
+ context "when FormBuilder.semantic_errors_link_to_inputs is true" do
142
+ before do
143
+ Formtastic::FormBuilder.semantic_errors_link_to_inputs = true
144
+ end
145
+
146
+ after do
147
+ Formtastic::FormBuilder.semantic_errors_link_to_inputs = false
148
+ end
149
+
150
+ context "when there are errors" do
151
+ before do
152
+ @errors = double('errors')
153
+ allow(@errors).to receive(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
154
+ allow(@errors).to receive(:[]).with(errors_matcher(:name)).and_return([])
155
+ allow(@bob).to receive(:errors).and_return(@errors)
156
+
157
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
158
+ concat(builder.semantic_fields_for(@bob) do |nested_builder|
159
+ concat(nested_builder.inputs(:login, :name))
160
+ end)
161
+ end)
162
+ end
163
+
164
+ it 'should render errors on the nested inputs with default aria attributes' do
165
+ expect(output_buffer.to_str).to include('aria-invalid="true"')
166
+ expect(output_buffer.to_str).to \
167
+ have_tag 'input#context2_post_author_login[aria-describedby="login_error"]', \
168
+ count: 1
169
+ end
170
+
171
+ it 'should preserve developer-set aria attributes' do
172
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
173
+ concat(builder.semantic_fields_for(@bob) do |nested_builder|
174
+ concat(nested_builder.input(:login, input_html: { 'aria-describedby': 'hint_for_email_field', 'aria-invalid': 'false' } ))
175
+ end)
176
+ end)
177
+
178
+ expect(output_buffer.to_str).to \
179
+ have_tag 'input#context2_post_author_login[aria-describedby="hint_for_email_field login_error"]', \
180
+ count: 1
181
+ expect(output_buffer.to_str).to \
182
+ have_tag 'input#context2_post_author_login[aria-invalid="false"]', \
183
+ count: 1
184
+ end
185
+ end
186
+
187
+ context "when there are no errors" do
188
+ before do
189
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
190
+ concat(builder.semantic_fields_for(@bob) do |nested_builder|
191
+ concat(nested_builder.input(:login))
192
+ end)
193
+ end)
194
+ end
195
+
196
+ it 'should not aria attributes on nested inputs' do
197
+ expect(output_buffer.to_str).not_to include('aria-invalid')
198
+ expect(output_buffer.to_str).not_to include('aria-describedby')
199
+ end
200
+
201
+ it 'should render aria attributes I set' do
202
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
203
+ concat(builder.semantic_fields_for(@bob) do |nested_builder|
204
+ concat(nested_builder.input(:login, input_html: { 'aria-describedby': 'hint_for_email_field', 'aria-invalid': 'false' } ))
205
+ end)
206
+ end)
207
+
208
+ expect(output_buffer.to_str).to include('aria-describedby="hint_for_email_field"')
209
+ expect(output_buffer.to_str).to include('aria-invalid="false"')
210
+ end
211
+ end
212
+ end
143
213
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  $LOAD_PATH << 'lib/formtastic'
4
3
  require 'active_support/all'
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ # Generators are not automatically loaded by Rails
5
+ require 'generators/formtastic/stylesheets/stylesheets_generator'
6
+
7
+ RSpec.describe Formtastic::StylesheetsGenerator do
8
+ # Tell the generator where to put its output (what it thinks of as Rails.root)
9
+ destination File.expand_path("../../../../../tmp", __FILE__)
10
+
11
+ before { prepare_destination }
12
+
13
+ describe 'no arguments' do
14
+ before { run_generator }
15
+
16
+ describe 'app/assets/stylesheets/formtastic.css' do
17
+ subject { file('app/assets/stylesheets/formtastic.css') }
18
+ it { is_expected.to exist }
19
+ it { is_expected.to contain ".formtastic" }
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -492,6 +491,7 @@ RSpec.describe 'with input class finder' do
492
491
  it 'should default to :datetime_select for :datetime and :timestamp column types' do
493
492
  expect(default_input_type(:datetime)).to eq(:datetime_select)
494
493
  expect(default_input_type(:timestamp)).to eq(:datetime_select)
494
+ expect(default_input_type(:timestamptz)).to eq(:datetime_select)
495
495
  end
496
496
 
497
497
  it 'should default to :time_select for :time column types' do
@@ -731,6 +731,17 @@ RSpec.describe 'with input class finder' do
731
731
 
732
732
  end
733
733
 
734
+ describe ':label_method option' do
735
+ it "should allow label_html to add custom attributes" do
736
+ concat(semantic_form_for(@new_post) do |builder|
737
+ concat(builder.input(:title, :label_html => { :data => { :tooltip => 'Great Tooltip' } }))
738
+ end)
739
+ aggregate_failures do
740
+ expect(output_buffer.to_str).to have_tag('form li label[data-tooltip="Great Tooltip"]')
741
+ end
742
+ end
743
+ end
744
+
734
745
  describe ':hint option' do
735
746
 
736
747
  describe 'when provided' do
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -138,7 +137,7 @@ RSpec.describe 'Formtastic::FormBuilder#inputs' do
138
137
  end
139
138
  end
140
139
 
141
- describe 'as an array containing the a symbole for the association name and the associated object' do
140
+ describe 'as an array containing the a symbol for the association name and the associated object' do
142
141
 
143
142
  it 'should nest the inputs with an _attributes suffix on the association name' do
144
143
  concat(semantic_form_for(@new_post) do |post|
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -11,7 +10,7 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
11
10
  mock_everything
12
11
  @title_errors = ['must not be blank', 'must be awesome']
13
12
  @base_errors = ['base error message', 'nasty error']
14
- @base_error = 'one base error'
13
+ @base_error = ['one base error']
15
14
  @errors = double('errors')
16
15
  allow(@new_post).to receive(:errors).and_return(@errors)
17
16
  end
@@ -23,7 +22,7 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
23
22
 
24
23
  it 'should render an unordered list' do
25
24
  semantic_form_for(@new_post) do |builder|
26
- expect(builder.semantic_errors).to have_tag('ul.errors li', :text => @base_error)
25
+ expect(builder.semantic_errors).to have_tag('ul.errors li', text: 'one base error')
27
26
  end
28
27
  end
29
28
  end
@@ -67,15 +66,15 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
67
66
  semantic_form_for(@new_post) do |builder|
68
67
  title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
69
68
  expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => title_name << " " << @title_errors.to_sentence)
70
- expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', :text => @base_error)
69
+ expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', text: 'one base error')
71
70
  end
72
71
  end
73
72
  end
74
73
 
75
74
  describe 'when there are no errors' do
76
75
  before do
77
- allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(nil)
78
- allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(nil)
76
+ allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return([])
77
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
79
78
  end
80
79
 
81
80
  it 'should return nil' do
@@ -92,7 +91,7 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
92
91
 
93
92
  it 'should render an unordered list with given class' do
94
93
  semantic_form_for(@new_post) do |builder|
95
- expect(builder.semantic_errors(:class => "awesome")).to have_tag('ul.awesome li', :text => @base_error)
94
+ expect(builder.semantic_errors(:class => "awesome")).to have_tag('ul.awesome li', text: 'one base error')
96
95
  end
97
96
  end
98
97
  end
@@ -110,4 +109,112 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
110
109
  end
111
110
  end
112
111
 
112
+ context 'when configure FormBuilder.semantic_errors_link_to_inputs is true' do
113
+ before do
114
+ Formtastic::FormBuilder.semantic_errors_link_to_inputs = true
115
+ end
116
+
117
+ after do
118
+ Formtastic::FormBuilder.semantic_errors_link_to_inputs = false
119
+ end
120
+
121
+
122
+ describe 'when there is only one error on base' do
123
+ before do
124
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
125
+ end
126
+
127
+ it 'should render an unordered list' do
128
+ semantic_form_for(@new_post) do |builder|
129
+ expect(builder.semantic_errors).to have_tag('ul.errors li', text: 'one base error')
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'when there is more than one error on base' do
135
+ before do
136
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_errors)
137
+ end
138
+
139
+ it 'should render an unordered list' do
140
+ semantic_form_for(@new_post) do |builder|
141
+ expect(builder.semantic_errors).to have_tag('ul.errors')
142
+ @base_errors.each do |error|
143
+ expect(builder.semantic_errors).to have_tag('ul.errors li', :text => error)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ describe 'when there are errors on title' do
150
+ before do
151
+ allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
152
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
153
+ end
154
+
155
+ it 'should render an unordered list' do
156
+ semantic_form_for(@new_post) do |builder|
157
+ title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
158
+ expect(builder.semantic_errors(:title)).to have_tag('ul.errors li a', :text => title_name << " " << @title_errors.to_sentence)
159
+ end
160
+ end
161
+ end
162
+
163
+ describe 'when there are errors on title and base' do
164
+ before do
165
+ allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return(@title_errors)
166
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
167
+ end
168
+
169
+ it 'should render an unordered list where base has no link, and title error attribute links to title input field' do
170
+ semantic_form_for(@new_post) do |builder|
171
+ title_name = builder.send(:localized_string, :title, :title, :label) || builder.send(:humanized_attribute_name, :title)
172
+ expect(builder.semantic_errors(:title)).to \
173
+ have_tag('ul.errors li a',
174
+ with: { href: "##{@new_post.model_name}_title" },
175
+ text: title_name << " " << @title_errors.to_sentence
176
+ )
177
+ expect(builder.semantic_errors(:title)).to have_tag('ul.errors li', text: 'one base error')
178
+ end
179
+ end
180
+ end
181
+
182
+ describe 'when there are no errors' do
183
+ before do
184
+ allow(@errors).to receive(:[]).with(errors_matcher(:title)).and_return([])
185
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return([])
186
+ end
187
+
188
+ it 'should return nil' do
189
+ semantic_form_for(@new_post) do |builder|
190
+ expect(builder.semantic_errors(:title)).to be_nil
191
+ end
192
+ end
193
+ end
194
+
195
+ describe 'when there is one error on base and options with class is passed' do
196
+ before do
197
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
198
+ end
199
+
200
+ it 'should render an unordered list with given class' do
201
+ semantic_form_for(@new_post) do |builder|
202
+ expect(builder.semantic_errors(class: "awesome")).to have_tag('ul.awesome li', text: 'one base error')
203
+ end
204
+ end
205
+ end
206
+
207
+ describe 'when :base is passed in as an argument' do
208
+ before do
209
+ allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
210
+ end
211
+
212
+ it 'should ignore :base and only render base errors once' do
213
+ semantic_form_for(@new_post) do |builder|
214
+ expect(builder.semantic_errors(:base)).to have_tag('ul li', count: 1)
215
+ expect(builder.semantic_errors(:base)).not_to have_tag('ul li', text: "Base #{@base_error}")
216
+ end
217
+ end
218
+ end
219
+ end # context 'when semantic_errors_link_to_inputs is true'
113
220
  end
data/spec/i18n_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -88,7 +87,7 @@ RSpec.describe 'Formtastic::I18n' do
88
87
 
89
88
  ::I18n.backend.store_translations :en, {:formtastic => {
90
89
  :labels => {
91
- :author => { :name => "Top author name transation" },
90
+ :author => { :name => "Top author name translation" },
92
91
  :post => {:title => "Hello post!", :author => {:name => "Hello author name!"}},
93
92
  :project => {:title => "Hello project!"},
94
93
  }
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
  require 'formtastic/input_class_finder'
@@ -74,5 +74,46 @@ RSpec.describe MyInput do
74
74
  end
75
75
  end
76
76
 
77
+ describe '#collection' do
78
+ context 'when the raw collection is a string' do
79
+ it 'returns the string' do
80
+ allow(instance).to receive(:raw_collection).and_return("one_status_only")
81
+ expect(instance.collection).to eq "one_status_only"
82
+ end
83
+ end
84
+
85
+ context 'when the raw collection is an array of strings' do
86
+ it 'returns the array of symbols' do
87
+ allow(instance).to receive(:raw_collection).and_return(["active", "inactive", "pending"])
88
+ expect(instance.collection).to be_an(Array)
89
+ expect(instance.collection).to eq ["active", "inactive", "pending"]
90
+ end
91
+ end
92
+
93
+ context 'when the raw collection is an array of arrays' do
94
+ it 'returns the array of arrays' do
95
+ allow(instance).to receive(:raw_collection).and_return([["inactive", "0"], ["active", "1"], ["pending", "2"]])
96
+ expect(instance.collection).to be_an(Array)
97
+ expect(instance.collection).to eq [["inactive", "0"], ["active", "1"], ["pending", "2"]]
98
+ end
99
+ end
100
+
101
+ context 'when the raw collection is an array of symbols' do
102
+ it 'returns the array of symbols' do
103
+ allow(instance).to receive(:raw_collection).and_return([:active, :inactive, :pending])
104
+ expect(instance.collection).to be_an(Array)
105
+ expect(instance.collection).to eq [:active, :inactive, :pending]
106
+ end
107
+ end
108
+
109
+ context 'when the raw collection is a hash' do
110
+ it 'will be mapped into array form' do
111
+ allow(instance).to receive(:raw_collection).and_return({ inactive: 0, active: 1, pending: 2 })
112
+ expect(instance.collection).to be_an(Array)
113
+ expect(instance.collection).to eq [[:inactive, 0], [:active, 1], [:pending, 2]]
114
+ end
115
+ end
116
+ end
117
+
77
118
  end
78
119
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -510,7 +509,7 @@ RSpec.describe 'check_boxes input' do
510
509
  end
511
510
 
512
511
  it "should not check any items" do
513
- expect(output_buffer.to_str).to have_tag('form li input[@checked]', :count => 0)
512
+ expect(output_buffer.to_str).not_to have_tag('form li input[@checked]')
514
513
  end
515
514
 
516
515
  describe "and the attribute has values" do
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -13,7 +12,7 @@ RSpec.describe 'country input' do
13
12
 
14
13
  describe "when country_select is not available as a helper from a plugin" do
15
14
 
16
- it "should raise an error, sugesting the author installs a plugin" do
15
+ it "should raise an error, suggesting the author installs a plugin" do
17
16
  expect {
18
17
  semantic_form_for(@new_post) do |builder|
19
18
  concat(builder.input(:country, :as => :country))
@@ -57,7 +56,7 @@ RSpec.describe 'country input' do
57
56
  priority_countries = ["Foo", "Bah"]
58
57
  semantic_form_for(@new_post) do |builder|
59
58
  allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
60
- expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
59
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => priority_countries }, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
61
60
 
62
61
  concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
63
62
  end
@@ -70,7 +69,7 @@ RSpec.describe 'country input' do
70
69
 
71
70
  semantic_form_for(@new_post) do |builder|
72
71
  allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
73
- expect(builder).to receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
72
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => priority_countries }, {:id => "post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
74
73
 
75
74
  concat(builder.input(:country, :as => :country))
76
75
  end
@@ -86,7 +85,7 @@ RSpec.describe 'country input' do
86
85
 
87
86
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
88
87
  allow(builder).to receive(:country_select).and_return("<select><option>...</option></select>".html_safe)
89
- expect(builder).to receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
88
+ expect(builder).to receive(:country_select).with(:country, { :priority_countries => [] }, {:id => "context2_post_country", :required => false, :autofocus => false, :readonly => false}).and_return("<select><option>...</option></select>".html_safe)
90
89
  concat(builder.input(:country, :priority_countries => []))
91
90
  end)
92
91
  end
@@ -112,7 +111,7 @@ RSpec.describe 'country input' do
112
111
  end
113
112
  end
114
113
 
115
- describe "whent the attribute is 'country_something'" do
114
+ describe "when the attribute is 'country_something'" do
116
115
 
117
116
  before do
118
117
  concat(semantic_form_for(@new_post) do |builder|
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -154,7 +153,7 @@ RSpec.describe 'date select input' do
154
153
  concat(semantic_form_for(@new_post) do |builder|
155
154
  concat(builder.input(:created_at, :as => :date_select, :labels => false))
156
155
  end)
157
- expect(output_buffer.to_str).to have_tag('form li.date_select fieldset ol li label', :count => 0)
156
+ expect(output_buffer.to_str).not_to have_tag('form li.date_select fieldset ol li label')
158
157
  end
159
158
  end
160
159
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -163,7 +162,7 @@ RSpec.describe 'datetime select input' do
163
162
  concat(semantic_form_for(@new_post) do |builder|
164
163
  concat(builder.input(:created_at, :as => :datetime_select, :labels => false))
165
164
  end)
166
- expect(output_buffer.to_str).to have_tag('form li.datetime_select fieldset ol li label', :count => 0)
165
+ expect(output_buffer.to_str).not_to have_tag('form li.datetime_select fieldset ol li label')
167
166
  end
168
167
  end
169
168
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3