fixing tests

This commit is contained in:
albert
2011-07-16 19:20:02 -04:00
parent 7d80057e20
commit 58c3d2af13
49 changed files with 896 additions and 488 deletions

View File

@@ -14,6 +14,7 @@ class Artist < ActiveRecord::Base
attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes
scope :url_match, lambda {|string| where(["id in (?)", Artist.find_all_by_url(string).map(&:id)])}
scope :other_names_match, lambda {|string| where(["other_names_index @@ to_tsquery('danbooru', ?)", Artist.normalize_name(string)])}
scope :name_equals, lambda {|string| where("name = ?", string)}
search_methods :url_match, :other_names_match
module UrlMethods

View File

@@ -89,15 +89,15 @@ class Dmail < ActiveRecord::Base
end
def mark_as_read!
update_attribute(:is_read, true)
update_column(:is_read, true)
unless Dmail.exists?(["to_id = ? AND is_read = false", to_id])
to.update_attribute(:has_mail, false)
to.update_column(:has_mail, false)
end
end
def update_recipient
to.update_attribute(:has_mail, true)
to.update_column(:has_mail, true)
end
def visible_to?(user)

View File

@@ -39,7 +39,7 @@ class ForumPost < ActiveRecord::Base
def update_topic_updated_at
if topic
topic.update_attribute(:updater_id, CurrentUser.id)
topic.update_column(:updater_id, CurrentUser.id)
topic.touch
end
end

View File

@@ -5,11 +5,16 @@ class JanitorTrial < ActiveRecord::Base
after_destroy :create_feedback
validates_presence_of :user
before_validation :initialize_creator
before_validation :initialize_original_level
def initialize_creator
self.creator_id = CurrentUser.id
end
def initialize_original_level
self.original_level = user.level
end
def user_name=(name)
self.user_id = User.name_to_id(name)
end
@@ -21,7 +26,7 @@ class JanitorTrial < ActiveRecord::Base
end
def promote_user
user.update_attribute(:is_janitor, true)
user.update_column(:level, User::Levels::JANITOR)
end
def create_feedback
@@ -36,7 +41,7 @@ class JanitorTrial < ActiveRecord::Base
end
def demote!
user.update_attribute(:is_janitor, false)
user.update_column(:level, original_level)
destroy
end
end

View File

@@ -6,7 +6,7 @@ module Jobs
CONFIG["tag_types"].values.uniq.each do |tag_type|
tags += user.calculate_uploaded_tags(tag_type)
end
user.update_attribute(:uploaded_tags, tags.join("\n"))
user.update_column(:uploaded_tags, tags.join("\n"))
end
end
end

View File

@@ -91,7 +91,6 @@ class Pool < ActiveRecord::Base
offset = options[:offset] || 0
limit = options[:limit] || Danbooru.config.posts_per_page
slice = post_id_array.slice(offset, limit)
puts slice.inspect
if slice && slice.any?
Post.where("id in (?)", slice).order(arbitrary_sql_order_clause(slice, "posts"))
else
@@ -150,7 +149,7 @@ class Pool < ActiveRecord::Base
last_version = versions.last
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id
last_version.update_attribute(:post_ids, post_ids)
last_version.update_column(:post_ids, post_ids)
else
versions.create(:post_ids => post_ids)
end

View File

@@ -15,6 +15,7 @@ class Post < ActiveRecord::Base
before_validation :initialize_uploader, :on => :create
belongs_to :updater, :class_name => "User"
belongs_to :approver, :class_name => "User"
belongs_to :uploader, :class_name => "User"
belongs_to :parent, :class_name => "Post"
has_one :upload, :dependent => :destroy
has_many :flags, :class_name => "PostFlag", :dependent => :destroy
@@ -36,7 +37,7 @@ class Post < ActiveRecord::Base
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_string = ?", "uploader:#{user_id}"])}
scope :for_user, lambda {|user_id| where(["uploader_id = ?", user_id])}
scope :available_for_moderation, lambda {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| Post.tag_match_helper(query)}
@@ -233,7 +234,7 @@ class Post < ActiveRecord::Base
module ApprovalMethods
def is_approvable?
(is_pending? || is_flagged? || is_deleted?) && approver_string != "approver:#{CurrentUser.name}"
(is_pending? || is_flagged? || is_deleted?) && approver_id != CurrentUser.id
end
def flag!(reason)
@@ -243,7 +244,7 @@ class Post < ActiveRecord::Base
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
end
update_attribute(:is_flagged, true)
update_column(:is_flagged, true)
end
def appeal!(reason)
@@ -255,13 +256,13 @@ class Post < ActiveRecord::Base
end
def approve!
raise ApprovalError.new("You have previously approved this post and cannot approve it again") if approver_string == "approver:#{CurrentUser.name}"
raise ApprovalError.new("You have previously approved this post and cannot approve it again") if approver_id == CurrentUser.id
flags.each {|x| x.resolve!}
self.is_flagged = false
self.is_pending = false
self.is_deleted = false
self.approver_string = "approver:#{CurrentUser.name}"
self.approver_id = CurrentUser.id
save!
end
end
@@ -295,7 +296,7 @@ class Post < ActiveRecord::Base
end
def create_tags
set_tag_string(tag_array.map {|x| Tag.find_or_create_by_name(x).name}.join(" "))
set_tag_string(tag_array.map {|x| Tag.find_or_create_by_name(x).name}.uniq.join(" "))
end
def increment_tag_post_counts
@@ -373,11 +374,12 @@ class Post < ActiveRecord::Base
normalized_tags = TagAlias.to_aliased(normalized_tags)
normalized_tags = TagImplication.with_descendants(normalized_tags)
normalized_tags = filter_metatags(normalized_tags)
normalized_tags = %w(tagme) if normalized_tags.empty?
set_tag_string(normalized_tags.uniq.join(" "))
end
def filter_metatags(tags)
tags.reject {|tag| tag =~ /\A(?:pool|rating|fav|approver|uploader):/}
tags.reject {|tag| tag =~ /\A(?:pool|rating|fav):/}
end
def has_tag?(tag)
@@ -395,7 +397,7 @@ class Post < ActiveRecord::Base
end
def append_user_to_fav_string(user_id)
update_attribute(:fav_string, (fav_string + " fav:#{user_id}").strip)
update_column(:fav_string, (fav_string + " fav:#{user_id}").strip)
end
def add_favorite!(user)
@@ -405,7 +407,7 @@ class Post < ActiveRecord::Base
end
def delete_user_from_fav_string(user_id)
update_attribute(:fav_string, fav_string.gsub(/(?:\A| )fav:#{user_id}(?:\Z| )/, " ").strip)
update_column(:fav_string, fav_string.gsub(/(?:\A| )fav:#{user_id}(?:\Z| )/, " ").strip)
end
def remove_favorite!(user)
@@ -542,6 +544,22 @@ class Post < ActiveRecord::Base
relation = add_tag_string_search_relation(q[:tags], relation)
if q[:uploader_id_neg]
relation = relation.where("posts.uploader_id not in (?)", q[:uploader_id_neg])
end
if q[:uploader_id]
relation = relation.where("posts.uploader_id = ?", q[:uploader_id])
end
if q[:approver_id_neg]
relation = relation.where("posts.approver_id not in (?)", q[:approver_id_neg])
end
if q[:approver_id]
relation = relation.where("posts.approver_id = ?", q[:approver_id])
end
if q[:rating] == "q"
relation = relation.where("posts.rating = 'q'")
elsif q[:rating] == "s"
@@ -601,29 +619,15 @@ class Post < ActiveRecord::Base
module UploaderMethods
def initialize_uploader
self.uploader = CurrentUser.user
self.uploader_ip_addr = CurrentUser.ip_addr
end
def uploader_id=(user_id)
self.uploader = User.find(user_id)
end
def uploader_id
uploader_string[9..-1].to_i
if uploader_id.blank?
self.uploader_id = CurrentUser.id
self.uploader_ip_addr = CurrentUser.ip_addr
end
end
def uploader_name
User.id_to_name(uploader_id)
end
def uploader
User.find(uploader_id)
end
def uploader=(user)
self.uploader_string = "uploader:#{user.id}"
end
end
module PoolMethods
@@ -640,13 +644,15 @@ class Post < ActiveRecord::Base
def add_pool!(pool)
return if belongs_to_pool?(pool)
update_attribute(:pool_string, "#{pool_string} pool:#{pool.id}".strip)
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
update_column(:pool_string, pool_string)
pool.add!(self)
end
def remove_pool!(pool)
return unless belongs_to_pool?(pool)
update_attribute(:pool_string, pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip)
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
update_column(:pool_string, pool_string)
pool.remove!(self)
end
end
@@ -762,13 +768,11 @@ class Post < ActiveRecord::Base
if children.size == 0
# do nothing
elsif children.size == 1
children.first.update_attribute(:parent_id, nil)
children.first.update_column(:parent_id, nil)
else
cached_children = children
cached_children[1..-1].each do |child|
child.update_attribute(:parent_id, cached_children[0].id)
end
cached_children[0].update_attribute(:parent_id, nil)
Post.update_all({:parent_id => cached_children[0].id}, :id => cached_children[1..-1].map(&:id))
cached_children[0].update_column(:parent_id, nil)
end
end
@@ -800,14 +804,14 @@ class Post < ActiveRecord::Base
update_children_on_destroy
delete_favorites
decrement_tag_post_counts
update_attribute(:is_deleted, true)
update_column(:is_deleted, true)
update_parent_on_destroy
tag_array.each {|x| expire_cache(x)}
end
end
def undelete!
update_attribute(:is_deleted, false)
update_column(:is_deleted, false)
tag_array.each {|x| expire_cache(x)}
update_parent_on_save
end
@@ -822,7 +826,7 @@ class Post < ActiveRecord::Base
:add_tags => tag_string,
:parent_id => parent_id
)
else
elsif rating_changed? || source_changed? || parent_id_changed? || tag_string_changed?
versions.create(
:rating => rating_changed? ? rating : nil,
:source => source_changed? ? source : nil,

View File

@@ -13,7 +13,7 @@ class PostFlag < ActiveRecord::Base
scope :unresolved, where(["is_resolved = ?", false])
def update_post
post.update_attribute(:is_flagged, true)
post.update_column(:is_flagged, true)
end
def validate_creator_is_not_limited
@@ -40,7 +40,7 @@ class PostFlag < ActiveRecord::Base
end
def resolve!
update_attribute(:is_resolved, true)
update_column(:is_resolved, true)
end
def flag_count_for_creator

View File

@@ -88,15 +88,15 @@ class Tag < ActiveRecord::Base
if tag
if category > 0 && !(options[:user] && !options[:user].is_privileged? && tag.post_count > 10)
tag.update_attribute(:category, category)
tag.update_column(:category, category)
end
tag
else
Tag.new.tap do |tag|
tag.name = name
tag.category = category
tag.save
Tag.new.tap do |t|
t.name = name
t.category = category
t.save
end
end
end
@@ -216,13 +216,21 @@ class Tag < ActiveRecord::Base
}
scan_query(query).each do |token|
if token =~ /\A(-uploader|uploader|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|status|tagcount|gentags|arttags|chartags|copytags):(.+)\Z/
if token =~ /\A(-uploader|uploader|-approver|approver|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|status|tagcount|gentags|arttags|chartags|copytags):(.+)\Z/
case $1
when "-uploader"
q[:tags][:exclude] << "uploader:#{User.name_to_id($2)}"
q[:uploader_id_neg] ||= []
q[:uploader_id_neg] << User.name_to_id($2)
when "uploader"
q[:tags][:related] << "uploader:#{User.name_to_id($2)}"
q[:uploader_id] = User.name_to_id($2)
when "-approver"
q[:approver_id_neg] ||= []
q[:approver_id_neg] << User.name.to_id($2)
when "approver"
q[:approver_id] = User.name.to_id($2)
when "-pool"
q[:tags][:exclude] << "pool:#{Pool.name_to_id($2)}"

View File

@@ -17,7 +17,7 @@ class Upload < ActiveRecord::Base
module ValidationMethods
def uploader_is_not_limited
if !uploader.can_upload?
update_attribute(:status, "error: uploader has reached their daily limit")
update_column(:status, "error: uploader has reached their daily limit")
end
end
@@ -29,19 +29,19 @@ class Upload < ActiveRecord::Base
def validate_file_exists
unless File.exists?(file_path)
update_attribute(:status, "error: file does not exist")
update_column(:status, "error: file does not exist")
end
end
def validate_file_content_type
unless is_valid_content_type?
update_attribute(:status, "error: invalid content type (#{file_ext} not allowed)")
update_column(:status, "error: invalid content type (#{file_ext} not allowed)")
end
end
def validate_md5_confirmation
if !md5_confirmation.blank? && md5_confirmation != md5
update_attribute(:status, "error: md5 mismatch")
update_column(:status, "error: md5 mismatch")
end
end
end
@@ -49,7 +49,7 @@ class Upload < ActiveRecord::Base
module ConversionMethods
def process!
CurrentUser.scoped(uploader, uploader_ip_addr) do
update_attribute(:status, "processing")
update_column(:status, "processing")
if is_downloadable?
download_from_source(temp_file_path)
end
@@ -67,12 +67,12 @@ class Upload < ActiveRecord::Base
if post.save
update_attributes(:status => "completed", :post_id => post.id)
else
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
update_column(:status, "error: " + post.errors.full_messages.join(", "))
end
end
rescue Exception => x
raise
update_attribute(:status, "error: #{x} - #{x.message}")
update_column(:status, "error: #{x} - #{x.message}")
ensure
delete_temp_file
end
@@ -87,6 +87,8 @@ class Upload < ActiveRecord::Base
p.rating = rating
p.source = source
p.file_size = file_size
p.uploader_id = uploader_id
p.uploader_ip_addr = uploader_ip_addr
unless uploader.is_contributor?
p.is_pending = true
@@ -97,7 +99,7 @@ class Upload < ActiveRecord::Base
def merge_tags(post)
post.tag_string += " #{tag_string}"
post.save
update_attribute(:status, "duplicate: #{post.id}")
update_column(:status, "duplicate: #{post.id}")
end
end

View File

@@ -28,6 +28,7 @@ class User < ActiveRecord::Base
after_save :update_cache
before_create :promote_to_admin_if_first_user
has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy
has_many :posts, :foreign_key => "uploader_id"
has_one :ban
has_many :subscriptions, :class_name => "TagSubscription"
has_many :note_versions, :foreign_key => "updater_id"
@@ -46,7 +47,7 @@ class User < ActiveRecord::Base
end
def unban!
update_attribute(:is_banned, false)
update_column(:is_banned, false)
ban.destroy
end
end
@@ -218,7 +219,7 @@ class User < ActiveRecord::Base
def verify!(key)
if email_verification_key == key
self.update_attribute(:email_verification_key, nil)
self.update_column(:email_verification_key, nil)
else
raise User::Error.new("Verification key does not match")
end
@@ -293,12 +294,6 @@ class User < ActiveRecord::Base
end
end
module PostMethods
def posts
Post.where("uploader_string = ?", "uploader:#{id}")
end
end
include BanMethods
include NameMethods
include PasswordMethods
@@ -309,7 +304,6 @@ class User < ActiveRecord::Base
include BlacklistMethods
include ForumMethods
include LimitMethods
include PostMethods
def initialize_default_image_size
self.default_image_size = "Medium"