User model test - still need the strong password and email validation.
This commit is contained in:
parent
d73d234465
commit
6006b8bc97
@ -2,8 +2,11 @@ class User < ApplicationRecord
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
has_and_belongs_to_many :companies
|
||||
devise :database_authenticatable,
|
||||
:recoverable, :rememberable, :validatable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :validatable
|
||||
|
||||
before_create do
|
||||
self.role = 100
|
||||
end
|
||||
|
||||
def admin?
|
||||
true if self.role == 1000
|
||||
|
||||
34
test/fixtures/users.yml
vendored
34
test/fixtures/users.yml
vendored
@ -4,8 +4,32 @@
|
||||
# model remove the "{}" from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
# one: {}
|
||||
# # column: value
|
||||
# #
|
||||
# two: {}
|
||||
# # column: value
|
||||
admin:
|
||||
email: "jez@hiddenagenda.ltd.uk"
|
||||
encrypted_password: <%= Devise::Encryptor.digest(User,'password') %>
|
||||
reset_password_token: <%= nil %>
|
||||
remember_created_at: <%= nil %>
|
||||
sign_in_count: 1
|
||||
current_sign_in_at: "2012-11-16 11:49:12"
|
||||
last_sign_in_at: "2012-11-16 11:49:12"
|
||||
current_sign_in_ip: "127.0.0.1"
|
||||
last_sign_in_ip: "127.0.0.1"
|
||||
failed_attempts: 0
|
||||
locked_at: <%= nil %>
|
||||
role: 1000
|
||||
|
||||
user:
|
||||
email: "user@hiddenagenda.ltd.uk"
|
||||
encrypted_password: <%= Devise::Encryptor.digest(User,'password') %>
|
||||
reset_password_token: <%= nil %>
|
||||
remember_created_at: <%= nil %>
|
||||
sign_in_count: 1
|
||||
current_sign_in_at: "2012-11-16 11:49:12"
|
||||
last_sign_in_at: "2012-11-16 11:49:12"
|
||||
current_sign_in_ip: "127.0.0.1"
|
||||
last_sign_in_ip: "127.0.0.1"
|
||||
failed_attempts: 0
|
||||
locked_at: <%= nil %>
|
||||
role: 100
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,30 @@
|
||||
require "test_helper"
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test "email must be unique" do
|
||||
u = User.new
|
||||
u.email = "jez@hiddenagenda.ltd.uk"
|
||||
u.password = "password"
|
||||
u.password_confirmation = "password"
|
||||
assert !u.save
|
||||
end
|
||||
|
||||
test "password must be strong" do
|
||||
assert true
|
||||
end
|
||||
|
||||
test "email must be valid" do
|
||||
assert true
|
||||
end
|
||||
|
||||
test "role is 100" do
|
||||
u = User.new
|
||||
u.email = "testuser@hiddenagenda.ltd.uk"
|
||||
u.password = "password"
|
||||
u.password_confirmation = "password"
|
||||
assert u.save
|
||||
assert_equal(100,u.role)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user