foodsoft/test/unit/user_test.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2009-01-06 11:49:19 +01:00
require File.dirname(__FILE__) + '/../test_helper'
2013-06-25 13:04:55 +02:00
class UserTest < ActiveSupport::TestCase
2009-01-06 11:49:19 +01:00
fixtures :users
def setup
@admin = users(:admin)
end
2013-06-25 13:04:55 +02:00
test 'read_user' do
2009-01-06 11:49:19 +01:00
assert_kind_of User, @admin
assert_equal "Anton", @admin.first_name
assert_equal "Admininistrator", @admin.last_name
assert_equal "admin@foo.test", @admin.email
assert @admin.role_admin?
end
2013-06-25 13:04:55 +02:00
test 'create_and_read_password' do
@admin.password = "some_secret"
@admin.password_confirmation = @admin.password
assert @admin.valid?
assert @admin.has_password("some_secret")
2009-01-06 11:49:19 +01:00
end
2013-06-25 13:04:55 +02:00
test 'invalid_password' do
@admin.password = "foo"
@admin.password_confirmation = @admin.password
assert @admin.invalid?
assert_equal [I18n.t('activemodel.errors.messages.too_short', count: 5)], @admin.errors[:password]
2009-01-06 11:49:19 +01:00
end
2013-06-25 13:04:55 +02:00
test 'password_not_match' do
@admin.password = "foobar"
@admin.password_confirmation = "foobor"
@admin.save
assert_equal [I18n.t('activemodel.errors.messages.confirmation')], @admin.errors[:password]
2009-01-06 11:49:19 +01:00
end
end