formtastic 3.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -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#label' do
5
+ RSpec.describe 'Formtastic::FormBuilder#label' 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
 
@@ -20,7 +21,7 @@ describe 'Formtastic::FormBuilder#label' do
20
21
  concat(semantic_form_for(@new_post) do |builder|
21
22
  builder.input(:title, :required => true, :label => true)
22
23
  end)
23
- output_buffer.replace ''
24
+ @output_buffer = ActionView::OutputBuffer.new ''
24
25
  concat(semantic_form_for(@new_post) do |builder|
25
26
  builder.input(:title, :required => true, :label => true)
26
27
  end)
@@ -28,7 +29,7 @@ describe 'Formtastic::FormBuilder#label' do
28
29
  ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
29
30
  Formtastic::FormBuilder.required_string = default_required_str
30
31
 
31
- output_buffer.scan(required_string).count.should == 1
32
+ expect(output_buffer.to_s.scan(required_string).count).to eq(1)
32
33
  end
33
34
  end
34
35
 
@@ -36,9 +37,9 @@ describe 'Formtastic::FormBuilder#label' do
36
37
  concat(semantic_form_for(@new_post) do |builder|
37
38
  builder.input(:title)
38
39
  end)
39
- output_buffer.should have_tag('label', /Title/)
40
+ expect(output_buffer.to_str).to have_tag('label', :text => /Title/)
40
41
  end
41
-
42
+
42
43
  it 'should use i18n instead of the method name when method given as a String' do
43
44
  with_config :i18n_cache_lookups, true do
44
45
  ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => "I18n title" } } } }
@@ -46,7 +47,7 @@ describe 'Formtastic::FormBuilder#label' do
46
47
  builder.input("title")
47
48
  end)
48
49
  ::I18n.backend.store_translations :en, { :formtastic => { :labels => { :post => { :title => nil } } } }
49
- output_buffer.should have_tag('label', /I18n title/)
50
+ expect(output_buffer.to_str).to have_tag('label', :text => /I18n title/)
50
51
  end
51
52
  end
52
53
 
@@ -54,7 +55,7 @@ describe 'Formtastic::FormBuilder#label' do
54
55
  concat(semantic_form_for(@new_post) do |builder|
55
56
  builder.input(:publish_at)
56
57
  end)
57
- output_buffer.should have_tag('label', /Publish at/)
58
+ expect(output_buffer.to_str).to have_tag('label', :text => /Publish at/)
58
59
  end
59
60
 
60
61
  describe 'when required is given' do
@@ -62,25 +63,29 @@ describe 'Formtastic::FormBuilder#label' do
62
63
  concat(semantic_form_for(@new_post) do |builder|
63
64
  builder.input(:title, :required => true)
64
65
  end)
65
- output_buffer.should have_tag('label abbr', '*')
66
+ expect(output_buffer.to_str).to have_tag('label abbr', '*')
66
67
  end
67
68
  end
68
69
 
69
70
  describe 'when a collection is given' do
70
71
  it 'should use a supplied label_method for simple collections' do
71
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
72
- concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => :to_s, :member_label => proc {|f| ('Label_%s' % [f])}))
73
- end)
74
- output_buffer.should have_tag('form li fieldset ol li label', /Label_[abc]/, :count => 3)
72
+ with_deprecation_silenced do
73
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
74
+ concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => :to_s, :member_label => proc {|f| ('Label_%s' % [f])}))
75
+ end)
76
+ end
77
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label', :text => /Label_[abc]/, :count => 3)
75
78
  end
76
79
 
77
80
  it 'should use a supplied value_method for simple collections' do
78
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
79
- concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
80
- end)
81
- output_buffer.should have_tag('form li fieldset ol li label input[value="Value_a"]')
82
- output_buffer.should have_tag('form li fieldset ol li label input[value="Value_b"]')
83
- output_buffer.should have_tag('form li fieldset ol li label input[value="Value_c"]')
81
+ with_deprecation_silenced do
82
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
83
+ concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
84
+ end)
85
+ end
86
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_a"]')
87
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_b"]')
88
+ expect(output_buffer.to_str).to have_tag('form li fieldset ol li label input[value="Value_c"]')
84
89
  end
85
90
  end
86
91
 
@@ -89,38 +94,38 @@ describe 'Formtastic::FormBuilder#label' do
89
94
  concat(semantic_form_for(@new_post) do |builder|
90
95
  builder.input(:title, :label => 'My label')
91
96
  end)
92
- output_buffer.should have_tag('label', /My label/)
97
+ expect(output_buffer.to_str).to have_tag('label', :text => /My label/)
93
98
  end
94
-
99
+
95
100
  it 'should allow the text to be given as label option for date fields' do
96
101
  concat(semantic_form_for(@new_post) do |builder|
97
102
  builder.input(:publish_at, :label => 'My other label')
98
103
  end)
99
- output_buffer.should have_tag('label', /My other label/)
104
+ expect(output_buffer.to_str).to have_tag('label', :text => /My other label/)
100
105
  end
101
106
 
102
107
  it 'should return nil if label is false' do
103
108
  concat(semantic_form_for(@new_post) do |builder|
104
109
  builder.input(:title, :label => false)
105
110
  end)
106
- output_buffer.should_not have_tag('label')
107
- output_buffer.should_not include(">")
111
+ expect(output_buffer.to_str).not_to have_tag('label')
112
+ expect(output_buffer.to_str).not_to include(">")
108
113
  end
109
-
114
+
110
115
  it 'should return nil if label is false for timeish fragments' do
111
116
  concat(semantic_form_for(@new_post) do |builder|
112
117
  builder.input(:title, :as => :time_select, :label => false)
113
118
  end)
114
- output_buffer.should_not have_tag('li.time > label')
115
- output_buffer.should_not include(">")
119
+ expect(output_buffer.to_str).not_to have_tag('li.time > label')
120
+ expect(output_buffer.to_str).not_to include(">")
116
121
  end
117
122
 
118
123
  it 'should html escape the label string by default' do
119
124
  concat(semantic_form_for(@new_post) do |builder|
120
125
  builder.input(:title, :label => '<b>My label</b>')
121
126
  end)
122
- output_buffer.should include('&lt;b&gt;')
123
- output_buffer.should_not include('<b>')
127
+ expect(output_buffer.to_str).to include('&lt;b&gt;')
128
+ expect(output_buffer.to_str).not_to include('<b>')
124
129
  end
125
130
 
126
131
  it 'should not html escape the label if configured that way' do
@@ -128,7 +133,7 @@ describe 'Formtastic::FormBuilder#label' do
128
133
  concat(semantic_form_for(@new_post) do |builder|
129
134
  builder.input(:title, :label => '<b>My label</b>')
130
135
  end)
131
- output_buffer.should have_tag("label b", "My label")
136
+ expect(output_buffer.to_str).to have_tag("label b", :text => "My label")
132
137
  end
133
138
 
134
139
  it 'should not html escape the label string for html_safe strings' do
@@ -136,7 +141,7 @@ describe 'Formtastic::FormBuilder#label' do
136
141
  concat(semantic_form_for(@new_post) do |builder|
137
142
  builder.input(:title, :label => '<b>My label</b>'.html_safe)
138
143
  end)
139
- output_buffer.should have_tag('label b')
144
+ expect(output_buffer.to_str).to have_tag('label b')
140
145
  end
141
146
 
142
147
  end