fixed tests

This commit is contained in:
albert 2010-11-19 17:20:13 -05:00
parent c6304c6e08
commit f8ab736677
10 changed files with 33 additions and 39 deletions

View File

@ -1,14 +1,18 @@
class FavoritesController < ApplicationController
def index
@posts = CurrentUser.favorite_posts(params)
end
def create
@favorite = Favorite.create(
:user_id => CurrentUser.user.id,
:user_id => CurrentUser.id,
:post_id => params[:favorite][:post_id]
)
end
def destroy
Favorite.destroy(
:user_id => CurrentUser.user.id,
:user_id => CurrentUser.id,
:post_id => params[:favorite][:post_id]
)
end

View File

@ -9,7 +9,7 @@ class Dmail < ActiveRecord::Base
belongs_to :from, :class_name => "User"
after_create :update_recipient
after_create :send_dmail
attr_accessible :title, :body, :is_deleted
attr_accessible :title, :body, :is_deleted, :to_id
scope :for, lambda {|user| where(["owner_id = ?", user])}
scope :inbox, where("to_id = owner_id")
scope :sent, where("from_id = owner_id")
@ -45,11 +45,11 @@ class Dmail < ActiveRecord::Base
Dmail.transaction do
copy = Dmail.new(params)
copy.owner_id = copy.to_id
copy.save
copy.save!
copy = Dmail.new(params)
copy.owner_id = CurrentUser.id
copy.save
copy.save!
end
end

View File

@ -4,5 +4,5 @@ class ForumTopic < ActiveRecord::Base
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc"
validates_presence_of :title, :creator_id
scope :search_title, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
accepts_nested_attributes_for :forum_posts
accepts_nested_attributes_for :posts
end

View File

@ -9,14 +9,12 @@ class IpBan < ActiveRecord::Base
def self.search(user_ids)
comments = count_by_ip_addr("comments", user_ids, "creator_id", "ip_addr")
posts = count_by_ip_addr("post_versions", user_ids, "updater_id", "updater_ip_addr")
notes = count_by_ip_addr("note_versions", user_ids, "updater_id", "updater_ip_addr")
pools = count_by_ip_addr("pool_versions", user_ids, "updater_id", "updater_ip_addr")
wiki_pages = count_by_ip_addr("wiki_page_versions", user_ids, "updater_id", "updater_ip_addr")
return {
"comments" => comments,
"posts" => posts,
"notes" => notes,
"pools" => pools,
"wiki_pages" => wiki_pages

View File

@ -5,12 +5,6 @@ class JanitorTrial < ActiveRecord::Base
def send_dmail
body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are quality uploads, then you will be promoted to full janitor status which grants you the ability to delete and undelete posts, ban users, and revert tag changes from vandals. If you fail the trial period, you will be demoted back to your original level and you'll receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 5 approvals a week to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
dmail = Dmail.new(
:title => "Test Janitor Trial Period",
:body => body
)
dmail.from_id = User.admins.first.id
dmail.to_id = user_id
Dmail.create_new(dmail)
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
end
end

View File

@ -112,21 +112,14 @@ class User < ActiveRecord::Base
module FavoriteMethods
def favorite_posts(options = {})
favorites_table = Favorite.table_name_for(id)
before_id = options[:before]
before_id_sql_fragment = "AND favorites.id < #{before_id.to_i}" if before_id
if options[:before_id]
before_id_sql_fragment = ["favorites.id < ?", options[:before_id]]
else
before_id_sql_fragment = "TRUE"
end
limit = options[:limit] || 20
sql = <<-EOS
SELECT posts.*, favorites.id AS favorite_id
FROM posts
JOIN #{favorites_table} AS favorites ON favorites.post_id = posts.id
WHERE
favorites.user_id = #{id}
#{before_id_sql_fragment}
ORDER BY favorite_id DESC
LIMIT #{limit.to_i}
EOS
Post.find_by_sql(sql)
Post.joins("JOIN #{favorites_table} AS favorites ON favorites.post_id = posts.id").where("favorites.user_id = ?", id).where(before_id_sql_fragment).order("favorite_id DESC").limit(limit).select("posts.*, favorites.id AS favorite_id")
end
end

View File

@ -4,11 +4,18 @@ class DmailTest < ActiveSupport::TestCase
context "A dmail" do
setup do
MEMCACHE.flush_all
@user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
teardown do
CurrentUser.user = nil
end
context "search" do
should "return results based on title contents" do
dmail = Factory.create(:dmail, :title => "xxx")
@ -28,11 +35,10 @@ class DmailTest < ActiveSupport::TestCase
end
should "should parse user names" do
user = Factory.create(:user)
dmail = Factory.build(:dmail)
dmail.to_id = nil
dmail.to_name = user.name
assert(dmail.to_id == user.id)
dmail.to_name = @user.name
assert(dmail.to_id == @user.id)
end
should "construct a response" do
@ -45,9 +51,8 @@ class DmailTest < ActiveSupport::TestCase
end
should "create a copy for each user" do
dmail = Factory.build(:dmail)
assert_difference("Dmail.count", 2) do
Dmail.create_split(dmail.attributes)
Dmail.create_split(:to_id => @user.id, :title => "foo", :body => "foo")
end
end

View File

@ -42,9 +42,9 @@ class FavoriteTest < ActiveSupport::TestCase
p1.add_favorite(user1)
p2.add_favorite(user1)
p3.add_favorite(user1)
favorites = user1.favorite_posts(:limit => 1)
favorites = user1.favorite_posts(:before => favorites.first.favorite_id)
assert_equal(2, favorites.size)
favorites = user1.favorite_posts
favorites = user1.favorite_posts(:before_id => favorites.first.favorite_id)
assert_equal(2, favorites.count)
assert_equal(p2.id, favorites[0].id)
assert_equal(p1.id, favorites[1].id)
end

View File

@ -68,7 +68,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
p1.reload
assert_not_equal("uploader:#{ta1.creator_id}", p1.uploader_string)
assert_equal(ta1.creator_id, p1.versions.last.updater_id)
assert_equal(ta1.creator_id, p1.history.revisions.last["user_id"])
end
end
end

View File

@ -114,7 +114,7 @@ class TagImplicationTest < ActiveSupport::TestCase
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
p1.reload
assert_not_equal("uploader:#{ti1.creator_id}", p1.uploader_string)
assert_equal(ti1.creator_id, p1.versions.last.updater_id)
assert_equal(ti1.creator_id, p1.history.revisions.last["user_id"])
end
end
end