formtastic 3.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,19 +1,20 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
- describe 'time select input' do
5
+ RSpec.describe 'time select input' 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
 
13
14
  describe "general" do
14
15
  before do
15
16
  ::I18n.backend.reload!
16
- output_buffer.replace ''
17
+ @output_buffer = ActionView::OutputBuffer.new ''
17
18
  end
18
19
 
19
20
  describe "with :ignore_date => true" do
@@ -24,42 +25,42 @@ describe 'time select input' do
24
25
  end
25
26
 
26
27
  it 'should not have hidden inputs for day, month and year' do
27
- output_buffer.should_not have_tag('input#post_publish_at_1i')
28
- output_buffer.should_not have_tag('input#post_publish_at_2i')
29
- output_buffer.should_not have_tag('input#post_publish_at_3i')
28
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_1i')
29
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_2i')
30
+ expect(output_buffer.to_str).not_to have_tag('input#post_publish_at_3i')
30
31
  end
31
32
 
32
33
  it 'should have an input for hour and minute' do
33
- output_buffer.should have_tag('select#post_publish_at_4i')
34
- output_buffer.should have_tag('select#post_publish_at_5i')
34
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
35
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
35
36
  end
36
37
 
37
38
  end
38
-
39
+
39
40
  describe "with :ignore_date => false" do
40
41
  before do
41
- @new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
42
+ allow(@new_post).to receive(:publish_at).and_return(Time.parse('2010-11-07'))
42
43
  concat(semantic_form_for(@new_post) do |builder|
43
44
  concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
44
45
  end)
45
46
  end
46
47
 
47
48
  it 'should have a hidden input for day, month and year' do
48
- output_buffer.should have_tag('input#post_publish_at_1i')
49
- output_buffer.should have_tag('input#post_publish_at_2i')
50
- output_buffer.should have_tag('input#post_publish_at_3i')
51
- output_buffer.should have_tag('input#post_publish_at_1i[@value="2010"]')
52
- output_buffer.should have_tag('input#post_publish_at_2i[@value="11"]')
53
- output_buffer.should have_tag('input#post_publish_at_3i[@value="7"]')
49
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i')
50
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i')
51
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i')
52
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_1i[@value="2010"]')
53
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_2i[@value="11"]')
54
+ expect(output_buffer.to_str).to have_tag('input#post_publish_at_3i[@value="7"]')
54
55
  end
55
56
 
56
57
  it 'should have an select for hour and minute' do
57
- output_buffer.should have_tag('select#post_publish_at_4i')
58
- output_buffer.should have_tag('select#post_publish_at_5i')
58
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_4i')
59
+ expect(output_buffer.to_str).to have_tag('select#post_publish_at_5i')
59
60
  end
60
61
 
61
62
  it 'should associate the legend label with the hour select' do
62
- output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
63
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
63
64
  end
64
65
 
65
66
  end
@@ -80,26 +81,26 @@ describe 'time select input' do
80
81
  it_should_apply_error_logic_for_input_type(:time_select)
81
82
 
82
83
  it 'should have a legend and label with the label text inside the fieldset' do
83
- output_buffer.should have_tag('form li.time_select fieldset legend.label label', /Publish at/)
84
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
84
85
  end
85
86
 
86
87
  it 'should associate the legend label with the first select' do
87
- output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
88
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
88
89
  end
89
90
 
90
91
  it 'should have an ordered list of two items inside the fieldset' do
91
- output_buffer.should have_tag('form li.time_select fieldset ol.fragments-group')
92
- output_buffer.should have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
92
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol.fragments-group')
93
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
93
94
  end
94
95
 
95
96
  it 'should have five labels for hour and minute' do
96
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 2)
97
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
98
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
97
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 2)
98
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
99
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
99
100
  end
100
101
 
101
102
  it 'should have two selects for hour and minute' do
102
- output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 2)
103
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 2)
103
104
  end
104
105
  end
105
106
 
@@ -111,20 +112,20 @@ describe 'time select input' do
111
112
  end
112
113
 
113
114
  it 'should have five labels for hour and minute' do
114
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 3)
115
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
116
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
117
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /second/i)
115
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 3)
116
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
117
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
118
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
118
119
  end
119
120
 
120
121
  it 'should have three selects for hour, minute and seconds' do
121
- output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 3)
122
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li', :count => 3)
122
123
  end
123
124
 
124
125
  it 'should generate a sanitized label and matching ids for attribute' do
125
126
  4.upto(6) do |i|
126
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
127
- output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
127
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
128
+ expect(output_buffer.to_str).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
128
129
  end
129
130
  end
130
131
  end
@@ -134,54 +135,67 @@ describe 'time select input' do
134
135
  fields = [:hour, :minute, :second]
135
136
  fields.each do |field|
136
137
  it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
137
- output_buffer.replace ''
138
+ @output_buffer = ActionView::OutputBuffer.new ''
138
139
  concat(semantic_form_for(@new_post) do |builder|
139
140
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
140
141
  end)
141
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length)
142
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
142
143
  fields.each do |f|
143
- output_buffer.should have_tag('form li.time_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
144
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
144
145
  end
145
146
  end
146
147
 
147
148
  it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
148
- output_buffer.replace ''
149
+ @output_buffer = ActionView::OutputBuffer.new ''
149
150
  concat(semantic_form_for(@new_post) do |builder|
150
151
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
151
152
  end)
152
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
153
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
153
154
  fields.each do |f|
154
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
155
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
155
156
  end
156
157
  end
157
-
158
- it "should not render the label when :labels[:#{field}] is false" do
159
- output_buffer.replace ''
158
+
159
+ it "should not render the label when :labels[:#{field}] is false" do
160
+ @output_buffer = ActionView::OutputBuffer.new ''
160
161
  concat(semantic_form_for(@new_post) do |builder|
161
162
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
162
163
  end)
163
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
164
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
164
165
  fields.each do |f|
165
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
166
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
166
167
  end
167
168
  end
168
169
 
169
- it "should not render unsafe HTML when :labels[:#{field}] is false" do
170
- output_buffer.replace ''
170
+ it "should not render unsafe HTML when :labels[:#{field}] is false" do
171
+ @output_buffer = ActionView::OutputBuffer.new ''
171
172
  concat(semantic_form_for(@new_post) do |builder|
172
173
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
173
174
  end)
174
- output_buffer.should_not include(">")
175
+ expect(output_buffer.to_str).not_to include(">")
175
176
  end
176
-
177
+
177
178
  end
178
179
 
179
180
  it "should not render labels when :labels is falsy" do
180
- output_buffer.replace ''
181
+ @output_buffer = ActionView::OutputBuffer.new ''
181
182
  concat(semantic_form_for(@new_post) do |builder|
182
183
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
183
184
  end)
184
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 0)
185
+ expect(output_buffer.to_str).to have_tag('form li.time_select fieldset ol li label', :count => 0)
186
+ end
187
+ end
188
+
189
+ describe ":selected option for setting a value" do
190
+ it "should set the selected value for the form" do
191
+ concat(
192
+ semantic_form_for(@new_post) do |f|
193
+ concat(f.input(:created_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)))
194
+ end
195
+ )
196
+
197
+ expect(output_buffer.to_str).to have_tag "option[value='12'][selected='selected']"
198
+ expect(output_buffer.to_str).to have_tag "option[value='00'][selected='selected']"
185
199
  end
186
200
  end
187
201
 
@@ -193,23 +207,23 @@ describe 'time select input' do
193
207
  end
194
208
 
195
209
  it 'should have a tag matching the namespace' do
196
- output_buffer.should have_tag('#form2_post_publish_at_input')
197
- output_buffer.should have_tag('#form2_post_publish_at_4i')
198
- output_buffer.should have_tag('#form2_post_publish_at_5i')
210
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_input')
211
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_4i')
212
+ expect(output_buffer.to_str).to have_tag('#form2_post_publish_at_5i')
199
213
  end
200
214
  end
201
-
215
+
202
216
  describe "when required" do
203
217
  it "should add the required attribute to the input's html options" do
204
- with_config :use_required_attribute, true do
218
+ with_config :use_required_attribute, true do
205
219
  concat(semantic_form_for(@new_post) do |builder|
206
220
  concat(builder.input(:title, :as => :time_select, :required => true))
207
221
  end)
208
- output_buffer.should have_tag("select[@required]", :count => 2)
222
+ expect(output_buffer.to_str).to have_tag("select[@required]", :count => 2)
209
223
  end
210
224
  end
211
225
  end
212
-
226
+
213
227
  describe "when index is provided" do
214
228
 
215
229
  before do
@@ -221,27 +235,27 @@ describe 'time select input' do
221
235
  end
222
236
 
223
237
  it 'should index the id of the wrapper' do
224
- output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
238
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_created_at_input")
225
239
  end
226
240
 
227
241
  it 'should index the id of the select tag' do
228
- output_buffer.should have_tag("input#post_author_attributes_3_created_at_1i")
229
- output_buffer.should have_tag("input#post_author_attributes_3_created_at_2i")
230
- output_buffer.should have_tag("input#post_author_attributes_3_created_at_3i")
231
- output_buffer.should have_tag("select#post_author_attributes_3_created_at_4i")
232
- output_buffer.should have_tag("select#post_author_attributes_3_created_at_5i")
242
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_1i")
243
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_2i")
244
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_created_at_3i")
245
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_4i")
246
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_created_at_5i")
233
247
  end
234
248
 
235
249
  it 'should index the name of the select tag' do
236
- output_buffer.should have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
237
- output_buffer.should have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
238
- output_buffer.should have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
239
- output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
240
- output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
250
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
251
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
252
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
253
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
254
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
241
255
  end
242
256
 
243
257
  end
244
-
258
+
245
259
  end
246
260
 
247
261
 
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
- describe 'time_zone input' do
5
+ RSpec.describe 'time_zone input' 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
 
12
13
  concat(semantic_form_for(@new_post) do |builder|
@@ -20,28 +21,28 @@ describe 'time_zone input' do
20
21
  it_should_apply_error_logic_for_input_type(:time_zone)
21
22
 
22
23
  it 'should generate a label for the input' do
23
- output_buffer.should have_tag('form li label')
24
- output_buffer.should have_tag('form li label[@for="post_time_zone"]')
25
- output_buffer.should have_tag('form li label', /Time zone/)
24
+ expect(output_buffer.to_str).to have_tag('form li label')
25
+ expect(output_buffer.to_str).to have_tag('form li label[@for="post_time_zone"]')
26
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
26
27
  end
27
28
 
28
29
  it "should generate a select" do
29
- output_buffer.should have_tag("form li select")
30
- output_buffer.should have_tag("form li select#post_time_zone")
31
- output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
30
+ expect(output_buffer.to_str).to have_tag("form li select")
31
+ expect(output_buffer.to_str).to have_tag("form li select#post_time_zone")
32
+ expect(output_buffer.to_str).to have_tag("form li select[@name=\"post[time_zone]\"]")
32
33
  end
33
34
 
34
35
  it 'should use input_html to style inputs' do
35
36
  concat(semantic_form_for(@new_post) do |builder|
36
37
  concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
37
38
  end)
38
- output_buffer.should have_tag("form li select.myclass")
39
+ expect(output_buffer.to_str).to have_tag("form li select.myclass")
39
40
  end
40
41
 
41
42
  describe "when namespace is provided" do
42
43
 
43
44
  before do
44
- @output_buffer = ''
45
+ @output_buffer = ActionView::OutputBuffer.new ''
45
46
  mock_everything
46
47
 
47
48
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
@@ -54,11 +55,11 @@ describe 'time_zone input' do
54
55
  it_should_have_label_for("context2_post_time_zone")
55
56
 
56
57
  end
57
-
58
+
58
59
  describe "when index is provided" do
59
60
 
60
61
  before do
61
- @output_buffer = ''
62
+ @output_buffer = ActionView::OutputBuffer.new ''
62
63
  mock_everything
63
64
 
64
65
  concat(semantic_form_for(@new_post) do |builder|
@@ -67,51 +68,77 @@ describe 'time_zone input' do
67
68
  end)
68
69
  end)
69
70
  end
70
-
71
+
71
72
  it 'should index the id of the wrapper' do
72
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
73
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
73
74
  end
74
-
75
+
75
76
  it 'should index the id of the select tag' do
76
- output_buffer.should have_tag("select#post_author_attributes_3_name")
77
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_name")
77
78
  end
78
-
79
+
79
80
  it 'should index the name of the select tag' do
80
- output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
81
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][name]']")
81
82
  end
82
-
83
+
83
84
  end
84
-
85
+
85
86
 
86
87
  describe 'when no object is given' do
87
- before(:each) do
88
+ before(:example) do
88
89
  concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
89
90
  concat(builder.input(:time_zone, :as => :time_zone))
90
91
  end)
91
92
  end
92
93
 
93
94
  it 'should generate labels' do
94
- output_buffer.should have_tag('form li label')
95
- output_buffer.should have_tag('form li label[@for="project_time_zone"]')
96
- output_buffer.should have_tag('form li label', /Time zone/)
95
+ expect(output_buffer.to_str).to have_tag('form li label')
96
+ expect(output_buffer.to_str).to have_tag('form li label[@for="project_time_zone"]')
97
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Time zone/)
97
98
  end
98
99
 
99
100
  it 'should generate select inputs' do
100
- output_buffer.should have_tag("form li select")
101
- output_buffer.should have_tag("form li select#project_time_zone")
102
- output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
101
+ expect(output_buffer.to_str).to have_tag("form li select")
102
+ expect(output_buffer.to_str).to have_tag("form li select#project_time_zone")
103
+ expect(output_buffer.to_str).to have_tag("form li select[@name=\"project[time_zone]\"]")
103
104
  end
104
105
  end
105
-
106
+
106
107
  context "when required" do
107
108
  it "should add the required attribute to the input's html options" do
108
- with_config :use_required_attribute, true do
109
+ with_config :use_required_attribute, true do
109
110
  concat(semantic_form_for(@new_post) do |builder|
110
111
  concat(builder.input(:title, :as => :time_zone, :required => true))
111
112
  end)
112
- output_buffer.should have_tag("select[@required]")
113
+ expect(output_buffer.to_str).to have_tag("select[@required]")
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "when priority time zone is provided" do
119
+ let(:time_zones) { [ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii']] }
120
+ let(:input_html_options) do
121
+ { id: "post_title", required: false, autofocus: false, readonly: false }
122
+ end
123
+
124
+ context "by priority_zone option" do
125
+ it "passes right time_zones" do
126
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
127
+ semantic_form_for(@new_post) do |builder|
128
+ builder.input(:title, as: :time_zone, priority_zones: time_zones)
129
+ end
130
+ end
131
+ end
132
+
133
+ context "by configuration" do
134
+ it "passes right time_zones" do
135
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
136
+ with_config :priority_time_zones, time_zones do
137
+ semantic_form_for(@new_post) do |builder|
138
+ builder.input(:title, as: :time_zone)
139
+ end
140
+ end
113
141
  end
114
142
  end
115
143
  end
116
-
117
144
  end
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
- describe 'url input' do
5
+ RSpec.describe 'url input' 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
 
@@ -41,11 +42,11 @@ describe 'url input' do
41
42
  it_should_have_label_and_input_with_id("context2_post_url")
42
43
 
43
44
  end
44
-
45
+
45
46
  describe "when index is provided" do
46
47
 
47
48
  before do
48
- @output_buffer = ''
49
+ @output_buffer = ActionView::OutputBuffer.new ''
49
50
  mock_everything
50
51
 
51
52
  concat(semantic_form_for(@new_post) do |builder|
@@ -54,32 +55,32 @@ describe 'url input' do
54
55
  end)
55
56
  end)
56
57
  end
57
-
58
+
58
59
  it 'should index the id of the wrapper' do
59
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
60
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
60
61
  end
61
-
62
+
62
63
  it 'should index the id of the select tag' do
63
- output_buffer.should have_tag("input#post_author_attributes_3_name")
64
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
64
65
  end
65
-
66
+
66
67
  it 'should index the name of the select tag' do
67
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
68
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
68
69
  end
69
-
70
+
70
71
  end
71
-
72
-
72
+
73
+
73
74
  describe "when required" do
74
75
  it "should add the required attribute to the input's html options" do
75
- with_config :use_required_attribute, true do
76
+ with_config :use_required_attribute, true do
76
77
  concat(semantic_form_for(@new_post) do |builder|
77
78
  concat(builder.input(:title, :as => :url, :required => true))
78
79
  end)
79
- output_buffer.should have_tag("input[@required]")
80
+ expect(output_buffer.to_str).to have_tag("input[@required]")
80
81
  end
81
82
  end
82
83
  end
83
-
84
+
84
85
  end
85
86
 
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
- describe 'string input' do
5
+ RSpec.describe 'string input' 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
 
@@ -21,23 +22,23 @@ describe 'string input' do
21
22
  end
22
23
 
23
24
  it "should have extra class on title" do
24
- output_buffer.should have_tag("form li#post_title_input.extra")
25
+ expect(output_buffer.to_str).to have_tag("form li#post_title_input.extra")
25
26
  end
26
27
  it "should have title as string" do
27
- output_buffer.should have_tag("form li#post_title_input.string")
28
+ expect(output_buffer.to_str).to have_tag("form li#post_title_input.string")
28
29
  end
29
30
  it "should not have title as radio" do
30
- output_buffer.should_not have_tag("form li#post_title_input.radio")
31
+ expect(output_buffer.to_str).not_to have_tag("form li#post_title_input.radio")
31
32
  end
32
33
 
33
34
  it "should have extra class on author" do
34
- output_buffer.should have_tag("form li#post_author_input.extra")
35
+ expect(output_buffer.to_str).to have_tag("form li#post_author_input.extra")
35
36
  end
36
37
  it "should not have author as string" do
37
- output_buffer.should_not have_tag("form li#post_author_input.string")
38
+ expect(output_buffer.to_str).not_to have_tag("form li#post_author_input.string")
38
39
  end
39
40
  it "should have author as radio" do
40
- output_buffer.should have_tag("form li#post_author_input.radio")
41
+ expect(output_buffer.to_str).to have_tag("form li#post_author_input.radio")
41
42
  end
42
43
  end
43
44
  end