diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 089bf55e286..d09c2fdbf28 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -366,7 +366,7 @@ def not_allowed(fallback=nil) redirect_to (fallback || root_path) rescue redirect_to '/' end - def get_page_title(fandom, author, title, options = {}) + def get_page_subtitle(fandom, author, title, options = {}) # truncate any piece that is over 15 chars long to the nearest word if options[:truncate] fandom = fandom.gsub(/^(.{15}[\w.]*)(.*)/) {$2.empty? ? $1 : $1 + '...'} @@ -383,7 +383,6 @@ def get_page_title(fandom, author, title, options = {}) page_title = "#{title} - #{author} - #{fandom}" end - page_title += " [#{ArchiveConfig.APP_NAME}]" unless options[:omit_archive_name] page_title.html_safe end diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index a4d16008a22..d5b43a52999 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -48,11 +48,11 @@ def show @next_chapter = @chapters[chapter_position + 1] end - if @work.unrevealed? - @page_subtitle = t(".unrevealed") + t(".chapter_position", position: @chapter.position.to_s) - else - @page_title = work_page_title(@work, @work.title + t(".chapter_position", position: @chapter.position.to_s)) - end + @page_subtitle = if @work.unrevealed? + t(".unrevealed") + t(".chapter_position", position: @chapter.position.to_s) + else + work_page_subtitle(@work, @work.title + t(".chapter_position", position: @chapter.position.to_s)) + end if params[:view_adult] cookies[:view_adult] = "true" diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 05b7ce921ad..b797a407db1 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -322,7 +322,7 @@ def set_page_subtitle return unless parent name = if parent.is_a?(Work) - work_page_title(parent, parent.title, { omit_archive_name: true }) + work_page_subtitle(parent, parent.title) else parent.commentable_name end diff --git a/app/controllers/series_controller.rb b/app/controllers/series_controller.rb index e34d60cc010..7eae849bb85 100644 --- a/app/controllers/series_controller.rb +++ b/app/controllers/series_controller.rb @@ -45,13 +45,14 @@ def show @works = @series.works_in_order.posted.includes(:pseuds).select(&:visible?).paginate(page: params[:page]) # sets the page title with the data for the series - if @series.unrevealed? - @page_subtitle = t(".unrevealed_series") - else - @page_title = get_page_title(@series.fandoms.pluck(:name).join(t("support.array.words_connector")), - helpers.text_byline(@series), - @series.title) - end + + @page_subtitle = if @series.unrevealed? + t(".unrevealed_series") + else + get_page_subtitle(@series.fandoms.pluck(:name).join(t("support.array.words_connector")), + helpers.text_byline(@series), + @series.title) + end return unless current_user.respond_to?(:subscriptions) diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 61e6ad43a02..f4d85aad6f6 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -176,11 +176,11 @@ def drafts # GET /works/1 # GET /works/1.xml def show - if @work.unrevealed? - @page_subtitle = t(".page_title.unrevealed") - else - @page_title = work_page_title(@work, @work.title) - end + @page_subtitle = if @work.unrevealed? + t(".page_title.unrevealed") + else + work_page_subtitle(@work, @work.title) + end # Users must explicitly okay viewing of adult content if params[:view_adult] diff --git a/app/helpers/works_helper.rb b/app/helpers/works_helper.rb index da6bd272e84..9d05547c01c 100644 --- a/app/helpers/works_helper.rb +++ b/app/helpers/works_helper.rb @@ -30,18 +30,18 @@ def work_meta_list(work, chapter = nil) content_tag(:dl, list.to_s, class: 'stats').html_safe end - def work_page_title(work, title, options = {}) + def work_page_subtitle(work, title, options = {}) fandoms = work.fandoms title_fandom = if fandoms.empty? - t("works_helper.work_page_title.unspecified_fandom") + t("works_helper.work_page_subtitle.unspecified_fandom") elsif fandoms.size > 2 - t("works_helper.work_page_title.multifandom") + t("works_helper.work_page_subtitle.multifandom") else fandoms.pluck(:name).join(t("support.array.words_connector")) end - author = work.anonymous? ? t("works_helper.work_page_title.anonymous") : work.pseuds.sort.collect(&:byline).join(t("support.array.words_connector")) + author = work.anonymous? ? t("works_helper.work_page_subtitle.anonymous") : work.pseuds.sort.collect(&:byline).join(t("support.array.words_connector")) - get_page_title(title_fandom, author, title, options) + get_page_subtitle(title_fandom, author, title, options) end def recipients_link(work) diff --git a/config/locales/helpers/en.yml b/config/locales/helpers/en.yml index de486305021..0b8c27fbbe1 100644 --- a/config/locales/helpers/en.yml +++ b/config/locales/helpers/en.yml @@ -79,7 +79,7 @@ en: works_helper: mark_as_read_button: Mark as Read mark_for_later_button: Mark for Later - work_page_title: + work_page_subtitle: anonymous: Anonymous multifandom: Multifandom unspecified_fandom: No fandom specified diff --git a/features/gift_exchanges/challenge_yuletide.feature b/features/gift_exchanges/challenge_yuletide.feature index 216209a49eb..b4a81ac47e8 100644 --- a/features/gift_exchanges/challenge_yuletide.feature +++ b/features/gift_exchanges/challenge_yuletide.feature @@ -19,6 +19,7 @@ Feature: Collection | myname4 | password | | pinchhitter | password | And I am logged in as "mod1" + And the app name is "Example Archive" And I have no collections And I have Yuletide challenge tags setup And I add the fandom "Stargate Atlantis" to the character "John Sheppard" @@ -588,7 +589,7 @@ Feature: Collection And I should not see "myname6" And I should not see "pinchhitter" When I follow "Fulfilling Story 1" - Then I should see the page title "Fulfilling Story 1 - Anonymous - Stargate Atlantis [Example Archive]" + Then I should see the page title "Fulfilling Story 1 - Anonymous - Stargate Atlantis | Example Archive" Then I should see "Anonymous" And I should not see "myname1" And I should not see "myname3" diff --git a/features/other_a/page_title.feature b/features/other_a/page_title.feature index 54cf69c25f1..6028ffc3a4e 100644 --- a/features/other_a/page_title.feature +++ b/features/other_a/page_title.feature @@ -33,7 +33,7 @@ Scenario: Work page title should respect user preference And I press "Update" And I post the work "New Story" with fandom "Stargate" When I view the work "New Story" - Then the page title should include "Stargate - author - New Story [Example Archive]" + Then the page title should include "Stargate - author - New Story | Example Archive" Scenario: Work page title should change when tags are edited @@ -55,10 +55,10 @@ Scenario: Work page title should be informative on the adult content notice page When I am logged out And I view the work "New Story" Then I should see "This work could have adult content" - And the page title should include "New Story - author - Stargate [Example Archive]" + And the page title should include "New Story - author - Stargate | Example Archive" When I follow the recent chapter link for the work "New Story" Then I should see "This work could have adult content" - And the page title should include "New Story - Chapter 2 - author - Stargate [Example Archive]" + And the page title should include "New Story - Chapter 2 - author - Stargate | Example Archive" Scenario: Inbox has the expected browser page title diff --git a/spec/controllers/chapters_controller_spec.rb b/spec/controllers/chapters_controller_spec.rb index c100485d6dc..6f2dd873ac2 100644 --- a/spec/controllers/chapters_controller_spec.rb +++ b/spec/controllers/chapters_controller_spec.rb @@ -189,9 +189,10 @@ expect(assigns[:next_chapter]).to be_nil end - it "assigns @page_title with fandom, author name, work title, and chapter" do + it "assigns @page_subtitle with fandom, author name, work title, and chapter" do get :show, params: { work_id: work.id, id: work.chapters.first.id } - expect(assigns[:page_title]).to start_with("My title is long enough - Chapter 1 - #{user.pseuds.first.name} - Testing [") + expect(assigns[:page_subtitle]).to start_with("My title is long enough - Chapter 1 - #{user.pseuds.first.name} - Testing") + expect(assigns[:page_title]).to be_nil end it "assigns @page_subtitle with unrevealed work" do @@ -200,39 +201,43 @@ expect(assigns[:page_subtitle]).to eq("Mystery Work - Chapter 1") end - it "assigns @page_title with anonymous work" do + it "assigns @page_subtitle with anonymous work" do allow_any_instance_of(Work).to receive(:anonymous?).and_return(true) get :show, params: { work_id: work.id, id: work.chapters.first.id } - expect(assigns[:page_title]).to start_with("My title is long enough - Chapter 1 - Anonymous - Testing [") + expect(assigns[:page_subtitle]).to start_with("My title is long enough - Chapter 1 - Anonymous - Testing") + expect(assigns[:page_title]).to be_nil end context "when work has many authors" do - it "assigns @page_title with all authors" do + it "assigns @page_subtitle with all authors" do authors = create_list(:pseud, 5) allow_any_instance_of(Work).to receive(:pseuds).and_return(authors) get :show, params: { work_id: work.id, id: work.chapters.first.id } expect(response).to have_http_status(:ok) - expect(assigns[:page_title]).to start_with("#{work.title} - Chapter 1 - #{authors.sort.map(&:byline).join(', ')} - #{work.fandoms.first.name} [") + expect(assigns[:page_subtitle]).to start_with("#{work.title} - Chapter 1 - #{authors.sort.map(&:byline).join(', ')} - #{work.fandoms.first.name}") + expect(assigns[:page_title]).to be_nil end end context "when work has no fandom" do - it "assigns @page_title with a placeholder for the fandom" do + it "assigns @page_subtitle with a placeholder for the fandom" do allow_any_instance_of(Work).to receive(:fandoms).and_return([]) get :show, params: { work_id: work.id, id: work.chapters.first.id } expect(response).to have_http_status(:ok) - expect(assigns[:page_title]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - No fandom specified [") + expect(assigns[:page_subtitle]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - No fandom specified") + expect(assigns[:page_title]).to be_nil end end context "when work has two fandoms" do - it "assigns @page_title with the fandoms deliminated by commas" do + it "assigns @page_subtitle with the fandoms deliminated by commas" do first = create(:fandom, name: "The First") second = create(:fandom, name: "The Second") allow_any_instance_of(Work).to receive(:fandoms).and_return([first, second]) get :show, params: { work_id: work.id, id: work.chapters.first.id } expect(response).to have_http_status(:ok) - expect(assigns[:page_title]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - The First, The Second [") + expect(assigns[:page_subtitle]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - The First, The Second") + expect(assigns[:page_title]).to be_nil end end @@ -242,7 +247,8 @@ allow_any_instance_of(Work).to receive(:fandoms).and_return(fandoms) get :show, params: { work_id: work.id, id: work.chapters.first.id } expect(response).to have_http_status(:ok) - expect(assigns[:page_title]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - Multifandom [") + expect(assigns[:page_subtitle]).to start_with("#{work.title} - Chapter 1 - #{user.pseuds.first.name} - Multifandom") + expect(assigns[:page_title]).to be_nil end end @@ -265,7 +271,7 @@ expect(assigns[:chapters]).to eq [work.chapters.first, second_chapter, third_chapter] expect(assigns[:previous_chapter]).to eq work.chapters.first expect(assigns[:next_chapter]).to eq third_chapter - expect(assigns[:page_title]).to start_with("My title is long enough - Chapter 2 - #{user.pseuds.first.name} - #{tag.name} [") + expect(assigns[:page_subtitle]).to start_with("My title is long enough - Chapter 2 - #{user.pseuds.first.name} - #{tag.name}") expect(assigns[:kudos]).to eq [kudo] expect(assigns[:subscription]).to be_nil end diff --git a/spec/controllers/series_controller_spec.rb b/spec/controllers/series_controller_spec.rb index aeebe05b850..6f4836630f6 100644 --- a/spec/controllers/series_controller_spec.rb +++ b/spec/controllers/series_controller_spec.rb @@ -253,19 +253,21 @@ end end - it "assigns page title for series" do + it "assigns page subtitle for series" do work = create(:work, fandom_string: "Fandom", authors: [user.default_pseud]) series_with_work = create(:series, works: [work], authors: [user.default_pseud]) get :show, params: { id: series_with_work } - expect(assigns[:page_title]).to eq("#{series_with_work.title} - #{user.default_pseud.name} - Fandom [#{ArchiveConfig.APP_NAME}]") + expect(assigns[:page_subtitle]).to eq("#{series_with_work.title} - #{user.default_pseud.name} - Fandom") + expect(assigns[:page_title]).to be_nil end - it "assigns page title for anonymous series" do + it "assigns page subtitle for anonymous series" do anonymous_collection = create(:anonymous_collection) anonymous_work = create(:work, fandom_string: "Fandom", collections: [anonymous_collection]) series_with_work = create(:series, works: [anonymous_work]) get :show, params: { id: series_with_work } - expect(assigns[:page_title]).to eq("#{series_with_work.title} - Anonymous - Fandom [#{ArchiveConfig.APP_NAME}]") + expect(assigns[:page_subtitle]).to eq("#{series_with_work.title} - Anonymous - Fandom") + expect(assigns[:page_title]).to be_nil end it "assigns page subtitle for unrevealed series" do diff --git a/spec/controllers/works/default_rails_actions_spec.rb b/spec/controllers/works/default_rails_actions_spec.rb index 34850a1f1b7..b7c5fe4a8a6 100644 --- a/spec/controllers/works/default_rails_actions_spec.rb +++ b/spec/controllers/works/default_rails_actions_spec.rb @@ -371,7 +371,7 @@ def call_with_params(params) get :show, params: { id: work_no_fandoms.id } - expect(assigns(:page_title)).to include "No fandom specified" + expect(assigns(:page_subtitle)).to include "No fandom specified" end it "assigns @page_subtitle with unrevealed work and not @page_title" do diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 57cbb22c387..8b7b17d82be 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -3,6 +3,36 @@ require "spec_helper" describe ApplicationHelper do + describe "#browser_page_title" do + it "returns page_title if set" do + expect(helper.browser_page_title("Title", "Subtitle")).to eq("Title") + end + + it "appends app name to page_subtitle" do + expect(helper.browser_page_title(nil, "Series Title - Author - Fandom")) + .to eq("Series Title - Author - Fandom | #{ArchiveConfig.APP_NAME}") + end + + it "generates title from controller/action when no title or subtitle" do + controller = double("controller", action_name: "show", controller_name: "works") + allow(helper).to receive(:controller).and_return(controller) + allow(helper).to receive(:process_title).with("show").and_return("Show") + allow(helper).to receive(:process_title).with("work").and_return("Work") + + expect(helper.browser_page_title(nil, nil)) + .to eq("Show Work | #{ArchiveConfig.APP_NAME}") + end + + it "generates title from controller name for index action" do + controller = double("controller", action_name: "index", controller_name: "works") + allow(helper).to receive(:controller).and_return(controller) + allow(helper).to receive(:process_title).with("works").and_return("Works") + + expect(helper.browser_page_title(nil, nil)) + .to eq("Works | #{ArchiveConfig.APP_NAME}") + end + end + describe "#creation_id_for_css_classes" do context "when creation is ExternalWork" do let(:external_work) { create(:external_work) }