/
error_test.rb
45 lines (36 loc) · 1.53 KB
/
error_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'test_helper'
class ErrorTest < ActionView::TestCase
def with_error_for(object, attribute_name, type, options={}, &block)
simple_form_for object do |f|
f.attribute_name = attribute_name
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
f.input_type = type
f.options = options
concat(SimpleForm::Inputs::Base.new(f).error.to_s)
end
end
test 'error should not generate content for attribute without errors' do
with_error_for @user, :active, :boolean
assert_no_select 'span.error'
end
test 'error should not generate messages when object is not present' do
with_error_for :project, :name, :string
assert_no_select 'span.error'
end
test 'error should generate messages for attribute with single error' do
with_error_for @user, :name, :string
assert_select 'span.error', "can't be blank"
end
test 'error should generate messages for attribute with several errors' do
with_error_for @user, :age, :numeric
assert_select 'span.error', 'is not a number and must be greater than 18'
end
test 'error should be able to pass html options' do
with_error_for @user, :name, :string, :error_html => { :id => 'error', :class => 'yay' }
assert_select 'span#error.error.yay'
end
test 'error should find errors on attribute and association' do
with_error_for @user, :company_id, :select, :setup_association => true
assert_select 'span.error', 'must be valid and company must be present'
end
end