Fix shell version logic in async info controller (#12262)

* Add .to_s to ForemInstance.deployed_at

* test: could it possibly be holding onto the cached value across the tests

Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
This commit is contained in:
Alex 2021-01-13 13:20:34 -05:00 committed by GitHub
parent a5e6f7942c
commit 01a4b41fed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -29,7 +29,7 @@ class AsyncInfoController < ApplicationController
set_surrogate_key_header "shell-version-endpoint"
# shell_version will change on every deploy.
# *Technically* could be only on changes to assets and shell, but this is more fool-proof.
shell_version = ForemInstance.deployed_at + SiteConfig.admin_action_taken_at.to_s
shell_version = ForemInstance.deployed_at.to_s + SiteConfig.admin_action_taken_at.to_s
render json: { version: shell_version }.to_json
end

View file

@ -2,32 +2,38 @@ require "rails_helper"
RSpec.describe ForemInstance, type: :model do
describe "deployed_at" do
before 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 be(ApplicationConfig["RELEASE_FOOTPRINT"])
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"))
described_class.instance_variable_set(:@deployed_at, nil)
expect(described_class.deployed_at).to be(ENV["HEROKU_RELEASE_CREATED_AT"])
expect(described_class.deployed_at).to eq(ENV["HEROKU_RELEASE_CREATED_AT"])
end
end
describe "latest_commit_id" do
before do
described_class.instance_variable_set(:@latest_commit_id, nil)
end
it "sets the FOREM_BUILD_SHA if present" do
allow(ApplicationConfig).to receive(:[]).with("FOREM_BUILD_SHA").and_return("A commit id")
stub_const("ENV", ENV.to_h.merge("HEROKU_SLUG_COMMIT" => ""))
expect(described_class.latest_commit_id).to be(ApplicationConfig["FOREM_BUILD_SHA"])
expect(described_class.latest_commit_id).to eq(ApplicationConfig["FOREM_BUILD_SHA"])
end
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
allow(ApplicationConfig).to receive(:[]).with("FOREM_BUILD_SHA").and_return("")
stub_const("ENV", ENV.to_h.merge("HEROKU_SLUG_COMMIT" => "A Commit ID set from Heroku"))
described_class.instance_variable_set(:@latest_commit_id, nil)
expect(described_class.latest_commit_id).to be(ENV["HEROKU_SLUG_COMMIT"])
expect(described_class.latest_commit_id).to eq(ENV["HEROKU_SLUG_COMMIT"])
end
end
end