Browse Source

Add status to the user

pull/2288/head
Kat 2 years ago
parent
commit
9dee9e61ee
  1. 12
      app/models/user.rb
  2. 5
      db/migrate/20240305091927_add_discarded_at_column_to_users.rb
  3. 1
      db/schema.rb
  4. 9
      spec/models/user_spec.rb

12
app/models/user.rb

@ -238,13 +238,11 @@ class User < ApplicationRecord
end
def status
if active == false
:deactivated
elsif confirmed? == false
:unconfirmed
else
:active
end
return :deleted if discarded_at.present?
return :deactivated unless active
return :unconfirmed if !confirmed?
:active
end
protected

5
db/migrate/20240305091927_add_discarded_at_column_to_users.rb

@ -0,0 +1,5 @@
class AddDiscardedAtColumnToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :discarded_at, :datetime
end
end

1
db/schema.rb

@ -763,6 +763,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_03_19_122706) do
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.boolean "initial_confirmation_sent"
t.datetime "discarded_at"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true

9
spec/models/user_spec.rb

@ -517,5 +517,14 @@ RSpec.describe User, type: :model do
expect(user.status).to eq(:active)
end
context "when the user is deleted" do
let(:user) { create(:user, discarded_at: Time.zone.yesterday) }
it "returns the status of the user" do
user.destroy!
expect(user.status).to eq(:deleted)
end
end
end
end

Loading…
Cancel
Save