-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show tenejo version info on production environments (#81)
When the application is running in a production environment only the current release version or branch is displayed. In non-production environments, more detailed git commit information and delpoyment dates are displayed. For lack of a better method to detect produciton environments, the code assumes that hostnames without hyphens are production: * tenejo = production (only display version) * tenejo-dev = non-production (display detailed deploy info) * localhost = non-production (display detailed commit info)
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module FooterHelper | ||
# returns true if running in a full production environment | ||
def production_host? | ||
return false if request.host == 'localhost' # dev and test environments | ||
return false if request.host.include?('-') # hostnames like qa-etd, tenejo-dev | ||
true # hostnames without a dash | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
describe FooterHelper do | ||
describe '#production_host?' do | ||
it 'returns true for hosts without a hyphen in their name' do | ||
controller.request.host = 'production.example.com' | ||
expect(helper.production_host?).to eq true | ||
end | ||
it 'returns false for localhost' do | ||
controller.request.host = 'localhost' | ||
expect(helper.production_host?).to eq false | ||
end | ||
it 'returns false for hosts with a hyphen in their name' do | ||
controller.request.host = 'prod-like.example.com' | ||
expect(helper.production_host?).to eq false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe "shared/_footer", type: :view do | ||
context "on prod-like servers" do | ||
# Assumes that prod-like servers have an environment name separated by a dash in the hostname\ | ||
# See FooterHelper for details | ||
it 'displays detailed git information' do | ||
controller.request.host = 'prod-like.example.com' | ||
render | ||
expect(rendered).to have_selector('.version', text: "SHA") | ||
end | ||
end | ||
|
||
context "on production servers" do | ||
# Assumes that production servers do not have dashed in hostnames | ||
it 'displays only version info' do | ||
controller.request.host = 'production.example.com' | ||
render | ||
expect(rendered).to have_selector('.version', text: "Unknown branch") | ||
expect(rendered).to have_no_selector('.version', text: "SHA") | ||
end | ||
end | ||
|
||
context "on local development and test environments" do | ||
it 'displays detailed git information' do | ||
controller.request.host = 'localhost' | ||
render | ||
expect(rendered).to have_selector('.version', text: "SHA") | ||
end | ||
end | ||
end |