From 8749c43b3ea0dba7f45d87899cbda9fc7c5670a1 Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 10 Jan 2013 17:45:52 -0500 Subject: [PATCH] refactored search --- app/assets/javascripts/notes.js | 2 +- app/assets/javascripts/pools.js | 2 +- app/controllers/forum_topics_controller.rb | 4 +- app/controllers/tag_aliases_controller.rb | 2 +- .../tag_implications_controller.rb | 2 +- app/controllers/wiki_pages_controller.rb | 2 +- app/helpers/application_helper.rb | 5 + app/logical/moderator/ip_addr_search.rb | 12 +- app/logical/post_sets/post.rb | 2 +- app/models/advertisement.rb | 3 +- app/models/artist.rb | 121 ++++++++-------- app/models/artist_version.rb | 1 + app/models/ban.rb | 1 + app/models/comment.rb | 79 ++++++----- app/models/dmail.rb | 84 +++++++++-- app/models/forum_post.rb | 50 ++++++- app/models/forum_topic.rb | 29 +++- app/models/ip_ban.rb | 11 ++ app/models/janitor_trial.rb | 11 ++ app/models/note.rb | 42 +++++- app/models/note_version.rb | 15 ++ app/models/pool.rb | 28 +++- app/models/pool_version.rb | 20 ++- app/models/post.rb | 132 ++++++++++++++---- app/models/post_appeal.rb | 25 +++- app/models/post_flag.rb | 30 +++- app/models/post_version.rb | 33 ++++- app/models/tag.rb | 39 +++++- app/models/tag_alias.rb | 28 +++- app/models/tag_implication.rb | 27 +++- app/models/tag_subscription.rb | 5 + app/models/upload.rb | 31 +++- app/models/user.rb | 50 ++++++- app/models/user_feedback.rb | 35 ++++- app/models/wiki_page.rb | 35 +++-- app/models/wiki_page_version.rb | 24 +++- app/presenters/user_presenter.rb | 14 +- app/views/artists/_secondary_links.html.erb | 2 +- app/views/artists/search.html.erb | 9 +- app/views/comments/search.html.erb | 10 +- app/views/dmails/_secondary_links.html.erb | 4 +- app/views/dmails/search.html.erb | 12 +- app/views/forum_posts/search.html.erb | 9 +- .../dashboards/_activity_artist.html.erb | 2 +- .../dashboards/_activity_note.html.erb | 2 +- .../dashboards/_activity_tag.html.erb | 2 +- .../dashboards/_activity_wiki_page.html.erb | 2 +- .../dashboards/_search_ip_addr.html.erb | 4 +- app/views/moderator/ip_addrs/search.html.erb | 16 +-- app/views/note_versions/index.html.erb | 2 +- app/views/notes/search.html.erb | 9 +- app/views/pools/_secondary_links.html.erb | 2 +- app/views/pools/search.html.erb | 9 +- app/views/post_versions/search.html.erb | 8 +- app/views/posts/show.html.erb | 4 +- app/views/tags/_secondary_links.html.erb | 2 +- app/views/tags/search.html.erb | 17 ++- app/views/uploads/show.html.erb | 2 +- .../user_feedbacks/_secondary_links.html.erb | 4 +- app/views/users/_secondary_links.html.erb | 2 +- app/views/users/index.html.erb | 10 +- app/views/users/search.html.erb | 12 +- .../wiki_pages/_secondary_links.html.erb | 4 +- config/danbooru_default_config.rb | 7 + test/factories/upload.rb | 1 + .../artist_versions_controller_test.rb | 2 +- test/functional/ip_bans_controller_test.rb | 2 +- .../janitor_trials_controller_test.rb | 2 +- .../moderator/ip_addrs_controller_test.rb | 6 +- .../note_versions_controller_test.rb | 2 +- .../pool_versions_controller_test.rb | 2 +- .../post_appeals_controller_test.rb | 2 +- test/functional/post_flags_controller_test.rb | 2 +- .../post_versions_controller_test.rb | 2 +- .../functional/tag_aliases_controller_test.rb | 2 +- .../tag_implications_controller_test.rb | 2 +- test/functional/tags_controller_test.rb | 2 +- test/functional/uploads_controller_test.rb | 2 +- .../user_feedbacks_controller_test.rb | 2 +- .../wiki_page_versions_controller_test.rb | 2 +- test/functional/wiki_pages_controller_test.rb | 2 +- test/unit/advertisement_test.rb | 1 + test/unit/artist_test.rb | 2 +- test/unit/sources/pixiv_test.rb | 2 +- test/unit/upload_test.rb | 4 +- 85 files changed, 946 insertions(+), 304 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 3f0005cec..8d004512d 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -397,7 +397,7 @@ Danbooru.Note = { var $this = $(this); var id = $this.data("id"); if (id.match(/\d/)) { - window.location.href = "/note_versions?search[note_id_eq]=" + id; + window.location.href = "/note_versions?search[note_id]=" + id; } $(this).dialog("close"); } diff --git a/app/assets/javascripts/pools.js b/app/assets/javascripts/pools.js index c32c34558..6fbde52ce 100644 --- a/app/assets/javascripts/pools.js +++ b/app/assets/javascripts/pools.js @@ -17,7 +17,7 @@ $("#c-pool-elements #a-new input[type=text]").autocomplete({ source: function(req, resp) { $.getJSON( - "/pools.json?search[name_contains]=" + req.term, + "/pools.json?search[name_matches]=" + req.term, function(data) { resp(data.map(function(x) {return x.name;})); } diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 41a475371..b7d079325 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -25,7 +25,7 @@ class ForumTopicsController < ApplicationController def show @forum_topic = ForumTopic.find(params[:id]) - @forum_posts = ForumPost.search(:topic_id_eq => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) + @forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) respond_with(@forum_topic) end @@ -72,7 +72,7 @@ private if params[:title] params[:search] ||= {} - params[:search][:title_eq] = params.delete(:title) + params[:search][:title] = params.delete(:title) end end diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index ced1c9984..805f1b9e1 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -24,7 +24,7 @@ class TagAliasesController < ApplicationController def create @tag_alias = TagAlias.create(params[:tag_alias]) - respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id_eq => @tag_alias.id})) + respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id => @tag_alias.id})) end def destroy diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 7ff9e910f..1360ead17 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -15,7 +15,7 @@ class TagImplicationsController < ApplicationController def create @tag_implication = TagImplication.create(params[:tag_implication]) - respond_with(@tag_implication, :location => tag_implications_path(:search => {:id_eq => @tag_implication.id})) + respond_with(@tag_implication, :location => tag_implications_path(:search => {:id => @tag_implication.id})) end def destroy diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index cb4bbed15..b0eb63220 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -68,7 +68,7 @@ private def normalize_search_params if params[:title] params[:search] ||= {} - params[:search][:title_equals] = params.delete(:title) + params[:search][:title] = params.delete(:title) end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1df0d24de..6ad9dd5c1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,6 +75,11 @@ module ApplicationHelper submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id]) end + def search_field(method, options = {}) + name = options[:label] || method.titleize + raw '
' + end + protected def nav_link_match(controller, url) url =~ case controller diff --git a/app/logical/moderator/ip_addr_search.rb b/app/logical/moderator/ip_addr_search.rb index 62c720d36..1ac29d848 100644 --- a/app/logical/moderator/ip_addr_search.rb +++ b/app/logical/moderator/ip_addr_search.rb @@ -8,12 +8,12 @@ module Moderator end def execute - if params[:user_id_eq] - search_by_user_id(params[:user_id_eq].split(/,/)) - elsif params[:user_name_eq] - search_by_user_name(params[:user_name_eq].split(/,/)) - elsif params[:ip_addr_eq] - search_by_ip_addr(params[:ip_addr_eq].split(/,/)) + if params[:user_id] + search_by_user_id(params[:user_id].split(/,/)) + elsif params[:user_name] + search_by_user_name(params[:user_name].split(/,/)) + elsif params[:ip_addr] + search_by_ip_addr(params[:ip_addr].split(/,/)) else [] end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index c686870a1..30c47726d 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -46,7 +46,7 @@ module PostSets end def artist - ::Artist.name_equals(tag_string).first + ::Artist.name_matches(tag_string).first end def is_single_tag? diff --git a/app/models/advertisement.rb b/app/models/advertisement.rb index 6318414be..26a2bb095 100644 --- a/app/models/advertisement.rb +++ b/app/models/advertisement.rb @@ -29,7 +29,7 @@ class Advertisement < ActiveRecord::Base end def date_prefix - created_at.strftime("%Y%m%d") + created_at.try(:strftime, "%Y%m%d") end def image_path @@ -43,6 +43,7 @@ class Advertisement < ActiveRecord::Base def file=(f) if f.size > 0 self.file_name = unique_identifier + File.extname(f.original_filename) + FileUtils.mkdir_p(File.dirname(image_path)) if f.local_path FileUtils.cp(f.local_path, image_path) diff --git a/app/models/artist.rb b/app/models/artist.rb index 1f07120ab..4687bb4e5 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -14,8 +14,6 @@ class Artist < ActiveRecord::Base accepts_nested_attributes_for :wiki_page attr_accessible :body, :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes, :is_active, :as => [:member, :privileged, :contributor, :janitor, :moderator, :default, :admin] attr_accessible :is_banned, :as => :admin - scope :active, where("is_active = true") - scope :banned, where("is_banned = true") module UrlMethods extend ActiveSupport::Concern @@ -191,67 +189,72 @@ class Artist < ActiveRecord::Base end module SearchMethods - extend ActiveSupport::Concern + def active + where("is_active = true") + end + + def banned + where("is_banned = true") + end + + def url_matches(string) + matches = find_all_by_url(string).map(&:id) + + if matches.any? + where("id in (?)", matches) + else + where("false") + end + end - module ClassMethods - def url_matches(string) - matches = find_all_by_url(string).map(&:id) + def other_names_match(string) + where("other_names_index @@ to_tsquery('danbooru', ?)", Artist.normalize_name(string)) + end + + def group_name_matches(name) + stripped_name = normalize_name(name).to_escaped_for_sql_like + where("group_name LIKE ? ESCAPE E'\\\\'", stripped_name) + end + + def name_matches(name) + stripped_name = normalize_name(name).to_escaped_for_sql_like + where("name LIKE ? ESCAPE E'\\\\'", stripped_name) + end + + def any_name_matches(name) + stripped_name = normalize_name(name).to_escaped_for_sql_like + where("(name LIKE ? ESCAPE E'\\\\' OR other_names_index @@ to_tsquery('danbooru', ?))", stripped_name, normalize_name(name)) + end + + def search(params) + q = active + return q if params.blank? - if matches.any? - where("id in (?)", matches) - else - where("false") - end - end - - def other_names_match(string) - where("other_names_index @@ to_tsquery('danbooru', ?)", Artist.normalize_name(string)) - end - - def group_name_matches(name) - stripped_name = normalize_name(name).to_escaped_for_sql_like - where("group_name LIKE ? ESCAPE E'\\\\'", stripped_name) - end - - def name_matches(name) - stripped_name = normalize_name(name).to_escaped_for_sql_like - where("name LIKE ? ESCAPE E'\\\\'", stripped_name) - end - - def any_name_matches(name) - stripped_name = normalize_name(name).to_escaped_for_sql_like - where("(name LIKE ? ESCAPE E'\\\\' OR other_names_index @@ to_tsquery('danbooru', ?))", stripped_name, normalize_name(name)) - end - - def search(params) - q = active + case params[:name] + when /^http/ + q = q.url_matches(params[:name]) - case params[:name] - when /^http/ - q = q.url_matches(params[:name]) - - when /name:(.+)/ - q = q.name_matches($1) - - when /other:(.+)/ - q = q.other_names_match($1) - - when /group:(.+)/ - q = q.group_name_matches($1) - - when /status:banned/ - q = q.banned - - when /./ - q = q.any_name_matches(params[:name]) - end - - if params[:id] - q = q.where("id = ?", params[:id]) - end + when /name:(.+)/ + q = q.name_matches($1) - q + when /other:(.+)/ + q = q.other_names_match($1) + + when /group:(.+)/ + q = q.group_name_matches($1) + + when /status:banned/ + q = q.banned + + when /./ + q = q.any_name_matches(params[:name]) end + + if params[:id] + q = q.where("id = ?", params[:id]) + end + + q end end @@ -263,7 +266,7 @@ class Artist < ActiveRecord::Base include NoteMethods include TagMethods include BanMethods - include SearchMethods + extend SearchMethods def status if is_banned? diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index a9c1e5fb7..437b96a04 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -4,6 +4,7 @@ class ArtistVersion < ActiveRecord::Base def self.search(params) q = scoped + return q if params.blank? if params[:artist_id] q = q.where("artist_id = ?", params[:artist_id].to_i) diff --git a/app/models/ban.rb b/app/models/ban.rb index e74bd854c..ab3766161 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -13,6 +13,7 @@ class Ban < ActiveRecord::Base def self.search(params) q = scoped + return q if params.blank? if params[:banner_name] q = q.where("banner_id = (select _.id from users _ where lower(_.name) = ?)", params[:banner_name].downcase) diff --git a/app/models/comment.rb b/app/models/comment.rb index 139531315..1c12ba890 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -9,57 +9,60 @@ class Comment < ActiveRecord::Base attr_accessible :body, :post_id attr_accessor :do_not_bump_post - scope :recent, :order => "comments.id desc", :limit => 6 - module SearchMethods - extend ActiveSupport::Concern + def recent + order("comments.id desc").limit(6) + end - module ClassMethods - def body_matches(query) - where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC") + def body_matches(query) + where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC") + end + + def hidden(user) + where("score < ?", user.comment_threshold) + end + + def visible(user) + where("score >= ?", user.comment_threshold) + end + + def post_tags_match(query) + joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query) + end + + def for_creator(user_id) + where("creator_id = ?", user_id) + end + + def for_creator_name(user_name) + where("creator_id = (select _.id from users _ where lower(_.name) = lower(?))", user_name) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:body_matches] + q = q.body_matches(params[:body_matches]) end - def hidden(user) - where("score < ?", user.comment_threshold) + if params[:post_tags_match] + q = q.post_tags_match(params[:post_tags_match]) end - def visible(user) - where("score >= ?", user.comment_threshold) + if params[:creator_name] + q = q.for_user_name(params[:creator_name]) end - def post_tags_match(query) - joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query) + if params[:creator_id] + q = q.for_creator(params[:creator_id].to_i) end - def for_creator(user_id) - where("creator_id = ?", user_id) - end - - def for_creator_name(user_name) - where("creator_id = (select _.id from users _ where lower(_.name) = lower(?))", user_name) - end - - def search(params) - q = scoped - - if params[:body_matches] - q = q.body_matches(params[:body_matches]) - end - - if params[:post_tags_match] - q = q.post_tags_match(params[:post_tags_match]) - end - - if params[:creator_name] - q = q.for_user_name(params[:creator_name]) - end - - q - end + q end end - include SearchMethods + extend SearchMethods def initialize_creator self.creator_id = CurrentUser.user.id diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 1451bca83..b2fc9fb76 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -10,16 +10,6 @@ class Dmail < ActiveRecord::Base after_create :update_recipient after_create :send_dmail attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name - scope :for, lambda {|user| where(["owner_id = ?", user])} - scope :inbox, where("to_id = owner_id") - scope :sent, where("from_id = owner_id") - scope :active, where(["is_deleted = ?", false]) - scope :deleted, where(["is_deleted = ?", true]) - scope :search_message, lambda {|query| where(["message_index @@ plainto_tsquery(?)", query])} - scope :unread, where("is_read = false and is_deleted = false") - scope :visible, lambda {where("owner_id = ?", CurrentUser.id)} - scope :to_name_matches, lambda {|name| where("to_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} - scope :from_name_matches, lambda {|name| where("from_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} module AddressMethods def to_name @@ -82,8 +72,82 @@ class Dmail < ActiveRecord::Base end end + module SearchMethods + def for(user) + where("owner_id = ?", user) + end + + def inbox + where("to_id = owner_id") + end + + def sent + where("from_id = owner_id") + end + + def active + where("is_deleted = ?", false) + end + + def deleted + where("is_deleted = ?", true) + end + + def search_message(query) + where("message_index @@ plainto_tsquery(?)", query) + end + + def unread + where("is_read = false and is_deleted = false") + end + + def visible + where("owner_id = ?", CurrentUser.id) + end + + def to_name_matches(name) + where("to_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase) + end + + def from_name_matches(name) + where("from_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:message_matches] + q = q.search_message(params[:message_matches]) + end + + if params[:owner_id] + q = q.for(params[:owner_id].to_i) + end + + if params[:to_name] + q = q.to_name_matches(params[:to_name]) + end + + if params[:to_id] + q = q.where("to_id = ?", params[:to_id].to_i) + end + + if params[:from_name] + q = q.from_name_matches(params[:from_name]) + end + + if params[:from_id] + q = q.where("from_id = ?", params[:from_id].to_i) + end + + q + end + end + include AddressMethods include FactoryMethods + extend SearchMethods def quoted_body "[quote]#{body}[/quote]" diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index d69755da3..b54988d98 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -10,9 +10,53 @@ class ForumPost < ActiveRecord::Base validates_presence_of :body, :creator_id validate :validate_topic_is_unlocked before_destroy :validate_topic_is_unlocked - scope :body_matches, lambda {|body| where(["forum_posts.text_index @@ plainto_tsquery(?)", body])} - scope :for_user, lambda {|user_id| where("forum_posts.creator_id = ?", user_id)} - scope :active, where("is_deleted = false") + + module SearchMethods + def body_matches(body) + where("forum_posts.text_index @@ plainto_tsquery(?)", body) + end + + def for_user(user_id) + where("forum_posts.creator_id = ?", user_id) + end + + def creator_name(name) + where("forum_posts.creator_id = (select _.id from users _ where lower(_.name) = ?)", name) + end + + def active + where("is_deleted = false") + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:creator_id] + q = q.where("creator_id = ?", params[:creator_id].to_i) + end + + if params[:topic_id] + q = q.where("topic_id = ?", params[:topic_id].to_i) + end + + if params[:topic_title_matches] + q = q.joins(:topic).where("forum_topics.text_index @@ plainto_tsquery(?)", params[:topic_title_matches]) + end + + if params[:body_matches] + q = q.body_matches(params[:body_matches]) + end + + if params[:creator_name] + q = q.creator_name(params[:creator_name]) + end + + q + end + end + + extend SearchMethods def self.new_reply(params) if params[:topic_id] diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 167361d24..a164d08a1 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -10,10 +10,35 @@ class ForumTopic < ActiveRecord::Base before_validation :initialize_is_deleted, :on => :create validates_presence_of :title, :creator_id validates_associated :original_post - scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])} - scope :active, where("is_deleted = false") accepts_nested_attributes_for :original_post + module SearchMethods + def title_matches(title) + where("text_index @@ plainto_tsquery(?)", title) + end + + def active + where("is_deleted = false") + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:title_matches] + q = q.title_matches(params[:title_matches]) + end + + if params[:title] + q = q.where("title = ?", params[:title]) + end + + q + end + end + + extend SearchMethods + def editable_by?(user) creator_id == user.id || user.is_moderator? end diff --git a/app/models/ip_ban.rb b/app/models/ip_ban.rb index 6548e8aa2..b07932b32 100644 --- a/app/models/ip_ban.rb +++ b/app/models/ip_ban.rb @@ -7,6 +7,17 @@ class IpBan < ActiveRecord::Base def self.is_banned?(ip_addr) exists?(["ip_addr = ?", ip_addr]) end + + def self.search(params) + q = scoped + return q if params.blank? + + if params[:ip_addr] + q = q.where("ip_addr = ?", params[:ip_addr]) + end + + q + end def self.query(user_ids) comments = count_by_ip_addr("comments", user_ids, "creator_id", "ip_addr") diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index 37b65beac..c23ca9ec4 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -6,6 +6,17 @@ class JanitorTrial < ActiveRecord::Base after_destroy :create_feedback validates_presence_of :user before_validation :initialize_creator + + def self.search(params) + q = scoped + return q if params.blank? + + if params[:user_name] + q = q.where("user_id = (select _.id from users _ where lower(_.name) = ?)", params[:user_name].downcase) + end + + q + end def initialize_creator self.creator_id = CurrentUser.id diff --git a/app/models/note.rb b/app/models/note.rb index 19dd309f6..8f9a53b76 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -12,9 +12,45 @@ class Note < ActiveRecord::Base after_save :create_version validate :post_must_not_be_note_locked attr_accessible :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id - scope :active, where("is_active = TRUE") - scope :body_matches, lambda {|query| where("body_index @@ plainto_tsquery(?)", query.scan(/\S+/).join(" & "))} - scope :post_tag_match, lambda {|query| joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query)} + + module SearchMethods + def active + where("is_active = TRUE") + end + + def body_matches(query) + where("body_index @@ plainto_tsquery(?)", query.scan(/\S+/).join(" & ")) + end + + def post_tags_match(query) + joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query) + end + + def creator_name(name) + where("creator_id = (select _.id from users _ where lower(_.name) = ?)", name) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:body_matches] + q = q.body_matches(params[:body_matches]) + end + + if params[:post_tags_match] + q = q.post_tags_match(params[:post_tags_match]) + end + + if params[:creator_name] + q = q.creator_name(params[:creator_name]) + end + + q + end + end + + extend SearchMethods def presenter @presenter ||= NotePresenter.new(self) diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 96076ac5e..bb3eea40a 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -2,6 +2,21 @@ class NoteVersion < ActiveRecord::Base before_validation :initialize_updater belongs_to :updater, :class_name => "User" scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)} + + def self.search(params) + q = scoped + return q if params.blank? + + if params[:updater_id] + q = q.where("updater_id = ?", params[:updater_id].to_i) + end + + if params[:post_id] + q = q.where("post_id = ?", params[:post_id].to_i) + end + + q + end def initialize_updater self.updater_id = CurrentUser.id diff --git a/app/models/pool.rb b/app/models/pool.rb index 100c0f435..6a92aff8a 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -14,7 +14,33 @@ class Pool < ActiveRecord::Base before_destroy :create_mod_action_for_destroy attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default] attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin] - scope :active, where("is_active = true and is_deleted = false") + + module SearchMethods + def active + where("is_active = true and is_deleted = false") + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:name_matches] + q = q.where("name like ? escape E'\\\\'", params[:name_matches]) + end + + if params[:description_matches] + q = q.where("description like ? escape E'\\\\'", params[:description_matches]) + end + + if params[:creator_name] + q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name]) + end + + q + end + end + + extend SearchMethods def self.name_to_id(name) if name =~ /^\d+$/ diff --git a/app/models/pool_version.rb b/app/models/pool_version.rb index c85cf236e..d1235f9b9 100644 --- a/app/models/pool_version.rb +++ b/app/models/pool_version.rb @@ -5,7 +5,25 @@ class PoolVersion < ActiveRecord::Base belongs_to :pool belongs_to :updater, :class_name => "User" before_validation :initialize_updater - scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)} + + module SearchMethods + def for_user(user_id) + where("updater_id = ?", user_id) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:updater_id] + q = q.for_user(params[:updater_id].to_i) + end + + q + end + end + + extend SearchMethods def initialize_updater self.updater_id = CurrentUser.id diff --git a/app/models/post.rb b/app/models/post.rb index 21fc3a866..7cf2e922a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -33,34 +33,6 @@ class Post < ActiveRecord::Base attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default] attr_accessible :is_rating_locked, :is_note_locked, :as => [:janitor, :moderator, :admin] attr_accessible :is_status_locked, :as => [:admin] - scope :pending, where(["is_pending = ?", true]) - scope :pending_or_flagged, where(["(is_pending = ? OR is_flagged = ?)", true, true]) - scope :undeleted, where(["is_deleted = ?", false]) - scope :deleted, where(["is_deleted = ?", true]) - scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)} - scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")} - scope :has_notes, where("last_noted_at is not null") - scope :for_user, lambda {|user_id| where(["uploader_id = ?", user_id])} - scope :available_for_moderation, lambda {|hidden| hidden.present? ? where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id]) : where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} - scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} - scope :tag_match, lambda {|query| PostQueryBuilder.new(query).build} - scope :positive, where("score > 1") - scope :negative, where("score < -1") - scope :updater_name_matches, lambda {|name| where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} - scope :after_id, Proc.new {|num| - if num.present? - where("id > ?", num.to_i).reorder("id asc") - else - where("true") - end - } - scope :before_id, Proc.new {|num| - if num.present? - where("id < ?", num.to_i).reorder("id desc") - else - where("true") - end - } module FileMethods def distribute_files @@ -619,13 +591,13 @@ class Post < ActiveRecord::Base tags = tags.to_s.strip count = get_count_from_cache(tags) if count.nil? - if tags.blank? - count = 1_000_000 + if tags.blank? && Danbooru.config.blank_tag_search_fast_count + count = Danbooru.config.blank_tag_search_fast_count else begin count = Post.tag_match(tags).undeleted.count rescue ActiveRecord::StatementInvalid - count = 1_000_000 + count = Danbooru.config.blank_tag_search_fast_count || 1_000_000 end end @@ -867,6 +839,103 @@ class Post < ActiveRecord::Base end end + module SearchMethods + def pending + where("is_pending = ?", true) + end + + def pending_or_flagged + where("(is_pending = ? OR is_flagged = ?)", true, true) + end + + def undeleted + where("is_deleted = ?", false) + end + + def deleted + where("is_deleted = ?", true) + end + + def visible(user) + Danbooru.config.can_user_see_post_conditions(user) + end + + def commented_before(date) + where("last_commented_at < ?", date).order("last_commented_at DESC") + end + + def has_notes + where("last_noted_at is not null") + end + + def for_user(user_id) + where("uploader_id = ?", user_id) + end + + def available_for_moderation(hidden) + if hidden.present? + where("id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id) + else + where("id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id) + end + end + + def hidden_from_moderation + where("id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id) + end + + def tag_match(query) + PostQueryBuilder.new(query).build + end + + def positive + where("score > 1") + end + + def negative + where("score < -1") + end + + def updater_name_matches(name) + where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase) + end + + def after_id(num) + if num.present? + where("id > ?", num.to_i).reorder("id asc") + else + where("true") + end + end + + def before_id(num) + if num.present? + where("id < ?", num.to_i).reorder("id desc") + else + where("true") + end + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:before_id] + q = q.before_id(params[:before_id].to_i) + end + + if params[:after_id] + q = q.after_id(params[:after_id].to_i) + end + + if params[:tag_match] + q = q.tag_match(params[:tag_match]) + end + + q + end + end + include FileMethods include ImageMethods include ApprovalMethods @@ -883,6 +952,7 @@ class Post < ActiveRecord::Base include VersionMethods include NoteMethods include ApiMethods + extend SearchMethods def reload(options = nil) super diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index 6c838e036..a36d6cee2 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -8,8 +8,29 @@ class PostAppeal < ActiveRecord::Base validate :validate_creator_is_not_limited before_validation :initialize_creator, :on => :create validates_uniqueness_of :creator_id, :scope => :post_id, :message => "have already appealed this post" - scope :for_user, lambda {|user_id| where(["creator_id = ?", user_id])} - scope :recent, lambda {where(["created_at >= ?", 1.day.ago])} + + module SearchMethods + def for_user(user_id) + where("creator_id = ?", user_id) + end + + def recent + where("created_at >= ?", 1.day.ago) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:post_id] + q = q.where("post_id = ?", params[:post_id].to_i) + end + + q + end + end + + extend SearchMethods def validate_creator_is_not_limited if appeal_count_for_creator >= Danbooru.config.max_appeals_per_day diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index d5981e0f0..6e38ae38a 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -9,9 +9,33 @@ class PostFlag < ActiveRecord::Base before_validation :initialize_creator, :on => :create validates_uniqueness_of :creator_id, :scope => :post_id, :message => "have already flagged this post" before_save :update_post - scope :resolved, where("is_resolved = ?", true) - scope :unresolved, where("is_resolved = ?", false) - scope :old, lambda {where("created_at <= ?", 3.days.ago)} + + module SearchMethods + def resolved + where("is_resolved = ?", true) + end + + def unresolved + where("is_resolved = ?", false) + end + + def old + where("created_at <= ?", 3.days.ago) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:post_id] + q = q.where("post_id = ?", params[:post_id].to_i) + end + + q + end + end + + extend SearchMethods def update_post post.update_column(:is_flagged, true) diff --git a/app/models/post_version.rb b/app/models/post_version.rb index bf2de4763..ab8fcf2c3 100644 --- a/app/models/post_version.rb +++ b/app/models/post_version.rb @@ -2,8 +2,37 @@ class PostVersion < ActiveRecord::Base belongs_to :post belongs_to :updater, :class_name => "User" before_validation :initialize_updater - scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)} - scope :updater_name_matches, lambda {|name| where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)} + + module SearchMethods + def for_user(user_id) + where("updater_id = ?", user_id) + end + + def updater_name(name) + where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:updater_name] + q = q.updater_name(params[:updater_name]) + end + + if params[:updater_id] + q = q.where("updater_id = ?", params[:updater_id].to_i) + end + + if params[:post_id] + q = q.where("post_id = ?", params[:post_id].to_i) + end + + q + end + end + + extend SearchMethods def self.create_from_post(post) if post.created_at == post.updated_at diff --git a/app/models/tag.rb b/app/models/tag.rb index 91ea7c132..7ff5b5581 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -2,8 +2,6 @@ class Tag < ActiveRecord::Base attr_accessible :category after_save :update_category_cache has_one :wiki_page, :foreign_key => "name", :primary_key => "title" - scope :name_matches, lambda {|name| where("name LIKE ? ESCAPE E'\\\\'", name.downcase.to_escaped_for_sql_like)} - scope :named, lambda {|name| where("name = ?", TagAlias.to_aliased([name]).join(""))} class CategoryMapping Danbooru.config.reverse_tag_category_mapping.each do |value, category| @@ -365,6 +363,42 @@ class Tag < ActiveRecord::Base end end + module SearchMethods + def name_matches(name) + where("name LIKE ? ESCAPE E'\\\\'", name.downcase.to_escaped_for_sql_like) + end + + def named(name) + where("name = ?", TagAlias.to_aliased([name]).join("")) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:name_matches] + q = q.name_matches(params[:name_matches]) + end + + if params[:category] + q = q.where("category = ?", params[:category]) + end + + case params[:sort] + when "count" + q = q.order("post_count") + + when "date" + q = q.order("created_at") + + else + q = q.order("name") + end + + q + end + end + extend CountMethods extend ViewCountMethods include CategoryMethods @@ -373,4 +407,5 @@ class Tag < ActiveRecord::Base extend ParseMethods include RelationMethods extend SuggestionMethods + extend SearchMethods end diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 17fe3db99..63baf8d91 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -7,8 +7,34 @@ class TagAlias < ActiveRecord::Base validates_uniqueness_of :antecedent_name validate :absence_of_transitive_relation belongs_to :creator, :class_name => "User" - scope :name_matches, lambda {|name| where("(antecedent_name = ? or consequent_name = ?)", name.downcase, name.downcase)} + + module SearchMethods + def name_matches(name) + where("(antecedent_name = ? or consequent_name = ?)", name.downcase, name.downcase) + end + def search(params) + q = scoped + return q if params.blank? + + if params[:name_matches] + q = q.name_matches(params[:name_matches]) + end + + if params[:antecedent_name] + q = q.where("antecedent_name = ?", params[:antecedent_name]) + end + + if params[:id] + q = q.where("id = ?", params[:id].to_i) + end + + q + end + end + + extend SearchMethods + def self.to_aliased(names) alias_hash = Cache.get_multi(names.flatten, "ta") do |name| ta = TagAlias.find_by_antecedent_name(name) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 5b26027e2..c11b8876d 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -6,7 +6,6 @@ class TagImplication < ActiveRecord::Base validates_presence_of :creator_id validates_uniqueness_of :antecedent_name, :scope => :consequent_name validate :absence_of_circular_relation - scope :name_matches, lambda {|name| where("(antecedent_name = ? or consequent_name = ?)", name.downcase, name.downcase)} module DescendantMethods extend ActiveSupport::Concern @@ -68,8 +67,34 @@ class TagImplication < ActiveRecord::Base end end + module SearchMethods + def name_matches(name) + where("(antecedent_name = ? or consequent_name = ?)", name.downcase, name.downcase) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:id] + q = q.where("id = ?", params[:id].to_i) + end + + if params[:name_matches] + q = q.name_matches(params[:name_matches]) + end + + if params[:antecedent_name] + q = q.where("antecedent_name = ?", params[:antecedent_name]) + end + + q + end + end + include DescendantMethods include ParentMethods + extend SearchMethods def initialize_creator self.creator_id = CurrentUser.user.id diff --git a/app/models/tag_subscription.rb b/app/models/tag_subscription.rb index 2ca79027c..f4ee52aca 100644 --- a/app/models/tag_subscription.rb +++ b/app/models/tag_subscription.rb @@ -42,6 +42,11 @@ class TagSubscription < ActiveRecord::Base user.is_moderator? || creator_id == user.id end + def self.search(params) + q = scoped + return q if params.blank? + end + def self.visible_to(user) where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?) end diff --git a/app/models/upload.rb b/app/models/upload.rb index 9e8a9d8af..7efd80123 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -12,8 +12,6 @@ class Upload < ActiveRecord::Base before_create :convert_cgi_file after_destroy :delete_temp_file validate :uploader_is_not_limited - scope :uploaded_by, lambda {|user_id| where(["uploader_id = ?", user_id])} - scope :pending, where(:status => "pending") module ValidationMethods def uploader_is_not_limited @@ -149,7 +147,8 @@ class Upload < ActiveRecord::Base end Danbooru.resize(source_path, resized_file_path_for(width), width, height, quality) - if width == Danbooru.config.small_image_width + + if width == Danbooru.config.small_image_width && Danbooru.config.ssd_path Danbooru.resize(source_path, ssd_file_path, width, height, quality) end end @@ -302,6 +301,31 @@ class Upload < ActiveRecord::Base end end + module SearchMethods + def uploaded_by(user_id) + where("uploader_id = ?", user_id) + end + + def pending + where(:status => "pending") + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:uploader_id] + q = q.uploaded_by(params[:uploader_id].to_i) + end + + if params[:source] + q = q.where("source = ?", params[:source]) + end + + q + end + end + include ConversionMethods include ValidationMethods include FileMethods @@ -313,6 +337,7 @@ class Upload < ActiveRecord::Base include CgiFileMethods include StatusMethods include UploaderMethods + extend SearchMethods def presenter @presenter ||= UploadPresenter.new(self) diff --git a/app/models/user.rb b/app/models/user.rb index 5533a9a2a..4cf2dcefc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,10 +40,6 @@ class User < ActiveRecord::Base has_many :note_versions, :foreign_key => "updater_id" has_many :dmails, :foreign_key => "owner_id", :order => "dmails.id desc" belongs_to :inviter, :class_name => "User" - scope :named, lambda {|name| where(["lower(name) = ?", name])} - scope :admins, where("is_admin = TRUE") - scope :with_email, lambda {|email| email.blank? ? where("FALSE") : where(["email = ?", email])} - scope :find_for_password_reset, lambda {|name, email| email.blank? ? where("FALSE") : where(["name = ? AND email = ?", name, email])} module BanMethods def validate_ip_addr_is_not_banned @@ -417,6 +413,51 @@ class User < ActiveRecord::Base end end + module SearchMethods + def named(name) + where("lower(name) = ?", name) + end + + def name_matches(name) + where("lower(name) like ? escape E'\\\\'", name.to_escaped_for_sql_like) + end + + def admins + where("is_admin = TRUE") + end + + def with_email(email) + if email.blank? + where("FALSE") + else + where("email = ?", email) + end + end + + def find_for_password_reset(name, email) + if email.blank? + where("FALSE") + else + where(["name = ? AND email = ?", name, email]) + end + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:name_matches] + q = q.name_matches(params[:name_matches]) + end + + if params[:min_level] + q = q.where("level >= ?", params[:min_level].to_i) + end + + q + end + end + include BanMethods include NameMethods include PasswordMethods @@ -429,6 +470,7 @@ class User < ActiveRecord::Base include LimitMethods include InvitationMethods include ApiMethods + extend SearchMethods def initialize_default_image_size self.default_image_size = "large" diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index 5cbf9eb86..2128c6a8f 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -6,11 +6,38 @@ class UserFeedback < ActiveRecord::Base attr_accessible :body, :user_id, :category, :user_name validates_presence_of :user, :creator, :body, :category validate :creator_is_privileged - scope :positive, where("category = ?", "positive") - scope :neutral, where("category = ?", "neutral") - scope :negative, where("category = ?", "negative") - scope :for_user, lambda {|user_id| where("user_id = ?", user_id)} + + module SearchMethods + def positive + where("category = ?", "positive") + end + def neutral + where("category = ?", "neutral") + end + + def negative + where("category = ?", "negative") + end + + def for_user(user_id) + where("user_id = ?", user_id) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:user_id] + q = q.for_user(params[:user_id].to_i) + end + + q + end + end + + extend SearchMethods + def initialize_creator self.creator_id = CurrentUser.id end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 2ea7b494f..97fb2d860 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -7,26 +7,37 @@ class WikiPage < ActiveRecord::Base validates_presence_of :title validate :validate_locker_is_janitor attr_accessible :title, :body, :is_locked - scope :titled, lambda {|title| where(["title = ?", title.downcase.tr(" ", "_")])} - scope :recent, order("updated_at DESC").limit(25) has_one :tag, :foreign_key => "name", :primary_key => "title" has_one :artist, :foreign_key => "name", :primary_key => "title" has_many :versions, :class_name => "WikiPageVersion", :dependent => :destroy, :order => "wiki_page_versions.id ASC" - - def self.build_relation(options = {}) - relation = where() - - if options[:title] - relation = relation.where(["title LIKE ? ESCAPE E'\\\\'", options[:title].downcase.tr(" ", "_").to_escaped_for_sql_like]) + + module SearchMethods + def titled(title) + where("title = ?", title.downcase.tr(" ", "_")) end - if options[:creator_id] - relation = relation.where(["creator_id = ?", options[:creator_id]]) + def recent + order("updated_at DESC").limit(25) + end + + def search(params = {}) + q = scoped + return q if params.blank? + + if params[:title] + q = q.where("title LIKE ? ESCAPE E'\\\\'", params[:title].downcase.tr(" ", "_").to_escaped_for_sql_like) + end + + if params[:creator_id] + q = q.where("creator_id = ?", params[:creator_id]) + end + + q end - - relation end + extend SearchMethods + def self.find_title_and_id(title) titled(title).select("title, id").first end diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb index d48472802..194d594e8 100644 --- a/app/models/wiki_page_version.rb +++ b/app/models/wiki_page_version.rb @@ -1,7 +1,29 @@ class WikiPageVersion < ActiveRecord::Base belongs_to :wiki_page belongs_to :updater, :class_name => "User" - scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)} + + module SearchMethods + def for_user(user_id) + where("updater_id = ?", user_id) + end + + def search(params) + q = scoped + return q if params.blank? + + if params[:updater_id] + q = q.for_user(params[:updater_id].to_i) + end + + if params[:wiki_page_id] + q = q.where("wiki_page_id = ?", params[:wiki_page_id].to_i) + end + + q + end + end + + extend SearchMethods def updater_name User.id_to_name(updater_id) diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index f2362a4d8..41d42e776 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -70,27 +70,27 @@ class UserPresenter end def comments(template) - template.link_to(Comment.for_user(user.id).count, template.comments_path(:search => {:creator_id_eq => user.id})) + template.link_to(Comment.for_user(user.id).count, template.comments_path(:search => {:creator_id => user.id})) end def post_versions(template) - template.link_to(user.post_update_count, template.post_versions_path(:search => {:updater_id_eq => user.id})) + template.link_to(user.post_update_count, template.post_versions_path(:search => {:updater_id => user.id})) end def note_versions(template) - template.link_to(user.note_update_count, template.note_versions_path(:search => {:updater_id_eq => user.id})) + template.link_to(user.note_update_count, template.note_versions_path(:search => {:updater_id => user.id})) end def wiki_page_versions(template) - template.link_to(WikiPageVersion.for_user(user.id).count, template.wiki_page_versions_path(:search => {:updater_id_eq => user.id})) + template.link_to(WikiPageVersion.for_user(user.id).count, template.wiki_page_versions_path(:search => {:updater_id => user.id})) end def forum_posts(template) - template.link_to(ForumPost.for_user(user.id).count, template.forum_posts_path(:search => {:creator_id_eq => user.id})) + template.link_to(ForumPost.for_user(user.id).count, template.forum_posts_path(:search => {:creator_id => user.id})) end def pool_versions(template) - template.link_to(PoolVersion.for_user(user.id).count, template.pool_versions_path(:search => {:updater_id_eq => user.id})) + template.link_to(PoolVersion.for_user(user.id).count, template.pool_versions_path(:search => {:updater_id => user.id})) end def inviter(template) @@ -110,7 +110,7 @@ class UserPresenter neutral = UserFeedback.for_user(user.id).neutral.count negative = UserFeedback.for_user(user.id).negative.count - template.link_to("positive:#{positive} neutral:#{neutral} negative:#{negative}", template.user_feedbacks_path(:search => {:user_id_eq => user.id})) + template.link_to("positive:#{positive} neutral:#{neutral} negative:#{negative}", template.user_feedbacks_path(:search => {:user_id => user.id})) end def subscriptions(template) diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index d6c17c229..be3ac98d6 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -8,7 +8,7 @@ <% if @artist && !@artist.new_record? %>
  • |
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • -
  • <%= link_to "History", artist_versions_path(:search => {:artist_id_eq => @artist.id}) %>
  • +
  • <%= link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %>
  • <%= link_to "Show", artist_path(@artist) %>
  • <% end %> diff --git a/app/views/artists/search.html.erb b/app/views/artists/search.html.erb index 0f740410f..fce70bc92 100644 --- a/app/views/artists/search.html.erb +++ b/app/views/artists/search.html.erb @@ -3,12 +3,9 @@

    Search Artists

    - <%= simple_form_for(@search) do |f| %> - <%= f.input :name_contains, :label => "Name", :required => false %> - <%= f.input :other_names_match, :label => "Other Names", :required => false %> - <%= f.input :group_name_contains, :label => "Group Name", :required => false %> - <%= f.input :url_match, :label => "URL", :required => false %> - <%= f.button :submit, "Search" %> + <%= form_tag(artists_path, :method => :get, :class => "simple_form") do %> + <%= search_field "name" %> + <%= submit_tag "Search" %> <% end %>
    diff --git a/app/views/comments/search.html.erb b/app/views/comments/search.html.erb index 93efdb0db..55e5a59a5 100644 --- a/app/views/comments/search.html.erb +++ b/app/views/comments/search.html.erb @@ -2,13 +2,13 @@ diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 9f5610f57..3534b0552 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -1,7 +1,7 @@ <% content_for(:secondary_links) do %> -
  • <%= link_to "Received", dmails_path(:search => {:owner_id_eq => CurrentUser.id, :to_id_eq => CurrentUser.id}, :folder => "received") %>
  • -
  • <%= link_to "Sent", dmails_path(:search => {:owner_id_eq => CurrentUser.id, :from_id_eq => CurrentUser.id}, :folder => "sent") %>
  • +
  • <%= link_to "Received", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") %>
  • +
  • <%= link_to "Sent", dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") %>
  • <%= link_to "New", new_dmail_path %>
  • <%= link_to "Search", search_dmails_path %>
  • diff --git a/app/views/dmails/search.html.erb b/app/views/dmails/search.html.erb index 941c89e58..2ad5d8209 100644 --- a/app/views/dmails/search.html.erb +++ b/app/views/dmails/search.html.erb @@ -1,13 +1,13 @@
    diff --git a/app/views/forum_posts/search.html.erb b/app/views/forum_posts/search.html.erb index dff178e36..4d1647748 100644 --- a/app/views/forum_posts/search.html.erb +++ b/app/views/forum_posts/search.html.erb @@ -1,10 +1,11 @@
    diff --git a/app/views/moderator/dashboards/_activity_artist.html.erb b/app/views/moderator/dashboards/_activity_artist.html.erb index ad49fd2f1..c736255ef 100644 --- a/app/views/moderator/dashboards/_activity_artist.html.erb +++ b/app/views/moderator/dashboards/_activity_artist.html.erb @@ -10,7 +10,7 @@ <% @dashboard.artists.each do |activity| %> <%= mod_link_to_user(activity.user, :positive) %> - <%= link_to activity.count, artist_versions_path(:search => {:updater_id_eq => activity.user.id}) %> + <%= link_to activity.count, artist_versions_path(:search => {:updater_id => activity.user.id}) %> <% end %> diff --git a/app/views/moderator/dashboards/_activity_note.html.erb b/app/views/moderator/dashboards/_activity_note.html.erb index 9bd6e4c4b..2da47f35c 100644 --- a/app/views/moderator/dashboards/_activity_note.html.erb +++ b/app/views/moderator/dashboards/_activity_note.html.erb @@ -10,7 +10,7 @@ <% @dashboard.notes.each do |activity| %> <%= mod_link_to_user(activity.user, :positive) %> - <%= link_to activity.count, note_versions_path(:search => {:updater_id_eq => activity.user.id}) %> + <%= link_to activity.count, note_versions_path(:search => {:updater_id => activity.user.id}) %> <% end %> diff --git a/app/views/moderator/dashboards/_activity_tag.html.erb b/app/views/moderator/dashboards/_activity_tag.html.erb index 9bce4d3e4..eb88ec37c 100644 --- a/app/views/moderator/dashboards/_activity_tag.html.erb +++ b/app/views/moderator/dashboards/_activity_tag.html.erb @@ -10,7 +10,7 @@ <% @dashboard.tags.each do |activity| %> <%= mod_link_to_user(activity.user, :positive) %> - <%= link_to activity.count, post_versions_path(:search => {:updater_id_eq => activity.user.id}) %> + <%= link_to activity.count, post_versions_path(:search => {:updater_id => activity.user.id}) %> <% end %> diff --git a/app/views/moderator/dashboards/_activity_wiki_page.html.erb b/app/views/moderator/dashboards/_activity_wiki_page.html.erb index fb1adf06b..a989b12c6 100644 --- a/app/views/moderator/dashboards/_activity_wiki_page.html.erb +++ b/app/views/moderator/dashboards/_activity_wiki_page.html.erb @@ -10,7 +10,7 @@ <% @dashboard.wiki_pages.each do |activity| %> <%= mod_link_to_user(activity.user, :positive) %> - <%= link_to activity.count, wiki_page_versions_path(:search => {:updater_id_eq => activity.user.id}) %> + <%= link_to activity.count, wiki_page_versions_path(:search => {:updater_id => activity.user.id}) %> <% end %> diff --git a/app/views/moderator/dashboards/_search_ip_addr.html.erb b/app/views/moderator/dashboards/_search_ip_addr.html.erb index 4a5c519d4..0e8c2d72a 100644 --- a/app/views/moderator/dashboards/_search_ip_addr.html.erb +++ b/app/views/moderator/dashboards/_search_ip_addr.html.erb @@ -1,7 +1,7 @@ <%= form_tag(moderator_ip_addrs_path, :method => :get, :class => "simple_form") do %>
    - <%= text_field_tag "search[ip_addr_eq]", params[:ip_addrs] %> + <%= text_field_tag "search[ip_addr]", params[:ip_addrs] %>
    <%= submit_tag "Search" %> @@ -10,7 +10,7 @@ <%= form_tag(moderator_ip_addrs_path, :method => :get, :class => "simple_form") do %>
    - <%= text_field_tag "search[user_id_eq]", params[:user_ids] %> + <%= text_field_tag "search[user_id]", params[:user_ids] %>
    <%= submit_tag "Search" %> diff --git a/app/views/moderator/ip_addrs/search.html.erb b/app/views/moderator/ip_addrs/search.html.erb index 66ba22338..3b44b59ae 100644 --- a/app/views/moderator/ip_addrs/search.html.erb +++ b/app/views/moderator/ip_addrs/search.html.erb @@ -2,18 +2,10 @@ diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index 8bfc823e7..6e8727bbd 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -20,7 +20,7 @@ <%= link_to note_version.post_id, post_path(note_version.post_id) %> - <%= link_to "#{note_version.note_id}", note_versions_path(:search => {:note_id_eq => note_version.note_id}) %> + <%= link_to "#{note_version.note_id}", note_versions_path(:search => {:note_id => note_version.note_id}) %> <%= h(note_version.body) %> <% unless note_version.is_active? %>(deleted)<% end %> <% if CurrentUser.is_janitor? %> diff --git a/app/views/notes/search.html.erb b/app/views/notes/search.html.erb index d55ef29b0..19670b321 100644 --- a/app/views/notes/search.html.erb +++ b/app/views/notes/search.html.erb @@ -2,11 +2,12 @@ diff --git a/app/views/pools/_secondary_links.html.erb b/app/views/pools/_secondary_links.html.erb index 09dcef9f0..0ad6af2ed 100644 --- a/app/views/pools/_secondary_links.html.erb +++ b/app/views/pools/_secondary_links.html.erb @@ -15,7 +15,7 @@
  • <%= link_to "Delete", pool_path(@pool), :method => :delete, :confirm => "Are you sure you want to delete this pool?", :remote => true %>
  • <% end %> <% end %> -
  • <%= link_to "History", pool_versions_path(:search => {:pool_id_eq => @pool.id}) %>
  • +
  • <%= link_to "History", pool_versions_path(:search => {:pool_id => @pool.id}) %>
  • <%= link_to "Order", edit_pool_order_path(@pool) %>
  • <% end %> diff --git a/app/views/pools/search.html.erb b/app/views/pools/search.html.erb index fb90e7117..64be218ca 100644 --- a/app/views/pools/search.html.erb +++ b/app/views/pools/search.html.erb @@ -1,9 +1,10 @@
    diff --git a/app/views/post_versions/search.html.erb b/app/views/post_versions/search.html.erb index b4757bfe1..13c7663ed 100644 --- a/app/views/post_versions/search.html.erb +++ b/app/views/post_versions/search.html.erb @@ -3,10 +3,10 @@

    Search Changes

    diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 79d6e770c..f0784704e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -29,8 +29,8 @@

    History

    diff --git a/app/views/tags/_secondary_links.html.erb b/app/views/tags/_secondary_links.html.erb index fcfd38b13..2086dc1de 100644 --- a/app/views/tags/_secondary_links.html.erb +++ b/app/views/tags/_secondary_links.html.erb @@ -2,7 +2,7 @@
  • <%= link_to "Listing", tags_path %>
  • <%= link_to "Search", search_tags_path %>
  • -
  • <%= link_to "Help", wiki_pages_path(:search => {:title_equals => "help:tags"}) %>
  • +
  • <%= link_to "Help", wiki_pages_path(:search => {:title => "help:tags"}) %>
  • <% if @tag %>
  • |
  • <%= link_to "Edit", edit_tag_path(@tag) %>
  • diff --git a/app/views/tags/search.html.erb b/app/views/tags/search.html.erb index 5ea55047a..2ed583ab2 100644 --- a/app/views/tags/search.html.erb +++ b/app/views/tags/search.html.erb @@ -1,9 +1,18 @@
    diff --git a/app/views/uploads/show.html.erb b/app/views/uploads/show.html.erb index 33bd00812..9f20ab5de 100644 --- a/app/views/uploads/show.html.erb +++ b/app/views/uploads/show.html.erb @@ -17,7 +17,7 @@ <% end %>

    - You can <%= link_to "upload another file", new_upload_path %> or <%= link_to "view your current uploads", uploads_path(:search => {:uploader_id_eq => CurrentUser.id}) %>. + You can <%= link_to "upload another file", new_upload_path %> or <%= link_to "view your current uploads", uploads_path(:search => {:uploader_id => CurrentUser.id}) %>. <% if CurrentUser.user.is_moderator? && @upload.is_pending? %> <%= link_to "Force update", upload_path(@upload, :format => "js"), :remote => true, :method => :put %>. <% end %> diff --git a/app/views/user_feedbacks/_secondary_links.html.erb b/app/views/user_feedbacks/_secondary_links.html.erb index 39ebdf742..8cf832199 100644 --- a/app/views/user_feedbacks/_secondary_links.html.erb +++ b/app/views/user_feedbacks/_secondary_links.html.erb @@ -2,8 +2,8 @@

    <% if @user_feedback %>
  • <%= link_to "New", new_user_feedback_path(:user_feedback => {:user_id => @user_feedback.user_id}) %>
  • - <% elsif params[:search] && params[:search][:user_id_eq] %> -
  • <%= link_to "New", new_user_feedback_path(:user_feedback => {:user_id => params[:search][:user_id_eq]}) %>
  • + <% elsif params[:search] && params[:search][:user_id] %> +
  • <%= link_to "New", new_user_feedback_path(:user_feedback => {:user_id => params[:search][:user_id]}) %>
  • <% else %>
  • <%= link_to "New", new_user_feedback_path %>
  • <% end %> diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index cbde7300e..731f4a4bf 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -10,7 +10,7 @@ <% if @user.id == CurrentUser.id %>
  • <%= link_to "Settings", edit_user_path(CurrentUser.user) %>
  • <%= link_to "Profile", user_path(CurrentUser.user) %>
  • -
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_path(:search => {:owner_id_eq => CurrentUser.id, :to_id_eq => CurrentUser.id}) %>
  • +
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}) %>
  • <% else %>
  • <%= link_to "Send message", new_dmail_path(:dmail => {:to_id => @user.id}) %>
  • <% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index a4ca1fe2a..6ba15659f 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -2,11 +2,9 @@

    Users

    - <% simple_form_for(@search) do |f| %> - <%= f.input :name_contains, :label => "Name" %> - <%= f.sort_link "Name", :name %> - <%= f.sort_link "Date", :created_at_desc %> - <%= f.button :submit %> + <% form_tag(users_path, :method => :get, :class => "simple_form") do %> + <%= search_field "name_matches", :label => "Name" %> + <%= submit_tag "Search" %> <% end %> @@ -46,7 +44,7 @@ <% end %> - + diff --git a/app/views/users/search.html.erb b/app/views/users/search.html.erb index f44355405..fbaf8f9a5 100644 --- a/app/views/users/search.html.erb +++ b/app/views/users/search.html.erb @@ -1,8 +1,14 @@
    diff --git a/app/views/wiki_pages/_secondary_links.html.erb b/app/views/wiki_pages/_secondary_links.html.erb index 4cc0e166d..7f2130b57 100644 --- a/app/views/wiki_pages/_secondary_links.html.erb +++ b/app/views/wiki_pages/_secondary_links.html.erb @@ -2,11 +2,11 @@
  • <%= link_to "Listing", wiki_pages_path %>
  • <%= link_to "New", new_wiki_page_path %>
  • -
  • <%= link_to "Help", wiki_pages_path(:search => {:title_equals => "help:wiki"}) %>
  • +
  • <%= link_to "Help", wiki_pages_path(:search => {:title => "help:wiki"}) %>
  • <% if @wiki_page %>
  • |
  • <%= link_to "Posts (#{Post.fast_count(@wiki_page.title)})", posts_path(:tags => @wiki_page.title) %>
  • -
  • <%= link_to "History", wiki_page_versions_path(:search => {:wiki_page_id_eq => @wiki_page.id}) %>
  • +
  • <%= link_to "History", wiki_page_versions_path(:search => {:wiki_page_id => @wiki_page.id}) %>
  • <% if CurrentUser.is_member? %> <% unless @wiki_page.new_record? %>
  • <%= link_to "Edit", edit_wiki_page_path(@wiki_page) %>
  • diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index dbce84613..2748aef6e 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -251,6 +251,13 @@ module Danbooru 1 end + # Counting every post is typically expensive because it involves a sequential scan on + # potentially millions of rows. If this method returns a value, then blank searches + # will return that number for the fast_count call instead. + def blank_tag_search_fast_count + nil + end + def pixiv_login nil end diff --git a/test/factories/upload.rb b/test/factories/upload.rb index 69b1c24fa..df37a781c 100644 --- a/test/factories/upload.rb +++ b/test/factories/upload.rb @@ -7,6 +7,7 @@ FactoryGirl.define do uploader_ip_addr "127.0.0.1" tag_string "special" status "pending" + server Socket.gethostname factory(:source_upload) do source "http://www.google.com/intl/en_ALL/images/logo.gif" diff --git a/test/functional/artist_versions_controller_test.rb b/test/functional/artist_versions_controller_test.rb index 8bb9d89e2..caee0f4b1 100644 --- a/test/functional/artist_versions_controller_test.rb +++ b/test/functional/artist_versions_controller_test.rb @@ -19,7 +19,7 @@ class ArtistVersionsControllerTest < ActionController::TestCase end should "get the index page when searching for something" do - get :index, {:search => {:name_equals => @artist.name}} + get :index, {:search => {:name => @artist.name}} assert_response :success end end diff --git a/test/functional/ip_bans_controller_test.rb b/test/functional/ip_bans_controller_test.rb index 3de7ce78a..b4ef9d7f5 100644 --- a/test/functional/ip_bans_controller_test.rb +++ b/test/functional/ip_bans_controller_test.rb @@ -35,7 +35,7 @@ class IpBansControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:ip_addr_equals => "1.2.3.4"}}, {:user_id => @admin.id} + get :index, {:search => {:ip_addr => "1.2.3.4"}}, {:user_id => @admin.id} assert_response :success end end diff --git a/test/functional/janitor_trials_controller_test.rb b/test/functional/janitor_trials_controller_test.rb index cf72f9e36..135d217c3 100644 --- a/test/functional/janitor_trials_controller_test.rb +++ b/test/functional/janitor_trials_controller_test.rb @@ -68,7 +68,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:user_name_equals => @user.name}}, {:user_id => @admin.id} + get :index, {:search => {:user_name => @user.name}}, {:user_id => @admin.id} assert_response :success end end diff --git a/test/functional/moderator/ip_addrs_controller_test.rb b/test/functional/moderator/ip_addrs_controller_test.rb index bf64c5764..1ced07095 100644 --- a/test/functional/moderator/ip_addrs_controller_test.rb +++ b/test/functional/moderator/ip_addrs_controller_test.rb @@ -12,17 +12,17 @@ module Moderator end should "find by ip addr" do - get :index, {:search => {:ip_addr_eq => "127.0.0.1"}}, {:user_id => @user.id} + get :index, {:search => {:ip_addr => "127.0.0.1"}}, {:user_id => @user.id} assert_response :success end should "find by user id" do - get :index, {:search => {:user_id_eq => @user.id.to_s}}, {:user_id => @user.id} + get :index, {:search => {:user_id => @user.id.to_s}}, {:user_id => @user.id} assert_response :success end should "find by user name" do - get :index, {:search => {:user_name_eq => @user.name}}, {:user_id => @user.id} + get :index, {:search => {:user_name => @user.name}}, {:user_id => @user.id} assert_response :success end diff --git a/test/functional/note_versions_controller_test.rb b/test/functional/note_versions_controller_test.rb index e88ed0a7c..dae829f0f 100644 --- a/test/functional/note_versions_controller_test.rb +++ b/test/functional/note_versions_controller_test.rb @@ -35,7 +35,7 @@ class NoteVersionsControllerTest < ActionController::TestCase end should "list all versions that match the search criteria" do - get :index, {:search => {:updater_id_equals => @user_2.id}} + get :index, {:search => {:updater_id => @user_2.id}} assert_response :success assert_not_nil(assigns(:note_versions)) assert_equal(1, assigns(:note_versions).size) diff --git a/test/functional/pool_versions_controller_test.rb b/test/functional/pool_versions_controller_test.rb index 1249079f2..14b1f68ac 100644 --- a/test/functional/pool_versions_controller_test.rb +++ b/test/functional/pool_versions_controller_test.rb @@ -36,7 +36,7 @@ class PoolVersionsControllerTest < ActionController::TestCase end should "list all versions that match the search criteria" do - get :index, {:search => {:updater_id_equals => @user_2.id}} + get :index, {:search => {:updater_id => @user_2.id}} assert_response :success assert_not_nil(assigns(:pool_versions)) assert_equal(1, assigns(:pool_versions).size) diff --git a/test/functional/post_appeals_controller_test.rb b/test/functional/post_appeals_controller_test.rb index 0a0dd897f..52869291f 100644 --- a/test/functional/post_appeals_controller_test.rb +++ b/test/functional/post_appeals_controller_test.rb @@ -33,7 +33,7 @@ class PostAppealsControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:post_id_equals => @post_appeal.post_id}}, {:user_id => @user.id} + get :index, {:search => {:post_id => @post_appeal.post_id}}, {:user_id => @user.id} assert_response :success end end diff --git a/test/functional/post_flags_controller_test.rb b/test/functional/post_flags_controller_test.rb index acbcbd211..4d665e6dc 100644 --- a/test/functional/post_flags_controller_test.rb +++ b/test/functional/post_flags_controller_test.rb @@ -33,7 +33,7 @@ class PostFlagsControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:post_id_equals => @post_flag.post_id}}, {:user_id => @user.id} + get :index, {:search => {:post_id => @post_flag.post_id}}, {:user_id => @user.id} assert_response :success end end diff --git a/test/functional/post_versions_controller_test.rb b/test/functional/post_versions_controller_test.rb index cdb5e3a56..4378e99d3 100644 --- a/test/functional/post_versions_controller_test.rb +++ b/test/functional/post_versions_controller_test.rb @@ -27,7 +27,7 @@ class PostVersionsControllerTest < ActionController::TestCase end should "list all versions that match the search criteria" do - get :index, {:search => {:post_id_equals => @post.id}} + get :index, {:search => {:post_id => @post.id}} assert_response :success assert_not_nil(assigns(:post_versions)) end diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index 3e8004b46..7ca6ce19b 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -26,7 +26,7 @@ class TagAliasesControllerTest < ActionController::TestCase end should "list all tag_aliass (with search)" do - get :index, {:search => {:antecedent_name_matches => "aaa"}} + get :index, {:search => {:antecedent_name => "aaa"}} assert_response :success end end diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index 850fb0cf7..393371dcf 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -26,7 +26,7 @@ class TagImplicationsControllerTest < ActionController::TestCase end should "list all tag_implications (with search)" do - get :index, {:search => {:antecedent_name_matches => "aaa"}} + get :index, {:search => {:antecedent_name => "aaa"}} assert_response :success end end diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 3d732c574..15d1187b8 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -36,7 +36,7 @@ class TagsControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:name_equals => "aaa"}} + get :index, {:search => {:name_matches => "aaa"}} assert_response :success end end diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 2d7e5dfeb..3b32840cc 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -44,7 +44,7 @@ class UploadsControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:source_equals => @upload.source}}, {:user_id => @user.id} + get :index, {:search => {:source => @upload.source}}, {:user_id => @user.id} assert_response :success end end diff --git a/test/functional/user_feedbacks_controller_test.rb b/test/functional/user_feedbacks_controller_test.rb index 7cedfbd77..aff6d7028 100644 --- a/test/functional/user_feedbacks_controller_test.rb +++ b/test/functional/user_feedbacks_controller_test.rb @@ -44,7 +44,7 @@ class UserFeedbacksControllerTest < ActionController::TestCase context "with search parameters" do should "render" do - get :index, {:search => {:user_id_equals => @user.id}}, {:user_id => @critic.id} + get :index, {:search => {:user_id => @user.id}}, {:user_id => @critic.id} assert_response :success end end diff --git a/test/functional/wiki_page_versions_controller_test.rb b/test/functional/wiki_page_versions_controller_test.rb index ea8084a67..84ba92600 100644 --- a/test/functional/wiki_page_versions_controller_test.rb +++ b/test/functional/wiki_page_versions_controller_test.rb @@ -27,7 +27,7 @@ class WikiPageVersionsControllerTest < ActionController::TestCase end should "list all versions that match the search criteria" do - get :index, {:search => {:wiki_page_id_equals => @wiki_page.id}} + get :index, {:search => {:wiki_page_id => @wiki_page.id}} assert_response :success assert_not_nil(assigns(:wiki_page_versions)) end diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index 895a6ee28..a14127666 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -25,7 +25,7 @@ class WikiPagesControllerTest < ActionController::TestCase end should "list all wiki_pages (with search)" do - get :index, {:search => {:title_matches => "abc"}} + get :index, {:search => {:title => "abc"}} assert_redirected_to(wiki_page_path(@wiki_page_abc)) end end diff --git a/test/unit/advertisement_test.rb b/test/unit/advertisement_test.rb index b158067de..5f23f9d53 100644 --- a/test/unit/advertisement_test.rb +++ b/test/unit/advertisement_test.rb @@ -3,6 +3,7 @@ require 'test_helper' class AdvertisementTest < ActiveSupport::TestCase context "An advertisement" do setup do + Danbooru.config.stubs(:advertisement_path).returns("/tmp") @ad = FactoryGirl.create(:advertisement, :file => upload_jpeg("#{Rails.root}/test/files/test.jpg")) end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 0aadc6f28..3bc323f73 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -127,7 +127,7 @@ class ArtistTest < ActiveSupport::TestCase yuu = FactoryGirl.create(:artist, :name => "yuu", :group_name => "cat_or_fish") cat_or_fish.reload assert_equal("yuu", cat_or_fish.member_names) - assert_not_nil(Artist.search(:group_name_contains => "cat_or_fish").first) + assert_not_nil(Artist.search(:name => "group:cat_or_fish").first) end should "have an associated wiki" do diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index d79405e78..7a67886e2 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -27,7 +27,7 @@ module Sources first_tag = @site.tags.first assert_equal(2, first_tag.size) assert(first_tag[0] =~ /./) - assert(first_tag[1] =~ /tags\.php\?tag=/) + assert(first_tag[1] =~ /search\.php/) end should "convert a page into a json representation" do diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 2df707b48..d4b0a249d 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -7,11 +7,13 @@ class UploadTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all + Delayed::Worker.delay_jobs = false end teardown do CurrentUser.user = nil CurrentUser.ip_addr = nil + Delayed::Worker.delay_jobs = true @upload.delete_temp_file if @upload end @@ -122,7 +124,7 @@ class UploadTest < ActiveSupport::TestCase assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.small_image_width))) assert_equal(6197, File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width))) assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.large_image_width))) - assert_equal(117877, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width))) + assert_equal(108224, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width))) end end
    <%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id_eq => user.id}) %><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id => user.id}) %> <%= user.level_string %> <%= time_ago_in_words user.created_at %> ago