formtastic 3.1.6 → 4.0.0.rc1

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -0
  3. data/.gitignore +3 -2
  4. data/.travis.yml +28 -40
  5. data/CHANGELOG.md +49 -0
  6. data/DEPRECATIONS +1 -1
  7. data/Gemfile.lock +104 -0
  8. data/README.md +628 -629
  9. data/Rakefile +20 -1
  10. data/app/assets/stylesheets/formtastic.css +1 -1
  11. data/bin/appraisal +8 -0
  12. data/formtastic.gemspec +9 -14
  13. data/gemfiles/rails_5.2/Gemfile +5 -0
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_edge/Gemfile +13 -0
  16. data/lib/formtastic/actions.rb +6 -3
  17. data/lib/formtastic/deprecation.rb +1 -38
  18. data/lib/formtastic/engine.rb +3 -1
  19. data/lib/formtastic/form_builder.rb +8 -24
  20. data/lib/formtastic/helpers/action_helper.rb +1 -48
  21. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  22. data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
  23. data/lib/formtastic/helpers/input_helper.rb +18 -76
  24. data/lib/formtastic/helpers/inputs_helper.rb +12 -3
  25. data/lib/formtastic/i18n.rb +1 -1
  26. data/lib/formtastic/inputs/base/collections.rb +1 -5
  27. data/lib/formtastic/inputs/base/errors.rb +4 -4
  28. data/lib/formtastic/inputs/base/hints.rb +1 -1
  29. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  30. data/lib/formtastic/inputs/base/validations.rb +19 -9
  31. data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
  32. data/lib/formtastic/inputs/color_input.rb +0 -1
  33. data/lib/formtastic/inputs/select_input.rb +1 -1
  34. data/lib/formtastic/inputs.rb +32 -29
  35. data/lib/formtastic/localizer.rb +4 -3
  36. data/lib/formtastic/version.rb +1 -1
  37. data/lib/formtastic.rb +5 -11
  38. data/lib/generators/templates/formtastic.rb +4 -6
  39. data/script/integration-template.rb +71 -0
  40. data/script/integration.sh +19 -0
  41. data/spec/action_class_finder_spec.rb +1 -1
  42. data/spec/actions/button_action_spec.rb +8 -8
  43. data/spec/actions/generic_action_spec.rb +60 -60
  44. data/spec/actions/input_action_spec.rb +7 -7
  45. data/spec/actions/link_action_spec.rb +10 -10
  46. data/spec/builder/custom_builder_spec.rb +36 -20
  47. data/spec/builder/error_proc_spec.rb +4 -4
  48. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  49. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  50. data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
  51. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  52. data/spec/helpers/action_helper_spec.rb +328 -10
  53. data/spec/helpers/actions_helper_spec.rb +17 -17
  54. data/spec/helpers/form_helper_spec.rb +33 -33
  55. data/spec/helpers/input_helper_spec.rb +975 -2
  56. data/spec/helpers/inputs_helper_spec.rb +120 -105
  57. data/spec/helpers/reflection_helper_spec.rb +3 -3
  58. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  59. data/spec/i18n_spec.rb +26 -26
  60. data/spec/input_class_finder_spec.rb +1 -1
  61. data/spec/inputs/base/collections_spec.rb +6 -6
  62. data/spec/inputs/base/validations_spec.rb +157 -19
  63. data/spec/inputs/boolean_input_spec.rb +55 -55
  64. data/spec/inputs/check_boxes_input_spec.rb +96 -95
  65. data/spec/inputs/color_input_spec.rb +51 -63
  66. data/spec/inputs/country_input_spec.rb +20 -20
  67. data/spec/inputs/custom_input_spec.rb +2 -6
  68. data/spec/inputs/datalist_input_spec.rb +1 -1
  69. data/spec/inputs/date_picker_input_spec.rb +42 -42
  70. data/spec/inputs/date_select_input_spec.rb +51 -37
  71. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  72. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  73. data/spec/inputs/email_input_spec.rb +5 -5
  74. data/spec/inputs/file_input_spec.rb +6 -6
  75. data/spec/inputs/hidden_input_spec.rb +18 -18
  76. data/spec/inputs/include_blank_spec.rb +8 -8
  77. data/spec/inputs/label_spec.rb +20 -20
  78. data/spec/inputs/number_input_spec.rb +112 -112
  79. data/spec/inputs/password_input_spec.rb +5 -5
  80. data/spec/inputs/phone_input_spec.rb +5 -5
  81. data/spec/inputs/placeholder_spec.rb +5 -5
  82. data/spec/inputs/radio_input_spec.rb +63 -65
  83. data/spec/inputs/range_input_spec.rb +66 -66
  84. data/spec/inputs/readonly_spec.rb +4 -4
  85. data/spec/inputs/search_input_spec.rb +5 -5
  86. data/spec/inputs/select_input_spec.rb +92 -96
  87. data/spec/inputs/string_input_spec.rb +23 -23
  88. data/spec/inputs/text_input_spec.rb +16 -16
  89. data/spec/inputs/time_picker_input_spec.rb +43 -43
  90. data/spec/inputs/time_select_input_spec.rb +67 -54
  91. data/spec/inputs/time_zone_input_spec.rb +19 -19
  92. data/spec/inputs/url_input_spec.rb +5 -5
  93. data/spec/inputs/with_options_spec.rb +7 -7
  94. data/spec/localizer_spec.rb +17 -17
  95. data/spec/namespaced_class_finder_spec.rb +2 -2
  96. data/spec/schema.rb +21 -0
  97. data/spec/spec_helper.rb +163 -223
  98. data/spec/support/custom_macros.rb +72 -75
  99. data/spec/support/shared_examples.rb +0 -1301
  100. data/spec/support/test_environment.rb +23 -9
  101. metadata +36 -122
  102. data/Appraisals +0 -43
  103. data/CHANGELOG +0 -54
  104. data/gemfiles/rails_3.2.gemfile +0 -9
  105. data/gemfiles/rails_4.0.4.gemfile +0 -8
  106. data/gemfiles/rails_4.1.gemfile +0 -8
  107. data/gemfiles/rails_4.2.gemfile +0 -8
  108. data/gemfiles/rails_4.gemfile +0 -8
  109. data/gemfiles/rails_5.0.gemfile +0 -8
  110. data/gemfiles/rails_edge.gemfile +0 -15
  111. data/lib/formtastic/util.rb +0 -57
  112. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  113. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  114. data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'boolean input' do
4
+ RSpec.describe 'boolean input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -23,31 +23,31 @@ describe 'boolean input' do
23
23
  it_should_apply_error_logic_for_input_type(:boolean)
24
24
 
25
25
  it 'should generate a label containing the input' do
26
- output_buffer.should_not have_tag('label.label')
27
- output_buffer.should have_tag('form li label', :count => 1)
28
- output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
29
- output_buffer.should have_tag('form li label', /Allow comments/)
30
- output_buffer.should have_tag('form li label input[@type="checkbox"]', :count => 1)
31
- output_buffer.should have_tag('form li input[@type="hidden"]', :count => 1)
32
- output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
26
+ expect(output_buffer).not_to have_tag('label.label')
27
+ expect(output_buffer).to have_tag('form li label', :count => 1)
28
+ expect(output_buffer).to have_tag('form li label[@for="post_allow_comments"]')
29
+ expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
30
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]', :count => 1)
31
+ expect(output_buffer).to have_tag('form li input[@type="hidden"]', :count => 1)
32
+ expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
33
33
  end
34
34
 
35
35
  it 'should not add a "name" attribute to the label' do
36
- output_buffer.should_not have_tag('form li label[@name]')
36
+ expect(output_buffer).not_to have_tag('form li label[@name]')
37
37
  end
38
38
 
39
39
  it 'should generate a checkbox input' do
40
- output_buffer.should have_tag('form li label input')
41
- output_buffer.should have_tag('form li label input#post_allow_comments')
42
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
43
- output_buffer.should have_tag('form li label input[@name="post[allow_comments]"]')
44
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"]')
40
+ expect(output_buffer).to have_tag('form li label input')
41
+ expect(output_buffer).to have_tag('form li label input#post_allow_comments')
42
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
43
+ expect(output_buffer).to have_tag('form li label input[@name="post[allow_comments]"]')
44
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"]')
45
45
  end
46
46
 
47
47
  it 'should generate a checked input if object.method returns true' do
48
- output_buffer.should have_tag('form li label input[@checked="checked"]')
49
- output_buffer.should have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
50
- output_buffer.should have_tag('form li input#post_allow_comments', :count => 1)
48
+ expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
49
+ expect(output_buffer).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
50
+ expect(output_buffer).to have_tag('form li input#post_allow_comments', :count => 1)
51
51
  end
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ describe 'boolean input' do
55
55
  concat(semantic_form_for(@new_post) do |builder|
56
56
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
57
57
  end)
58
- output_buffer.should have_tag('form li label input[@checked="checked"]')
58
+ expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
59
59
  end
60
60
 
61
61
  it 'should name the hidden input with the :name html_option' do
@@ -63,8 +63,8 @@ describe 'boolean input' do
63
63
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
64
64
  end)
65
65
 
66
- output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
67
- output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
66
+ expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
67
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
68
68
  end
69
69
 
70
70
  it 'should name the hidden input with the :name html_option' do
@@ -72,93 +72,93 @@ describe 'boolean input' do
72
72
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
73
73
  end)
74
74
 
75
- output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
76
- output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
75
+ expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
76
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
77
77
  end
78
78
 
79
79
  it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
80
80
  concat(semantic_form_for(@new_post) do |builder|
81
81
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
82
82
  end)
83
- output_buffer.should have_tag('form li label input[@disabled="disabled"]', :count => 1)
84
- output_buffer.should have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
83
+ expect(output_buffer).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
84
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
85
85
  end
86
86
 
87
87
  it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
88
88
  concat(semantic_form_for(@new_post) do |builder|
89
89
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
90
90
  end)
91
- output_buffer.should have_tag('form li label input[@id="custom_id"]')
92
- output_buffer.should have_tag('form li label[@for="custom_id"]')
91
+ expect(output_buffer).to have_tag('form li label input[@id="custom_id"]')
92
+ expect(output_buffer).to have_tag('form li label[@for="custom_id"]')
93
93
  end
94
94
 
95
95
  it 'should allow checked and unchecked values to be sent' do
96
96
  concat(semantic_form_for(@new_post) do |builder|
97
97
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
98
98
  end)
99
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
100
- output_buffer.should have_tag('form li input[@type="hidden"][@value="unchecked"]')
101
- output_buffer.should_not have_tag('form li label input[@type="hidden"]') # invalid HTML5
99
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
100
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
101
+ expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
102
102
  end
103
103
 
104
104
  it 'should generate a checked input if object.method returns checked value' do
105
- @new_post.stub(:allow_comments).and_return('yes')
105
+ allow(@new_post).to receive(:allow_comments).and_return('yes')
106
106
 
107
107
  concat(semantic_form_for(@new_post) do |builder|
108
108
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
109
109
  end)
110
110
 
111
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
111
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
112
112
  end
113
113
 
114
114
  it 'should not generate a checked input if object.method returns unchecked value' do
115
- @new_post.stub(:allow_comments).and_return('no')
115
+ allow(@new_post).to receive(:allow_comments).and_return('no')
116
116
 
117
117
  concat(semantic_form_for(@new_post) do |builder|
118
118
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
119
119
  end)
120
120
 
121
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
121
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
122
122
  end
123
123
 
124
124
  it 'should generate a checked input if object.method returns checked value' do
125
- @new_post.stub(:allow_comments).and_return('yes')
125
+ allow(@new_post).to receive(:allow_comments).and_return('yes')
126
126
 
127
127
  concat(semantic_form_for(@new_post) do |builder|
128
128
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
129
129
  end)
130
130
 
131
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
131
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
132
132
  end
133
133
 
134
134
  it 'should generate a checked input for boolean database values compared to string checked values' do
135
- @new_post.stub(:foo).and_return(1)
135
+ allow(@new_post).to receive(:foo).and_return(1)
136
136
 
137
137
  concat(semantic_form_for(@new_post) do |builder|
138
138
  concat(builder.input(:foo, :as => :boolean))
139
139
  end)
140
140
 
141
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
141
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
142
142
  end
143
143
 
144
144
  it 'should generate a checked input if object.method returns checked value when inverted' do
145
- @new_post.stub(:allow_comments).and_return(0)
145
+ allow(@new_post).to receive(:allow_comments).and_return(0)
146
146
 
147
147
  concat(semantic_form_for(@new_post) do |builder|
148
148
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
149
149
  end)
150
150
 
151
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
151
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
152
152
  end
153
153
 
154
154
  it 'should not generate a checked input if object.method returns unchecked value' do
155
- @new_post.stub(:allow_comments).and_return('no')
155
+ allow(@new_post).to receive(:allow_comments).and_return('no')
156
156
 
157
157
  concat(semantic_form_for(@new_post) do |builder|
158
158
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
159
159
  end)
160
160
 
161
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
161
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
162
162
  end
163
163
 
164
164
  it 'should generate a label and a checkbox even if no object is given' do
@@ -166,21 +166,21 @@ describe 'boolean input' do
166
166
  concat(builder.input(:allow_comments, :as => :boolean))
167
167
  end)
168
168
 
169
- output_buffer.should have_tag('form li label[@for="project_allow_comments"]')
170
- output_buffer.should have_tag('form li label', /Allow comments/)
171
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
169
+ expect(output_buffer).to have_tag('form li label[@for="project_allow_comments"]')
170
+ expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
171
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
172
172
 
173
- output_buffer.should have_tag('form li label input#project_allow_comments')
174
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
175
- output_buffer.should have_tag('form li label input[@name="project[allow_comments]"]')
173
+ expect(output_buffer).to have_tag('form li label input#project_allow_comments')
174
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
175
+ expect(output_buffer).to have_tag('form li label input[@name="project[allow_comments]"]')
176
176
  end
177
177
 
178
178
  it 'should not pass input_html options down to the label html' do
179
179
  concat(semantic_form_for(@new_post) do |builder|
180
180
  builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
181
181
  end)
182
- output_buffer.should_not have_tag('label[tabindex]')
183
- output_buffer.should_not have_tag('label[x]')
182
+ expect(output_buffer).not_to have_tag('label[tabindex]')
183
+ expect(output_buffer).not_to have_tag('label[x]')
184
184
  end
185
185
 
186
186
  context "when required" do
@@ -190,7 +190,7 @@ describe 'boolean input' do
190
190
  concat(semantic_form_for(@new_post) do |builder|
191
191
  concat(builder.input(:title, :as => :boolean, :required => true))
192
192
  end)
193
- output_buffer.should have_tag("input[@required]")
193
+ expect(output_buffer).to have_tag("input[@required]")
194
194
  end
195
195
  end
196
196
 
@@ -199,7 +199,7 @@ describe 'boolean input' do
199
199
  concat(semantic_form_for(@new_post) do |builder|
200
200
  concat(builder.input(:title, :as => :boolean))
201
201
  end)
202
- output_buffer.should_not have_tag("input[@required]")
202
+ expect(output_buffer).not_to have_tag("input[@required]")
203
203
  end
204
204
  end
205
205
 
@@ -235,19 +235,19 @@ describe 'boolean input' do
235
235
  end
236
236
 
237
237
  it 'should index the id of the wrapper' do
238
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
238
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
239
239
  end
240
240
 
241
241
  it 'should index the id of the input tag' do
242
- output_buffer.should have_tag("input#post_author_attributes_3_name")
242
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
243
243
  end
244
244
 
245
245
  it 'should index the name of the hidden input' do
246
- output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
246
+ expect(output_buffer).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
247
247
  end
248
248
 
249
249
  it 'should index the name of the checkbox input' do
250
- output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
250
+ expect(output_buffer).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
251
251
  end
252
252
 
253
253
  end