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

@@ -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