Attempt to fix random test failures when dealing with the ForemInstance class (#12294)

* fix: set the deployed at to nil

* chore: make sure the heroku env is also set to empty

* Sprinkle more after block

Co-authored-by: Mac Siri <krairit.siri@gmail.com>
This commit is contained in:
Ridhwana 2021-01-15 19:44:18 +02:00 committed by GitHub
parent c0f38b4567
commit 65d439e70d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -62,6 +62,8 @@ RSpec.describe ApplicationHelper, type: :helper do
end
describe "#release_adjusted_cache_key" do
after { ForemInstance.instance_variable_set(:@deployed_at, nil) }
it "does nothing when RELEASE_FOOTPRINT is not set" do
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return(nil)
expect(helper.release_adjusted_cache_key("cache-me")).to include("cache-me")

View file

@ -2,19 +2,20 @@ require "rails_helper"
RSpec.describe ForemInstance, type: :model do
describe "deployed_at" do
before do
before { allow(ENV).to receive(:[]) }
after do
described_class.instance_variable_set(:@deployed_at, nil)
end
it "sets the RELEASE_FOOTPRINT if present" do
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("A deploy date")
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => ""))
expect(described_class.deployed_at).to eq(ApplicationConfig["RELEASE_FOOTPRINT"])
end
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("")
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => "A deploy date set on Heroku"))
allow(ENV).to receive(:[]).with("HEROKU_RELEASE_CREATED_AT").and_return("A deploy date set on Heroku")
expect(described_class.deployed_at).to eq(ENV["HEROKU_RELEASE_CREATED_AT"])
end
end

View file

@ -24,6 +24,10 @@ RSpec.describe "/admin", type: :request do
end
describe "Last deployed and Lastest Commit ID card" do
after do
ForemInstance.instance_variable_set(:@deployed_at, nil)
end
it "shows 'Not Available' if the Last deployed time is missing" do
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => ""))
@ -34,7 +38,6 @@ RSpec.describe "/admin", type: :request do
it "shows the correct value if the Last deployed time is available" do
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => "Some date"))
ForemInstance.instance_variable_set(:@deployed_at, nil)
get admin_path