fixed tests
This commit is contained in:
@@ -1,14 +1,18 @@
|
|||||||
class FavoritesController < ApplicationController
|
class FavoritesController < ApplicationController
|
||||||
|
def index
|
||||||
|
@posts = CurrentUser.favorite_posts(params)
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@favorite = Favorite.create(
|
@favorite = Favorite.create(
|
||||||
:user_id => CurrentUser.user.id,
|
:user_id => CurrentUser.id,
|
||||||
:post_id => params[:favorite][:post_id]
|
:post_id => params[:favorite][:post_id]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
Favorite.destroy(
|
Favorite.destroy(
|
||||||
:user_id => CurrentUser.user.id,
|
:user_id => CurrentUser.id,
|
||||||
:post_id => params[:favorite][:post_id]
|
:post_id => params[:favorite][:post_id]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Dmail < ActiveRecord::Base
|
|||||||
belongs_to :from, :class_name => "User"
|
belongs_to :from, :class_name => "User"
|
||||||
after_create :update_recipient
|
after_create :update_recipient
|
||||||
after_create :send_dmail
|
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 :for, lambda {|user| where(["owner_id = ?", user])}
|
||||||
scope :inbox, where("to_id = owner_id")
|
scope :inbox, where("to_id = owner_id")
|
||||||
scope :sent, where("from_id = owner_id")
|
scope :sent, where("from_id = owner_id")
|
||||||
@@ -45,11 +45,11 @@ class Dmail < ActiveRecord::Base
|
|||||||
Dmail.transaction do
|
Dmail.transaction do
|
||||||
copy = Dmail.new(params)
|
copy = Dmail.new(params)
|
||||||
copy.owner_id = copy.to_id
|
copy.owner_id = copy.to_id
|
||||||
copy.save
|
copy.save!
|
||||||
|
|
||||||
copy = Dmail.new(params)
|
copy = Dmail.new(params)
|
||||||
copy.owner_id = CurrentUser.id
|
copy.owner_id = CurrentUser.id
|
||||||
copy.save
|
copy.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc"
|
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc"
|
||||||
validates_presence_of :title, :creator_id
|
validates_presence_of :title, :creator_id
|
||||||
scope :search_title, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
|
scope :search_title, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
|
||||||
accepts_nested_attributes_for :forum_posts
|
accepts_nested_attributes_for :posts
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ class IpBan < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.search(user_ids)
|
def self.search(user_ids)
|
||||||
comments = count_by_ip_addr("comments", user_ids, "creator_id", "ip_addr")
|
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")
|
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")
|
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")
|
wiki_pages = count_by_ip_addr("wiki_page_versions", user_ids, "updater_id", "updater_ip_addr")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"comments" => comments,
|
"comments" => comments,
|
||||||
"posts" => posts,
|
|
||||||
"notes" => notes,
|
"notes" => notes,
|
||||||
"pools" => pools,
|
"pools" => pools,
|
||||||
"wiki_pages" => wiki_pages
|
"wiki_pages" => wiki_pages
|
||||||
|
|||||||
@@ -5,12 +5,6 @@ class JanitorTrial < ActiveRecord::Base
|
|||||||
def send_dmail
|
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."
|
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(
|
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
|
||||||
:title => "Test Janitor Trial Period",
|
|
||||||
:body => body
|
|
||||||
)
|
|
||||||
dmail.from_id = User.admins.first.id
|
|
||||||
dmail.to_id = user_id
|
|
||||||
Dmail.create_new(dmail)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -112,21 +112,14 @@ class User < ActiveRecord::Base
|
|||||||
module FavoriteMethods
|
module FavoriteMethods
|
||||||
def favorite_posts(options = {})
|
def favorite_posts(options = {})
|
||||||
favorites_table = Favorite.table_name_for(id)
|
favorites_table = Favorite.table_name_for(id)
|
||||||
before_id = options[:before]
|
if options[:before_id]
|
||||||
before_id_sql_fragment = "AND favorites.id < #{before_id.to_i}" if before_id
|
before_id_sql_fragment = ["favorites.id < ?", options[:before_id]]
|
||||||
|
else
|
||||||
|
before_id_sql_fragment = "TRUE"
|
||||||
|
end
|
||||||
limit = options[:limit] || 20
|
limit = options[:limit] || 20
|
||||||
|
|
||||||
sql = <<-EOS
|
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")
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,18 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
context "A dmail" do
|
context "A dmail" do
|
||||||
setup do
|
setup do
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
|
@user = Factory.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
ActionMailer::Base.delivery_method = :test
|
ActionMailer::Base.delivery_method = :test
|
||||||
ActionMailer::Base.perform_deliveries = true
|
ActionMailer::Base.perform_deliveries = true
|
||||||
ActionMailer::Base.deliveries = []
|
ActionMailer::Base.deliveries = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
end
|
||||||
|
|
||||||
context "search" do
|
context "search" do
|
||||||
should "return results based on title contents" do
|
should "return results based on title contents" do
|
||||||
dmail = Factory.create(:dmail, :title => "xxx")
|
dmail = Factory.create(:dmail, :title => "xxx")
|
||||||
@@ -28,11 +35,10 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "should parse user names" do
|
should "should parse user names" do
|
||||||
user = Factory.create(:user)
|
|
||||||
dmail = Factory.build(:dmail)
|
dmail = Factory.build(:dmail)
|
||||||
dmail.to_id = nil
|
dmail.to_id = nil
|
||||||
dmail.to_name = user.name
|
dmail.to_name = @user.name
|
||||||
assert(dmail.to_id == user.id)
|
assert(dmail.to_id == @user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "construct a response" do
|
should "construct a response" do
|
||||||
@@ -45,9 +51,8 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "create a copy for each user" do
|
should "create a copy for each user" do
|
||||||
dmail = Factory.build(:dmail)
|
|
||||||
assert_difference("Dmail.count", 2) do
|
assert_difference("Dmail.count", 2) do
|
||||||
Dmail.create_split(dmail.attributes)
|
Dmail.create_split(:to_id => @user.id, :title => "foo", :body => "foo")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class FavoriteTest < ActiveSupport::TestCase
|
|||||||
p1.add_favorite(user1)
|
p1.add_favorite(user1)
|
||||||
p2.add_favorite(user1)
|
p2.add_favorite(user1)
|
||||||
p3.add_favorite(user1)
|
p3.add_favorite(user1)
|
||||||
favorites = user1.favorite_posts(:limit => 1)
|
favorites = user1.favorite_posts
|
||||||
favorites = user1.favorite_posts(:before => favorites.first.favorite_id)
|
favorites = user1.favorite_posts(:before_id => favorites.first.favorite_id)
|
||||||
assert_equal(2, favorites.size)
|
assert_equal(2, favorites.count)
|
||||||
assert_equal(p2.id, favorites[0].id)
|
assert_equal(p2.id, favorites[0].id)
|
||||||
assert_equal(p1.id, favorites[1].id)
|
assert_equal(p1.id, favorites[1].id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
|
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||||
p1.reload
|
p1.reload
|
||||||
assert_not_equal("uploader:#{ta1.creator_id}", p1.uploader_string)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class TagImplicationTest < ActiveSupport::TestCase
|
|||||||
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||||
p1.reload
|
p1.reload
|
||||||
assert_not_equal("uploader:#{ti1.creator_id}", p1.uploader_string)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user