simple_form 1.5.2 → 2.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.
Files changed (108) hide show
  1. data/CHANGELOG.md +234 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +816 -0
  4. data/lib/generators/simple_form/install_generator.rb +15 -1
  5. data/lib/generators/simple_form/templates/README +12 -0
  6. data/lib/generators/simple_form/templates/_form.html.erb +2 -2
  7. data/lib/generators/simple_form/templates/_form.html.haml +2 -2
  8. data/lib/generators/simple_form/templates/_form.html.slim +4 -4
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +176 -0
  10. data/lib/simple_form/action_view_extensions/builder.rb +206 -59
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +30 -23
  12. data/lib/simple_form/components/errors.rb +6 -24
  13. data/lib/simple_form/components/hints.rb +7 -21
  14. data/lib/simple_form/components/html5.rb +26 -0
  15. data/lib/simple_form/components/labels.rb +22 -14
  16. data/lib/simple_form/components/maxlength.rb +41 -0
  17. data/lib/simple_form/components/min_max.rb +49 -0
  18. data/lib/simple_form/components/pattern.rb +34 -0
  19. data/lib/simple_form/components/placeholders.rb +5 -17
  20. data/lib/simple_form/components/readonly.rb +22 -0
  21. data/lib/simple_form/components.rb +11 -1
  22. data/lib/simple_form/core_ext/hash.rb +16 -0
  23. data/lib/simple_form/error_notification.rb +9 -3
  24. data/lib/simple_form/form_builder.rb +105 -28
  25. data/lib/simple_form/helpers/autofocus.rb +11 -0
  26. data/lib/simple_form/helpers/disabled.rb +15 -0
  27. data/lib/simple_form/helpers/readonly.rb +15 -0
  28. data/lib/simple_form/helpers/required.rb +10 -11
  29. data/lib/simple_form/helpers/validators.rb +4 -4
  30. data/lib/simple_form/helpers.rb +7 -4
  31. data/lib/simple_form/inputs/base.rb +53 -81
  32. data/lib/simple_form/inputs/boolean_input.rb +46 -4
  33. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  34. data/lib/simple_form/inputs/collection_input.rb +27 -13
  35. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +67 -0
  36. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  37. data/lib/simple_form/inputs/date_time_input.rb +10 -6
  38. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  39. data/lib/simple_form/inputs/hidden_input.rb +3 -6
  40. data/lib/simple_form/inputs/numeric_input.rb +3 -51
  41. data/lib/simple_form/inputs/password_input.rb +1 -2
  42. data/lib/simple_form/inputs/priority_input.rb +2 -2
  43. data/lib/simple_form/inputs/range_input.rb +1 -3
  44. data/lib/simple_form/inputs/string_input.rb +6 -8
  45. data/lib/simple_form/inputs/text_input.rb +1 -2
  46. data/lib/simple_form/inputs.rb +17 -13
  47. data/lib/simple_form/version.rb +1 -1
  48. data/lib/simple_form/wrappers/builder.rb +103 -0
  49. data/lib/simple_form/wrappers/many.rb +69 -0
  50. data/lib/simple_form/wrappers/root.rb +34 -0
  51. data/lib/simple_form/wrappers/single.rb +18 -0
  52. data/lib/simple_form/wrappers.rb +8 -0
  53. data/lib/simple_form.rb +118 -48
  54. data/test/action_view_extensions/builder_test.rb +285 -102
  55. data/test/action_view_extensions/form_helper_test.rb +32 -10
  56. data/test/components/label_test.rb +44 -5
  57. data/test/form_builder/association_test.rb +177 -0
  58. data/test/form_builder/button_test.rb +47 -0
  59. data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +18 -1
  60. data/test/form_builder/error_test.rb +121 -0
  61. data/test/form_builder/general_test.rb +356 -0
  62. data/test/form_builder/hint_test.rb +123 -0
  63. data/test/form_builder/input_field_test.rb +63 -0
  64. data/test/form_builder/label_test.rb +65 -0
  65. data/test/form_builder/wrapper_test.rb +149 -0
  66. data/test/generators/simple_form_generator_test.rb +32 -0
  67. data/test/inputs/boolean_input_test.rb +101 -0
  68. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  69. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  70. data/test/inputs/collection_select_input_test.rb +241 -0
  71. data/test/inputs/datetime_input_test.rb +99 -0
  72. data/test/inputs/disabled_test.rb +38 -0
  73. data/test/inputs/discovery_test.rb +61 -0
  74. data/test/inputs/file_input_test.rb +16 -0
  75. data/test/inputs/general_test.rb +69 -0
  76. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  77. data/test/inputs/hidden_input_test.rb +30 -0
  78. data/test/inputs/numeric_input_test.rb +167 -0
  79. data/test/inputs/priority_input_test.rb +43 -0
  80. data/test/inputs/readonly_test.rb +61 -0
  81. data/test/inputs/required_test.rb +113 -0
  82. data/test/inputs/string_input_test.rb +140 -0
  83. data/test/inputs/text_input_test.rb +24 -0
  84. data/test/support/misc_helpers.rb +53 -12
  85. data/test/support/mock_controller.rb +2 -2
  86. data/test/support/models.rb +20 -5
  87. data/test/test_helper.rb +11 -12
  88. metadata +124 -96
  89. data/.gitignore +0 -3
  90. data/.gitmodules +0 -3
  91. data/.travis.yml +0 -15
  92. data/CHANGELOG.rdoc +0 -159
  93. data/Gemfile +0 -9
  94. data/README.rdoc +0 -466
  95. data/Rakefile +0 -27
  96. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
  97. data/lib/simple_form/components/wrapper.rb +0 -38
  98. data/lib/simple_form/helpers/has_errors.rb +0 -15
  99. data/lib/simple_form/helpers/maxlength.rb +0 -24
  100. data/lib/simple_form/helpers/pattern.rb +0 -28
  101. data/simple_form.gemspec +0 -25
  102. data/test/components/error_test.rb +0 -56
  103. data/test/components/hint_test.rb +0 -74
  104. data/test/components/wrapper_test.rb +0 -63
  105. data/test/custom_components.rb +0 -7
  106. data/test/form_builder_test.rb +0 -930
  107. data/test/inputs_test.rb +0 -995
  108. /data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
@@ -1,7 +1,8 @@
1
1
  # encoding: UTF-8
2
2
  require 'test_helper'
3
3
 
4
- class LabelTest < ActionView::TestCase
4
+ # Isolated tests for label without triggering f.label.
5
+ class IsolatedLabelTest < ActionView::TestCase
5
6
  setup do
6
7
  SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
7
8
  end
@@ -71,16 +72,16 @@ class LabelTest < ActionView::TestCase
71
72
  end
72
73
  end
73
74
 
74
- test 'input should use i18n based only on attribute to lookup translation' do
75
- store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
75
+ test 'input should use i18n under defaults to lookup translation' do
76
+ store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
76
77
  with_label_for @user, :age, :integer
77
78
  assert_select 'label[for=user_age]', /Idade/
78
79
  end
79
80
  end
80
81
 
81
82
  test 'input should not use i18n label if translate is false' do
82
- swap SimpleForm, :translate => false do
83
- store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
83
+ swap SimpleForm, :translate_labels => false do
84
+ store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
84
85
  with_label_for @user, :age, :integer
85
86
  assert_select 'label[for=user_age]', /Age/
86
87
  end
@@ -165,6 +166,21 @@ class LabelTest < ActionView::TestCase
165
166
  assert_select 'label.datetime'
166
167
  end
167
168
 
169
+ test 'label should not have css class from type when generate_additional_classes_for does not include :label' do
170
+ swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
171
+ with_label_for @user, :name, :string
172
+ assert_no_select 'label.string'
173
+ with_label_for @user, :description, :text
174
+ assert_no_select 'label.text'
175
+ with_label_for @user, :age, :integer
176
+ assert_no_select 'label.integer'
177
+ with_label_for @user, :born_at, :date
178
+ assert_no_select 'label.date'
179
+ with_label_for @user, :created_at, :datetime
180
+ assert_no_select 'label.datetime'
181
+ end
182
+ end
183
+
168
184
  test 'label should obtain required from ActiveModel::Validations when it is included' do
169
185
  with_label_for @validating_user, :name, :string
170
186
  assert_select 'label.required'
@@ -172,6 +188,15 @@ class LabelTest < ActionView::TestCase
172
188
  assert_select 'label.optional'
173
189
  end
174
190
 
191
+ test 'label should not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
192
+ swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
193
+ with_label_for @validating_user, :name, :string
194
+ assert_no_select 'label.required'
195
+ with_label_for @validating_user, :status, :string
196
+ assert_no_select 'label.optional'
197
+ end
198
+ end
199
+
175
200
  test 'label should allow overriding required when ActiveModel::Validations is included' do
176
201
  with_label_for @validating_user, :name, :string, :required => false
177
202
  assert_select 'label.optional'
@@ -246,6 +271,11 @@ class LabelTest < ActionView::TestCase
246
271
  assert_select 'label[for=project_name]', /Name/
247
272
  end
248
273
 
274
+ test 'label should include for attribute for select collection' do
275
+ with_label_for @user, :sex, :select, :collection => [:male, :female]
276
+ assert_select 'label[for=user_sex]'
277
+ end
278
+
249
279
  test 'label should use i18n properly when object is not present' do
250
280
  store_translations(:en, :simple_form => { :labels => {
251
281
  :project => { :name => 'Nome' }
@@ -268,4 +298,13 @@ class LabelTest < ActionView::TestCase
268
298
  assert_select 'label.my_custom_class'
269
299
  end
270
300
  end
301
+
302
+ test 'label strips extra classes even when label_class is nil' do
303
+ swap SimpleForm, :label_class => nil do
304
+ with_label_for @user, :name, :string
305
+ assert_select "label[class='string required']"
306
+ assert_no_select "label[class='string required ']"
307
+ assert_no_select "label[class=' string required']"
308
+ end
309
+ end
271
310
  end
@@ -0,0 +1,177 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class AssociationTest < ActionView::TestCase
5
+ def with_association_for(object, *args)
6
+ with_concat_form_for(object) do |f|
7
+ f.association(*args)
8
+ end
9
+ end
10
+
11
+ test 'builder should not allow creating an association input when no object exists' do
12
+ assert_raise ArgumentError do
13
+ with_association_for :post, :author
14
+ end
15
+ end
16
+
17
+ test 'builder association with a block calls simple_fields_for' do
18
+ simple_form_for @user do |f|
19
+ f.association :posts do |posts_form|
20
+ assert posts_form.instance_of?(SimpleForm::FormBuilder)
21
+ end
22
+ end
23
+ end
24
+
25
+ test 'builder association forwards collection to simple_fields_for' do
26
+ calls = 0
27
+ simple_form_for @user do |f|
28
+ f.association :company, :collection => Company.all do |c|
29
+ calls += 1
30
+ end
31
+ end
32
+
33
+ assert_equal 3, calls
34
+ end
35
+
36
+ test 'builder association marks input as required based on both association and attribute' do
37
+ swap SimpleForm, :required_by_default => false do
38
+ with_association_for @validating_user, :company, :collection => []
39
+ assert_select 'label.required'
40
+ end
41
+ end
42
+
43
+ test 'builder preloads collection association' do
44
+ value = @user.tags
45
+ value.expects(:to_a).returns(value)
46
+ with_association_for @user, :tags
47
+ assert_select 'form select.select#user_tag_ids'
48
+ assert_select 'form select option[value=1]', 'Tag 1'
49
+ assert_select 'form select option[value=2]', 'Tag 2'
50
+ assert_select 'form select option[value=3]', 'Tag 3'
51
+ end
52
+
53
+ test 'builder does not preload collection association if preload is false' do
54
+ value = @user.company
55
+ value.expects(:to_a).never
56
+ with_association_for @user, :company, :preload => false
57
+ assert_select 'form select.select#user_company_id'
58
+ assert_select 'form select option[value=1]', 'Company 1'
59
+ assert_select 'form select option[value=2]', 'Company 2'
60
+ assert_select 'form select option[value=3]', 'Company 3'
61
+ end
62
+
63
+ test 'builder does not preload non-collection association' do
64
+ value = @user.company
65
+ value.expects(:to_a).never
66
+ with_association_for @user, :company, :preload => false
67
+ assert_select 'form select.select#user_company_id'
68
+ assert_select 'form select option[value=1]', 'Company 1'
69
+ assert_select 'form select option[value=2]', 'Company 2'
70
+ assert_select 'form select option[value=3]', 'Company 3'
71
+ end
72
+
73
+ # ASSOCIATIONS - BELONGS TO
74
+ test 'builder creates a select for belongs_to associations' do
75
+ with_association_for @user, :company
76
+ assert_select 'form select.select#user_company_id'
77
+ assert_select 'form select option[value=1]', 'Company 1'
78
+ assert_select 'form select option[value=2]', 'Company 2'
79
+ assert_select 'form select option[value=3]', 'Company 3'
80
+ end
81
+
82
+ test 'builder allows collection radio for belongs_to associations' do
83
+ with_association_for @user, :company, :as => :radio_buttons
84
+ assert_select 'form input.radio_buttons#user_company_id_1'
85
+ assert_select 'form input.radio_buttons#user_company_id_2'
86
+ assert_select 'form input.radio_buttons#user_company_id_3'
87
+ end
88
+
89
+ test 'builder marks the record which already belongs to the user' do
90
+ @user.company_id = 2
91
+ with_association_for @user, :company, :as => :radio_buttons
92
+ assert_no_select 'form input.radio_buttons#user_company_id_1[checked=checked]'
93
+ assert_select 'form input.radio_buttons#user_company_id_2[checked=checked]'
94
+ assert_no_select 'form input.radio_buttons#user_company_id_3[checked=checked]'
95
+ end
96
+
97
+ # ASSOCIATIONS - FINDERS
98
+ test 'builder should use reflection conditions to find collection' do
99
+ with_association_for @user, :special_company
100
+ assert_select 'form select.select#user_special_company_id'
101
+ assert_select 'form select option[value=1]'
102
+ assert_no_select 'form select option[value=2]'
103
+ assert_no_select 'form select option[value=3]'
104
+ end
105
+
106
+ test 'builder should allow overriding collection to association input' do
107
+ with_association_for @user, :company, :include_blank => false,
108
+ :collection => [Company.new(999, 'Teste')]
109
+ assert_select 'form select.select#user_company_id'
110
+ assert_no_select 'form select option[value=1]'
111
+ assert_select 'form select option[value=999]', 'Teste'
112
+ assert_select 'form select option', :count => 1
113
+ end
114
+
115
+ # ASSOCIATIONS - has_*
116
+ test 'builder does not allow has_one associations' do
117
+ assert_raise RuntimeError do
118
+ with_association_for @user, :first_company, :as => :radio_buttons
119
+ end
120
+ end
121
+
122
+ test 'builder creates a select with multiple options for collection associations' do
123
+ with_association_for @user, :tags
124
+ assert_select 'form select.select#user_tag_ids'
125
+ assert_select 'form select[multiple=multiple][size=5]'
126
+ assert_select 'form select option[value=1]', 'Tag 1'
127
+ assert_select 'form select option[value=2]', 'Tag 2'
128
+ assert_select 'form select option[value=3]', 'Tag 3'
129
+ end
130
+
131
+ test 'builder allows size to be overwritten for collection associations' do
132
+ with_association_for @user, :tags, :input_html => { :size => 10 }
133
+ assert_select 'form select[multiple=multiple][size=10]'
134
+ end
135
+
136
+ test 'builder marks all selected records which already belongs to user' do
137
+ @user.tag_ids = [1, 2]
138
+ with_association_for @user, :tags
139
+ assert_select 'form select option[value=1][selected=selected]'
140
+ assert_select 'form select option[value=2][selected=selected]'
141
+ assert_no_select 'form select option[value=3][selected=selected]'
142
+ end
143
+
144
+ test 'builder allows a collection of check boxes for collection associations' do
145
+ @user.tag_ids = [1, 2]
146
+ with_association_for @user, :tags, :as => :check_boxes
147
+ assert_select 'form input#user_tag_ids_1[type=checkbox]'
148
+ assert_select 'form input#user_tag_ids_2[type=checkbox]'
149
+ assert_select 'form input#user_tag_ids_3[type=checkbox]'
150
+ end
151
+
152
+ test 'builder marks all selected records for collection boxes' do
153
+ @user.tag_ids = [1, 2]
154
+ with_association_for @user, :tags, :as => :check_boxes
155
+ assert_select 'form input[type=checkbox][value=1][checked=checked]'
156
+ assert_select 'form input[type=checkbox][value=2][checked=checked]'
157
+ assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
158
+ end
159
+
160
+ test 'builder with collection support giving collection and item wrapper tags' do
161
+ with_association_for @user, :tags, :as => :check_boxes,
162
+ :collection_wrapper_tag => :ul, :item_wrapper_tag => :li
163
+
164
+ assert_select 'form ul', :count => 1
165
+ assert_select 'form ul li', :count => 3
166
+ end
167
+
168
+ test 'builder with collection support should not change the options hash' do
169
+ options = { :as => :check_boxes, :collection_wrapper_tag => :ul, :item_wrapper_tag => :li}
170
+ with_association_for @user, :tags, options
171
+
172
+ assert_select 'form ul', :count => 1
173
+ assert_select 'form ul li', :count => 3
174
+ assert_equal({ :as => :check_boxes, :collection_wrapper_tag => :ul, :item_wrapper_tag => :li},
175
+ options)
176
+ end
177
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class ButtonTest < ActionView::TestCase
5
+ def with_button_for(object, *args)
6
+ with_concat_form_for(object) do |f|
7
+ f.button(*args)
8
+ end
9
+ end
10
+
11
+ test 'builder should create buttons' do
12
+ with_button_for :post, :submit
13
+ assert_select 'form input.button[type=submit][value=Save Post]'
14
+ end
15
+
16
+ test 'builder should create buttons with options' do
17
+ with_button_for :post, :submit, :class => 'my_button'
18
+ assert_select 'form input.button.my_button[type=submit][value=Save Post]'
19
+ end
20
+
21
+ test 'builder should not modify the options hash' do
22
+ options = { :class => 'my_button' }
23
+ with_button_for :post, :submit, options
24
+ assert_select 'form input.button.my_button[type=submit][value=Save Post]'
25
+ assert_equal({ :class => 'my_button' }, options)
26
+ end
27
+
28
+ test 'builder should create buttons for records' do
29
+ @user.new_record!
30
+ with_button_for @user, :submit
31
+ assert_select 'form input.button[type=submit][value=Create User]'
32
+ end
33
+
34
+ test "builder should use the default class from the configuration" do
35
+ swap SimpleForm, :button_class => 'btn' do
36
+ with_button_for :post, :submit
37
+ assert_select 'form input.btn[type=submit][value=Save Post]'
38
+ end
39
+ end
40
+
41
+ if ActionView::Helpers::FormBuilder.method_defined?(:button)
42
+ test "allows to use Rails button helper when available" do
43
+ with_button_for :post, :button, 'Save!'
44
+ assert_select 'form button.button[type=submit]', 'Save!'
45
+ end
46
+ end
47
+ end
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
  require 'test_helper'
3
3
 
4
+ # Tests for f.error_notification
4
5
  class ErrorNotificationTest < ActionView::TestCase
5
-
6
6
  def with_error_notification_for(object, options={}, &block)
7
7
  with_concat_form_for(object) do |f|
8
8
  f.error_notification(options)
@@ -11,6 +11,7 @@ class ErrorNotificationTest < ActionView::TestCase
11
11
 
12
12
  test 'error notification is not generated when the object has no error' do
13
13
  assert @validating_user.valid?
14
+
14
15
  with_error_notification_for @validating_user
15
16
  assert_no_select 'p.error_notification'
16
17
  end
@@ -59,4 +60,20 @@ class ErrorNotificationTest < ActionView::TestCase
59
60
  assert_select 'div.error_notification'
60
61
  end
61
62
  end
63
+
64
+ test 'error notification can contain HTML tags' do
65
+ with_error_notification_for @user, :message => 'Erro encontrado ao criar <b>usuário</b>'
66
+ assert_select 'p.error_notification', 'Erro encontrado ao criar usuário'
67
+ assert_select 'p.error_notification b', 'usuário'
68
+ end
69
+
70
+ test 'error notification uses I18n based on model to generate the notification message and accepts HTML' do
71
+ store_translations(:en, :simple_form => { :error_notification => { :user =>
72
+ 'Alguns erros foram encontrados para o <b>usuário</b>:'
73
+ } }) do
74
+ with_error_notification_for @user
75
+ assert_select 'p.error_notification', 'Alguns erros foram encontrados para o usuário:'
76
+ assert_select 'p.error_notification b', 'usuário'
77
+ end
78
+ end
62
79
  end
@@ -0,0 +1,121 @@
1
+ require 'test_helper'
2
+
3
+ # Tests for f.error and f.full_error
4
+ class ErrorTest < ActionView::TestCase
5
+ def with_error_for(object, *args)
6
+ with_concat_form_for(object) do |f|
7
+ f.error(*args)
8
+ end
9
+ end
10
+
11
+ def with_full_error_for(object, *args)
12
+ with_concat_form_for(object) do |f|
13
+ f.full_error(*args)
14
+ end
15
+ end
16
+
17
+ test 'error should not generate content for attribute without errors' do
18
+ with_error_for @user, :active
19
+ assert_no_select 'span.error'
20
+ end
21
+
22
+ test 'error should not generate messages when object is not present' do
23
+ with_error_for :project, :name
24
+ assert_no_select 'span.error'
25
+ end
26
+
27
+ test "error should not generate messages when object doesn't respond to errors method" do
28
+ @user.instance_eval { undef errors }
29
+ with_error_for @user, :name
30
+ assert_no_select 'span.error'
31
+ end
32
+
33
+ test 'error should generate messages for attribute with single error' do
34
+ with_error_for @user, :name
35
+ assert_select 'span.error', "can't be blank"
36
+ end
37
+
38
+ test 'error should generate messages for attribute with one error when using first' do
39
+ swap SimpleForm, :error_method => :first do
40
+ with_error_for @user, :age
41
+ assert_select 'span.error', 'is not a number'
42
+ end
43
+ end
44
+
45
+ test 'error should generate messages for attribute with several errors when using to_sentence' do
46
+ swap SimpleForm, :error_method => :to_sentence do
47
+ with_error_for @user, :age
48
+ assert_select 'span.error', 'is not a number and must be greater than 18'
49
+ end
50
+ end
51
+
52
+ test 'error should be able to pass html options' do
53
+ with_error_for @user, :name, :id => 'error', :class => 'yay'
54
+ assert_select 'span#error.error.yay'
55
+ end
56
+
57
+ test 'error should not modify the options hash' do
58
+ options = { :id => 'error', :class => 'yay' }
59
+ with_error_for @user, :name, options
60
+ assert_select 'span#error.error.yay'
61
+ assert_equal({ :id => 'error', :class => 'yay' }, options)
62
+ end
63
+
64
+ test 'error should find errors on attribute and association' do
65
+ with_error_for @user, :company_id, :as => :select,
66
+ :error_method => :to_sentence, :reflection => Association.new(Company, :company, {})
67
+ assert_select 'span.error', 'must be valid and company must be present'
68
+ end
69
+
70
+ test 'error should generate an error tag with a clean HTML' do
71
+ with_error_for @user, :name
72
+ assert_no_select 'span.error[error_html]'
73
+ end
74
+
75
+ test 'error should generate an error tag with a clean HTML when errors options are present' do
76
+ with_error_for @user, :name, :error_tag => :p, :error_prefix => 'Name', :error_method => :first
77
+ assert_no_select 'p.error[error_html]'
78
+ assert_no_select 'p.error[error_tag]'
79
+ assert_no_select 'p.error[error_prefix]'
80
+ assert_no_select 'p.error[error_method]'
81
+ end
82
+
83
+ test 'error should generate an error message with raw HTML tags' do
84
+ with_error_for @user, :name, :error_prefix => '<b>Name</b>'
85
+ assert_select 'span.error', "Name can't be blank"
86
+ assert_select 'span.error b', "Name"
87
+ end
88
+
89
+ # FULL ERRORS
90
+
91
+ test 'full error should generate an full error tag for the attribute' do
92
+ with_full_error_for @user, :name
93
+ assert_select 'span.error', "Super User Name! can't be blank"
94
+ end
95
+
96
+ test 'full error should generate an full error tag with a clean HTML' do
97
+ with_full_error_for @user, :name
98
+ assert_no_select 'span.error[error_html]'
99
+ end
100
+
101
+ test 'full error should allow passing options to full error tag' do
102
+ with_full_error_for @user, :name, :id => 'name_error', :error_prefix => "Your name"
103
+ assert_select 'span.error#name_error', "Your name can't be blank"
104
+ end
105
+
106
+ test 'full error should not modify the options hash' do
107
+ options = { :id => 'name_error' }
108
+ with_full_error_for @user, :name, options
109
+ assert_select 'span.error#name_error', "Super User Name! can't be blank"
110
+ assert_equal({ :id => 'name_error' }, options)
111
+ end
112
+
113
+ # CUSTOM WRAPPERS
114
+
115
+ test 'error with custom wrappers works' do
116
+ swap_wrapper do
117
+ with_error_for @user, :name
118
+ assert_select 'span.omg_error', "can't be blank"
119
+ end
120
+ end
121
+ end