From 1b8f864febb9e6f39099cdfbc0a8c8fef89ee6a8 Mon Sep 17 00:00:00 2001 From: James Mason Date: Tue, 7 Nov 2017 13:51:10 -0800 Subject: [PATCH] Use organization name for title link if available, but link to / --- app/helpers/application_helper.rb | 14 ++++++++++++++ app/views/layouts/_navigation.html.haml | 6 ++---- spec/features/splashpage_spec.rb | 14 +++++++++----- spec/helpers/application_helper_spec.rb | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6174500e..f77d7963 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -171,4 +171,18 @@ module ApplicationHelper def hidden_if_conference_over(conference) 'hidden' if Date.today > conference.end_date end + + def nav_root_link_for(conference) + link_text = ( + conference.try(:organization).try(:name) || + ENV['OSEM_NAME'] || + 'OSEM' + ) + link_to( + link_text, + root_path, + class: 'navbar-brand', + title: 'Open Source Event Manager' + ) + end end diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 9995123b..f7d5fa30 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -13,10 +13,8 @@ %span.icon-bar %span.icon-bar %span.icon-bar - - if conference.nil? || conference.new_record? - = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' - - else - = link_to conference.organization.name, organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' + = nav_root_link_for conference + .collapse.navbar-collapse#main-nav - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav diff --git a/spec/features/splashpage_spec.rb b/spec/features/splashpage_spec.rb index ee9b63d5..d33c6c85 100644 --- a/spec/features/splashpage_spec.rb +++ b/spec/features/splashpage_spec.rb @@ -62,14 +62,18 @@ feature Splashpage do end end - context 'public splashpage already created' do + context 'navigation' do let!(:splashpage) { create(:splashpage, conference: conference, public: true)} - scenario 'should have organization name', feature: true, js: true do - sign_in participant - visit conference_path(conference.short_title) + context 'multiple organizations' do + let!(:additional_organization) { create(:organization) } - expect(page).to have_text(conference.organization.name) + scenario 'should have organization name', feature: true, js: true do + sign_in participant + visit conference_path(conference.short_title) + + expect(page).to have_text(conference.organization.name) + end end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 139a5cf9..6cd71d2a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -58,5 +58,21 @@ describe ApplicationHelper, type: :helper do expect(concurrent_events(event).present?).to eq false end end + + describe 'navigation title link' do + it 'should default to OSEM' do + ENV.delete('OSEM_NAME') + expect(nav_root_link_for(nil)).to match 'OSEM' + end + + it 'should use the environment variable' do + ENV['OSEM_NAME'] = Faker::Company.name + expect(nav_root_link_for(nil)).to match ENV['OSEM_NAME'] + end + + it 'should use the conference organization name' do + expect(nav_root_link_for(conference)).to match conference.organization.name + end + end end end