Skip to content

Commit

Permalink
Show environment for the newly added dev domain
Browse files Browse the repository at this point in the history
All non-production environments show a banner in the top left corner of
the page, and a prefix in emails sent from the application, to indicate
what environment they are coming from.

This is in order to avoid user confusion about what site they are on,
and reassure them that they are not accidentally modifying production
data without intending to.

We cannot use Rails.env, because the Rails env is production for all -
in that they are live sites, not local dev or testing. We have to use
the hostname from the `DOMAIN` environment variable.

When we originally added the banner, there was no dev environment, and
the script defaults to not showing a banner for any unrecognised hosts,
to avoid showing a banner unintentionally.
  • Loading branch information
CristinaRO committed Nov 9, 2023
1 parent 4d892ba commit 3e3a6dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add `is_oda` attribute to reports and populate it to `false` for all existing ISPF reports
- Amend report validation to permit two editable reports per fund and organisation, as long as they have different ODA types
- Amend the check for a pre-existing later report to take ODA type into account
- Show environment banner on the `dev` domain

## Release 138 - 2023-10-27

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def environment_name
case hostname
when "www"
"production"
when "staging", "sandbox", "training"
when "staging", "sandbox", "training", "dev"
hostname
when "pentest"
"training"
Expand All @@ -55,7 +55,7 @@ def environment_name
end

def display_env_name?
environment_name.in? %w[training staging sandbox development]
environment_name.in? %w[training staging sandbox dev development]
end

def environment_mailer_prefix
Expand Down
24 changes: 16 additions & 8 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,45 @@
end

context "when the domain is 'https://training'" do
it "returns 'training" do
it "returns 'training'" do
ClimateControl.modify DOMAIN: "https://training.report-official-development-assistance.service.gov.uk" do
expect(helper.environment_name).to eql("training")
end
end
end

context "when the domain is 'https://pentest'" do
it "returns 'training" do
it "returns 'training'" do
ClimateControl.modify DOMAIN: "https://pentest.report-official-development-assistance.service.gov.uk" do
expect(helper.environment_name).to eql("training")
end
end
end

context "when the domain is 'https://sandbox'" do
it "returns 'sandbox" do
it "returns 'sandbox'" do
ClimateControl.modify DOMAIN: "sandbox.report-official-development-assistance.service.gov.uk" do
expect(helper.environment_name).to eql("sandbox")
end
end
end

context "when the domain is 'https://staging'" do
it "returns 'staging" do
it "returns 'staging'" do
ClimateControl.modify DOMAIN: "https://staging.report-official-development-assistance.service.gov.uk" do
expect(helper.environment_name).to eql("staging")
end
end
end

context "when the domain is 'https://dev'" do
it "returns 'dev'" do
ClimateControl.modify DOMAIN: "https://dev.report-official-development-assistance.service.gov.uk" do
expect(helper.environment_name).to eql("dev")
end
end
end

context "when the domain is something not listed" do
it "returns the Rails environment" do
ClimateControl.modify DOMAIN: "https://something" do
Expand All @@ -126,9 +134,9 @@
end

describe "#display_env_name?" do
context "when the environment_name is one of training, staging, sandbox, or development" do
context "when the environment_name is one of training, staging, sandbox, dev, or development" do
it "returns true" do
%w[training staging sandbox development].each do |env_name|
%w[training staging sandbox dev development].each do |env_name|
allow(helper).to receive(:environment_name).and_return(env_name)
expect(helper.display_env_name?).to be(true)
end
Expand All @@ -146,9 +154,9 @@
end

describe "#environment_mailer_prefix" do
context "when the environment_name is one of training, staging, sandbox, or development" do
context "when the environment_name is one of training, staging, sandbox, dev, or development" do
it "returns the titleised environment name enclosed in square brackets and with a trailing space" do
%w[training staging sandbox development].each do |env_name|
%w[training staging sandbox dev development].each do |env_name|
allow(helper).to receive(:environment_name).and_return(env_name)
expect(helper.environment_mailer_prefix).to eql("[#{env_name.titleize}] ")
end
Expand Down

0 comments on commit 3e3a6dd

Please sign in to comment.