Require an owner for 'community' billboards (#19167)
* Require an owner for 'community' billboards * Reduce flakiness in this unrelated test
This commit is contained in:
parent
4668e11dcc
commit
db2b571bd6
5 changed files with 600 additions and 374 deletions
|
|
@ -24,7 +24,9 @@ class DisplayAd < ApplicationRecord
|
|||
validates :placement_area, presence: true,
|
||||
inclusion: { in: ALLOWED_PLACEMENT_AREAS }
|
||||
validates :body_markdown, presence: true
|
||||
validates :organization, presence: true, if: :community?
|
||||
validate :validate_tag
|
||||
|
||||
before_save :process_markdown
|
||||
after_save :generate_display_ad_name
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe DisplayAd do
|
||||
let(:organization) { create(:organization) }
|
||||
let(:display_ad) { create(:display_ad, organization_id: organization.id) }
|
||||
let(:organization) { build(:organization) }
|
||||
let(:display_ad) { build(:display_ad, organization: nil) }
|
||||
|
||||
it_behaves_like "Taggable"
|
||||
|
||||
|
|
@ -47,9 +47,23 @@ RSpec.describe DisplayAd do
|
|||
display_ad.creator = nil
|
||||
expect(display_ad).to be_valid
|
||||
end
|
||||
|
||||
it "requires organization_id for community-type ads" do
|
||||
expect(display_ad).to be_valid
|
||||
|
||||
display_ad.type_of = "community"
|
||||
expect(display_ad).not_to be_valid
|
||||
expect(display_ad.errors[:organization]).not_to be_blank
|
||||
|
||||
display_ad.organization = organization
|
||||
expect(display_ad).to be_valid
|
||||
expect(display_ad.errors[:organization]).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "when callbacks are triggered before save" do
|
||||
before { display_ad.save! }
|
||||
|
||||
it "generates #processed_html from #body_markdown" do
|
||||
expect(display_ad.processed_html).to start_with("<p>Hello <em>hey</em> Hey hey")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -185,7 +185,8 @@ RSpec.describe "api/v1/display_ads" do
|
|||
body_markdown: { type: :string, description: "The text (in markdown) of the ad (required)" },
|
||||
approved: { type: :boolean, description: "Ad must be both published and approved to be in rotation" },
|
||||
published: { type: :boolean, description: "Ad must be both published and approved to be in rotation" },
|
||||
organization_id: { type: :integer, description: "Identifies the organization to which the ad belongs" },
|
||||
organization_id: { type: :integer,
|
||||
description: "Identifies the organization to which the ad belongs, required for 'community' type ads" }, # rubocop:disable Layout/LineLength
|
||||
display_to: { type: :string, enum: DisplayAd.display_tos.keys, default: "all",
|
||||
description: "Potentially limits visitors to whom the ad is visible" },
|
||||
placement_area: { type: :string, enum: DisplayAd::ALLOWED_PLACEMENT_AREAS,
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ RSpec.describe "NotificationsIndex" do
|
|||
|
||||
it "properly renders reactable titles for multiple reactions" do
|
||||
amount = rand(3..10)
|
||||
mock_heart_reaction_notifications(amount, %w[unicorn like readinglist], special_characters_article)
|
||||
mock_heart_reaction_notifications(amount, %w[unicorn like], special_characters_article)
|
||||
|
||||
get notifications_path(filter: :org, org_id: organization.id)
|
||||
expect(response.body).to include(ERB::Util.html_escape(special_characters_article.title))
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue