simple_form 0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/README.rdoc +339 -6
- data/generators/simple_form_install/USAGE +3 -0
- data/generators/simple_form_install/simple_form_install_generator.rb +19 -0
- data/generators/simple_form_install/templates/simple_form.rb +38 -0
- data/init.rb +1 -0
- data/lib/simple_form.rb +57 -1
- data/lib/simple_form/action_view_extensions/builder.rb +122 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +33 -0
- data/lib/simple_form/action_view_extensions/instance_tag.rb +37 -0
- data/lib/simple_form/components.rb +8 -0
- data/lib/simple_form/components/errors.rb +35 -0
- data/lib/simple_form/components/hints.rb +21 -0
- data/lib/simple_form/components/labels.rb +68 -0
- data/lib/simple_form/components/wrapper.rb +21 -0
- data/lib/simple_form/form_builder.rb +332 -0
- data/lib/simple_form/i18n_cache.rb +22 -0
- data/lib/simple_form/inputs.rb +12 -0
- data/lib/simple_form/inputs/base.rb +107 -0
- data/lib/simple_form/inputs/block_input.rb +13 -0
- data/lib/simple_form/inputs/collection_input.rb +58 -0
- data/lib/simple_form/inputs/date_time_input.rb +18 -0
- data/lib/simple_form/inputs/hidden_input.rb +11 -0
- data/lib/simple_form/inputs/mapping_input.rb +23 -0
- data/lib/simple_form/inputs/priority_input.rb +20 -0
- data/lib/simple_form/inputs/text_field_input.rb +16 -0
- data/lib/simple_form/locale/en.yml +14 -0
- data/lib/simple_form/map_type.rb +13 -0
- data/lib/simple_form/version.rb +3 -0
- data/test/action_view_extensions/builder_test.rb +172 -0
- data/test/action_view_extensions/form_helper_test.rb +50 -0
- data/test/components/error_test.rb +45 -0
- data/test/components/hint_test.rb +78 -0
- data/test/components/label_test.rb +170 -0
- data/test/form_builder_test.rb +550 -0
- data/test/inputs_test.rb +337 -0
- data/test/simple_form_test.rb +9 -0
- data/test/support/country_select/init.rb +1 -0
- data/test/support/country_select/install.rb +2 -0
- data/test/support/country_select/lib/country_select.rb +84 -0
- data/test/support/country_select/uninstall.rb +1 -0
- data/test/support/misc_helpers.rb +29 -0
- data/test/support/mock_controller.rb +11 -0
- data/test/support/mock_response.rb +14 -0
- data/test/support/models.rb +100 -0
- data/test/test_helper.rb +60 -0
- metadata +50 -10
- data/CHANGELOG +0 -27
- data/Rakefile +0 -17
data/test/inputs_test.rb
ADDED
@@ -0,0 +1,337 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InputTest < ActionView::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
SimpleForm::Inputs::CollectionInput.reset_i18n_cache :boolean_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_input_for(object, attribute_name, type, options={})
|
10
|
+
simple_form_for object do |f|
|
11
|
+
concat f.input(attribute_name, options.merge(:as => type))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# ALL
|
16
|
+
test 'input should generate css class based on default input type' do
|
17
|
+
with_input_for @user, :name, :string
|
18
|
+
assert_select 'input.string'
|
19
|
+
with_input_for @user, :description, :text
|
20
|
+
assert_select 'textarea.text'
|
21
|
+
with_input_for @user, :age, :integer
|
22
|
+
assert_select 'input.integer'
|
23
|
+
with_input_for @user, :born_at, :date
|
24
|
+
assert_select 'select.date'
|
25
|
+
with_input_for @user, :created_at, :datetime
|
26
|
+
assert_select 'select.datetime'
|
27
|
+
end
|
28
|
+
|
29
|
+
# TextFieldInput
|
30
|
+
test 'input should map text field to string attribute' do
|
31
|
+
with_input_for @user, :name, :string
|
32
|
+
assert_select 'input[name=\'user[name]\'][id=user_name][value=New in Simple Form!]'
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'input should generate an integer text field for integer attributes ' do
|
36
|
+
with_input_for @user, :age, :integer
|
37
|
+
assert_select 'input.integer#user_age'
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'input should generate a float text field for float attributes ' do
|
41
|
+
with_input_for @user, :age, :float
|
42
|
+
assert_select 'input.float#user_age'
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'input should generate a decimal text field for decimal attributes ' do
|
46
|
+
with_input_for @user, :age, :decimal
|
47
|
+
assert_select 'input.decimal#user_age'
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'input should get options from column definition for string attributes' do
|
51
|
+
with_input_for @user, :name, :string
|
52
|
+
assert_select 'input.string[maxlength=100]'
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'input should get options from column definition for decimal attributes' do
|
56
|
+
with_input_for @user, :credit_limit, :decimal
|
57
|
+
assert_select 'input.decimal[maxlength=15]'
|
58
|
+
end
|
59
|
+
|
60
|
+
# MappingInput
|
61
|
+
test 'input should generate a text area for text attributes' do
|
62
|
+
with_input_for @user, :description, :text
|
63
|
+
assert_select 'textarea.text#user_description'
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'input should generate a checkbox by default for boolean attributes' do
|
67
|
+
with_input_for @user, :active, :boolean
|
68
|
+
assert_select 'input[type=checkbox].boolean#user_active'
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'input should generate a password field for password attributes' do
|
72
|
+
with_input_for @user, :password, :password
|
73
|
+
assert_select 'input[type=password].password#user_password'
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'input should generate a file field' do
|
77
|
+
with_input_for @user, :name, :file
|
78
|
+
assert_select 'input#user_name[type=file]'
|
79
|
+
end
|
80
|
+
|
81
|
+
# HiddenInput
|
82
|
+
test 'input should generate a hidden field' do
|
83
|
+
with_input_for @user, :name, :hidden
|
84
|
+
assert_no_select 'input[type=text]'
|
85
|
+
assert_select 'input#user_name[type=hidden]'
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'hint should not be generated for hidden fields' do
|
89
|
+
with_input_for @user, :name, :hidden, :hint => 'Use with care...'
|
90
|
+
assert_no_select 'span.hint'
|
91
|
+
end
|
92
|
+
|
93
|
+
test 'label should not be generated for hidden inputs' do
|
94
|
+
with_input_for @user, :name, :hidden
|
95
|
+
assert_no_select 'label'
|
96
|
+
end
|
97
|
+
|
98
|
+
# PriorityInput
|
99
|
+
test 'input should generate a country select field' do
|
100
|
+
with_input_for @user, :country, :country
|
101
|
+
assert_select 'select#user_country'
|
102
|
+
assert_select 'select option[value=Brazil]', 'Brazil'
|
103
|
+
assert_no_select 'select option[value=][disabled=disabled]'
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'input should generate a country select with simple form default' do
|
107
|
+
swap SimpleForm, :country_priority => [ 'Brazil' ] do
|
108
|
+
with_input_for @user, :country, :country
|
109
|
+
assert_select 'select option[value=][disabled=disabled]'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
test 'input should generate a time zone select field' do
|
114
|
+
with_input_for @user, :time_zone, :time_zone
|
115
|
+
assert_select 'select#user_time_zone'
|
116
|
+
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
117
|
+
assert_no_select 'select option[value=][disabled=disabled]'
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'input should generate a time zone select field with default' do
|
121
|
+
with_input_for @user, :time_zone, :time_zone, :default => 'Brasilia'
|
122
|
+
assert_select 'select option[value=Brasilia][selected=selected]'
|
123
|
+
assert_no_select 'select option[value=]'
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'input should generate a time zone select using options priority' do
|
127
|
+
with_input_for @user, :time_zone, :time_zone, :priority => /Brasilia/
|
128
|
+
assert_select 'select option[value=][disabled=disabled]'
|
129
|
+
assert_no_select 'select option[value=]', /^$/
|
130
|
+
end
|
131
|
+
|
132
|
+
# DateTime input
|
133
|
+
test 'input should generate a datetime select by default for datetime attributes' do
|
134
|
+
with_input_for @user, :created_at, :datetime
|
135
|
+
1.upto(5) do |i|
|
136
|
+
assert_select "form select.datetime#user_created_at_#{i}i"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
test 'input should be able to pass options to datetime select' do
|
141
|
+
with_input_for @user, :created_at, :datetime,
|
142
|
+
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
143
|
+
|
144
|
+
assert_select 'select.datetime[disabled=disabled]'
|
145
|
+
assert_select 'select.datetime option', 'ano'
|
146
|
+
assert_select 'select.datetime option', 'mês'
|
147
|
+
assert_select 'select.datetime option', 'dia'
|
148
|
+
end
|
149
|
+
|
150
|
+
test 'input should generate a date select for date attributes' do
|
151
|
+
with_input_for @user, :born_at, :date
|
152
|
+
assert_select 'select.date#user_born_at_1i'
|
153
|
+
assert_select 'select.date#user_born_at_2i'
|
154
|
+
assert_select 'select.date#user_born_at_3i'
|
155
|
+
assert_no_select 'select.date#user_born_at_4i'
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'input should be able to pass options to date select' do
|
159
|
+
with_input_for @user, :born_at, :date, :as => :date,
|
160
|
+
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
161
|
+
|
162
|
+
assert_select 'select.date[disabled=disabled]'
|
163
|
+
assert_select 'select.date option', 'ano'
|
164
|
+
assert_select 'select.date option', 'mês'
|
165
|
+
assert_select 'select.date option', 'dia'
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'input should be able to pass :default to date select' do
|
169
|
+
with_input_for @user, :born_at, :date, :default => Date.today
|
170
|
+
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
171
|
+
end
|
172
|
+
|
173
|
+
test 'input should generate a time select for time attributes' do
|
174
|
+
with_input_for @user, :delivery_time, :time
|
175
|
+
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
176
|
+
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
177
|
+
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
178
|
+
assert_select 'select.time#user_delivery_time_4i'
|
179
|
+
assert_select 'select.time#user_delivery_time_5i'
|
180
|
+
end
|
181
|
+
|
182
|
+
test 'input should be able to pass options to time select' do
|
183
|
+
with_input_for @user, :delivery_time, :time, :required => true,
|
184
|
+
:disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
|
185
|
+
|
186
|
+
assert_select 'select.time[disabled=disabled]'
|
187
|
+
assert_select 'select.time option', 'hora'
|
188
|
+
assert_select 'select.time option', 'minuto'
|
189
|
+
end
|
190
|
+
|
191
|
+
test 'label should point to first option when date input type' do
|
192
|
+
with_input_for :project, :created_at, :date
|
193
|
+
assert_select 'label[for=project_created_at_1i]'
|
194
|
+
end
|
195
|
+
|
196
|
+
test 'label should point to first option when datetime input type' do
|
197
|
+
with_input_for :project, :created_at, :datetime
|
198
|
+
assert_select 'label[for=project_created_at_1i]'
|
199
|
+
end
|
200
|
+
|
201
|
+
test 'label should point to first option when time input type' do
|
202
|
+
with_input_for :project, :created_at, :time
|
203
|
+
assert_select 'label[for=project_created_at_4i]'
|
204
|
+
end
|
205
|
+
|
206
|
+
# CollectionInput
|
207
|
+
test 'input should generate boolean radio buttons by default for radio types' do
|
208
|
+
with_input_for @user, :active, :radio
|
209
|
+
assert_select 'input[type=radio][value=true].radio#user_active_true'
|
210
|
+
assert_select 'input[type=radio][value=false].radio#user_active_false'
|
211
|
+
end
|
212
|
+
|
213
|
+
test 'input as radio should generate internal labels by default' do
|
214
|
+
with_input_for @user, :active, :radio
|
215
|
+
assert_select 'label[for=user_active_true]', 'Yes'
|
216
|
+
assert_select 'label[for=user_active_false]', 'No'
|
217
|
+
end
|
218
|
+
|
219
|
+
test 'input as radio should use i18n to translate internal labels' do
|
220
|
+
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
221
|
+
with_input_for @user, :active, :radio
|
222
|
+
assert_select 'label[for=user_active_true]', 'Sim'
|
223
|
+
assert_select 'label[for=user_active_false]', 'Não'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
test 'input should generate a boolean select with options by default for select types' do
|
228
|
+
with_input_for @user, :active, :select
|
229
|
+
assert_select 'select.select#user_active'
|
230
|
+
assert_select 'select option[value=true]', 'Yes'
|
231
|
+
assert_select 'select option[value=false]', 'No'
|
232
|
+
end
|
233
|
+
|
234
|
+
test 'input as select should use i18n to translate select boolean options' do
|
235
|
+
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
236
|
+
with_input_for @user, :active, :select
|
237
|
+
assert_select 'select option[value=true]', 'Sim'
|
238
|
+
assert_select 'select option[value=false]', 'Não'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
test 'input should allow overriding collection for select types' do
|
243
|
+
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
244
|
+
assert_select 'select.select#user_name'
|
245
|
+
assert_select 'select option', 'Jose'
|
246
|
+
assert_select 'select option', 'Carlos'
|
247
|
+
end
|
248
|
+
|
249
|
+
test 'input should mark the selected value by default' do
|
250
|
+
@user.name = "Carlos"
|
251
|
+
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
252
|
+
assert_select 'select option[selected=selected]', 'Carlos'
|
253
|
+
end
|
254
|
+
|
255
|
+
test 'input should mark the selected value also when using integers' do
|
256
|
+
@user.age = 18
|
257
|
+
with_input_for @user, :age, :select, :collection => 18..60
|
258
|
+
assert_select 'select option[selected=selected]', '18'
|
259
|
+
end
|
260
|
+
|
261
|
+
test 'input should automatically set include blank' do
|
262
|
+
with_input_for @user, :age, :select, :collection => 18..30
|
263
|
+
assert_select 'select option[value=]', ''
|
264
|
+
end
|
265
|
+
|
266
|
+
test 'input should not set include blank if otherwise is told' do
|
267
|
+
with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false
|
268
|
+
assert_no_select 'select option[value=]', ''
|
269
|
+
end
|
270
|
+
|
271
|
+
test 'input should not set include blank if prompt is given' do
|
272
|
+
with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo"
|
273
|
+
assert_no_select 'select option[value=]', ''
|
274
|
+
end
|
275
|
+
|
276
|
+
test 'input should not set include blank if multiple is given' do
|
277
|
+
with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true }
|
278
|
+
assert_no_select 'select option[value=]', ''
|
279
|
+
end
|
280
|
+
|
281
|
+
test 'input should detect label and value on collections' do
|
282
|
+
users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ]
|
283
|
+
with_input_for @user, :description, :select, :collection => users
|
284
|
+
assert_select 'select option[value=1]', 'Jose'
|
285
|
+
assert_select 'select option[value=2]', 'Carlos'
|
286
|
+
end
|
287
|
+
|
288
|
+
test 'input should allow overriding collection for radio types' do
|
289
|
+
with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
|
290
|
+
assert_select 'input[type=radio][value=Jose]'
|
291
|
+
assert_select 'input[type=radio][value=Carlos]'
|
292
|
+
assert_select 'label.collection_radio', 'Jose'
|
293
|
+
assert_select 'label.collection_radio', 'Carlos'
|
294
|
+
end
|
295
|
+
|
296
|
+
test 'input should mark the current radio value by default' do
|
297
|
+
@user.name = "Carlos"
|
298
|
+
with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
|
299
|
+
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
300
|
+
end
|
301
|
+
|
302
|
+
test 'input should allow using a collection with text/value arrays' do
|
303
|
+
with_input_for @user, :name, :radio, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']]
|
304
|
+
assert_select 'input[type=radio][value=jose]'
|
305
|
+
assert_select 'input[type=radio][value=carlos]'
|
306
|
+
assert_select 'label.collection_radio', 'Jose'
|
307
|
+
assert_select 'label.collection_radio', 'Carlos'
|
308
|
+
end
|
309
|
+
|
310
|
+
test 'input should allow overriding label and value method for collections' do
|
311
|
+
with_input_for @user, :name, :radio,
|
312
|
+
:collection => ['Jose' , 'Carlos'],
|
313
|
+
:label_method => :upcase,
|
314
|
+
:value_method => :downcase
|
315
|
+
assert_select 'input[type=radio][value=jose]'
|
316
|
+
assert_select 'input[type=radio][value=carlos]'
|
317
|
+
assert_select 'label.collection_radio', 'JOSE'
|
318
|
+
assert_select 'label.collection_radio', 'CARLOS'
|
319
|
+
end
|
320
|
+
|
321
|
+
# With no object
|
322
|
+
test 'input should be generated properly when object is not present' do
|
323
|
+
with_input_for :project, :name, :string
|
324
|
+
assert_select 'input.string.required#project_name'
|
325
|
+
end
|
326
|
+
|
327
|
+
test 'input as radio should be generated properly when object is not present ' do
|
328
|
+
with_input_for :project, :name, :radio
|
329
|
+
assert_select 'input.radio#project_name_true'
|
330
|
+
assert_select 'input.radio#project_name_false'
|
331
|
+
end
|
332
|
+
|
333
|
+
test 'input as select with collection should be generated properly when object is not present' do
|
334
|
+
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
335
|
+
assert_select 'select.select#project_name'
|
336
|
+
end
|
337
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'country_select'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# CountrySelect
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
module FormOptionsHelper
|
5
|
+
# Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
|
6
|
+
def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
7
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
|
8
|
+
end
|
9
|
+
# Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
|
10
|
+
# have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
|
11
|
+
# that they will be listed above the rest of the (long) list.
|
12
|
+
#
|
13
|
+
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
|
14
|
+
def country_options_for_select(selected = nil, priority_countries = nil)
|
15
|
+
country_options = ""
|
16
|
+
|
17
|
+
if priority_countries
|
18
|
+
country_options += options_for_select(priority_countries, selected)
|
19
|
+
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
return country_options + options_for_select(COUNTRIES, selected)
|
23
|
+
end
|
24
|
+
# All the countries included in the country_options output.
|
25
|
+
COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
|
26
|
+
"Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
|
27
|
+
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
|
28
|
+
"Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
|
29
|
+
"British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
|
30
|
+
"Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
|
31
|
+
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
|
32
|
+
"Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
|
33
|
+
"Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
|
34
|
+
"El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
|
35
|
+
"Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
|
36
|
+
"French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
|
37
|
+
"Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
|
38
|
+
"Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
|
39
|
+
"Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
|
40
|
+
"Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
|
41
|
+
"Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
|
42
|
+
"Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
|
43
|
+
"Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
|
44
|
+
"Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
|
45
|
+
"Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
|
46
|
+
"Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
|
47
|
+
"Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
|
48
|
+
"Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
|
49
|
+
"Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
|
50
|
+
"Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
|
51
|
+
"Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
|
52
|
+
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
|
53
|
+
"Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
|
54
|
+
"South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
|
55
|
+
"Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
|
56
|
+
"Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
|
57
|
+
"Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
|
58
|
+
"Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
|
59
|
+
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
|
60
|
+
"Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
|
61
|
+
"Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
|
62
|
+
end
|
63
|
+
|
64
|
+
class InstanceTag
|
65
|
+
def to_country_select_tag(priority_countries, options, html_options)
|
66
|
+
html_options = html_options.stringify_keys
|
67
|
+
add_default_name_and_id(html_options)
|
68
|
+
value = value(object)
|
69
|
+
content_tag("select",
|
70
|
+
add_options(
|
71
|
+
country_options_for_select(value, priority_countries),
|
72
|
+
options, value
|
73
|
+
), html_options
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class FormBuilder
|
79
|
+
def country_select(method, priority_countries = nil, options = {}, html_options = {})
|
80
|
+
@template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MiscHelpers
|
2
|
+
def store_translations(locale, translations, &block)
|
3
|
+
begin
|
4
|
+
I18n.backend.store_translations locale, translations
|
5
|
+
yield
|
6
|
+
ensure
|
7
|
+
I18n.reload!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_no_select(*args)
|
12
|
+
assert_raise Test::Unit::AssertionFailedError do
|
13
|
+
assert_select(*args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def swap(object, new_values)
|
18
|
+
old_values = {}
|
19
|
+
new_values.each do |key, value|
|
20
|
+
old_values[key] = object.send key
|
21
|
+
object.send :"#{key}=", value
|
22
|
+
end
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
old_values.each do |key, value|
|
26
|
+
object.send :"#{key}=", value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|