Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,12 @@ def icon_for_mimetype(mime)
def display_count(value)
value.to_i.zero? ? "--" : number_with_delimiter(value)
end

def navbar_bg_class
staging_environment? ? "bg-red-600" : "bg-primary"
end

def staging_environment?
ENV["RAILS_ENV"] == "staging" || Rails.env == "staging"
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="flex-grow" id="main">
<div class="sticky top-0 left-0 w-full z-50 print:hidden">
<!-- Navbar -->
<nav class="bg-primary text-white">
<nav class="<%= navbar_bg_class %> text-white">
<%= render "shared/navbar" %>
</nav>
<!-- Banner -->
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav class="relative bg-primary print:hidden" data-controller="dropdown">
<nav class="relative <%= navbar_bg_class %> print:hidden" data-controller="dropdown">
<div class="px-2 sm:px-6 lg:px-8">
<div class="relative flex items-center justify-between py-2.5">
<div class="absolute inset-y-0 left-0 flex items-center md:hidden">
Expand Down
62 changes: 62 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "rails_helper"

RSpec.describe ApplicationHelper, type: :helper do
describe "#staging_environment?" do
context "when RAILS_ENV is staging" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging")
end

it "returns true" do
expect(helper.staging_environment?).to be true
end
end

context "when Rails.env is staging" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return(nil)
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("staging"))
end

it "returns true" do
expect(helper.staging_environment?).to be true
end
end

context "when environment is not staging" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production")
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("production"))
end

it "returns false" do
expect(helper.staging_environment?).to be false
end
end
end

describe "#navbar_bg_class" do
context "when in staging environment" do
before do
allow(helper).to receive(:staging_environment?).and_return(true)
end

it "returns bg-red-600" do
expect(helper.navbar_bg_class).to eq("bg-red-600")
end
end

context "when not in staging environment" do
before do
allow(helper).to receive(:staging_environment?).and_return(false)
end

it "returns bg-primary" do
expect(helper.navbar_bg_class).to eq("bg-primary")
end
end
end
end
28 changes: 28 additions & 0 deletions spec/views/shared/_navbar.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,32 @@ def render_nav
expect(rendered).to include("My profile")
end
end

context "when in staging environment" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging")
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:user_signed_in?).and_return(false)
render_nav
end

it "uses red background color" do
expect(rendered).to have_css("nav.bg-red-600")
end
end

context "when not in staging environment" do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production")
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:user_signed_in?).and_return(false)
render_nav
end

it "uses primary background color" do
expect(rendered).to have_css("nav.bg-primary")
end
end
end