formtastic 3.1.1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.gitignore +3 -2
  4. data/.travis.yml +29 -24
  5. data/CHANGELOG.md +49 -0
  6. data/DEPRECATIONS +4 -1
  7. data/Gemfile.lock +104 -0
  8. data/{README.textile → README.md} +178 -166
  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 -15
  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.rb +9 -11
  17. data/lib/formtastic/actions.rb +6 -3
  18. data/lib/formtastic/deprecation.rb +1 -38
  19. data/lib/formtastic/engine.rb +3 -1
  20. data/lib/formtastic/form_builder.rb +11 -24
  21. data/lib/formtastic/helpers.rb +1 -1
  22. data/lib/formtastic/helpers/action_helper.rb +1 -48
  23. data/lib/formtastic/helpers/enum.rb +13 -0
  24. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  25. data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
  26. data/lib/formtastic/helpers/form_helper.rb +1 -1
  27. data/lib/formtastic/helpers/input_helper.rb +23 -77
  28. data/lib/formtastic/helpers/inputs_helper.rb +27 -22
  29. data/lib/formtastic/i18n.rb +1 -1
  30. data/lib/formtastic/inputs.rb +32 -29
  31. data/lib/formtastic/inputs/base/choices.rb +1 -1
  32. data/lib/formtastic/inputs/base/collections.rb +43 -10
  33. data/lib/formtastic/inputs/base/database.rb +7 -2
  34. data/lib/formtastic/inputs/base/errors.rb +4 -4
  35. data/lib/formtastic/inputs/base/hints.rb +1 -1
  36. data/lib/formtastic/inputs/base/html.rb +7 -6
  37. data/lib/formtastic/inputs/base/naming.rb +4 -4
  38. data/lib/formtastic/inputs/base/options.rb +2 -3
  39. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  40. data/lib/formtastic/inputs/base/validations.rb +38 -12
  41. data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
  42. data/lib/formtastic/inputs/color_input.rb +0 -1
  43. data/lib/formtastic/inputs/country_input.rb +3 -1
  44. data/lib/formtastic/inputs/radio_input.rb +20 -0
  45. data/lib/formtastic/inputs/select_input.rb +29 -1
  46. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  47. data/lib/formtastic/localizer.rb +20 -22
  48. data/lib/formtastic/namespaced_class_finder.rb +1 -1
  49. data/lib/formtastic/version.rb +1 -1
  50. data/lib/generators/formtastic/form/form_generator.rb +1 -1
  51. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  52. data/lib/generators/templates/formtastic.rb +14 -13
  53. data/lib/generators/templates/input.rb +19 -0
  54. data/script/integration-template.rb +71 -0
  55. data/script/integration.sh +19 -0
  56. data/spec/action_class_finder_spec.rb +1 -1
  57. data/spec/actions/button_action_spec.rb +8 -8
  58. data/spec/actions/generic_action_spec.rb +60 -60
  59. data/spec/actions/input_action_spec.rb +7 -7
  60. data/spec/actions/link_action_spec.rb +10 -10
  61. data/spec/builder/custom_builder_spec.rb +36 -20
  62. data/spec/builder/error_proc_spec.rb +4 -4
  63. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  64. data/spec/fast_spec_helper.rb +12 -0
  65. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  66. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  67. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  68. data/spec/helpers/action_helper_spec.rb +328 -10
  69. data/spec/helpers/actions_helper_spec.rb +17 -17
  70. data/spec/helpers/form_helper_spec.rb +37 -37
  71. data/spec/helpers/input_helper_spec.rb +975 -2
  72. data/spec/helpers/inputs_helper_spec.rb +120 -105
  73. data/spec/helpers/reflection_helper_spec.rb +3 -3
  74. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  75. data/spec/i18n_spec.rb +26 -26
  76. data/spec/input_class_finder_spec.rb +1 -1
  77. data/spec/inputs/base/collections_spec.rb +76 -0
  78. data/spec/inputs/base/validations_spec.rb +480 -0
  79. data/spec/inputs/boolean_input_spec.rb +55 -55
  80. data/spec/inputs/check_boxes_input_spec.rb +155 -108
  81. data/spec/inputs/color_input_spec.rb +51 -63
  82. data/spec/inputs/country_input_spec.rb +20 -20
  83. data/spec/inputs/custom_input_spec.rb +2 -6
  84. data/spec/inputs/datalist_input_spec.rb +1 -1
  85. data/spec/inputs/date_picker_input_spec.rb +42 -42
  86. data/spec/inputs/date_select_input_spec.rb +51 -37
  87. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  88. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  89. data/spec/inputs/email_input_spec.rb +5 -5
  90. data/spec/inputs/file_input_spec.rb +6 -6
  91. data/spec/inputs/hidden_input_spec.rb +18 -18
  92. data/spec/inputs/include_blank_spec.rb +8 -8
  93. data/spec/inputs/label_spec.rb +20 -20
  94. data/spec/inputs/number_input_spec.rb +112 -112
  95. data/spec/inputs/password_input_spec.rb +5 -5
  96. data/spec/inputs/phone_input_spec.rb +5 -5
  97. data/spec/inputs/placeholder_spec.rb +5 -5
  98. data/spec/inputs/radio_input_spec.rb +84 -58
  99. data/spec/inputs/range_input_spec.rb +66 -66
  100. data/spec/inputs/readonly_spec.rb +50 -0
  101. data/spec/inputs/search_input_spec.rb +5 -5
  102. data/spec/inputs/select_input_spec.rb +149 -93
  103. data/spec/inputs/string_input_spec.rb +23 -23
  104. data/spec/inputs/text_input_spec.rb +16 -16
  105. data/spec/inputs/time_picker_input_spec.rb +43 -43
  106. data/spec/inputs/time_select_input_spec.rb +67 -54
  107. data/spec/inputs/time_zone_input_spec.rb +54 -28
  108. data/spec/inputs/url_input_spec.rb +5 -5
  109. data/spec/inputs/with_options_spec.rb +7 -7
  110. data/spec/localizer_spec.rb +17 -17
  111. data/spec/namespaced_class_finder_spec.rb +2 -2
  112. data/spec/schema.rb +21 -0
  113. data/spec/spec_helper.rb +165 -253
  114. data/spec/support/custom_macros.rb +72 -75
  115. data/spec/support/shared_examples.rb +0 -1232
  116. data/spec/support/test_environment.rb +23 -9
  117. metadata +67 -174
  118. data/Appraisals +0 -29
  119. data/CHANGELOG +0 -31
  120. data/gemfiles/rails_3.2.gemfile +0 -7
  121. data/gemfiles/rails_4.0.4.gemfile +0 -7
  122. data/gemfiles/rails_4.1.gemfile +0 -7
  123. data/gemfiles/rails_4.2.gemfile +0 -7
  124. data/gemfiles/rails_4.gemfile +0 -7
  125. data/gemfiles/rails_edge.gemfile +0 -10
  126. data/lib/formtastic/util.rb +0 -53
  127. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  128. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  129. data/spec/support/deferred_garbage_collection.rb +0 -21
  130. 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 'time select input' do
4
+ RSpec.describe 'time select input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -24,42 +24,42 @@ describe 'time select input' do
24
24
  end
25
25
 
26
26
  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')
27
+ expect(output_buffer).not_to have_tag('input#post_publish_at_1i')
28
+ expect(output_buffer).not_to have_tag('input#post_publish_at_2i')
29
+ expect(output_buffer).not_to have_tag('input#post_publish_at_3i')
30
30
  end
31
31
 
32
32
  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')
33
+ expect(output_buffer).to have_tag('select#post_publish_at_4i')
34
+ expect(output_buffer).to have_tag('select#post_publish_at_5i')
35
35
  end
36
36
 
37
37
  end
38
38
 
39
39
  describe "with :ignore_date => false" do
40
40
  before do
41
- @new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
41
+ allow(@new_post).to receive(:publish_at).and_return(Time.parse('2010-11-07'))
42
42
  concat(semantic_form_for(@new_post) do |builder|
43
43
  concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
44
44
  end)
45
45
  end
46
46
 
47
47
  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"]')
48
+ expect(output_buffer).to have_tag('input#post_publish_at_1i')
49
+ expect(output_buffer).to have_tag('input#post_publish_at_2i')
50
+ expect(output_buffer).to have_tag('input#post_publish_at_3i')
51
+ expect(output_buffer).to have_tag('input#post_publish_at_1i[@value="2010"]')
52
+ expect(output_buffer).to have_tag('input#post_publish_at_2i[@value="11"]')
53
+ expect(output_buffer).to have_tag('input#post_publish_at_3i[@value="7"]')
54
54
  end
55
55
 
56
56
  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')
57
+ expect(output_buffer).to have_tag('select#post_publish_at_4i')
58
+ expect(output_buffer).to have_tag('select#post_publish_at_5i')
59
59
  end
60
60
 
61
61
  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"]')
62
+ expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
63
63
  end
64
64
 
65
65
  end
@@ -80,26 +80,26 @@ describe 'time select input' do
80
80
  it_should_apply_error_logic_for_input_type(:time_select)
81
81
 
82
82
  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/)
83
+ expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label', :text => /Publish at/)
84
84
  end
85
85
 
86
86
  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"]')
87
+ expect(output_buffer).to have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
88
88
  end
89
89
 
90
90
  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)
91
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol.fragments-group')
92
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
93
93
  end
94
94
 
95
95
  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)
96
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 2)
97
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
98
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
99
99
  end
100
100
 
101
101
  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)
102
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li', :count => 2)
103
103
  end
104
104
  end
105
105
 
@@ -111,20 +111,20 @@ describe 'time select input' do
111
111
  end
112
112
 
113
113
  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)
114
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 3)
115
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /hour/i)
116
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /minute/i)
117
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /second/i)
118
118
  end
119
119
 
120
120
  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)
121
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li', :count => 3)
122
122
  end
123
123
 
124
124
  it 'should generate a sanitized label and matching ids for attribute' do
125
125
  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")
126
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
127
+ expect(output_buffer).to have_tag("form li fieldset ol li #post_publish_at_#{i}i")
128
128
  end
129
129
  end
130
130
  end
@@ -138,9 +138,9 @@ describe 'time select input' do
138
138
  concat(semantic_form_for(@new_post) do |builder|
139
139
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
140
140
  end)
141
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length)
141
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length)
142
142
  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)
143
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => f == field ? /another #{f} label/i : /#{f}/i)
144
144
  end
145
145
  end
146
146
 
@@ -149,9 +149,9 @@ describe 'time select input' do
149
149
  concat(semantic_form_for(@new_post) do |builder|
150
150
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
151
151
  end)
152
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
152
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
153
153
  fields.each do |f|
154
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
154
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
155
155
  end
156
156
  end
157
157
 
@@ -160,9 +160,9 @@ describe 'time select input' do
160
160
  concat(semantic_form_for(@new_post) do |builder|
161
161
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
162
162
  end)
163
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
163
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
164
164
  fields.each do |f|
165
- output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
165
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :text => /#{f}/i) unless field == f
166
166
  end
167
167
  end
168
168
 
@@ -171,7 +171,7 @@ describe 'time select input' do
171
171
  concat(semantic_form_for(@new_post) do |builder|
172
172
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
173
173
  end)
174
- output_buffer.should_not include(">")
174
+ expect(output_buffer).not_to include(">")
175
175
  end
176
176
 
177
177
  end
@@ -181,7 +181,20 @@ describe 'time select input' do
181
181
  concat(semantic_form_for(@new_post) do |builder|
182
182
  concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
183
183
  end)
184
- output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 0)
184
+ expect(output_buffer).to have_tag('form li.time_select fieldset ol li label', :count => 0)
185
+ end
186
+ end
187
+
188
+ describe ":selected option for setting a value" do
189
+ it "should set the selected value for the form" do
190
+ concat(
191
+ semantic_form_for(@new_post) do |f|
192
+ concat(f.input(:created_at, :as => :datetime_select, :selected => DateTime.new(2018, 10, 4, 12, 00)))
193
+ end
194
+ )
195
+
196
+ expect(output_buffer).to have_tag "option[value='12'][selected='selected']"
197
+ expect(output_buffer).to have_tag "option[value='00'][selected='selected']"
185
198
  end
186
199
  end
187
200
 
@@ -193,9 +206,9 @@ describe 'time select input' do
193
206
  end
194
207
 
195
208
  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')
209
+ expect(output_buffer).to have_tag('#form2_post_publish_at_input')
210
+ expect(output_buffer).to have_tag('#form2_post_publish_at_4i')
211
+ expect(output_buffer).to have_tag('#form2_post_publish_at_5i')
199
212
  end
200
213
  end
201
214
 
@@ -205,7 +218,7 @@ describe 'time select input' do
205
218
  concat(semantic_form_for(@new_post) do |builder|
206
219
  concat(builder.input(:title, :as => :time_select, :required => true))
207
220
  end)
208
- output_buffer.should have_tag("select[@required]", :count => 2)
221
+ expect(output_buffer).to have_tag("select[@required]", :count => 2)
209
222
  end
210
223
  end
211
224
  end
@@ -221,23 +234,23 @@ describe 'time select input' do
221
234
  end
222
235
 
223
236
  it 'should index the id of the wrapper' do
224
- output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
237
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_created_at_input")
225
238
  end
226
239
 
227
240
  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")
241
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_1i")
242
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_2i")
243
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_created_at_3i")
244
+ expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_4i")
245
+ expect(output_buffer).to have_tag("select#post_author_attributes_3_created_at_5i")
233
246
  end
234
247
 
235
248
  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)]']")
249
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(1i)]']")
250
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(2i)]']")
251
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][created_at(3i)]']")
252
+ expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
253
+ expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
241
254
  end
242
255
 
243
256
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'time_zone input' do
4
+ RSpec.describe 'time_zone input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -20,22 +20,22 @@ describe 'time_zone input' do
20
20
  it_should_apply_error_logic_for_input_type(:time_zone)
21
21
 
22
22
  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/)
23
+ expect(output_buffer).to have_tag('form li label')
24
+ expect(output_buffer).to have_tag('form li label[@for="post_time_zone"]')
25
+ expect(output_buffer).to have_tag('form li label', :text => /Time zone/)
26
26
  end
27
27
 
28
28
  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]\"]")
29
+ expect(output_buffer).to have_tag("form li select")
30
+ expect(output_buffer).to have_tag("form li select#post_time_zone")
31
+ expect(output_buffer).to have_tag("form li select[@name=\"post[time_zone]\"]")
32
32
  end
33
33
 
34
34
  it 'should use input_html to style inputs' do
35
35
  concat(semantic_form_for(@new_post) do |builder|
36
36
  concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
37
37
  end)
38
- output_buffer.should have_tag("form li select.myclass")
38
+ expect(output_buffer).to have_tag("form li select.myclass")
39
39
  end
40
40
 
41
41
  describe "when namespace is provided" do
@@ -54,7 +54,7 @@ describe 'time_zone input' do
54
54
  it_should_have_label_for("context2_post_time_zone")
55
55
 
56
56
  end
57
-
57
+
58
58
  describe "when index is provided" do
59
59
 
60
60
  before do
@@ -67,51 +67,77 @@ describe 'time_zone input' do
67
67
  end)
68
68
  end)
69
69
  end
70
-
70
+
71
71
  it 'should index the id of the wrapper' do
72
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
72
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
73
73
  end
74
-
74
+
75
75
  it 'should index the id of the select tag' do
76
- output_buffer.should have_tag("select#post_author_attributes_3_name")
76
+ expect(output_buffer).to have_tag("select#post_author_attributes_3_name")
77
77
  end
78
-
78
+
79
79
  it 'should index the name of the select tag' do
80
- output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
80
+ expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][name]']")
81
81
  end
82
-
82
+
83
83
  end
84
-
84
+
85
85
 
86
86
  describe 'when no object is given' do
87
- before(:each) do
87
+ before(:example) do
88
88
  concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
89
89
  concat(builder.input(:time_zone, :as => :time_zone))
90
90
  end)
91
91
  end
92
92
 
93
93
  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/)
94
+ expect(output_buffer).to have_tag('form li label')
95
+ expect(output_buffer).to have_tag('form li label[@for="project_time_zone"]')
96
+ expect(output_buffer).to have_tag('form li label', :text => /Time zone/)
97
97
  end
98
98
 
99
99
  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]\"]")
100
+ expect(output_buffer).to have_tag("form li select")
101
+ expect(output_buffer).to have_tag("form li select#project_time_zone")
102
+ expect(output_buffer).to have_tag("form li select[@name=\"project[time_zone]\"]")
103
103
  end
104
104
  end
105
-
105
+
106
106
  context "when required" do
107
107
  it "should add the required attribute to the input's html options" do
108
- with_config :use_required_attribute, true do
108
+ with_config :use_required_attribute, true do
109
109
  concat(semantic_form_for(@new_post) do |builder|
110
110
  concat(builder.input(:title, :as => :time_zone, :required => true))
111
111
  end)
112
- output_buffer.should have_tag("select[@required]")
112
+ expect(output_buffer).to have_tag("select[@required]")
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "when priority time zone is provided" do
118
+ let(:time_zones) { [ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii']] }
119
+ let(:input_html_options) do
120
+ { id: "post_title", required: false, autofocus: false, readonly: false }
121
+ end
122
+
123
+ context "by priority_zone option" do
124
+ it "passes right time_zones" do
125
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
126
+ semantic_form_for(@new_post) do |builder|
127
+ builder.input(:title, as: :time_zone, priority_zones: time_zones)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "by configuration" do
133
+ it "passes right time_zones" do
134
+ expect_any_instance_of(Formtastic::FormBuilder).to receive(:time_zone_select).with(:title, time_zones, {}, input_html_options)
135
+ with_config :priority_time_zones, time_zones do
136
+ semantic_form_for(@new_post) do |builder|
137
+ builder.input(:title, as: :time_zone)
138
+ end
139
+ end
113
140
  end
114
141
  end
115
142
  end
116
-
117
143
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'url input' do
4
+ RSpec.describe 'url input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -56,15 +56,15 @@ describe 'url input' do
56
56
  end
57
57
 
58
58
  it 'should index the id of the wrapper' do
59
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
59
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
60
60
  end
61
61
 
62
62
  it 'should index the id of the select tag' do
63
- output_buffer.should have_tag("input#post_author_attributes_3_name")
63
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
64
64
  end
65
65
 
66
66
  it 'should index the name of the select tag' do
67
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
67
+ expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
68
68
  end
69
69
 
70
70
  end
@@ -76,7 +76,7 @@ describe 'url input' do
76
76
  concat(semantic_form_for(@new_post) do |builder|
77
77
  concat(builder.input(:title, :as => :url, :required => true))
78
78
  end)
79
- output_buffer.should have_tag("input[@required]")
79
+ expect(output_buffer).to have_tag("input[@required]")
80
80
  end
81
81
  end
82
82
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'string input' do
4
+ RSpec.describe 'string input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -21,23 +21,23 @@ describe 'string input' do
21
21
  end
22
22
 
23
23
  it "should have extra class on title" do
24
- output_buffer.should have_tag("form li#post_title_input.extra")
24
+ expect(output_buffer).to have_tag("form li#post_title_input.extra")
25
25
  end
26
26
  it "should have title as string" do
27
- output_buffer.should have_tag("form li#post_title_input.string")
27
+ expect(output_buffer).to have_tag("form li#post_title_input.string")
28
28
  end
29
29
  it "should not have title as radio" do
30
- output_buffer.should_not have_tag("form li#post_title_input.radio")
30
+ expect(output_buffer).not_to have_tag("form li#post_title_input.radio")
31
31
  end
32
32
 
33
33
  it "should have extra class on author" do
34
- output_buffer.should have_tag("form li#post_author_input.extra")
34
+ expect(output_buffer).to have_tag("form li#post_author_input.extra")
35
35
  end
36
36
  it "should not have author as string" do
37
- output_buffer.should_not have_tag("form li#post_author_input.string")
37
+ expect(output_buffer).not_to have_tag("form li#post_author_input.string")
38
38
  end
39
39
  it "should have author as radio" do
40
- output_buffer.should have_tag("form li#post_author_input.radio")
40
+ expect(output_buffer).to have_tag("form li#post_author_input.radio")
41
41
  end
42
42
  end
43
43
  end