From 58f9c303aab85e333ef3e4f030bcc477c4b6013d Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Tue, 16 Jun 2020 13:04:14 -0600 Subject: [PATCH] Add active_status_updated_at to the Broadcasts Table (#8451) [deploy] * Add last_active_at datetime to Broadcasts table * Add last_active_at to Broadcast index view * Add callback to Broadcast.rb to update last_active_at * Add a data_update script to backfill the last_active_at column on the Broadcasts table * Add a spec for updating the last_active_at timestamp in models/broadcast_spec.rb * Format last_active_at timestamp via strftime in index.html.erb * Remove data_update_script: backfill_last_active_at_for_broadcasts * Remove ActiveRecord::Dirty method from broadcast.rb * Adjust callback in broadcast.rb and last_active_at timestamp format in index.html.erb * Adjust time in #update_last_active_at and add the safe navigation operator to index.html.erb * Accounts for nil last_active_at values in the view * Uses Time.current in place of Time.zone.now * Remove last_active_at param from Broadcasts::Controller * Add spec to broadcasts_spec.rb to test the updated attribute via a request * Adjust current_time in broadcasts_spec.rb * Adjust Timecop.freeze in broadcasts_spec.rb to resolve Travis faliure (fingers crossed) * Adjust expectation to compare against last_active_at timestamp rather than current time * Adds Timecop back and stores last_active_at timestamp to test against * Rename last_active_at to active_status_updated_at on Broadcasts table - Renames last_active_at to active_status_updated_at in specs - Renames last_active_at to active_status_updated_at in model - Renames last_active_at to active_status_updated_at in view - Adjusts spelling in spec descriptions - Rewords active_status_updated_at in view to Last Active On --- app/models/broadcast.rb | 6 ++++++ app/views/internal/broadcasts/index.html.erb | 1 + ...3_add_active_status_updated_at_to_broadcasts.rb | 5 +++++ db/schema.rb | 1 + spec/factories/broadcasts.rb | 1 + spec/models/broadcast_spec.rb | 10 ++++++++++ spec/requests/internal/broadcasts_spec.rb | 14 ++++++++++++++ 7 files changed, 38 insertions(+) create mode 100644 db/migrate/20200609195523_add_active_status_updated_at_to_broadcasts.rb diff --git a/app/models/broadcast.rb b/app/models/broadcast.rb index 22a59932a..55e394f77 100644 --- a/app/models/broadcast.rb +++ b/app/models/broadcast.rb @@ -10,6 +10,8 @@ class Broadcast < ApplicationRecord validates :banner_style, inclusion: { in: VALID_BANNER_STYLES }, allow_blank: true validate :single_active_announcement_broadcast + before_save :update_active_status_updated_at, if: :will_save_change_to_active? + scope :active, -> { where(active: true) } scope :announcement, -> { where(type_of: "Announcement") } scope :welcome, -> { where(type_of: "Welcome") } @@ -32,4 +34,8 @@ class Broadcast < ApplicationRecord errors.add(:base, "You can only have one active announcement broadcast") end + + def update_active_status_updated_at + self.active_status_updated_at = Time.current + end end diff --git a/app/views/internal/broadcasts/index.html.erb b/app/views/internal/broadcasts/index.html.erb index 1493fdc5f..3b3ab014a 100644 --- a/app/views/internal/broadcasts/index.html.erb +++ b/app/views/internal/broadcasts/index.html.erb @@ -31,6 +31,7 @@
<%= broadcast.processed_html %>
+