Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ad_plugin:
discourse_adplugin_enabled:
client: true
default: true
default: false
no_ads_for_personal_messages:
client: true
default: true
Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20250721192553_enable_adplugin_if_already_installed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class EnableAdpluginIfAlreadyInstalled < ActiveRecord::Migration[7.2]
def up
installed_at = DB.query_single(<<~SQL)&.first
SELECT created_at FROM schema_migration_details WHERE version='20190603112536'
SQL

if installed_at && installed_at < 1.hour.ago
# The plugin was installed before we changed it to be disabled-by-default
# Therefore, if there is no existing database value, enable the plugin
execute <<~SQL
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
VALUES('discourse_adplugin_enabled', 5, 't', NOW(), NOW())
ON CONFLICT (name) DO NOTHING
SQL
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 2 additions & 0 deletions spec/models/house_ad_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
describe AdPlugin::HouseAdSetting do
let(:defaults) { AdPlugin::HouseAdSetting::DEFAULTS }

before { enable_current_plugin }

describe ".all" do
subject { AdPlugin::HouseAdSetting.all }

Expand Down
2 changes: 2 additions & 0 deletions spec/models/house_ad_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
}
end

before { enable_current_plugin }

def create_anon_ad
AdPlugin::HouseAd.create(
name: "anon-ad",
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/house_ad_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
)
end

before { enable_current_plugin }

describe "#update" do
context "when used by admins" do
before { sign_in(admin) }
Expand Down
5 changes: 4 additions & 1 deletion spec/requests/house_ad_settings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
describe AdPlugin::HouseAdSettingsController do
let(:admin) { Fabricate(:admin) }

before { AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>") }
before do
enable_current_plugin
AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>")
end

describe "update" do
let(:valid_params) { { value: "Banner" } }
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/site_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.describe SiteController do
fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) }

fab!(:user)
fab!(:group_2) { Fabricate(:group) }
fab!(:user_with_group) { Fabricate(:user, group_ids: [group.id]) }
Expand Down Expand Up @@ -75,6 +74,7 @@
end

before do
enable_current_plugin
AdPlugin::HouseAdSetting.update(
"topic_list_top",
"logged-in-ad|anon-ad|everyone-ad|logged-in-ad-with-category|logged-in-ad-with-group|everyone-group-ad",
Expand Down
2 changes: 1 addition & 1 deletion spec/serializer/current_user_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

let(:admin_serializer) { described_class.new(admin, scope: Guardian.new(admin), root: false) }

before { SiteSetting.discourse_adplugin_enabled = true }
before { enable_current_plugin }

describe "#adsense" do
it "is displayed for TL0 by default" do
Expand Down
5 changes: 4 additions & 1 deletion spec/system/admin_house_ad_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
)
end

before { sign_in(admin) }
before do
enable_current_plugin
sign_in(admin)
end

describe "when visiting the page for creating new ads" do
it "has the visibility checkboxes on by default" do
Expand Down