Skip to content

Commit

Permalink
AO3-5649 Sort authors_to_sort_on to match byline (#3555)
Browse files Browse the repository at this point in the history
* AO3-5649 Sort authors_to_sort_on to match byline

* AO3-5649 Sort the pseuds themselves, not the names

* Update work spec
  • Loading branch information
redsummernight authored and sarken committed Sep 12, 2019
1 parent 73f1315 commit dfdb367
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/models/work.rb
Expand Up @@ -1100,12 +1100,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

0 comments on commit dfdb367

Please sign in to comment.