Skip to content
16 changes: 9 additions & 7 deletions app/helpers/share_helper.rb
Comment thread
domvrk marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ module ShareHelper
# Get work title, word count, and creators and add app short name,
# but do not add formatting so it can be link text for Tumblr sharing.
def get_tumblr_embed_link_title(work)
title = work.title + " (#{work.word_count} #{ts('words')})"
pseud = text_byline(work)
"#{title} #{ts("by")} #{pseud} #{ts("[#{ArchiveConfig.APP_SHORT_NAME}]")}"
t("share_helper.tumblr_embed_link_title",
title: work.title,
count: work.word_count,
creators: text_byline(work, visibility: "public"),
app_name: ArchiveConfig.APP_SHORT_NAME)
end

def get_tweet_text(work)
if work.unrevealed?
ts("Mystery Work")
t("share_helper.unrevealed_tweet_text")
else
names = text_byline(work)
names = text_byline(work, visibility: "public")
fandoms = short_fandom_string(work)
"#{work.title} by #{names} - #{fandoms}".truncate(95)
end
Expand All @@ -21,7 +23,7 @@ def get_tweet_text(work)
def get_tweet_text_for_bookmark(bookmark)
return unless bookmark.bookmarkable.is_a?(Work)

names = text_byline(bookmark.bookmarkable)
names = text_byline(bookmark.bookmarkable, visibility: "public")
fandoms = short_fandom_string(bookmark.bookmarkable)
"Bookmark of #{bookmark.bookmarkable.title} by #{names} - #{fandoms}".truncate(83)
end
Expand Down Expand Up @@ -51,7 +53,7 @@ def sharing_button(site, address, text, target: nil)
private

def short_fandom_string(work)
work.fandoms.size > 2 ? ts("Multifandom") : work.fandom_string
work.fandoms.size > 2 ? t("share_helper.multi_fandom_short_string") : work.fandom_string
end

# Being able to add line breaks in the sharing templates makes the code
Expand Down
6 changes: 6 additions & 0 deletions config/locales/helpers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ en:
default_label: QR code
series_helper:
series_description_html: Part %{index} of %{series_link}
share_helper:
multi_fandom_short_string: Multifandom
tumblr_embed_link_title:
one: "%{title} (%{count} word) by %{creators} [%{app_name}]"
other: "%{title} (%{count} words) by %{creators} [%{app_name}]"
unrevealed_tweet_text: Mystery Work
tags_helper:
get_symbol_link:
title: Symbols key
Expand Down
10 changes: 10 additions & 0 deletions features/step_definitions/share_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
expect(page).to have_css("li.tumblr", text: "Tumblr")
end
end

Then "the {word} share link should include {string}" do |site, text|
href = CGI.unescape(find("#share li.#{site} a")[:href])
expect(href).to include(text)
end

Then "the {word} share link should not include {string}" do |site, text|
href = CGI.unescape(find("#share li.#{site} a")[:href])
expect(href).not_to include(text)
end
14 changes: 14 additions & 0 deletions features/works/work_share.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ Feature: Share Works
Then the url should not include "share"
# Shown when the share url is accessed directly
And I should not see "Sorry, you need to have JavaScript enabled for this."

@javascript
Scenario: Share hides the creator for anonymous works
Given the anonymous collection "AnonCollection"
And I am logged in as "testuser"
And I post the work "AnonWork" in the collection "AnonCollection"
When I view the work "AnonWork"
And I follow "Share"
Then I should see "by Anonymous" within "#share textarea"
And I should not see "testuser" within "#share textarea"
And the twitter share link should include "by Anonymous"
And the twitter share link should not include "testuser"
And the tumblr share link should include "by Anonymous"
And the tumblr share link should not include "testuser"
27 changes: 22 additions & 5 deletions spec/helpers/byline_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,30 @@
let(:user) { create(:user, login: "Joe") }
let(:work) { create(:work, authors: [user.default_pseud], collections: [create(:anonymous_collection)]) }

before do
allow(helper).to receive(:logged_in_as_admin?).and_return(true)
context "when logged in as an admin" do
before do
allow(helper).to receive(:logged_in_as_admin?).and_return(true)
end

it "includes no links for partially anonymous byline shown to admins" do
expect(helper.text_byline(work)).to_not include("href")
expect(helper.text_byline(work)).to eq("Anonymous [Joe]")
end
end

it "includes no links for partially anonymous byline shown to admins" do
expect(helper.text_byline(work)).to_not include("href")
expect(helper.text_byline(work)).to eq("Anonymous [Joe]")
context "when logged in as the creator" do
before do
allow(helper).to receive(:logged_in_as_admin?).and_return(false)
allow(helper).to receive(:is_author_of?).and_return(true)
end

it "returns partially anonymous byline" do
expect(helper.text_byline(work)).to eq("Anonymous [Joe]")
end

it "returns only Anonymous when visibility is public" do
expect(helper.text_byline(work, visibility: "public")).to eq("Anonymous")
end
end
end
end
2 changes: 1 addition & 1 deletion spec/helpers/share_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe "#get_tumblr_embed_link_title" do
context "on anonymous works" do
let(:work) { build_stubbed(:work, in_anon_collection: true) }
let(:work) { build_stubbed(:work, in_anon_collection: true, word_count: 0) }

it "does not link to a user's profile" do
expect(helper.get_tumblr_embed_link_title(work)).to include("by Anonymous")
Expand Down
Loading