Stop pinging sitemap tools locally (#10314)

This commit is contained in:
rhymes 2020-09-14 16:10:52 +02:00 committed by GitHub
parent 83d37df4d7
commit f6e24bc85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 3 deletions

View file

@ -167,4 +167,9 @@ class SiteConfig < RailsSettings::Base
large: 300,
xlarge: 250
}
# Returns true if we are operating on a local installation, false otherwise
def self.local?
app_domain.include?("localhost")
end
end

View file

@ -5,6 +5,9 @@ class SitemapRefreshWorker
def perform
Rails.application.load_tasks
Rake::Task["sitemap:refresh"].invoke
sitemap_task = SiteConfig.local? ? "sitemap:refresh:no_ping" : "sitemap:refresh"
Rake::Task[sitemap_task].invoke
end
end

View file

@ -0,0 +1,17 @@
require "rails_helper"
RSpec.describe SiteConfig, type: :model do
describe ".local?" do
it "returns true if the .app_domain points to localhost" do
allow(described_class).to receive(:app_domain).and_return("localhost:3000")
expect(described_class.local?).to be(true)
end
it "returns false if the .app_domain points to a regular domain" do
allow(described_class).to receive(:app_domain).and_return("forem.dev")
expect(described_class.local?).to be(false)
end
end
end

View file

@ -5,12 +5,26 @@ RSpec.describe SitemapRefreshWorker, type: :woker do
describe "#perform" do
let(:worker) { subject }
let(:mock_task) { instance_double(Rake::Task, invoke: true) }
it "runs sitemap refresh rake task" do
before do
allow(Rails.application).to receive(:load_tasks)
mock_task = instance_double(Rake::Task, invoke: true)
allow(Rake::Task).to receive(:[]).and_return(mock_task)
end
it "runs sitemap:refresh:no_ping Rake task locally" do
allow(SiteConfig).to receive(:local?).and_return(true)
worker.perform
expect(Rake::Task).to have_received(:[]).with("sitemap:refresh:no_ping")
end
it "runs sitemap:refresh Rake task on regular installations" do
allow(SiteConfig).to receive(:local?).and_return(false)
worker.perform
expect(Rake::Task).to have_received(:[]).with("sitemap:refresh")
end
end