case_form 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/CHANGELOG.rdoc +1 -0
  2. data/MIT-LICENSE.rdoc +20 -0
  3. data/Manifest +86 -0
  4. data/README.rdoc +0 -0
  5. data/Rakefile +30 -0
  6. data/TODO.rdoc +7 -0
  7. data/case_form.gemspec +31 -0
  8. data/lib/case_form.rb +88 -0
  9. data/lib/case_form/associations.rb +50 -0
  10. data/lib/case_form/buttons.rb +175 -0
  11. data/lib/case_form/core_ext/form_helper.rb +54 -0
  12. data/lib/case_form/core_ext/layout_helper.rb +16 -0
  13. data/lib/case_form/core_ext/sentence_error.rb +38 -0
  14. data/lib/case_form/element.rb +40 -0
  15. data/lib/case_form/element/base.rb +95 -0
  16. data/lib/case_form/element/button.rb +64 -0
  17. data/lib/case_form/element/error.rb +54 -0
  18. data/lib/case_form/element/errors/complex_error.rb +107 -0
  19. data/lib/case_form/element/errors/simple_error.rb +76 -0
  20. data/lib/case_form/element/fieldset.rb +35 -0
  21. data/lib/case_form/element/hint.rb +54 -0
  22. data/lib/case_form/element/input.rb +106 -0
  23. data/lib/case_form/element/inputs/collection/checkbox_input.rb +36 -0
  24. data/lib/case_form/element/inputs/collection/radio_input.rb +27 -0
  25. data/lib/case_form/element/inputs/collection/select_input.rb +22 -0
  26. data/lib/case_form/element/inputs/collection_input.rb +89 -0
  27. data/lib/case_form/element/inputs/datetime/date_input.rb +45 -0
  28. data/lib/case_form/element/inputs/datetime/date_time_input.rb +50 -0
  29. data/lib/case_form/element/inputs/datetime/time_input.rb +34 -0
  30. data/lib/case_form/element/inputs/datetime/time_zone_input.rb +24 -0
  31. data/lib/case_form/element/inputs/file_input.rb +13 -0
  32. data/lib/case_form/element/inputs/hidden_input.rb +17 -0
  33. data/lib/case_form/element/inputs/number_input.rb +42 -0
  34. data/lib/case_form/element/inputs/search_input.rb +32 -0
  35. data/lib/case_form/element/inputs/string_input.rb +18 -0
  36. data/lib/case_form/element/inputs/text_input.rb +19 -0
  37. data/lib/case_form/element/label.rb +52 -0
  38. data/lib/case_form/element/nested_model.rb +105 -0
  39. data/lib/case_form/element/nested_models/handle.rb +18 -0
  40. data/lib/case_form/element/nested_models/handles/destructor_handle.rb +47 -0
  41. data/lib/case_form/element/nested_models/handles/generator_handle.rb +55 -0
  42. data/lib/case_form/element_ext/associationable.rb +54 -0
  43. data/lib/case_form/element_ext/columnable.rb +21 -0
  44. data/lib/case_form/element_ext/naming.rb +17 -0
  45. data/lib/case_form/element_ext/validationable.rb +13 -0
  46. data/lib/case_form/errors.rb +189 -0
  47. data/lib/case_form/form_builder.rb +11 -0
  48. data/lib/case_form/inputs.rb +1095 -0
  49. data/lib/case_form/labels.rb +102 -0
  50. data/lib/case_form/version.rb +6 -0
  51. data/lib/generators/case_form/install_generator.rb +33 -0
  52. data/lib/generators/case_form/templates/case_form.rb +63 -0
  53. data/lib/generators/case_form/templates/javascripts/jquery.case_form.js +10 -0
  54. data/lib/generators/case_form/templates/javascripts/prototype.case_form.js +0 -0
  55. data/lib/generators/case_form/templates/locales/en.yml +28 -0
  56. data/lib/generators/case_form/templates/locales/pl.yml +28 -0
  57. data/lib/generators/case_form/templates/stylesheets/stylesheet.css +93 -0
  58. data/lib/generators/case_form/templates/stylesheets/stylesheet_changes.css +1 -0
  59. data/lib/generators/case_form/uninstall_generator.rb +30 -0
  60. data/rails/init.rb +1 -0
  61. data/test/element/button_test.rb +85 -0
  62. data/test/element/errors/complex_error_test.rb +140 -0
  63. data/test/element/errors/simple_error_test.rb +92 -0
  64. data/test/element/fieldset_test.rb +28 -0
  65. data/test/element/hint_test.rb +81 -0
  66. data/test/element/input_test.rb +197 -0
  67. data/test/element/inputs/collection/checkbox_input_test.rb +176 -0
  68. data/test/element/inputs/collection/radio_input_test.rb +156 -0
  69. data/test/element/inputs/collection/select_input_test.rb +152 -0
  70. data/test/element/inputs/datetime/date_input_test.rb +160 -0
  71. data/test/element/inputs/datetime/datetime_input_test.rb +227 -0
  72. data/test/element/inputs/datetime/time_input_test.rb +72 -0
  73. data/test/element/inputs/datetime/time_zone_input_test.rb +42 -0
  74. data/test/element/inputs/file_input_test.rb +13 -0
  75. data/test/element/inputs/hidden_input_test.rb +13 -0
  76. data/test/element/inputs/number_input_test.rb +50 -0
  77. data/test/element/inputs/search_input_test.rb +13 -0
  78. data/test/element/inputs/string_input_test.rb +33 -0
  79. data/test/element/inputs/text_input_test.rb +13 -0
  80. data/test/element/label_test.rb +62 -0
  81. data/test/element/nested_model_test.rb +163 -0
  82. data/test/element/nested_models/handles/destructor_handle_test.rb +35 -0
  83. data/test/element/nested_models/handles/generator_handle_test.rb +27 -0
  84. data/test/form_builder_test.rb +25 -0
  85. data/test/form_helper_test.rb +15 -0
  86. data/test/lib/models.rb +268 -0
  87. data/test/test_helper.rb +74 -0
  88. metadata +235 -0
@@ -0,0 +1,176 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+
4
+ class CheckboxInputTest < ActionView::TestCase
5
+ def checkbox_case_form_for(object, attribute, options={})
6
+ concat(case_form_for(object) { |f| f.checkbox(attribute, options) })
7
+ end
8
+
9
+ test "should generate checkbox input" do
10
+ checkbox_case_form_for(@user, :admin)
11
+ assert_select "input[type=checkbox]", 1
12
+ end
13
+
14
+ test "should generate checkbox input with default values" do
15
+ checkbox_case_form_for(@user, :admin)
16
+ assert_select "input[type=checkbox][value=true]", 1
17
+ end
18
+
19
+ test "should generate checkbox input with boolean attributes" do
20
+ checkbox_case_form_for(@user, :admin)
21
+ assert_select "label", "Admin"
22
+ assert_select "input[type=checkbox][value=true]", 1
23
+ assert_select "label", "Yes"
24
+ assert_select "input[type=hidden][value='']", 1
25
+ end
26
+
27
+ test "should generate checkbox input with array collection" do
28
+ collection = [['Adam', 1], ['John', 2], ['Martin', 3]]
29
+ checkbox_case_form_for(@user, :description, :collection => collection)
30
+ assert_select "label", "Description"
31
+ collection.each do |c|
32
+ assert_select "input[type=checkbox][value=#{c.last}]", 1
33
+ assert_select "label", c.first
34
+ end
35
+ end
36
+
37
+ test "should generate checkbox input with flat array collection" do
38
+ collection = ['Adam', 'John', 'Martin']
39
+ checkbox_case_form_for(@user, :description, :collection => collection)
40
+ assert_select "label", "Description"
41
+ collection.each do |c|
42
+ assert_select "input[type=checkbox][value='#{c}']", 1
43
+ assert_select "label", c
44
+ end
45
+ end
46
+
47
+ test "should generate checkbox input with hash collection" do
48
+ collection = { 'Adam' => 1, 'John' => 2, 'Martin' => 3 }
49
+ checkbox_case_form_for(@user, :description, :collection => collection)
50
+ assert_select "label", "Description"
51
+ collection.each do |label, value|
52
+ assert_select "input[type=checkbox][value=#{value}]", 1
53
+ assert_select "label", label
54
+ end
55
+ end
56
+
57
+ test "should generate checkbox input with range collection" do
58
+ collection = 1..5
59
+ checkbox_case_form_for(@user, :description, :collection => collection)
60
+ assert_select "label", "Description"
61
+ collection.each do |value|
62
+ assert_select "input[type=checkbox][value=#{value}]", 1
63
+ assert_select "label", :text => value
64
+ end
65
+ end
66
+
67
+ test "should generate checkbox input for :belongs_to association" do
68
+ checkbox_case_form_for(@user, :country)
69
+ assert_select "label", "Country"
70
+ assert_select "input[type=checkbox][name='user[country_id]']", 5
71
+ assert_select "label", 6
72
+ end
73
+
74
+ test "should generate checkbox input for :belongs_to association and class name" do
75
+ checkbox_case_form_for(@user, :country, :collection => Country)
76
+ assert_select "label", "Country"
77
+ assert_select "input[type=checkbox][name='user[country_id]']", 5
78
+ assert_select "label", 6
79
+ end
80
+
81
+ test "should generate checkbox input for :belongs_to association with array collection" do
82
+ checkbox_case_form_for(@user, :country, :collection => Country.all)
83
+ assert_select "label", "Country"
84
+ assert_select "input[type=checkbox][name='user[country_id]']", 5
85
+ assert_select "label", 6
86
+ end
87
+
88
+ test "should generate checkbox input for :belongs_to association with scoped array collection" do
89
+ checkbox_case_form_for(@user, :country, :collection => Country.priority)
90
+ assert_select "label", "Country"
91
+ assert_select "input[type=checkbox][name='user[country_id]']", 3
92
+ assert_select "label", 4
93
+ end
94
+
95
+ test "should generate checkbox input for :has_many association" do
96
+ checkbox_case_form_for(@user, :projects)
97
+ assert_select "label", "Projects"
98
+ assert_select "input[type=checkbox][name='user[project_ids][]']", 5
99
+ assert_select "label", 6
100
+ end
101
+
102
+ test "should generate checkbox input for :has_many association and class name" do
103
+ checkbox_case_form_for(@user, :projects, :collection => Project)
104
+ assert_select "label", "Projects"
105
+ assert_select "input[type=checkbox][name='user[project_ids][]']", 5
106
+ assert_select "label", 6
107
+ end
108
+
109
+ test "should generate checkbox input for :has_many association with array collection" do
110
+ checkbox_case_form_for(@user, :projects, :collection => Project.all)
111
+ assert_select "label", "Projects"
112
+ assert_select "input[type=checkbox][name='user[project_ids][]']", 5
113
+ assert_select "label", 6
114
+ end
115
+
116
+ test "should generate checkbox input for :has_many association with scoped array collection" do
117
+ checkbox_case_form_for(@user, :projects, :collection => Project.extra)
118
+ assert_select "label", "Projects"
119
+ assert_select "input[type=checkbox][name='user[project_ids][]']", 3
120
+ assert_select "label", 4
121
+ end
122
+
123
+ test "should generate checkbox input for association with specified label and value methods" do
124
+ checkbox_case_form_for(@user, :country, :label_method => :short, :value_method => :id)
125
+ assert_select "input[type=checkbox][name='user[country_id]']", 5
126
+ end
127
+
128
+ test "should generate checkbox input for association with specified label method" do
129
+ checkbox_case_form_for(@user, :country, :label_method => :short)
130
+ assert_select "input[type=checkbox][name='user[country_id]'][value=1]", 1 # "Poland" => 1
131
+ assert_select "label", "Pol"
132
+ end
133
+
134
+ test "should generate checkbox input for association with specified value method" do
135
+ checkbox_case_form_for(@user, :country, :value_method => :non_id)
136
+ assert_select "input[type=checkbox][name='user[country_id]'][value=P]", 1 # "Poland" => 1
137
+ end
138
+
139
+ test "should generate checkbox input with checked value" do
140
+ checkbox_case_form_for(@user, :country, :checked => 1)
141
+ assert_select "input[type=checkbox][checked=checked]", 1
142
+ end
143
+
144
+ test "should generate checkbox input with selected value" do
145
+ checkbox_case_form_for(@user, :country, :selected => 1)
146
+ assert_select "input[type=checkbox][checked=checked]", 1
147
+ end
148
+
149
+ test "should generate checkbox input with disabled value" do
150
+ checkbox_case_form_for(@user, :country, :disabled => [1, 2])
151
+ assert_select "input[type=checkbox][disabled=disabled]", 2
152
+ end
153
+
154
+ test "should generate checkbox input with checked value as object value" do
155
+ @user.country_id = 1
156
+ checkbox_case_form_for(@user, :country)
157
+ assert_select "input[type=checkbox][checked=checked]", :count => 1
158
+ end
159
+
160
+ test "should generate checkbox input as checked" do
161
+ @user.admin = false
162
+ checkbox_case_form_for(@user, :admin, :checked => true )
163
+ assert_select "input[type=checkbox][checked=checked]", 1
164
+ end
165
+
166
+ test "should generate checkbox input as not checked" do
167
+ @user.admin = true
168
+ checkbox_case_form_for(@user, :admin, :checked => false )
169
+ assert_select "input[type=checkbox][checked=checked]", 0
170
+ end
171
+
172
+ test "should generate checkbox input with multiple option" do
173
+ checkbox_case_form_for(@user, :admin, :allow_multiple => true )
174
+ assert_select "input[type=checkbox][name='user[admin][]']", 1
175
+ end
176
+ end
@@ -0,0 +1,156 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+
4
+ class RadioInputTest < ActionView::TestCase
5
+ def radio_case_form_for(object, attribute, options={})
6
+ concat(case_form_for(object) { |f| f.radio(attribute, options) })
7
+ end
8
+
9
+ test "should generate radio input" do
10
+ radio_case_form_for(@user, :admin)
11
+ assert_select "input[type=radio]", 2
12
+ assert_select "label", 3
13
+ end
14
+
15
+ test "should generate radio input with boolean attributes" do
16
+ radio_case_form_for(@user, :admin)
17
+ assert_select "label", "Admin"
18
+ assert_select "input[type=radio][value=true]", 1
19
+ assert_select "label", "Yes"
20
+ assert_select "input[type=radio][value=false]", 1
21
+ assert_select "label", "No"
22
+ end
23
+
24
+ test "should generate radio input with array collection" do
25
+ collection = [['Adam', 1], ['John', 2], ['Martin', 3]]
26
+ radio_case_form_for(@user, :description, :collection => collection)
27
+ assert_select "label", "Description"
28
+ collection.each do |c|
29
+ assert_select "input[type=radio][value=#{c.last}]", 1
30
+ assert_select "label", c.first
31
+ end
32
+ end
33
+
34
+ test "should generate radio input with flat array collection" do
35
+ collection = ['Adam', 'John', 'Martin']
36
+ radio_case_form_for(@user, :description, :collection => collection)
37
+ assert_select "label", "Description"
38
+ collection.each do |c|
39
+ assert_select "input[type=radio][value='#{c}']", 1
40
+ assert_select "label", c
41
+ end
42
+ end
43
+
44
+ test "should generate radio input with hash collection" do
45
+ collection = { 'Adam' => 1, 'John' => 2, 'Martin' => 3 }
46
+ radio_case_form_for(@user, :description, :collection => collection)
47
+ assert_select "label", "Description"
48
+ collection.each do |label, value|
49
+ assert_select "input[type=radio][value=#{value}]", 1
50
+ assert_select "label", label
51
+ end
52
+ end
53
+
54
+ test "should generate radio input with range collection" do
55
+ collection = 1..5
56
+ radio_case_form_for(@user, :description, :collection => collection)
57
+ assert_select "label", "Description"
58
+ collection.each do |value|
59
+ assert_select "input[type=radio][value=#{value}]", 1
60
+ assert_select "label", :text => value
61
+ end
62
+ end
63
+
64
+ test "should generate radio input for :belongs_to association" do
65
+ radio_case_form_for(@user, :country)
66
+ assert_select "label", "Country"
67
+ assert_select "input[type=radio][name='user[country_id]']", 5
68
+ assert_select "label", 6
69
+ end
70
+
71
+ test "should generate radio input for :belongs_to association and class name" do
72
+ radio_case_form_for(@user, :country, :collection => Country)
73
+ assert_select "label", "Country"
74
+ assert_select "input[type=radio][name='user[country_id]']", 5
75
+ assert_select "label", 6
76
+ end
77
+
78
+ test "should generate radio input for :belongs_to association with array collection" do
79
+ radio_case_form_for(@user, :country, :collection => Country.all)
80
+ assert_select "label", "Country"
81
+ assert_select "input[type=radio][name='user[country_id]']", 5
82
+ assert_select "label", 6
83
+ end
84
+
85
+ test "should generate radio input for :belongs_to association with scoped array collection" do
86
+ radio_case_form_for(@user, :country, :collection => Country.priority)
87
+ assert_select "label", "Country"
88
+ assert_select "input[type=radio][name='user[country_id]']", 3
89
+ assert_select "label", 4
90
+ end
91
+
92
+ test "should generate radio input for :has_many association" do
93
+ radio_case_form_for(@user, :projects)
94
+ assert_select "label", "Projects"
95
+ assert_select "input[type=radio][name='user[project_ids]']", 5
96
+ assert_select "label", 6
97
+ end
98
+
99
+ test "should generate radio input for :has_many association and class name" do
100
+ radio_case_form_for(@user, :projects, :collection => Project)
101
+ assert_select "label", "Projects"
102
+ assert_select "input[type=radio][name='user[project_ids]']", 5
103
+ assert_select "label", 6
104
+ end
105
+
106
+ test "should generate radio input for :has_many association with array collection" do
107
+ radio_case_form_for(@user, :projects, :collection => Project.all)
108
+ assert_select "label", "Projects"
109
+ assert_select "input[type=radio][name='user[project_ids]']", 5
110
+ assert_select "label", 6
111
+ end
112
+
113
+ test "should generate radio input for :has_many association with scoped array collection" do
114
+ radio_case_form_for(@user, :projects, :collection => Project.extra)
115
+ assert_select "label", "Projects"
116
+ assert_select "input[type=radio][name='user[project_ids]']", 3
117
+ assert_select "label", 4
118
+ end
119
+
120
+ test "should generate radio input for association with specified label and value methods" do
121
+ radio_case_form_for(@user, :country, :label_method => :short, :value_method => :id)
122
+ assert_select "input[type=radio][name='user[country_id]']", 5
123
+ end
124
+
125
+ test "should generate radio input for association with specified label method" do
126
+ radio_case_form_for(@user, :country, :label_method => :short)
127
+ assert_select "input[type=radio][name='user[country_id]'][value=1]", 1 # "Poland" => 1
128
+ assert_select "label", "Pol"
129
+ end
130
+
131
+ test "should generate radio input for association with specified value method" do
132
+ radio_case_form_for(@user, :country, :value_method => :non_id)
133
+ assert_select "input[type=radio][name='user[country_id]'][value=P]", 1 # "Poland" => 1
134
+ end
135
+
136
+ test "should generate radio input with checked value" do
137
+ radio_case_form_for(@user, :country, :checked => 1)
138
+ assert_select "input[type=radio][checked=checked]", 1
139
+ end
140
+
141
+ test "should generate radio input with selected value" do
142
+ radio_case_form_for(@user, :country, :selected => 1)
143
+ assert_select "input[type=radio][checked=checked]", 1
144
+ end
145
+
146
+ test "should generate radio input with disabled value" do
147
+ radio_case_form_for(@user, :country, :disabled => [1, 2])
148
+ assert_select "input[type=radio][disabled=disabled]", 2
149
+ end
150
+
151
+ test "should generate radio input with checked value as object value" do
152
+ @user.country_id = 1
153
+ radio_case_form_for(@user, :country)
154
+ assert_select "input[type=radio][checked=checked]", :count => 1
155
+ end
156
+ end
@@ -0,0 +1,152 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+
4
+ class SelectInputTest < ActionView::TestCase
5
+ def select_case_form_for(object, attribute, options={})
6
+ concat(case_form_for(object) { |f| f.select(attribute, options) })
7
+ end
8
+
9
+ test "should generate select input" do
10
+ select_case_form_for(@user, :admin)
11
+ assert_select "label", "Admin"
12
+ assert_select "select", 1
13
+ end
14
+
15
+ test "should generate select input with default values" do
16
+ select_case_form_for(@user, :admin)
17
+ assert_select("select", 1) { assert_select "option", 3 }
18
+ end
19
+
20
+ test "should generate select input with array collection" do
21
+ collection = [['Adam', 1], ['John', 2], ['Martin', 3]]
22
+ select_case_form_for(@user, :description, :collection => collection)
23
+ assert_select("select", 1) { collection.each { |c| assert_select "option[value=#{c.last}]", c.first } }
24
+ end
25
+
26
+ test "should generate select input with flat array collection" do
27
+ collection = ['Adam', 'John', 'Martin']
28
+ select_case_form_for(@user, :description, :collection => collection)
29
+ assert_select("select", 1) { collection.each { |c| assert_select "option[value=#{c}]", c } }
30
+ end
31
+
32
+ test "should generate select input with hash collection" do
33
+ collection = { 'Adam' => 1, 'John' => 2, 'Martin' => 3 }
34
+ select_case_form_for(@user, :description, :collection => collection)
35
+ assert_select("select", 1) { collection.each { |k, v| assert_select "option[value=#{v}]", k } }
36
+ end
37
+
38
+ test "should generate select input with range collection" do
39
+ collection = 1..5
40
+ select_case_form_for(@user, :description, :collection => collection)
41
+ assert_select("select", 1) { collection.each { |c| assert_select "option[value=#{c}]", 1 } }
42
+ end
43
+
44
+ test "should generate select input for :belongs_to association" do
45
+ select_case_form_for(@user, :country)
46
+ assert_select "label", "Country"
47
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option", 6 }
48
+ end
49
+
50
+ test "should generate select input for :belongs_to association and class name" do
51
+ select_case_form_for(@user, :country, :collection => Country)
52
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option", 6 }
53
+ end
54
+
55
+ test "should generate select input for :belongs_to association with array collection" do
56
+ select_case_form_for(@user, :country, :collection => Country.all)
57
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option", 6 }
58
+ end
59
+
60
+ test "should generate select input for :belongs_to association with scoped array collection" do
61
+ select_case_form_for(@user, :country, :collection => Country.priority)
62
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option", 4 }
63
+ end
64
+
65
+ test "should generate select input for :has_many association" do
66
+ select_case_form_for(@user, :projects)
67
+ assert_select "label", "Projects"
68
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option", 6 }
69
+ end
70
+
71
+ test "should generate select input for :has_many association and class name" do
72
+ select_case_form_for(@user, :projects, :collection => Project)
73
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option", 6 }
74
+ end
75
+
76
+ test "should generate select input for :has_many association with array collection" do
77
+ select_case_form_for(@user, :projects, :collection => Project.all)
78
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option", 6 }
79
+ end
80
+
81
+ test "should generate select input for :has_many association with scoped array collection" do
82
+ select_case_form_for(@user, :projects, :collection => Project.extra)
83
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option", 4 }
84
+ end
85
+
86
+ test "should generate select input for association with specified label and value methods" do
87
+ select_case_form_for(@user, :country, :label_method => :short, :value_method => :id)
88
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=1]", "Pol" }
89
+ end
90
+
91
+ test "should generate select input for association with specified label method" do
92
+ select_case_form_for(@user, :country, :label_method => :short)
93
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option", "Pol" }
94
+ end
95
+
96
+ test "should generate select input for association with specified value method" do
97
+ select_case_form_for(@user, :country, :value_method => :non_id)
98
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=P]", "Poland" }
99
+ end
100
+
101
+ test "should generate select input with checked value" do
102
+ select_case_form_for(@user, :country, :checked => 1)
103
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=1][selected=selected]", 1 }
104
+ end
105
+
106
+ test "should generate select input with multiple checked value" do
107
+ select_case_form_for(@user, :projects, :checked => [1, 3])
108
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option[selected=selected]", 2 }
109
+ end
110
+
111
+ test "should generate select input with selected value" do
112
+ select_case_form_for(@user, :country, :selected => 1)
113
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=1][selected=selected]", 1 }
114
+ end
115
+
116
+ test "should generate select input with multiple selected value" do
117
+ select_case_form_for(@user, :projects, :selected => [1, 3])
118
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option[selected=selected]", 2 }
119
+ end
120
+
121
+ test "should generate select input with disabled value" do
122
+ select_case_form_for(@user, :country, :disabled => 1)
123
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=1][disabled=disabled]", 1 }
124
+ end
125
+
126
+ test "should generate select input with multiple disabled value" do
127
+ select_case_form_for(@user, :projects, :disabled => [1, 3])
128
+ assert_select("select[name='user[project_ids][]']", 1) { assert_select "option[disabled=disabled]", 2 }
129
+ end
130
+
131
+ test "should generate select input with checked value as object value" do
132
+ @user.country_id = 1
133
+ select_case_form_for(@user, :country)
134
+ assert_select("select[name='user[country_id]']", 1) { assert_select "option[value=1][selected=selected]", 1 }
135
+ end
136
+
137
+ test "should generate select input with multiple option" do
138
+ select_case_form_for(@user, :admin, :allow_multiple => true )
139
+ assert_select("select[name='user[admin][]']", 1)
140
+ end
141
+
142
+ #test "should generate select input without blank option" do
143
+ # select_case_form_for(@user, :admin, :blank => false )
144
+ # assert_select("select", 1) { assert_select "option[value='']", 0 }
145
+ #end
146
+ #
147
+ #test "should generate select input with prompt" do
148
+ # text = "Choose..."
149
+ # puts select_case_form_for(@user, :admin, :prompt => text )
150
+ # assert_select("select", 1) { assert_select "option", text }
151
+ #end
152
+ end