docbrown/spec/models/broadcast_spec.rb
Vaidehi Joshi a4be185720
Leverage announcement broadcasts (#8150) [deploy]
* Differentiate between welcome + announcement broadcasts

* Allow admins to filter between these two types in the `/internal/broadcasts` UI.
* Ensure that the index endpoint fetches the correct Broadcast models.

* Only allow one Announcement broadcast to be created at a time

* Also add some `announcement` and `welcome` scopes on the `Broadcast` class.
* Add flash[:success] messages in BroadcastsController.

* Add some tests for Announcement broadcast validations

* Remove unused active_announcement_params method

* Order Broadcasts by title, optimization improvements

* Fix missing closing tags in broadcast specs
2020-05-29 11:38:41 -07:00

19 lines
739 B
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 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
end