Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-5649 Sort authors_to_sort_on to match byline #3555

Merged
merged 5 commits into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/models/work.rb
Expand Up @@ -1097,12 +1097,11 @@ def self.in_series(series)

SORTED_AUTHOR_REGEX = %r{^[\+\-=_\?!'"\.\/]}

# TODO drop unused database column authors_to_sort_on
def authors_to_sort_on
if self.anonymous?
"Anonymous"
else
self.pseuds.map(&:name).join(", ").downcase.gsub(SORTED_AUTHOR_REGEX, '')
self.pseuds.sort.map(&:name).join(", ").downcase.gsub(SORTED_AUTHOR_REGEX, '')
end
end

Expand Down
11 changes: 7 additions & 4 deletions spec/models/work_spec.rb
Expand Up @@ -297,7 +297,7 @@
let(:work) { build(:work) }

context "when the pseuds start with special characters" do
it "should remove those characters" do
it "removes those characters" do
allow(work).to receive(:pseuds).and_return [Pseud.new(name: "-jolyne")]
expect(work.authors_to_sort_on).to eq "jolyne"

Expand All @@ -307,24 +307,27 @@
end

context "when the pseuds start with numbers" do
it "should not remove numbers" do
it "does not remove numbers" do
allow(work).to receive(:pseuds).and_return [Pseud.new(name: "007james")]
expect(work.authors_to_sort_on).to eq "007james"
end
end

context "when the work is anonymous" do
it "should set the author sorting to Anonymous" do
it "returns Anonymous" do
work.in_anon_collection = true
allow(work).to receive(:pseuds).and_return [Pseud.new(name: "stealthy")]
expect(work.authors_to_sort_on).to eq "Anonymous"
end
end

context "when the work has multiple pseuds" do
it "should combine them with commas" do
it "sorts them like the byline then joins them with commas" do
allow(work).to receive(:pseuds).and_return [Pseud.new(name: "diavolo"), Pseud.new(name: "doppio")]
expect(work.authors_to_sort_on).to eq "diavolo, doppio"

allow(work).to receive(:pseuds).and_return [Pseud.new(name: "Tiziano"), Pseud.new(name: "squalo")]
expect(work.authors_to_sort_on).to eq "squalo, tiziano"
end
end
end
Expand Down