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-5262 AO3-3576: Move query cleaning out of the works controller, fix sa"m/f"rodo #3189
Conversation
| @@ -0,0 +1,100 @@ | ||
| +# This is currently being tested without loading most of Rails |
| +# This is currently being tested without loading most of Rails | ||
| +# so beware of changes that rely on other classes or Rails methods | ||
| +class QueryCleaner | ||
| + |
| + attr_reader :params | ||
| + | ||
| + SORT_OPTIONS = [ | ||
| + ['Author', 'authors_to_sort_on'], |
| + | ||
| + SORT_OPTIONS = [ | ||
| + ['Author', 'authors_to_sort_on'], | ||
| + ['Title', 'title_to_sort_on'], |
| + ['Date Posted', 'created_at'], | ||
| + ['Date Updated', 'revised_at'], | ||
| + ['Word Count', 'word_count'], | ||
| + ['Hits', 'hits'], |
| + ['Date Updated', 'revised_at'], | ||
| + ['Word Count', 'word_count'], | ||
| + ['Hits', 'hits'], | ||
| + ['Kudos', 'kudos_count'], |
| + ['Word Count', 'word_count'], | ||
| + ['Hits', 'hits'], | ||
| + ['Kudos', 'kudos_count'], | ||
| + ['Comments', 'comments_count'], |
| + ['Hits', 'hits'], | ||
| + ['Kudos', 'kudos_count'], | ||
| + ['Comments', 'comments_count'], | ||
| + ['Bookmarks', 'bookmarks_count'] |
| + # turn word_count or word count or words into just "word" eg | ||
| + sortby = m[2].gsub(/\s*_?count/, '').singularize | ||
| + | ||
| + sort_column = SORT_OPTIONS.find { |opt, _| opt =~ /#{sortby}/i }&.last |
| + end | ||
| + | ||
| + def sort_direction(sortdir) | ||
| + if sortdir == '>' || sortdir == 'ascending' |
houndci-bot
Nov 30, 2017
Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
| + def sort_direction(sortdir) | ||
| + if sortdir == '>' || sortdir == 'ascending' | ||
| + 'asc' | ||
| + elsif sortdir == '<' || sortdir == 'descending' |
houndci-bot
Nov 30, 2017
Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
| + | ||
| + # If we've stripped out everything in the query, null it out | ||
| + def clean_up_query | ||
| + if params[:query] =~ /^\s*$/ |
| @@ -440,7 +428,7 @@ def sort_values | ||
| # extract the pretty name | ||
| def name_for_sort_column(sort_column) | ||
| - Hash[SORT_OPTIONS.collect {|v| [ v[1], v[0] ]}][sort_column] | ||
| + Hash[sort_options.collect {|v| [ v[1], v[0] ]}][sort_column] |
houndci-bot
Nov 30, 2017
Prefer map over collect.
Space between { and | missing.
Space inside square brackets detected.
Space missing inside }.
| +require 'active_support/inflector' | ||
| +require File.expand_path('../../app/models/search/query_cleaner', File.dirname(__FILE__)) | ||
| + | ||
| +describe QueryCleaner do |
| +require File.expand_path('../../app/models/search/query_cleaner', File.dirname(__FILE__)) | ||
| + | ||
| +describe QueryCleaner do | ||
| + describe "#clean" do |
| +require 'active_support/inflector' | ||
| +require File.expand_path('../../app/models/search/query_cleaner', File.dirname(__FILE__)) | ||
| + | ||
| +describe QueryCleaner do |
| +require File.expand_path('../../app/models/search/query_cleaner', File.dirname(__FILE__)) | ||
| + | ||
| +describe QueryCleaner do | ||
| + describe "#clean" do |
elzj
added
the
Awaiting review
label
Nov 30, 2017
sarken
added
Priority: Broken on Test (High)
Reviewed: Ready to Merge
and removed
Awaiting review
labels
Dec 1, 2017
sarken
merged commit 9fabec2
into
otwcode:master
Dec 1, 2017
redsummernight
changed the title from
AO3-5262: Move query cleaning out of the works controller
to
AO3-5262 AO3-3576: Move query cleaning out of the works controller, fix sa"m/f"rodo
Dec 2, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
elzj commentedNov 30, 2017
•
Edited 1 time
-
elzj
Nov 30, 2017
Issue
https://otwarchive.atlassian.net/browse/AO3-5262
https://otwarchive.atlassian.net/browse/AO3-3576
Purpose
Extracts the query cleanup code from the works controller into a separate class. Also ended up fixing the weird category-escaping-overreach bug.
Testing
Behavior should be the same, other than the category tag escaping, which should now be case-insensitive, but should only match when the letters are not part of larger words.