Skip to content

Commit

Permalink
removes users.validation_status
Browse files Browse the repository at this point in the history
  • Loading branch information
fermion committed Jan 14, 2024
1 parent b1b7a16 commit 5a57d12
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 34 deletions.
12 changes: 0 additions & 12 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ class User < ApplicationRecord
has_many :projects, through: :assignments
has_many :work_weeks, through: :assignments

VALIDATION_STATUS_PENDING = 'pending'.freeze
VALIDATION_STATUS_VALIDATED = 'validated'.freeze

validates :name, presence: true
validates :current_company, presence: true
validates :email,
presence: true,
uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP }
validates :validation_status, inclusion: { in: [VALIDATION_STATUS_VALIDATED, VALIDATION_STATUS_PENDING] }

passwordless_with :email

def owner?
memberships.find_by(company: current_company).role == Membership::OWNER
end

def email_validated?
validation_status == VALIDATION_STATUS_VALIDATED
end

def email_validation_pending?
validation_status == VALIDATION_STATUS_PENDING
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240114005440_remove_users_validation_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveUsersValidationStatus < ActiveRecord::Migration[7.1]
def change
remove_column :users, :validation_status
end
end
3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
name { Faker::Name.name + " #{rand(1..100).to_s}" }
sequence(:email) { |n| "#{n}#{Faker::Internet.email}" }

trait(:needs_validation) do
validation_status { User::VALIDATION_STATUS_PENDING }
end

after(:build) do |user, options|
# a current company is required for the user to be valid
# unless one is already set, create one
Expand Down
16 changes: 0 additions & 16 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,4 @@
end
end
end

describe "#email_validated?" do
context "when user has a validated email address" do
it "returns true" do
user = build(:user, validation_status: User::VALIDATION_STATUS_VALIDATED)
expect(user.email_validated?).to be_truthy
end
end

context "when user does not have a validated email address" do
it "returns false" do
user = build(:user, validation_status: User::VALIDATION_STATUS_PENDING)
expect(user.email_validated?).to be_falsey
end
end
end
end

0 comments on commit 5a57d12

Please sign in to comment.