From 9e3389a7dcf118d78a2654bf918eed545ca21d37 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 20 Sep 2024 17:07:43 +0700 Subject: [PATCH] Create user_spec.rb --- .../business/spec/models/user_spec.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 global_business/business/spec/models/user_spec.rb diff --git a/global_business/business/spec/models/user_spec.rb b/global_business/business/spec/models/user_spec.rb new file mode 100644 index 000000000..5dbc51bda --- /dev/null +++ b/global_business/business/spec/models/user_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + it { is_expected.to validate_presence_of(:email) } + it { is_expected.to validate_uniqueness_of(:email) } + it { is_expected.to have_secure_password } + it { is_expected.to have_many(:accounts) } + + describe 'password validation' do + it 'validates password length' do + user = User.new(password: 'short') + expect(user).not_to be_valid + end + + it 'validates password complexity' do + user = User.new(password: 'password123') + expect(user).not_to be_valid + end + end + + describe 'email validation' do + it 'validates email format' do + user = User.new(email: 'invalid_email') + expect(user).not_to be_valid + end + end +end