formtastic 1.2.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +46 -0
  5. data/.yardopts +1 -0
  6. data/Appraisals +43 -0
  7. data/CHANGELOG +54 -0
  8. data/DEPRECATIONS +52 -0
  9. data/Gemfile +3 -0
  10. data/README.md +629 -0
  11. data/RELEASE_PROCESS +6 -0
  12. data/Rakefile +35 -0
  13. data/app/assets/stylesheets/formtastic.css +289 -0
  14. data/app/assets/stylesheets/formtastic_ie6.css +33 -0
  15. data/app/assets/stylesheets/formtastic_ie7.css +23 -0
  16. data/formtastic.gemspec +42 -0
  17. data/gemfiles/rails_3.2.gemfile +9 -0
  18. data/gemfiles/rails_4.0.4.gemfile +8 -0
  19. data/gemfiles/rails_4.1.gemfile +8 -0
  20. data/gemfiles/rails_4.2.gemfile +8 -0
  21. data/gemfiles/rails_4.gemfile +8 -0
  22. data/gemfiles/rails_5.0.gemfile +8 -0
  23. data/gemfiles/rails_edge.gemfile +15 -0
  24. data/lib/formtastic.rb +40 -1945
  25. data/lib/formtastic/action_class_finder.rb +18 -0
  26. data/lib/formtastic/actions.rb +11 -0
  27. data/lib/formtastic/actions/base.rb +156 -0
  28. data/lib/formtastic/actions/button_action.rb +67 -0
  29. data/lib/formtastic/actions/buttonish.rb +17 -0
  30. data/lib/formtastic/actions/input_action.rb +70 -0
  31. data/lib/formtastic/actions/link_action.rb +88 -0
  32. data/lib/formtastic/deprecation.rb +42 -0
  33. data/lib/formtastic/engine.rb +11 -0
  34. data/lib/formtastic/form_builder.rb +124 -0
  35. data/lib/formtastic/helpers.rb +16 -0
  36. data/lib/formtastic/helpers/action_helper.rb +162 -0
  37. data/lib/formtastic/helpers/actions_helper.rb +168 -0
  38. data/lib/formtastic/helpers/enum.rb +13 -0
  39. data/lib/formtastic/helpers/errors_helper.rb +81 -0
  40. data/lib/formtastic/helpers/fieldset_wrapper.rb +80 -0
  41. data/lib/formtastic/helpers/file_column_detection.rb +16 -0
  42. data/lib/formtastic/helpers/form_helper.rb +203 -0
  43. data/lib/formtastic/helpers/input_helper.rb +407 -0
  44. data/lib/formtastic/helpers/inputs_helper.rb +411 -0
  45. data/lib/formtastic/helpers/reflection.rb +37 -0
  46. data/lib/formtastic/html_attributes.rb +32 -0
  47. data/lib/formtastic/i18n.rb +4 -2
  48. data/lib/formtastic/input_class_finder.rb +18 -0
  49. data/lib/formtastic/inputs.rb +39 -0
  50. data/lib/formtastic/inputs/base.rb +76 -0
  51. data/lib/formtastic/inputs/base/associations.rb +31 -0
  52. data/lib/formtastic/inputs/base/choices.rb +108 -0
  53. data/lib/formtastic/inputs/base/collections.rb +159 -0
  54. data/lib/formtastic/inputs/base/database.rb +22 -0
  55. data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
  56. data/lib/formtastic/inputs/base/errors.rb +58 -0
  57. data/lib/formtastic/inputs/base/fileish.rb +23 -0
  58. data/lib/formtastic/inputs/base/hints.rb +31 -0
  59. data/lib/formtastic/inputs/base/html.rb +53 -0
  60. data/lib/formtastic/inputs/base/labelling.rb +52 -0
  61. data/lib/formtastic/inputs/base/naming.rb +42 -0
  62. data/lib/formtastic/inputs/base/numeric.rb +50 -0
  63. data/lib/formtastic/inputs/base/options.rb +17 -0
  64. data/lib/formtastic/inputs/base/placeholder.rb +17 -0
  65. data/lib/formtastic/inputs/base/stringish.rb +38 -0
  66. data/lib/formtastic/inputs/base/timeish.rb +241 -0
  67. data/lib/formtastic/inputs/base/validations.rb +215 -0
  68. data/lib/formtastic/inputs/base/wrapping.rb +50 -0
  69. data/lib/formtastic/inputs/boolean_input.rb +118 -0
  70. data/lib/formtastic/inputs/check_boxes_input.rb +197 -0
  71. data/lib/formtastic/inputs/color_input.rb +42 -0
  72. data/lib/formtastic/inputs/country_input.rb +86 -0
  73. data/lib/formtastic/inputs/datalist_input.rb +41 -0
  74. data/lib/formtastic/inputs/date_picker_input.rb +93 -0
  75. data/lib/formtastic/inputs/date_select_input.rb +34 -0
  76. data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
  77. data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
  78. data/lib/formtastic/inputs/email_input.rb +41 -0
  79. data/lib/formtastic/inputs/file_input.rb +42 -0
  80. data/lib/formtastic/inputs/hidden_input.rb +62 -0
  81. data/lib/formtastic/inputs/number_input.rb +88 -0
  82. data/lib/formtastic/inputs/password_input.rb +41 -0
  83. data/lib/formtastic/inputs/phone_input.rb +42 -0
  84. data/lib/formtastic/inputs/radio_input.rb +163 -0
  85. data/lib/formtastic/inputs/range_input.rb +95 -0
  86. data/lib/formtastic/inputs/search_input.rb +41 -0
  87. data/lib/formtastic/inputs/select_input.rb +235 -0
  88. data/lib/formtastic/inputs/string_input.rb +36 -0
  89. data/lib/formtastic/inputs/text_input.rb +48 -0
  90. data/lib/formtastic/inputs/time_picker_input.rb +99 -0
  91. data/lib/formtastic/inputs/time_select_input.rb +38 -0
  92. data/lib/formtastic/inputs/time_zone_input.rb +58 -0
  93. data/lib/formtastic/inputs/url_input.rb +41 -0
  94. data/lib/formtastic/localized_string.rb +17 -0
  95. data/lib/formtastic/localizer.rb +152 -0
  96. data/lib/formtastic/namespaced_class_finder.rb +99 -0
  97. data/lib/formtastic/util.rb +35 -16
  98. data/lib/formtastic/version.rb +3 -0
  99. data/lib/generators/formtastic/form/form_generator.rb +64 -37
  100. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  101. data/lib/generators/formtastic/install/install_generator.rb +13 -5
  102. data/lib/generators/templates/_form.html.erb +10 -4
  103. data/lib/generators/templates/_form.html.haml +8 -4
  104. data/lib/generators/templates/_form.html.slim +8 -0
  105. data/lib/generators/templates/formtastic.rb +77 -44
  106. data/lib/generators/templates/input.rb +19 -0
  107. data/lib/locale/en.yml +3 -0
  108. data/sample/basic_inputs.html +224 -0
  109. data/sample/config.ru +69 -0
  110. data/sample/index.html +14 -0
  111. data/spec/action_class_finder_spec.rb +12 -0
  112. data/spec/actions/button_action_spec.rb +63 -0
  113. data/spec/actions/generic_action_spec.rb +521 -0
  114. data/spec/actions/input_action_spec.rb +59 -0
  115. data/spec/actions/link_action_spec.rb +92 -0
  116. data/spec/builder/custom_builder_spec.rb +116 -0
  117. data/spec/builder/error_proc_spec.rb +27 -0
  118. data/spec/builder/semantic_fields_for_spec.rb +142 -0
  119. data/spec/fast_spec_helper.rb +12 -0
  120. data/spec/generators/formtastic/form/form_generator_spec.rb +131 -0
  121. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  122. data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
  123. data/spec/helpers/action_helper_spec.rb +19 -0
  124. data/spec/helpers/actions_helper_spec.rb +143 -0
  125. data/spec/helpers/form_helper_spec.rb +218 -0
  126. data/spec/helpers/input_helper_spec.rb +6 -0
  127. data/spec/helpers/inputs_helper_spec.rb +655 -0
  128. data/spec/helpers/namespaced_action_helper_spec.rb +43 -0
  129. data/spec/helpers/namespaced_input_helper_spec.rb +36 -0
  130. data/spec/helpers/reflection_helper_spec.rb +32 -0
  131. data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
  132. data/spec/i18n_spec.rb +210 -0
  133. data/spec/input_class_finder_spec.rb +10 -0
  134. data/spec/inputs/base/collections_spec.rb +76 -0
  135. data/spec/inputs/base/validations_spec.rb +342 -0
  136. data/spec/inputs/boolean_input_spec.rb +254 -0
  137. data/spec/inputs/check_boxes_input_spec.rb +546 -0
  138. data/spec/inputs/color_input_spec.rb +97 -0
  139. data/spec/inputs/country_input_spec.rb +133 -0
  140. data/spec/inputs/custom_input_spec.rb +55 -0
  141. data/spec/inputs/datalist_input_spec.rb +61 -0
  142. data/spec/inputs/date_picker_input_spec.rb +449 -0
  143. data/spec/inputs/date_select_input_spec.rb +235 -0
  144. data/spec/inputs/datetime_picker_input_spec.rb +490 -0
  145. data/spec/inputs/datetime_select_input_spec.rb +193 -0
  146. data/spec/inputs/email_input_spec.rb +85 -0
  147. data/spec/inputs/file_input_spec.rb +89 -0
  148. data/spec/inputs/hidden_input_spec.rb +135 -0
  149. data/spec/inputs/include_blank_spec.rb +78 -0
  150. data/spec/inputs/label_spec.rb +149 -0
  151. data/spec/inputs/number_input_spec.rb +815 -0
  152. data/spec/inputs/password_input_spec.rb +99 -0
  153. data/spec/inputs/phone_input_spec.rb +85 -0
  154. data/spec/inputs/placeholder_spec.rb +71 -0
  155. data/spec/inputs/radio_input_spec.rb +328 -0
  156. data/spec/inputs/range_input_spec.rb +505 -0
  157. data/spec/inputs/readonly_spec.rb +50 -0
  158. data/spec/inputs/search_input_spec.rb +84 -0
  159. data/spec/inputs/select_input_spec.rb +615 -0
  160. data/spec/inputs/string_input_spec.rb +260 -0
  161. data/spec/inputs/text_input_spec.rb +187 -0
  162. data/spec/inputs/time_picker_input_spec.rb +455 -0
  163. data/spec/inputs/time_select_input_spec.rb +248 -0
  164. data/spec/inputs/time_zone_input_spec.rb +143 -0
  165. data/spec/inputs/url_input_spec.rb +85 -0
  166. data/spec/inputs/with_options_spec.rb +43 -0
  167. data/spec/localizer_spec.rb +130 -0
  168. data/spec/namespaced_class_finder_spec.rb +79 -0
  169. data/spec/spec.opts +2 -0
  170. data/spec/spec_helper.rb +525 -0
  171. data/spec/support/custom_macros.rb +564 -0
  172. data/spec/support/deprecation.rb +6 -0
  173. data/spec/support/shared_examples.rb +1313 -0
  174. data/spec/support/specialized_class_finder_shared_example.rb +27 -0
  175. data/spec/support/test_environment.rb +31 -0
  176. data/spec/util_spec.rb +66 -0
  177. metadata +434 -161
  178. data/README.textile +0 -682
  179. data/generators/form/USAGE +0 -16
  180. data/generators/form/form_generator.rb +0 -111
  181. data/generators/formtastic/formtastic_generator.rb +0 -26
  182. data/init.rb +0 -5
  183. data/lib/formtastic/layout_helper.rb +0 -12
  184. data/lib/formtastic/railtie.rb +0 -14
  185. data/lib/generators/templates/formtastic.css +0 -145
  186. data/lib/generators/templates/formtastic_changes.css +0 -14
  187. data/lib/generators/templates/rails2/_form.html.erb +0 -5
  188. data/lib/generators/templates/rails2/_form.html.haml +0 -4
  189. data/rails/init.rb +0 -2
@@ -0,0 +1,248 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'time select input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "general" do
14
+ before do
15
+ ::I18n.backend.reload!
16
+ output_buffer.replace ''
17
+ end
18
+
19
+ describe "with :ignore_date => true" do
20
+ before do
21
+ concat(semantic_form_for(@new_post) do |builder|
22
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => true))
23
+ end)
24
+ end
25
+
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')
30
+ end
31
+
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')
35
+ end
36
+
37
+ end
38
+
39
+ describe "with :ignore_date => false" do
40
+ before do
41
+ @new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
42
+ concat(semantic_form_for(@new_post) do |builder|
43
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
44
+ end)
45
+ end
46
+
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"]')
54
+ end
55
+
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')
59
+ end
60
+
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"]')
63
+ end
64
+
65
+ end
66
+
67
+ describe "without seconds" do
68
+ before do
69
+ concat(semantic_form_for(@new_post) do |builder|
70
+ concat(builder.input(:publish_at, :as => :time_select))
71
+ end)
72
+ end
73
+
74
+ it_should_have_input_wrapper_with_class("time_select")
75
+ it_should_have_input_wrapper_with_class(:input)
76
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
77
+ it_should_have_a_nested_fieldset
78
+ it_should_have_a_nested_fieldset_with_class('fragments')
79
+ it_should_have_a_nested_ordered_list_with_class('fragments-group')
80
+ it_should_apply_error_logic_for_input_type(:time_select)
81
+
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/)
84
+ end
85
+
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"]')
88
+ end
89
+
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)
93
+ end
94
+
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)
99
+ end
100
+
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)
103
+ end
104
+ end
105
+
106
+ describe "with seconds" do
107
+ before do
108
+ concat(semantic_form_for(@new_post) do |builder|
109
+ concat(builder.input(:publish_at, :as => :time_select, :include_seconds => true))
110
+ end)
111
+ end
112
+
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)
118
+ end
119
+
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)
122
+ end
123
+
124
+ it 'should generate a sanitized label and matching ids for attribute' do
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")
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ describe ':labels option' do
134
+ fields = [:hour, :minute, :second]
135
+ fields.each do |field|
136
+ it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
137
+ output_buffer.replace ''
138
+ concat(semantic_form_for(@new_post) do |builder|
139
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
140
+ end)
141
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length)
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)
144
+ end
145
+ end
146
+
147
+ it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
148
+ output_buffer.replace ''
149
+ concat(semantic_form_for(@new_post) do |builder|
150
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
151
+ end)
152
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
153
+ fields.each do |f|
154
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
155
+ end
156
+ end
157
+
158
+ it "should not render the label when :labels[:#{field}] is false" do
159
+ output_buffer.replace ''
160
+ concat(semantic_form_for(@new_post) do |builder|
161
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
162
+ end)
163
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
164
+ fields.each do |f|
165
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
166
+ end
167
+ end
168
+
169
+ it "should not render unsafe HTML when :labels[:#{field}] is false" do
170
+ output_buffer.replace ''
171
+ concat(semantic_form_for(@new_post) do |builder|
172
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
173
+ end)
174
+ output_buffer.should_not include(">")
175
+ end
176
+
177
+ end
178
+
179
+ it "should not render labels when :labels is falsy" do
180
+ output_buffer.replace ''
181
+ concat(semantic_form_for(@new_post) do |builder|
182
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
183
+ end)
184
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 0)
185
+ end
186
+ end
187
+
188
+ describe ':namespace option' do
189
+ before do
190
+ concat(semantic_form_for(@new_post, :namespace => 'form2') do |builder|
191
+ concat(builder.input(:publish_at, :as => :time_select))
192
+ end)
193
+ end
194
+
195
+ 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')
199
+ end
200
+ end
201
+
202
+ describe "when required" do
203
+ it "should add the required attribute to the input's html options" do
204
+ with_config :use_required_attribute, true do
205
+ concat(semantic_form_for(@new_post) do |builder|
206
+ concat(builder.input(:title, :as => :time_select, :required => true))
207
+ end)
208
+ output_buffer.should have_tag("select[@required]", :count => 2)
209
+ end
210
+ end
211
+ end
212
+
213
+ describe "when index is provided" do
214
+
215
+ before do
216
+ concat(semantic_form_for(@new_post) do |builder|
217
+ concat(builder.fields_for(:author, :index => 3) do |author|
218
+ concat(author.input(:created_at, :as => :time_select))
219
+ end)
220
+ end)
221
+ end
222
+
223
+ it 'should index the id of the wrapper' do
224
+ output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
225
+ end
226
+
227
+ 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")
233
+ end
234
+
235
+ 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)]']")
241
+ end
242
+
243
+ end
244
+
245
+ end
246
+
247
+
248
+
@@ -0,0 +1,143 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'time_zone input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ concat(semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:time_zone))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("time_zone")
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_id("post_time_zone_input")
20
+ it_should_apply_error_logic_for_input_type(:time_zone)
21
+
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/)
26
+ end
27
+
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]\"]")
32
+ end
33
+
34
+ it 'should use input_html to style inputs' do
35
+ concat(semantic_form_for(@new_post) do |builder|
36
+ concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
37
+ end)
38
+ output_buffer.should have_tag("form li select.myclass")
39
+ end
40
+
41
+ describe "when namespace is provided" do
42
+
43
+ before do
44
+ @output_buffer = ''
45
+ mock_everything
46
+
47
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
48
+ concat(builder.input(:time_zone))
49
+ end)
50
+ end
51
+
52
+ it_should_have_input_wrapper_with_id("context2_post_time_zone_input")
53
+ it_should_have_select_with_id("context2_post_time_zone")
54
+ it_should_have_label_for("context2_post_time_zone")
55
+
56
+ end
57
+
58
+ describe "when index is provided" do
59
+
60
+ before do
61
+ @output_buffer = ''
62
+ mock_everything
63
+
64
+ concat(semantic_form_for(@new_post) do |builder|
65
+ concat(builder.fields_for(:author, :index => 3) do |author|
66
+ concat(author.input(:name, :as => :time_zone))
67
+ end)
68
+ end)
69
+ end
70
+
71
+ it 'should index the id of the wrapper' do
72
+ output_buffer.should have_tag("li#post_author_attributes_3_name_input")
73
+ end
74
+
75
+ it 'should index the id of the select tag' do
76
+ output_buffer.should have_tag("select#post_author_attributes_3_name")
77
+ end
78
+
79
+ it 'should index the name of the select tag' do
80
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
81
+ end
82
+
83
+ end
84
+
85
+
86
+ describe 'when no object is given' do
87
+ before(:each) do
88
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
89
+ concat(builder.input(:time_zone, :as => :time_zone))
90
+ end)
91
+ end
92
+
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/)
97
+ end
98
+
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]\"]")
103
+ end
104
+ end
105
+
106
+ context "when required" do
107
+ it "should add the required attribute to the input's html options" do
108
+ with_config :use_required_attribute, true do
109
+ concat(semantic_form_for(@new_post) do |builder|
110
+ concat(builder.input(:title, :as => :time_zone, :required => true))
111
+ end)
112
+ output_buffer.should 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
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'url input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:url))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:url)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:stringish)
23
+ it_should_have_input_wrapper_with_id("post_url_input")
24
+ it_should_have_label_with_text(/Url/)
25
+ it_should_have_label_for("post_url")
26
+ it_should_have_input_with_id("post_url")
27
+ it_should_have_input_with_type(:url)
28
+ it_should_have_input_with_name("post[url]")
29
+
30
+ end
31
+
32
+ describe "when namespace is provided" do
33
+
34
+ before do
35
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
36
+ concat(builder.input(:url))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_url_input")
41
+ it_should_have_label_and_input_with_id("context2_post_url")
42
+
43
+ end
44
+
45
+ describe "when index is provided" do
46
+
47
+ before do
48
+ @output_buffer = ''
49
+ mock_everything
50
+
51
+ concat(semantic_form_for(@new_post) do |builder|
52
+ concat(builder.fields_for(:author, :index => 3) do |author|
53
+ concat(author.input(:name, :as => :url))
54
+ end)
55
+ end)
56
+ end
57
+
58
+ it 'should index the id of the wrapper' do
59
+ output_buffer.should have_tag("li#post_author_attributes_3_name_input")
60
+ end
61
+
62
+ it 'should index the id of the select tag' do
63
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
64
+ end
65
+
66
+ it 'should index the name of the select tag' do
67
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
68
+ end
69
+
70
+ end
71
+
72
+
73
+ describe "when required" do
74
+ it "should add the required attribute to the input's html options" do
75
+ with_config :use_required_attribute, true do
76
+ concat(semantic_form_for(@new_post) do |builder|
77
+ concat(builder.input(:title, :as => :url, :required => true))
78
+ end)
79
+ output_buffer.should have_tag("input[@required]")
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+