diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index cfe3e7dfa..0330901d6 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -5,6 +5,6 @@ class SystemNotification < ApplicationRecord has_many :users, through: :user_system_notifications validates :title, :modal_title, :modal_body, :description, - :source_created_at, :source_id, + :source_created_at, :source_id, :last_time_changed_at, presence: true end diff --git a/db/migrate/20190125122852_create_system_notifications.rb b/db/migrate/20190125122852_create_system_notifications.rb index 6db882771..4f167ec5a 100644 --- a/db/migrate/20190125122852_create_system_notifications.rb +++ b/db/migrate/20190125122852_create_system_notifications.rb @@ -10,6 +10,7 @@ class CreateSystemNotifications < ActiveRecord::Migration[5.1] t.boolean :show_on_login, default: false t.datetime :source_created_at, index: true t.bigint :source_id, index: true, unique: true + t.datetime :last_time_changed_at, index: true, null: false t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index b5a443368..c3c1a08ee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -668,8 +668,10 @@ ActiveRecord::Schema.define(version: 20190125123107) do t.boolean "show_on_login", default: false t.datetime "source_created_at" t.bigint "source_id" + t.datetime "last_time_changed_at", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["last_time_changed_at"], name: "index_system_notifications_on_last_time_changed_at" t.index ["source_created_at"], name: "index_system_notifications_on_source_created_at" t.index ["source_id"], name: "index_system_notifications_on_source_id" end diff --git a/spec/factories/system_notifications.rb b/spec/factories/system_notifications.rb index 5fb66046e..86e3c43e2 100644 --- a/spec/factories/system_notifications.rb +++ b/spec/factories/system_notifications.rb @@ -8,6 +8,7 @@ FactoryBot.define do modal_body { Faker::Lorem.paragraphs(4).map { |pr| "
#{pr}
" }.join } source_created_at { Faker::Time.between(3.days.ago, Date.today) } source_id { Faker::Number.between(1, 1000) } + last_time_changed_at { Time.now } trait :show_on_login do show_on_login { true } end diff --git a/spec/models/system_notification_spec.rb b/spec/models/system_notification_spec.rb index 5b4ac9561..6c6d780c2 100644 --- a/spec/models/system_notification_spec.rb +++ b/spec/models/system_notification_spec.rb @@ -33,6 +33,10 @@ describe SystemNotification do describe '#source_created_at' do it { is_expected.to validate_presence_of(:source_created_at) } end + + describe '#last_time_changed_at' do + it { is_expected.to validate_presence_of(:last_time_changed_at) } + end end describe 'Associations' do