formtastic 5.0.0 → 6.0.0.alpha

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration.yaml +36 -0
  3. data/.github/workflows/test.yml +26 -20
  4. data/.gitignore +2 -1
  5. data/Appraisals +23 -0
  6. data/CHANGELOG.md +18 -0
  7. data/CONTRIBUTING.md +27 -0
  8. data/Gemfile +5 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +9 -41
  11. data/Rakefile +1 -1
  12. data/formtastic.gemspec +17 -10
  13. data/gemfiles/rails_72.gemfile +9 -0
  14. data/gemfiles/rails_80.gemfile +9 -0
  15. data/gemfiles/rails_81.gemfile +9 -0
  16. data/gemfiles/rails_edge.gemfile +9 -0
  17. data/lib/formtastic/form_builder.rb +25 -25
  18. data/lib/formtastic/helpers/action_helper.rb +0 -1
  19. data/lib/formtastic/helpers/errors_helper.rb +71 -14
  20. data/lib/formtastic/helpers/input_helper.rb +4 -2
  21. data/lib/formtastic/i18n.rb +0 -1
  22. data/lib/formtastic/inputs/base/aria.rb +26 -0
  23. data/lib/formtastic/inputs/base/collections.rb +1 -1
  24. data/lib/formtastic/inputs/base/errors.rb +1 -1
  25. data/lib/formtastic/inputs/base/html.rb +1 -1
  26. data/lib/formtastic/inputs/base/labelling.rb +1 -1
  27. data/lib/formtastic/inputs/base/validations.rb +32 -8
  28. data/lib/formtastic/inputs/base.rb +4 -2
  29. data/lib/formtastic/inputs/country_input.rb +9 -6
  30. data/lib/formtastic/version.rb +1 -1
  31. data/lib/formtastic.rb +6 -2
  32. data/lib/generators/formtastic/form/form_generator.rb +2 -3
  33. data/lib/generators/formtastic/install/install_generator.rb +0 -1
  34. data/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  35. data/{app/assets/stylesheets → lib/generators/templates}/formtastic.css +4 -4
  36. data/lib/generators/templates/formtastic.rb +7 -1
  37. data/script/integration-template.rb +14 -11
  38. data/script/integration.sh +17 -4
  39. data/spec/action_class_finder_spec.rb +0 -1
  40. data/spec/actions/button_action_spec.rb +0 -1
  41. data/spec/actions/generic_action_spec.rb +0 -1
  42. data/spec/actions/input_action_spec.rb +0 -1
  43. data/spec/actions/link_action_spec.rb +0 -1
  44. data/spec/builder/custom_builder_spec.rb +0 -1
  45. data/spec/builder/error_proc_spec.rb +0 -1
  46. data/spec/builder/semantic_fields_for_spec.rb +72 -2
  47. data/spec/fast_spec_helper.rb +0 -1
  48. data/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  49. data/spec/helpers/actions_helper_spec.rb +0 -1
  50. data/spec/helpers/form_helper_spec.rb +0 -1
  51. data/spec/helpers/input_helper_spec.rb +12 -1
  52. data/spec/helpers/inputs_helper_spec.rb +0 -1
  53. data/spec/helpers/reflection_helper_spec.rb +0 -1
  54. data/spec/helpers/semantic_errors_helper_spec.rb +114 -7
  55. data/spec/i18n_spec.rb +0 -1
  56. data/spec/input_class_finder_spec.rb +0 -1
  57. data/spec/inputs/base/collections_spec.rb +41 -0
  58. data/spec/inputs/boolean_input_spec.rb +0 -1
  59. data/spec/inputs/check_boxes_input_spec.rb +1 -2
  60. data/spec/inputs/color_input_spec.rb +0 -1
  61. data/spec/inputs/country_input_spec.rb +5 -6
  62. data/spec/inputs/custom_input_spec.rb +0 -1
  63. data/spec/inputs/datalist_input_spec.rb +0 -1
  64. data/spec/inputs/date_picker_input_spec.rb +0 -1
  65. data/spec/inputs/date_select_input_spec.rb +1 -2
  66. data/spec/inputs/datetime_picker_input_spec.rb +0 -1
  67. data/spec/inputs/datetime_select_input_spec.rb +1 -2
  68. data/spec/inputs/email_input_spec.rb +0 -1
  69. data/spec/inputs/file_input_spec.rb +0 -1
  70. data/spec/inputs/hidden_input_spec.rb +0 -1
  71. data/spec/inputs/include_blank_spec.rb +0 -1
  72. data/spec/inputs/label_spec.rb +32 -1
  73. data/spec/inputs/number_input_spec.rb +0 -1
  74. data/spec/inputs/password_input_spec.rb +1 -2
  75. data/spec/inputs/phone_input_spec.rb +0 -1
  76. data/spec/inputs/placeholder_spec.rb +0 -1
  77. data/spec/inputs/radio_input_spec.rb +0 -1
  78. data/spec/inputs/range_input_spec.rb +0 -1
  79. data/spec/inputs/readonly_spec.rb +0 -1
  80. data/spec/inputs/search_input_spec.rb +0 -1
  81. data/spec/inputs/select_input_spec.rb +0 -1
  82. data/spec/inputs/string_input_spec.rb +67 -2
  83. data/spec/inputs/text_input_spec.rb +0 -1
  84. data/spec/inputs/time_picker_input_spec.rb +0 -1
  85. data/spec/inputs/time_select_input_spec.rb +1 -2
  86. data/spec/inputs/time_zone_input_spec.rb +0 -1
  87. data/spec/inputs/url_input_spec.rb +0 -1
  88. data/spec/inputs/with_options_spec.rb +0 -1
  89. data/spec/localizer_spec.rb +0 -1
  90. data/spec/namespaced_class_finder_spec.rb +0 -1
  91. data/spec/spec_helper.rb +2 -1
  92. data/spec/support/custom_macros.rb +11 -3
  93. data/spec/support/specialized_class_finder_shared_example.rb +0 -1
  94. data/spec/support/test_environment.rb +1 -1
  95. metadata +53 -40
  96. data/Gemfile.lock +0 -140
  97. data/app/assets/stylesheets/formtastic_ie6.css +0 -33
  98. data/app/assets/stylesheets/formtastic_ie7.css +0 -23
  99. data/gemfiles/rails_6.0/Gemfile +0 -5
  100. data/gemfiles/rails_6.1/Gemfile +0 -5
  101. data/gemfiles/rails_7.0/Gemfile +0 -5
  102. data/gemfiles/rails_7.1/Gemfile +0 -5
  103. data/gemfiles/rails_edge/Gemfile +0 -13
  104. 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
 
@@ -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
 
@@ -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
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -40,6 +39,20 @@ RSpec.describe 'Formtastic::FormBuilder#label' do
40
39
  expect(output_buffer.to_str).to have_tag('label', :text => /Title/)
41
40
  end
42
41
 
42
+ it 'should apply a "for" attribute to the label' do
43
+ concat(semantic_form_for(@new_post) do |builder|
44
+ builder.input(:title)
45
+ end)
46
+ expect(output_buffer.to_str).to have_tag('label[for=post_title]')
47
+ end
48
+
49
+ it 'should apply a "label" class to the label' do
50
+ concat(semantic_form_for(@new_post) do |builder|
51
+ builder.input(:title)
52
+ end)
53
+ expect(output_buffer.to_str).to have_tag('label.label')
54
+ end
55
+
43
56
  it 'should use i18n instead of the method name when method given as a String' do
44
57
  with_config :i18n_cache_lookups, true do
45
58
  ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
@@ -67,6 +80,24 @@ RSpec.describe 'Formtastic::FormBuilder#label' do
67
80
  end
68
81
  end
69
82
 
83
+ describe "when label_html is given" do
84
+ it "should allow label_html to override the class" do
85
+ concat(semantic_form_for(@new_post) do |builder|
86
+ builder.input(:title, :label_html => { :class => 'my_class' } )
87
+ end)
88
+ expect(output_buffer.to_str).to have_tag('label.my_class', /Title/)
89
+ end
90
+
91
+ it "should allow label_html to add custom attributes" do
92
+ concat(semantic_form_for(@new_post) do |builder|
93
+ builder.input(:title, :label_html => { :data => { :tooltip => 'Great Tooltip' } } )
94
+ end)
95
+ aggregate_failures do
96
+ expect(output_buffer.to_str).to have_tag('label[data-tooltip="Great Tooltip"]')
97
+ end
98
+ end
99
+ end
100
+
70
101
  describe 'when a collection is given' do
71
102
  it 'should use a supplied label_method for simple collections' do
72
103
  with_deprecation_silenced 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
 
@@ -24,7 +23,7 @@ RSpec.describe 'password input' do
24
23
  it_should_have_input_with_id("post_title")
25
24
  it_should_have_input_with_type(:password)
26
25
  it_should_have_input_with_name("post[title]")
27
- it_should_have_maxlength_matching_column_limit
26
+ it_should_have_maxlength_matching_string_column_limit
28
27
  it_should_use_default_text_field_size_when_not_nil(:string)
29
28
  it_should_not_use_default_text_field_size_when_nil(:string)
30
29
  it_should_apply_custom_input_attributes_when_input_html_provided(:string)
@@ -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
 
@@ -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
 
@@ -15,6 +14,7 @@ RSpec.describe 'string input' do
15
14
  before do
16
15
  concat(semantic_form_for(@new_post) do |builder|
17
16
  concat(builder.input(:title, :as => :string))
17
+ concat(builder.input(:status, :as => :string))
18
18
  end)
19
19
  end
20
20
 
@@ -27,7 +27,8 @@ RSpec.describe 'string input' do
27
27
  it_should_have_input_with_id("post_title")
28
28
  it_should_have_input_with_type(:text)
29
29
  it_should_have_input_with_name("post[title]")
30
- it_should_have_maxlength_matching_column_limit
30
+ it_should_have_maxlength_matching_string_column_limit
31
+ it_should_have_maxlength_matching_integer_column_limit
31
32
  it_should_use_default_text_field_size_when_not_nil(:string)
32
33
  it_should_not_use_default_text_field_size_when_nil(:string)
33
34
  it_should_apply_custom_input_attributes_when_input_html_provided(:string)
@@ -110,6 +111,70 @@ RSpec.describe 'string input' do
110
111
  end
111
112
  end
112
113
 
114
+ describe 'and validates_length_of was called with a proc for :maximum' do
115
+ before do
116
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
117
+ active_model_length_validator([:title], { :maximum => Proc.new { 128 } })
118
+ ])
119
+ end
120
+
121
+ it 'should use the proc result as maxlength' do
122
+ concat(semantic_form_for(@new_post) do |builder|
123
+ concat(builder.input(:title))
124
+ end)
125
+ expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='128']")
126
+ end
127
+ end
128
+
129
+ describe 'and validates_length_of was called with a proc for :within' do
130
+ before do
131
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
132
+ active_model_length_validator([:title], { :within => Proc.new { 5..100 } })
133
+ ])
134
+ end
135
+
136
+ it 'should use the proc result maximum as maxlength' do
137
+ concat(semantic_form_for(@new_post) do |builder|
138
+ concat(builder.input(:title))
139
+ end)
140
+ expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='100']")
141
+ end
142
+ end
143
+
144
+ describe 'and validates_length_of was called with a proc for :minimum' do
145
+ before do
146
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
147
+ active_model_length_validator([:title], { :minimum => Proc.new { 8 }, :allow_blank => false })
148
+ ])
149
+ end
150
+
151
+ it 'should use the proc result to determine required status' do
152
+ concat(semantic_form_for(@new_post) do |builder|
153
+ concat(builder.input(:title))
154
+ end)
155
+ expect(output_buffer.to_str).to have_tag("form li.required")
156
+ end
157
+ end
158
+
159
+ describe 'and validates_length_of was called with a callable object for :maximum' do
160
+ before do
161
+ callable = Object.new
162
+ def callable.call(record)
163
+ 128
164
+ end
165
+ allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
166
+ active_model_length_validator([:title], { :maximum => callable })
167
+ ])
168
+ end
169
+
170
+ it 'should use the callable result as maxlength' do
171
+ concat(semantic_form_for(@new_post) do |builder|
172
+ concat(builder.input(:title))
173
+ end)
174
+ expect(output_buffer.to_str).to have_tag("form li input##{@new_post.class.name.underscore}_title[@maxlength='128']")
175
+ end
176
+ end
177
+
113
178
  describe 'any conditional validation' do
114
179
  describe 'proc that calls an instance method' do
115
180
  it 'calls the method on the object' 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
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
  require 'spec_helper'
4
3
 
@@ -182,7 +181,7 @@ RSpec.describe 'time select input' do
182
181
  concat(semantic_form_for(@new_post) do |builder|
183
182
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
184
183
  end)
185
- expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 0)
184
+ expect(output_buffer.to_str).not_to have_tag('form li.time_select fieldset ol li label')
186
185
  end
187
186
  end
188
187
 
@@ -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
  require 'formtastic/namespaced_class_finder'