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

@@ -0,0 +1,14 @@
module Moderator
module Dashboard
module Queries
class Comment
attr_reader :comment, :count
def initialize(hash)
@comment = Comment.find(hash["comment_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -0,0 +1,14 @@
module Moderator
module Dashboard
module Queries
class Post
attr_reader :post, :count
def initialize(hash)
@post = Post.find(hash["post_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -0,0 +1,30 @@
module Moderator
module Dashboard
module Queries
class PostAppeal
attr_reader :post, :reason
def self.all(min_date)
sql = <<-EOS
SELECT post_appeals.post_id, count(*)
FROM post_appeals
JOIN posts ON posts.id = post_appeals.post_id
WHERE
post_appeals.created_at > ?
and posts.status <> ?
GROUP BY post_appeals.post_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date).map {|x| new(x)}
end
def initialize(hash)
@post = Post.find(hash["post_id"])
@reason = hash["reason"]
end
end
end
end
end

View File

@@ -0,0 +1,31 @@
module Moderator
module Dashboard
module Queries
class PostFlag
attr_reader :post, :count
def self.all(min_date)
sql = <<-EOS
SELECT post_flags.post_id, count(*)
FROM post_flags
JOIN posts ON posts.id = post_flags.post_id
WHERE
post_flags.created_at > ?
AND post_flags.reason <> ?
AND posts.status <> 'deleted'
GROUP BY post_flags.post_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, "Unapproved in three days").map {|x| new(x)}
end
def initialize(hash)
@post = Post.find(hash["post_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -0,0 +1,13 @@
module Moderator
module Dashboard
module Queries
class Upload
def self.all(min_date)
ActiveRecord::Base.without_timeout do
@upload_activity = ActiveRecord::Base.select_all_sql("select posts.uploader_string, count(*) from posts join users on posts.user_id = users.id where posts.created_at > ? and users.level <= ? group by posts.user_id order by count(*) desc limit 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
end
end
end
end
end

View File

@@ -0,0 +1,14 @@
module Moderator
module Dashboard
module Queries
class User
attr_reader :user, :count
def initialize(hash)
@user = User.find(hash["user_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -0,0 +1,6 @@
module Moderator
module Dashboard
class Report
end
end
end

View File

@@ -0,0 +1,54 @@
class ModeratorDashboard
attr_reader :min_date, :max_level
def initialize(min_date, max_level)
@min_date = min_date
@max_level = max_level
end
def upload_activity
@upload_activity
end
def comment_activity(positive = false)
if positive
ActiveRecord::Base.select_all_sql("SELECT comment_votes.comment_id, count(*) FROM comment_votes JOIN comments ON comments.id = comment_votes.comment_id JOIN users ON users.id = comments.user_id WHERE comment_votes.created_at > ? AND comments.score > 0 AND users.level <= ? GROUP BY comment_votes.comment_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| CommentActivity.new(x)}
else
ActiveRecord::Base.select_all_sql("SELECT comment_votes.comment_id, count(*) FROM comment_votes JOIN comments ON comments.id = comment_votes.comment_id JOIN users ON users.id = comments.user_id WHERE comment_votes.created_at > ? AND comments.score < 0 AND users.level <= ? GROUP BY comment_votes.comment_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| CommentActivity.new(x)}
end
end
def post_activity(positive = false)
ActiveRecord::Base.without_timeout do
if positive
@post_activity = ActiveRecord::Base.select_all_sql("SELECT post_votes.post_id, count(*) FROM post_votes JOIN posts ON posts.id = post_votes.post_id JOIN users ON users.id = posts.user_id WHERE post_votes.created_at > ? AND posts.score > 0 AND users.level <= ? GROUP BY post_votes.post_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| PostActivity.new(x)}
else
@post_activity = ActiveRecord::Base.select_all_sql("SELECT post_votes.post_id, count(*) FROM post_votes JOIN posts ON posts.id = post_votes.post_id JOIN users ON users.id = posts.user_id WHERE post_votes.created_at > ? AND posts.score < 0 AND users.level <= ? AND posts.status <> 'deleted' GROUP BY post_votes.post_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| PostActivity.new(x)}
end
end
@post_activity
end
def tag_activity
ActiveRecord::Base.without_timeout do
@tag_activity = ActiveRecord::Base.select_all_sql("SELECT post_tag_histories.user_id, count(*) FROM post_tag_histories JOIN users ON users.id = post_tag_histories.user_id WHERE post_tag_histories.created_at > ? AND users.level <= ? GROUP BY post_tag_histories.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
@tag_activity
end
def note_activity
ActiveRecord::Base.select_all_sql("SELECT note_versions.user_id, count(*) FROM note_versions JOIN users ON users.id = note_versions.user_id WHERE note_versions.created_at > ? AND users.level <= ? GROUP BY note_versions.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
def wiki_page_activity
ActiveRecord::Base.select_all_sql("SELECT wiki_page_versions.user_id, count(*) FROM wiki_page_versions JOIN users ON users.id = wiki_page_versions.user_id WHERE wiki_page_versions.created_at > ? AND users.level <= ? GROUP BY wiki_page_versions.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
def artist_activity
ActiveRecord::Base.select_all_sql("SELECT artist_versions.updater_id AS user_id, count(*) FROM artist_versions JOIN users ON users.id = artist_versions.updater_id WHERE artist_versions.created_at > ? AND users.level <= ? GROUP BY artist_versions.updater_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
end

View File

@@ -2,7 +2,7 @@ module PostSets
class Favorite < Base
attr_reader :user, :page, :favorites
def initialize(user_id, page)
def initialize(user_id, page = 1)
@user = ::User.find(user_id)
@favorites = ::Favorite.model_for(user.id).for_user(user.id).paginate(page)
end

View File

@@ -4,15 +4,11 @@ module PostSets
attr_accessor :total_pages, :current_page
end
attr_reader :pool, :page, :posts
attr_reader :pool, :page
def initialize(pool, page)
def initialize(pool, page = 1)
@pool = pool
@page = page
@posts = pool.posts(:offset => offset, :limit => limit)
@posts.extend(ActiveRecordExtension)
@posts.total_pages = total_pages
@posts.current_page = current_page
end
def offset
@@ -27,6 +23,16 @@ module PostSets
["pool:#{pool.id}"]
end
def posts
@posts ||= begin
x = pool.posts(:offset => offset, :limit => limit)
x.extend(ActiveRecordExtension)
x.total_pages = total_pages
x.current_page = current_page
x
end
end
def tag_string
tag_array.join("")
end

View File

@@ -1,11 +1,13 @@
module PostSets
class SearchError < Exception
end
class Post < Base
attr_reader :tag_array, :page, :posts
attr_reader :tag_array, :page
def initialize(params)
@tag_array = Tag.scan_query(params[:tags])
@page = params[:page]
@posts = ::Post.tag_match(tag_string).paginate(page)
def initialize(tags, page = 1)
@tag_array = Tag.scan_query(tags)
@page = page
end
def tag_string
@@ -24,6 +26,14 @@ module PostSets
end
end
def posts
if tag_array.size > 2 && !CurrentUser.is_privileged?
raise SearchError
end
@posts ||= ::Post.tag_match(tag_string).paginate(page)
end
def has_artist?
tag_array.any? && ::Artist.name_equals(tag_string).exists?
end
@@ -36,6 +46,10 @@ module PostSets
tag_array.size == 1
end
def current_page
[page.to_i, 1].max
end
def presenter
@presenter ||= ::PostSetPresenters::Post.new(self)
end