diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index 437b96a04..6d28e3afc 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -6,6 +6,10 @@ class ArtistVersion < ActiveRecord::Base q = scoped return q if params.blank? + if params[:name] + q = q.where("name like ? escape E'\\\\'", params[:name].to_escaped_for_sql_like) + end + if params[:artist_id] q = q.where("artist_id = ?", params[:artist_id].to_i) end diff --git a/app/models/ban.rb b/app/models/ban.rb index ab3766161..94edc8216 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -19,10 +19,18 @@ class Ban < ActiveRecord::Base q = q.where("banner_id = (select _.id from users _ where lower(_.name) = ?)", params[:banner_name].downcase) end + if params[:banner_id] + q = q.where("banner_id = ?", params[:banner_id].to_i) + end + if params[:user_name] q = q.where("user_id = (select _.id from users _ where lower(_.name) = ?)", params[:user_name].downcase) end + if params[:user_id] + q = q.where("user_id = ?", params[:user_id].to_i) + end + q end diff --git a/app/models/comment_vote.rb b/app/models/comment_vote.rb index ba2001998..8b4cd9484 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -11,7 +11,7 @@ class CommentVote < ActiveRecord::Base validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1" def self.prune! - destroy_all(["created_at < ?", 14.days.ago]) + destroy_all("created_at < ?", 14.days.ago) end def validate_user_can_vote diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 3bc323f73..ba7b75f4b 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -115,11 +115,18 @@ class ArtistTest < ActiveSupport::TestCase assert_equal("aaa bbb ccc_ddd", artist.other_names) end + should "search on its name should return results" do + artist = FactoryGirl.create(:artist, :name => "artist") + assert_not_nil(Artist.search(:name => "artist").first) + end + should "search on other names should return matches" do artist = FactoryGirl.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd") assert_nil(Artist.other_names_match("artist").first) assert_not_nil(Artist.other_names_match("aaa").first) assert_not_nil(Artist.other_names_match("ccc_ddd").first) + assert_not_nil(Artist.search(:name => "other:aaa").first) + assert_not_nil(Artist.search(:name => "aaa").first) end should "search on group name and return matches" do