Fix Rails/HasManyOrHasOneDependent for Broadcast and Collection (#9662)

This commit is contained in:
rhymes 2020-08-07 20:27:24 +02:00 committed by GitHub
parent eabb24f40b
commit b6e0723031
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 6 deletions

View file

@ -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'

View file

@ -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

View file

@ -1,5 +1,6 @@
class Collection < ApplicationRecord
has_many :articles
has_many :articles, dependent: :nullify
belongs_to :user
belongs_to :organization, optional: true

View file

@ -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)

View file

@ -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) }