Fixes for home nav link positioning (#16381)

* Add new DUS to fix home nav link positioning

* fix bug in local db seeding
This commit is contained in:
Suzanne Aitchison 2022-02-01 14:06:51 +00:00 committed by GitHub
parent 5904543295
commit 0dd77bcf52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,14 @@
module DataUpdateScripts
class UpdateHomeNavigationLinkPosition
def run
NavigationLink.create_or_update_by_identity(
name: "Home",
url: URL.url("/"),
icon: File.read(Rails.root.join("app/assets/images/twemoji/house.svg")),
display_only_when_signed_in: false,
position: 1,
section: :default,
)
end
end
end

View file

@ -128,6 +128,7 @@ namespace :navigation_links do
base_url = "#{protocol}#{domain}".freeze
NavigationLink.create_or_update_by_identity(
url: "/",
name: "Home",
icon: home_icon,
display_only_when_signed_in: false,

View file

@ -0,0 +1,18 @@
require "rails_helper"
require Rails.root.join(
"lib/data_update_scripts/20220201114309_update_home_navigation_link_position.rb",
)
describe DataUpdateScripts::UpdateHomeNavigationLinkPosition do
it "creates a home navigation link when it doesn't already exist" do
expect do
described_class.new.run
end.to change { NavigationLink.exists?(url: "/", name: "Home", position: 1) }.from(false).to(true)
end
it "updates any existing home navigation link to have position 1" do
link = create(:navigation_link, url: "/", name: "Home", position: 4)
described_class.new.run
expect(link.reload.position).to eq(1)
end
end