Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
AO3-5269 Fix regex for getting sortable work authors #3199
Conversation
redsummernight
added
the
Awaiting review
label
Dec 5, 2017
| + describe "sorting results" do | ||
| + describe "by authors" do | ||
| + before do | ||
| + %w(-zzz _yasuho 21st_wombat 007aardvark 6tasmanian_devil).each do |pseud_name| |
elzj
Dec 5, 2017
Owner
My only thought here is that since it's the work method that was broken, maybe we should test the behavior of it primarily in a work spec unit test. Then when we know it's saving the values correctly, we might not need to create as many works here and we can save some runtime that way.
| @@ -102,6 +102,26 @@ | ||
| end | ||
| end | ||
| + describe "authors to sort on" do |
elzj
Dec 7, 2017
Owner
So this is totally fine, but while I'm nitpicking, I'd say you want the spec names to be a little more readable, and, whenever possible, to not touch the database if you can avoid it. I would make it something like this:
describe "#set_author_sorting" do
let(:work) { build(:work) }
context "when the pseuds start with special characters" do
it "should remove those characters" do
work.authors = [Pseud.new(name: "-jolyne")]
work.set_author_sorting
expect(work.authors_to_sort_on).to eq "jolyne"
work.authors = [Pseud.new(name: "_hermes")]
work.set_author_sorting
expect(work.authors_to_sort_on).to eq "hermes"
end
end
context "when the pseuds start with numbers" do
it "should not remove them" do
work.authors = [Pseud.new(name: "007james")]
work.set_author_sorting
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
work.in_anon_collection = true
work.authors = [Pseud.new(name: "stealthy")]
work.set_author_sorting
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
work.authors = [Pseud.new(name: "diavolo"), Pseud.new(name: "doppio")]
work.set_author_sorting
expect(work.authors_to_sort_on).to eq "diavolo, doppio"
end
end
end
There, you can add as many examples as you like, and it's not going to add significantly to the test runtime because nothing gets saved. And then the integration test in the feature will confirm that the whole thing works together - that the field gets saved and that we can sort on it.
redsummernight
Dec 8, 2017
Contributor
Thanks! It didn't occur to me to just call work.set_author_sorting, I'll update the specs.
Should I remove or keep the new tests in spec/models/work_search_form_spec.rb?
redsummernight commentedDec 5, 2017
Issue
https://otwarchive.atlassian.net/browse/AO3-5269
Purpose
The hyphen should be escaped, otherwise we're removing the first character if it's anything in the range from "+" to "=".
Testing
See issue.