Browse Source

rubocop

pull/643/head
JG 3 years ago
parent
commit
6fef06fe5b
  1. 11
      app/helpers/title_helper.rb
  2. 49
      spec/helpers/title_helper_spec.rb

11
app/helpers/title_helper.rb

@ -3,19 +3,18 @@ module TitleHelper
count > 1 ? item.pluralize : item
end
def format_title(path, searched, page_title, current_user, item_label, count, organisation_name)
def format_title(_path, searched, page_title, current_user, item_label, count, organisation_name)
if searched.present?
actual_title = support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name}" : page_title
title = "#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)"
actual_title = support_user_sab_nav?(current_user, organisation_name) ? organisation_name.to_s : page_title
"#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)"
else
actual_title = support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title
title = actual_title
support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title
end
end
private
def support_user_sab_nav? current_user, organisation_name
def support_user_sab_nav?(current_user, organisation_name)
current_user.support? && organisation_name
end
end

49
spec/helpers/title_helper_spec.rb

@ -3,6 +3,7 @@ require "rails_helper"
RSpec.describe TitleHelper do
describe "#format_label" do
let(:item) { "organisation" }
it "returns singular when count is 1" do
expect(format_label(1, item)).to eq("organisation")
end
@ -19,15 +20,15 @@ RSpec.describe TitleHelper do
let(:count) { 1 }
let(:organisation_name) { nil }
context "coordinator user" do
context "when coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
context "specific organisation details path" do
context "when specific organisation details path" do
let(:path) { "organisations/1/details" }
let(:page_title) { "Organisation details" }
let(:organisation_name) { nil }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { page_title }
it "returns expected title when no search" do
@ -37,15 +38,15 @@ RSpec.describe TitleHelper do
end
end
context "support user" do
context "when support user" do
let(:user) { FactoryBot.create(:user, :support) }
context "highest level links" do
context "organisation path" do
context "when highest level links" do
context "when organisation path" do
let(:path) { "/organisations" }
let(:page_title) { "Organisations" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { page_title }
it "returns expected title when no search" do
@ -53,7 +54,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" }
@ -63,11 +64,11 @@ RSpec.describe TitleHelper do
end
end
context "users path" do
context "when users path" do
let(:path) { "/users" }
let(:page_title) { "Users" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { page_title }
it "returns expected title when no search" do
@ -75,7 +76,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" }
@ -85,11 +86,11 @@ RSpec.describe TitleHelper do
end
end
context "logs path" do
context "when logs path" do
let(:path) { "/logs" }
let(:page_title) { "Logs" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { page_title }
it "returns expected title when no search" do
@ -97,7 +98,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" }
@ -108,13 +109,13 @@ RSpec.describe TitleHelper do
end
end
context "sub nav links" do
context "specific organisation logs path" do
context "when sub nav links" do
context "when specific organisation logs path" do
let(:path) { "organisations/1/logs" }
let(:page_title) { "Logs" }
let(:organisation_name) { "Foo Bar" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { "#{organisation_name} (#{page_title})" }
it "returns expected title when no search" do
@ -122,7 +123,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" }
@ -132,12 +133,12 @@ RSpec.describe TitleHelper do
end
end
context "specific organisation users path" do
context "when specific organisation users path" do
let(:path) { "organisations/1/users" }
let(:page_title) { "Users" }
let(:organisation_name) { "Foo Bar" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { "#{organisation_name} (#{page_title})" }
it "returns expected title when no search" do
@ -145,7 +146,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" }
@ -155,12 +156,12 @@ RSpec.describe TitleHelper do
end
end
context "specific organisation details path" do
context "when specific organisation details path" do
let(:path) { "organisations/1/details" }
let(:page_title) { "Organisation details" }
let(:organisation_name) { "Foo Bar" }
context "search is missing" do
context "when search is missing" do
let(:expected_title) { "#{organisation_name} (#{page_title})" }
it "returns expected title when no search" do
@ -168,7 +169,7 @@ RSpec.describe TitleHelper do
end
end
context "search is present" do
context "when search is present" do
let(:search_item) { "foobar" }
let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" }

Loading…
Cancel
Save