Skip to content
Open
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
3 changes: 1 addition & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '...'}
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions app/controllers/series_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions app/helpers/works_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/locales/helpers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion features/gift_exchanges/challenge_yuletide.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One extra (optional) note: Since this test is being updated, could you add a And the app name is "Example Archive" to the list of Given steps? This prevents the test from failing when a custom app name is set in the config.

Then I should see "Anonymous"
And I should not see "myname1"
And I should not see "myname3"
Expand Down
6 changes: 3 additions & 3 deletions features/other_a/page_title.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
30 changes: 18 additions & 12 deletions spec/controllers/chapters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions spec/controllers/series_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/works/default_rails_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Loading