diff --git a/Gemfile b/Gemfile index 4730e8c7..a96cfc28 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ group :development do # Use console on exceptions pages [https://github.com/rails/web-console] gem "web-console" + gem "annotate" # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" diff --git a/Gemfile.lock b/Gemfile.lock index 39b69259..6d90d537 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,9 @@ GEM tzinfo (~> 2.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.8) @@ -299,6 +302,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + annotate bootsnap capybara codeclimate-test-reporter diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 00000000..4dc909ed --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +module UsersHelper +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..7bd1bd84 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: users +# +# id :bigint not null, primary key +# email :string(255) not null +# password_hash :string(255) +# token :uuid +# first_name :string(255) +# last_name :string(255) +# phone_number :string(255) +# inserted_at :datetime not null +# updated_at :datetime not null +# email_verification_token :string(255) +# email_verified_at :datetime +# role :string(255) default("user"), not null +# password_reset_token :uuid +# password_reset_expires_at :datetime +# finalized :boolean default(TRUE), not null +# avatar_key :uuid +# avatar_extension :string(255) +# display :boolean default(TRUE), not null +# terms_of_use :datetime +# privacy_guidelines :datetime +# agency_id :bigint +# last_active :datetime +# status :string(255) +# active_session :boolean default(FALSE) +# renewal_request :string(255) +# jwt_token :text +# recertification_expired_at :datetime +# +class User < ApplicationRecord + has_many :challenges, dependent: :destroy + has_many :challenge_managers, dependent: :destroy + has_many :challenge_manager_challenges, through: :challenge_managers, source: :challenge, dependent: :destroy + has_many :members, dependent: :destroy + has_many :supporting_documents, class_name: 'Document', dependent: :destroy + has_many :submissions, foreign_key: :submitter_id, inverse_of: :submitter, dependent: :destroy + has_many :managed_submissions, + class_name: 'Submission', + foreign_key: :manager_id, + inverse_of: :manager, + dependent: :destroy + has_many :submission_documents, class_name: 'Submissions::Document', dependent: :destroy + has_many :message_context_statuses, dependent: :destroy + + attribute :role, :string, default: -> { self[:role] } + attribute :status, :string, default: 'pending' + attribute :finalized, :boolean, default: true + attribute :display, :boolean, default: true + + attribute :email, :string + attribute :password_hash, :string + attribute :token, :uuid + attribute :jwt_token, :string + + attribute :email_verification_token, :string + attribute :email_verified_at, :datetime + + attribute :password_reset_token, :uuid + attribute :password_reset_expires_at, :datetime + + attribute :first_name, :string + attribute :last_name, :string + attribute :phone_number, :string + + attribute :avatar_key, :uuid + attribute :avatar_extension, :string + + attribute :terms_of_use, :datetime + attribute :privacy_guidelines, :datetime + attribute :agency_id, :integer + + attribute :last_active, :datetime + attribute :recertification_expired_at, :datetime + attribute :active_session, :boolean, default: false + + attribute :renewal_request, :string + + attribute :created_at, :datetime, precision: 6 + attribute :updated_at, :datetime, precision: 6 + + validates :email, presence: true +end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb new file mode 100644 index 00000000..48d28dd6 --- /dev/null +++ b/spec/helpers/users_helper_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the UsersHelper. For example: +# +# describe UsersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 00000000..e1550e7a --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: users +# +# id :bigint not null, primary key +# email :string(255) not null +# password_hash :string(255) +# token :uuid +# first_name :string(255) +# last_name :string(255) +# phone_number :string(255) +# inserted_at :datetime not null +# updated_at :datetime not null +# email_verification_token :string(255) +# email_verified_at :datetime +# role :string(255) default("user"), not null +# password_reset_token :uuid +# password_reset_expires_at :datetime +# finalized :boolean default(TRUE), not null +# avatar_key :uuid +# avatar_extension :string(255) +# display :boolean default(TRUE), not null +# terms_of_use :datetime +# privacy_guidelines :datetime +# agency_id :bigint +# last_active :datetime +# status :string(255) +# active_session :boolean default(FALSE) +# renewal_request :string(255) +# jwt_token :text +# recertification_expired_at :datetime +# +require 'rails_helper' + +RSpec.describe User do + describe 'validations' do + it 'validates presence of email' do + user = described_class.new(email: nil) + expect(user).not_to be_valid + expect(user.errors[:email]).to include("can't be blank") + end + end + + describe 'default values' do + it 'sets active_session to false by default' do + user = described_class.new + expect(user.active_session).to be_falsey + end + end +end