* 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
31 lines
1.3 KiB
Ruby
31 lines
1.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Broadcast, type: :model do
|
|
it { is_expected.to validate_presence_of(:title) }
|
|
it { is_expected.to validate_presence_of(:type_of) }
|
|
it { is_expected.to validate_presence_of(:processed_html) }
|
|
it { is_expected.to validate_inclusion_of(:type_of).in_array(%w[Announcement Welcome]) }
|
|
it { is_expected.to validate_inclusion_of(:banner_style).in_array(%w[default brand success warning error]) }
|
|
it { is_expected.to validate_uniqueness_of(:title).scoped_to(:type_of) }
|
|
|
|
it { is_expected.to have_many(:notifications) }
|
|
|
|
it "validates that only one Broadcast with a type_of Announcement can be active" do
|
|
create(:announcement_broadcast)
|
|
|
|
inactive_broadcast = build(:announcement_broadcast)
|
|
|
|
expect(inactive_broadcast).not_to be_valid
|
|
expect(inactive_broadcast.errors.full_messages.join).to include("You can only have one active announcement broadcast")
|
|
end
|
|
|
|
it "updates the Broadcast's active_status_updated_at timestamp" do
|
|
Timecop.freeze(Time.current) do
|
|
current_time = Time.zone.now
|
|
broadcast = create(:welcome_broadcast, active: false)
|
|
expect(broadcast.active_status_updated_at).to eq(2.days.ago)
|
|
broadcast.update(active: true)
|
|
expect(broadcast.active_status_updated_at).to eq current_time
|
|
end
|
|
end
|
|
end
|