Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[38] Create Rails User model #46

Merged
merged 13 commits into from
Jul 26, 2024
Merged
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -299,6 +302,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
annotate
bootsnap
capybara
codeclimate-test-reporter
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
82 changes: 82 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# == 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
has_many :challenge_managers
has_many :challenge_manager_challenges, through: :challenge_managers, source: :challenge
has_many :members
has_many :supporting_documents, class_name: 'Document'
has_many :submissions, foreign_key: :submitter_id
has_many :managed_submissions, class_name: 'Submission', foreign_key: :manager_id
has_many :submission_documents, class_name: 'Submissions::Document'
has_many :message_context_statuses

# Virtual Attributes
attr_accessor :email_confirmation, :password, :password_confirmation
Copy link
Contributor

@stepchud stepchud Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docs for the attribute method say it doesn't need to be backed by the DB. however, I'm not sure that we need these attributes anyways. AFAIK users shouldn't be able to reset their login.gov password from the app, and I don't know about the email_confirmation.
Screenshot 2024-07-22 at 5 18 35 PM


attribute :role, :string, default: -> { read_attribute(: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
bilalhankins marked this conversation as resolved.
Show resolved Hide resolved

attribute :renewal_request, :string

attribute :created_at, :datetime, precision: 6
attribute :updated_at, :datetime, precision: 6
end
15 changes: 15 additions & 0 deletions spec/helpers/users_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
RSpec.describe UsersHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
bilalhankins marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 37 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# == 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, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
stepchud marked this conversation as resolved.
Show resolved Hide resolved
end
Loading