1
0
Fork 0

Add column Session#logged_at

This commit is contained in:
Alex Kotov 2019-09-03 19:01:00 +05:00
parent b3ca6b0e59
commit da504901e2
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
6 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,7 @@ class LogUserSession
def call
Session.create!(
account: context.user.account,
logged_at: context.user.current_sign_in_at,
ip_address: context.user.current_sign_in_ip,
)
end

View File

@ -11,5 +11,7 @@ class Session < ApplicationRecord
# Validations #
###############
validates :logged_at, presence: true
validates :ip_address, presence: true
end

View File

@ -271,7 +271,8 @@ private
t.references :account, null: false, index: true, foreign_key: true
t.string :ip_address, null: false
t.datetime :logged_at, null: false
t.string :ip_address, null: false
end
create_table :person_comments do |t|

View File

@ -737,6 +737,7 @@ CREATE TABLE public.sessions (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
account_id bigint NOT NULL,
logged_at timestamp without time zone NOT NULL,
ip_address character varying NOT NULL,
CONSTRAINT ip_address CHECK (public.is_good_small_text((ip_address)::text))
);

View File

@ -4,6 +4,8 @@ FactoryBot.define do
factory :some_session, class: Session do
association :account, factory: :usual_account
logged_at { Faker::Time.backward.utc }
ip_address { Faker::Internet.ip_v4_address }
trait :with_ipv6_address do

View File

@ -11,6 +11,17 @@ RSpec.describe Session do
it { is_expected.to validate_presence_of(:account).with_message(:required) }
end
describe '#logged_at' do
def allow_value(*)
super.for :logged_at
end
it { is_expected.to validate_presence_of :logged_at }
it { is_expected.to allow_value Faker::Time.backward.utc }
it { is_expected.to allow_value Faker::Time.forward.utc }
end
describe '#ip_address' do
it { is_expected.to validate_presence_of :ip_address }
end