Update FilteredAdsQuery and user settings for opting-out of Billboards (#19208)
* Users can only opt-out of external ads * Move random sampling out of FilteredAdsQuery * Refactor filtered_ads_query_spec * Add test for new permit_adjacent setting * Rubocop * Use permit_adjacent_sponsors on article sidebar and post-comments * Remove, unused * Update copy * type_matched -> type_of_ads * Remove non-applicable test --------- Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
This commit is contained in:
parent
67b6fbcbd9
commit
230e77e5cd
10 changed files with 145 additions and 168 deletions
|
|
@ -8,7 +8,7 @@ function initializeDisplayAdVisibility() {
|
|||
var user = userData();
|
||||
|
||||
displayAds.forEach((ad) => {
|
||||
if (user && !user.display_sponsors) {
|
||||
if (user && !user.display_sponsors && ad.dataset['typeOf'] == 'external') {
|
||||
ad.classList.add('hidden');
|
||||
} else {
|
||||
ad.classList.remove('hidden');
|
||||
|
|
|
|||
|
|
@ -37,14 +37,33 @@ class DisplayAd < ApplicationRecord
|
|||
search: "%#{term}%"
|
||||
}
|
||||
|
||||
def self.for_display(area:, user_signed_in:, organization_id: nil, article_tags: [])
|
||||
DisplayAds::FilteredAdsQuery.call(
|
||||
def self.for_display(area:, user_signed_in:, organization_id: nil, article_tags: [], permit_adjacent_sponsors: true)
|
||||
ads_for_display = DisplayAds::FilteredAdsQuery.call(
|
||||
display_ads: self,
|
||||
area: area,
|
||||
organization_id: organization_id,
|
||||
user_signed_in: user_signed_in,
|
||||
article_tags: article_tags,
|
||||
permit_adjacent_sponsors: permit_adjacent_sponsors,
|
||||
)
|
||||
|
||||
# Business Logic Context:
|
||||
# We are always showing more of the good stuff — but we are also always testing the system to give any a chance to
|
||||
# rise to the top. 1 out of every 8 times we show an ad (12.5%), it is totally random. This gives "not yet
|
||||
# evaluated" stuff a chance to get some engagement and start showing up more. If it doesn't get engagement, it
|
||||
# stays in this area.
|
||||
|
||||
# Ads that get engagement have a higher "success rate", and among this category, we sample from the top 15 that
|
||||
# meet that criteria. Within those 15 top "success rates" likely to be clicked, there is a weighting towards the
|
||||
# top ranked outcome as well, and a steady decline over the next 15 — that's because it's not "Here are the top 15
|
||||
# pick one randomly", it is actually "Let's cut off the query at a random limit between 1 and 15 and sample from
|
||||
# that". So basically the "limit" logic will result in 15 sets, and then we sample randomly from there. The
|
||||
# "first ranked" ad will show up in all 15 sets, where as 15 will only show in 1 of the 15.
|
||||
if rand(8) == 1
|
||||
ads_for_display.sample
|
||||
else
|
||||
ads_for_display.limit(rand(1..15)).sample
|
||||
end
|
||||
end
|
||||
|
||||
def human_readable_placement_area
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ module DisplayAds
|
|||
new(...).call
|
||||
end
|
||||
|
||||
def initialize(display_ads:, area:, user_signed_in:, organization_id: nil, article_tags: [])
|
||||
def initialize(area:, user_signed_in:, display_ads: DisplayAd, organization_id: nil, article_tags: [],
|
||||
permit_adjacent_sponsors: true)
|
||||
@filtered_display_ads = display_ads
|
||||
@area = area
|
||||
@user_signed_in = user_signed_in
|
||||
@organization_id = organization_id
|
||||
@article_tags = article_tags
|
||||
@permit_adjacent_sponsors = permit_adjacent_sponsors
|
||||
end
|
||||
|
||||
def call
|
||||
|
|
@ -30,10 +32,9 @@ module DisplayAds
|
|||
authenticated_ads(%w[all logged_out])
|
||||
end
|
||||
|
||||
@filtered_display_ads = community_or_in_house_ads
|
||||
@filtered_display_ads = type_of_ads
|
||||
|
||||
@filtered_display_ads = @filtered_display_ads.order(success_rate: :desc)
|
||||
@filtered_display_ads = sample_ads
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -59,33 +60,26 @@ module DisplayAds
|
|||
@filtered_display_ads.where(display_to: display_auth_audience)
|
||||
end
|
||||
|
||||
def community_or_in_house_ads
|
||||
@filtered_display_ads.where(
|
||||
"(type_of = :in_house) OR
|
||||
(type_of = :community AND organization_id = :organization_id) OR
|
||||
(type_of = :external AND organization_id != :organization_id)",
|
||||
DisplayAd.type_ofs.merge({ organization_id: @organization_id }),
|
||||
)
|
||||
end
|
||||
def type_of_ads
|
||||
# Always match in-house-type ads
|
||||
in_house = "(type_of = :in_house)"
|
||||
|
||||
# Business Logic Context:
|
||||
# We are always showing more of the good stuff — but we are also always testing the system to give any a chance to
|
||||
# rise to the top. 1 out of every 8 times we show an ad (12.5%), it is totally random. This gives "not yet
|
||||
# evaluated" stuff a chance to get some engagement and start showing up more. If it doesn't get engagement, it
|
||||
# stays in this area.
|
||||
# If this is an article that belongs to an organization, we might show community-type ads
|
||||
community = if @organization_id
|
||||
"(type_of = :community AND organization_id = :organization_id)"
|
||||
end
|
||||
|
||||
# Ads that get engagement have a higher "success rate", and among this category, we sample from the top 15 that
|
||||
# meet that criteria. Within those 15 top "success rates" likely to be clicked, there is a weighting towards the
|
||||
# top ranked outcome as well, and a steady decline over the next 15 — that's because it's not "Here are the top 15
|
||||
# pick one randomly", it is actually "Let's cut off the query at a random limit between 1 and 15 and sample from
|
||||
# that". So basically the "limit" logic will result in 15 sets, and then we sample randomly from there. The
|
||||
# "first ranked" ad will show up in all 15 sets, where as 15 will only show in 1 of the 15.
|
||||
def sample_ads
|
||||
if rand(8) == 1
|
||||
@filtered_display_ads.sample
|
||||
else
|
||||
@filtered_display_ads.limit(rand(1..15)).sample
|
||||
end
|
||||
# If the article's author permits adjacent sponsors, we might show an external-type ad
|
||||
# *if* the organization_id doesn't match the current article's organization id
|
||||
external = if @permit_adjacent_sponsors && @organization_id
|
||||
"(type_of = :external AND organization_id != :organization_id)"
|
||||
elsif @permit_adjacent_sponsors
|
||||
"(type_of = :external)"
|
||||
end
|
||||
|
||||
types_matching = [in_house, community, external].compact.join(" OR ")
|
||||
@filtered_display_ads.where(types_matching,
|
||||
DisplayAd.type_ofs.merge({ organization_id: @organization_id }))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -56,10 +56,14 @@
|
|||
</div>
|
||||
|
||||
<%# cache("article-sidebar-content-#{rand(5)}-#{@article.id}-#{user_signed_in?}-#{(@organization || @user).latest_article_updated_at}", expires_in: 15.minutes) do %>
|
||||
<% sidebar_ad = DisplayAd.for_display(area: "post_sidebar", user_signed_in: user_signed_in?, organization_id: @article.organization_id, article_tags: @article.decorate.cached_tag_list_array) %>
|
||||
<% if @article.permit_adjacent_sponsors? && sidebar_ad %>
|
||||
<% sidebar_ad = DisplayAd.for_display(area: "post_sidebar",
|
||||
user_signed_in: user_signed_in?,
|
||||
organization_id: @article.organization_id,
|
||||
article_tags: @article.decorate.cached_tag_list_array,
|
||||
permit_adjacent_sponsors: @article.decorate.permit_adjacent_sponsors?) %>
|
||||
<% if sidebar_ad %>
|
||||
<div class="crayons-article-sticky grid gap-4 break-word pt-4">
|
||||
<%= render partial: "shared/display_ad", locals: {display_ad: sidebar_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_ARTICLE } %>
|
||||
<%= render partial: "shared/display_ad", locals: { display_ad: sidebar_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_ARTICLE } %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%# end %>
|
||||
|
|
|
|||
|
|
@ -193,10 +193,14 @@
|
|||
</article>
|
||||
|
||||
<% cache("article-bottom-content-#{rand(5)}-#{@article.id}-#{user_signed_in?}-#{(@organization || @user).latest_article_updated_at}", expires_in: 15.minutes) do %>
|
||||
<% @display_ad = DisplayAd.for_display(area: "post_comments", user_signed_in: user_signed_in?, organization_id: @article.organization_id, article_tags: @article.decorate.cached_tag_list_array) %>
|
||||
<% @display_ad = DisplayAd.for_display(area: "post_comments",
|
||||
user_signed_in: user_signed_in?,
|
||||
organization_id: @article.organization_id,
|
||||
permit_adjacent_sponsors: @article.decorate.permit_adjacent_sponsors?,
|
||||
article_tags: @article.decorate.cached_tag_list_array) %>
|
||||
<% if @display_ad %>
|
||||
<div class="pb-4 crayons-layout__comments-display-ad">
|
||||
<%= render partial: "shared/display_ad", locals: {display_ad: @display_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_ARTICLE } %>
|
||||
<%= render partial: "shared/display_ad", locals: { display_ad: @display_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_ARTICLE } %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
data-display-unit data-id="<%= display_ad.id %>"
|
||||
data-category-click="<%= DisplayAdEvent::CATEGORY_CLICK %>"
|
||||
data-category-impression="<%= DisplayAdEvent::CATEGORY_IMPRESSION %>"
|
||||
data-context-type="<%= data_context_type %>">
|
||||
data-context-type="<%= data_context_type %>"
|
||||
data-type-of="<%= display_ad.type_of %>">
|
||||
<div class="crayons-sponsorship__header relative">
|
||||
<% if Page.exists?(slug: "billboards") && display_ad.organization_id? && display_ad.type_of == "community" %>
|
||||
<img width="24" height="24" class="radius-default crayons-sponsorship__image" src="<%= display_ad.organization.profile_image_url_for(length: 64) %>" alt="profile" loading="lazy" />
|
||||
|
|
@ -10,7 +11,7 @@
|
|||
<% else %>
|
||||
<div class="crayons-sponsorship__title"><%= Settings::Community.community_name %></div>
|
||||
<% end %>
|
||||
<button id="sponsorship-dropdown-trigger-<%= display_ad.id %>" aria-controls="sponsorship-dropdown-<%= display_ad.id %>" aria-expanded="false" aria-haspopup="true"
|
||||
<button id="sponsorship-dropdown-trigger-<%= display_ad.id %>" aria-controls="sponsorship-dropdown-<%= display_ad.id %>" aria-expanded="false" aria-haspopup="true"
|
||||
class="dropBtn crayons-sponsorship__dropdown crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon"
|
||||
aria-label="<%= t("display_ad.menu.aria_label") %>">
|
||||
<%= crayons_icon_tag("small-overflow-horizontal", class: "pointer-events-none", title: t("display_ad.menu.icon")) %>
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@
|
|||
<%= t("views.settings.custom.sponsor") %>
|
||||
</h2>
|
||||
<p>
|
||||
<%= t("views.settings.custom.sponsor_desc") %>
|
||||
<%= t("views.settings.custom.sponsor_desc_html") %>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ en:
|
|||
github: Connect your github account as well to complete your identity.
|
||||
twitter: Connect your twitter account as well to complete your identity.
|
||||
custom:
|
||||
adjacent: Permit Nearby Sponsors (When publishing)
|
||||
adjacent: Permit Nearby External Sponsors (When publishing)
|
||||
announce: Announcements
|
||||
announce_desc: Announcements inform you on important site-wide information, like updates and events.
|
||||
announce_field: Display Announcements (When browsing)
|
||||
|
|
@ -73,8 +73,8 @@ en:
|
|||
rich: Rich + markdown
|
||||
save: Save
|
||||
sponsor: Sponsors
|
||||
sponsor_desc: You have the option to remove sponsor messaging (where it is practical to do so). Our wonderful sponsors help sustain the platform and improve your experience, and we strive to make their presence constructive to the community, but feel free to use this setting if you wish.
|
||||
sponsor_field: Display Sponsors (When browsing)
|
||||
sponsor_desc_html: You have the option to disable billboards from external sponsors. Our wonderful partners help sustain the platform, and we strive to ensure that their presence is constructive and valuable to the community, but you are welcome to make use of this setting if you wish. More details in our <a href="/billboards">billboards FAQ</a>.
|
||||
sponsor_field: Display External Sponsors (When browsing)
|
||||
static: Static top of page
|
||||
theme: Site Theme
|
||||
writing: Writing
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ fr:
|
|||
github: Connect your github account as well to complete your identity.
|
||||
twitter: Connect your twitter account as well to complete your identity.
|
||||
custom:
|
||||
adjacent: Permit Nearby Sponsors (When publishing)
|
||||
adjacent: Permit Nearby External Sponsors (When publishing)
|
||||
announce: Announcements
|
||||
announce_desc: Announcements inform you on important site-wide information, like updates and events.
|
||||
announce_field: Display Announcements (When browsing)
|
||||
|
|
@ -73,8 +73,8 @@ fr:
|
|||
rich: Rich + markdown
|
||||
save: Save
|
||||
sponsor: Sponsors
|
||||
sponsor_desc: You have the option to remove sponsor messaging (where it is practical to do so). Our wonderful sponsors help sustain the platform and improve your experience, and we strive to make their presence constructive to the community, but feel free to use this setting if you wish.
|
||||
sponsor_field: Display Sponsors (When browsing)
|
||||
sponsor_desc_html: You have the option to disable billboards from external sponsors. Our wonderful partners help sustain the platform, and we strive to ensure that their presence is constructive and valuable to the community, but you are welcome to make use of this setting if you wish. More details in our <a href="/billboards">billboards FAQ</a>.
|
||||
sponsor_field: Display External Sponsors (When browsing)
|
||||
static: Static top of page
|
||||
theme: Site Theme
|
||||
writing: Writing
|
||||
|
|
|
|||
|
|
@ -1,154 +1,109 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe DisplayAds::FilteredAdsQuery, type: :query do
|
||||
let(:organization) { create(:organization) }
|
||||
let(:placement_area) { "post_sidebar" }
|
||||
|
||||
context "when updating the published and approved values" do
|
||||
let!(:display_ad) { create(:display_ad, organization_id: organization.id) }
|
||||
def create_display_ad(**options)
|
||||
defaults = {
|
||||
approved: true,
|
||||
published: true,
|
||||
placement_area: placement_area,
|
||||
display_to: :all
|
||||
}
|
||||
create(:display_ad, **options.reverse_merge(defaults))
|
||||
end
|
||||
|
||||
it "does not return unpublished ads" do
|
||||
display_ad.update!(published: false, approved: true)
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: nil, user_signed_in: false)).to be_nil
|
||||
end
|
||||
def filter_ads(**options)
|
||||
defaults = {
|
||||
display_ads: DisplayAd, area: placement_area, user_signed_in: false
|
||||
}
|
||||
described_class.call(**options.reverse_merge(defaults))
|
||||
end
|
||||
|
||||
it "does not return unapproved ads" do
|
||||
display_ad.update!(published: true, approved: false)
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: nil, user_signed_in: false)).to be_nil
|
||||
end
|
||||
context "when ads are not approved or published" do
|
||||
let!(:unapproved) { create_display_ad approved: false }
|
||||
let!(:unpublished) { create_display_ad published: false }
|
||||
let!(:display_ad) { create_display_ad }
|
||||
|
||||
it "returns published and approved ads" do
|
||||
display_ad.update!(published: true, approved: true)
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: nil, user_signed_in: false)).to eq(display_ad)
|
||||
it "does not display unapproved or unpublished ads" do
|
||||
filtered = filter_ads
|
||||
expect(filtered).not_to include(unapproved)
|
||||
expect(filtered).not_to include(unpublished)
|
||||
expect(filtered).to include(display_ad)
|
||||
end
|
||||
end
|
||||
|
||||
context "when considering article_tags" do
|
||||
it "will show the display ads that contain tags that match any of the article tags" do
|
||||
display_ad = create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "linux, git, go")
|
||||
let!(:no_tags) { create_display_ad cached_tag_list: "" }
|
||||
let!(:mismatched) { create_display_ad cached_tag_list: "career" }
|
||||
|
||||
create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "career")
|
||||
|
||||
article_tags = %w[linux productivity]
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: "post_comments", user_signed_in: false,
|
||||
organization_id: nil, article_tags: article_tags)).to eq(display_ad)
|
||||
end
|
||||
|
||||
it "will show display ads that have no tags set" do
|
||||
display_ad = create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "")
|
||||
|
||||
create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "career")
|
||||
|
||||
article_tags = %w[productivity java]
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: "post_comments", user_signed_in: false,
|
||||
organization_id: display_ad.organization.id, article_tags: article_tags)).to eq(display_ad)
|
||||
end
|
||||
|
||||
it "will show no display ads if the available display ads have no tags set or do not contain matching tags" do
|
||||
create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "productivity")
|
||||
article_tags = %w[javascript]
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: "post_comments", user_signed_in: false,
|
||||
organization_id: nil, article_tags: article_tags)).to be_nil
|
||||
it "will show no-tag display ads if the article tags do not contain matching tags" do
|
||||
filtered = filter_ads(article_tags: %w[javascript])
|
||||
expect(filtered).not_to include(mismatched)
|
||||
expect(filtered).to include(no_tags)
|
||||
end
|
||||
|
||||
it "will show display ads with no tags set if there are no article tags" do
|
||||
create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "productivity")
|
||||
filtered = filter_ads(article_tags: [])
|
||||
expect(filtered).not_to include(mismatched)
|
||||
expect(filtered).to include(no_tags)
|
||||
end
|
||||
|
||||
display_ad_without_tags = create(:display_ad, organization_id: organization.id,
|
||||
placement_area: "post_comments",
|
||||
published: true,
|
||||
approved: true,
|
||||
cached_tag_list: "")
|
||||
context "when available ads have matching tags" do
|
||||
let!(:matching) { create_display_ad cached_tag_list: "linux, git, go" }
|
||||
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: "post_comments",
|
||||
organization_id: nil, user_signed_in: false)).to eq(display_ad_without_tags)
|
||||
it "will show the display ads that contain tags that match any of the article tags" do
|
||||
filtered = filter_ads article_tags: %w[linux productivity]
|
||||
expect(filtered).not_to include(mismatched)
|
||||
expect(filtered).to include(matching)
|
||||
expect(filtered).to include(no_tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when display_to is set to 'logged_in' or 'logged_out'" do
|
||||
let!(:display_ad2) do
|
||||
create(:display_ad, organization_id: organization.id, published: true, approved: true, display_to: "logged_in")
|
||||
end
|
||||
let!(:display_ad3) do
|
||||
create(:display_ad, organization_id: organization.id, published: true, approved: true, display_to: "logged_out")
|
||||
end
|
||||
context "when considering users_signed_in" do
|
||||
let!(:for_logged_in) { create_display_ad display_to: :logged_in }
|
||||
let!(:for_logged_out) { create_display_ad display_to: :logged_out }
|
||||
let!(:for_all_users) { create_display_ad display_to: :all }
|
||||
|
||||
it "shows ads that have a display_to of 'logged_in' if a user is signed in" do
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad2.placement_area,
|
||||
organization_id: display_ad2.organization.id, user_signed_in: true)).to eq(display_ad2)
|
||||
end
|
||||
it "always shows :all, only shows -in/-out appropriately" do
|
||||
filtered = filter_ads user_signed_in: true
|
||||
expect(filtered).to contain_exactly(for_logged_in, for_all_users)
|
||||
|
||||
it "shows ads that have a display_to of 'logged_out' if a user is signed in" do
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad3.placement_area,
|
||||
organization_id: display_ad3.organization.id, user_signed_in: false)).to eq(display_ad3)
|
||||
filtered = filter_ads user_signed_in: false
|
||||
expect(filtered).to contain_exactly(for_logged_out, for_all_users)
|
||||
end
|
||||
end
|
||||
|
||||
context "when display_to is set to 'all'" do
|
||||
let!(:display_ad) do
|
||||
create(:display_ad, organization_id: organization.id, published: true, approved: true, display_to: "all")
|
||||
context "when considering ads with organization_id" do
|
||||
let!(:in_house_ad) { create_display_ad type_of: :in_house }
|
||||
|
||||
let(:organization) { create(:organization) }
|
||||
let(:other_org) { create(:organization) }
|
||||
let!(:community_ad) { create_display_ad organization_id: organization.id, type_of: :community }
|
||||
let!(:other_community) { create_display_ad organization_id: other_org.id, type_of: :community }
|
||||
|
||||
let!(:external_ad) { create_display_ad organization_id: organization.id, type_of: :external }
|
||||
let!(:other_external) { create_display_ad organization_id: other_org.id, type_of: :external }
|
||||
|
||||
it "always shows :in_house, only shows community/external appropriately" do
|
||||
filtered = filter_ads organization_id: organization.id
|
||||
expect(filtered).to contain_exactly(community_ad, in_house_ad, other_external)
|
||||
expect(filtered).not_to include(other_community)
|
||||
|
||||
filtered = filter_ads organization_id: nil
|
||||
expect(filtered).to contain_exactly(in_house_ad, external_ad, other_external)
|
||||
expect(filtered).not_to include(other_community)
|
||||
end
|
||||
|
||||
it "shows ads that have a display_to of 'all' if a user is signed in" do
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: display_ad.organization.id, user_signed_in: true)).to eq(display_ad)
|
||||
end
|
||||
it "suppresses external ads when permit_adjacent_sponsors is false" do
|
||||
filtered = filter_ads organization_id: organization.id, permit_adjacent_sponsors: false
|
||||
expect(filtered).to contain_exactly(community_ad, in_house_ad)
|
||||
expect(filtered).not_to include(other_community)
|
||||
|
||||
it "shows ads that have a display_to of 'all' if a user is not signed in" do
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: display_ad.organization.id, user_signed_in: false)).to eq(display_ad)
|
||||
end
|
||||
end
|
||||
|
||||
context "when organization is set on ad" do
|
||||
it "shows ads that have that are of type community and associated with the organization" do
|
||||
display_ad = create(:display_ad, organization_id: organization.id,
|
||||
published: true,
|
||||
approved: true,
|
||||
placement_area: "post_comments",
|
||||
type_of: "community",
|
||||
display_to: "all")
|
||||
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: display_ad.organization.id, user_signed_in: false)).to eq(display_ad)
|
||||
end
|
||||
|
||||
it "shows ads that have that are of type in house" do
|
||||
display_ad = create(:display_ad, organization_id: organization.id,
|
||||
published: true,
|
||||
approved: true,
|
||||
placement_area: "post_comments",
|
||||
type_of: "in_house",
|
||||
display_to: "all")
|
||||
|
||||
expect(described_class.call(display_ads: DisplayAd.all, area: display_ad.placement_area,
|
||||
organization_id: display_ad.organization.id, user_signed_in: false)).to eq(display_ad)
|
||||
filtered = filter_ads organization_id: nil, permit_adjacent_sponsors: false
|
||||
expect(filtered).to contain_exactly(in_house_ad)
|
||||
expect(filtered).not_to include(other_community)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue