Fix Rails/HasManyOrHasOneDependent for Broadcast and Collection (#9662)
This commit is contained in:
parent
eabb24f40b
commit
b6e0723031
5 changed files with 5 additions and 6 deletions
|
|
@ -24,8 +24,6 @@ Performance/OpenStruct:
|
|||
Rails/HasManyOrHasOneDependent:
|
||||
Exclude:
|
||||
- 'app/models/article.rb'
|
||||
- 'app/models/broadcast.rb'
|
||||
- 'app/models/collection.rb'
|
||||
- 'app/models/concerns/user_subscription_sourceable.rb'
|
||||
- 'app/models/display_ad.rb'
|
||||
- 'app/models/html_variant.rb'
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class Broadcast < ApplicationRecord
|
|||
VALID_BANNER_STYLES = %w[default brand success warning error].freeze
|
||||
resourcify
|
||||
|
||||
has_many :notifications, as: :notifiable, inverse_of: :notifiable
|
||||
has_many :notifications, as: :notifiable, inverse_of: :notifiable, dependent: :destroy
|
||||
|
||||
validates :title, uniqueness: { scope: :type_of }, presence: true
|
||||
validates :type_of, :processed_html, presence: true
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class Collection < ApplicationRecord
|
||||
has_many :articles
|
||||
has_many :articles, dependent: :nullify
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :organization, optional: true
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ RSpec.describe Broadcast, type: :model do
|
|||
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 { is_expected.to have_many(:notifications).dependent(:destroy) }
|
||||
|
||||
it "validates that only one Broadcast with a type_of Announcement can be active" do
|
||||
create(:announcement_broadcast)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ RSpec.describe Collection, type: :model do
|
|||
describe "validations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:organization).optional }
|
||||
it { is_expected.to have_many(:articles) }
|
||||
it { is_expected.to have_many(:articles).dependent(:nullify) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:user_id) }
|
||||
it { is_expected.to validate_presence_of(:slug) }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue