* Some major bug fixes related to post sets. Tests for pools and favorites were added.
* Refactored the favorites code a bit. Adding a favorite from either an user or a post now works and will update all necessary records.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module PostSets
|
||||
module Favorite
|
||||
def user
|
||||
@user ||= User.find(params[:id])
|
||||
@user ||= ::User.find(params[:id])
|
||||
end
|
||||
|
||||
def tags
|
||||
@@ -19,11 +19,15 @@ module PostSets
|
||||
end
|
||||
|
||||
def count
|
||||
@count ||= Favorite.count(user.id)
|
||||
@count ||= relation.count
|
||||
end
|
||||
|
||||
def posts
|
||||
@posts ||= user.favorites(pagination_options)
|
||||
@posts ||= slice(relation).map(&:post)
|
||||
end
|
||||
|
||||
def relation
|
||||
::Favorite.model_for(user.id).where("user_id = ?", user.id).order("id desc")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
module PostSets
|
||||
module Numbered
|
||||
attr_reader :page
|
||||
|
||||
def initialize(params)
|
||||
super
|
||||
@page = options[:page] ? options[:page].to_i : 1
|
||||
end
|
||||
|
||||
def total_pages
|
||||
@total_pages ||= (count / limit.to_f).ceil.to_i
|
||||
end
|
||||
@@ -17,7 +10,7 @@ module PostSets
|
||||
end
|
||||
|
||||
def slice(relation)
|
||||
relation.offset(offset).all
|
||||
relation.offset(offset).limit(limit).all
|
||||
end
|
||||
|
||||
def pagination_options
|
||||
@@ -28,6 +21,10 @@ module PostSets
|
||||
offset == 0
|
||||
end
|
||||
|
||||
def page
|
||||
@page ||= params[:page] ? params[:page].to_i : 1
|
||||
end
|
||||
|
||||
def offset
|
||||
((page < 1) ? 0 : (page - 1)) * limit
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module PostSets
|
||||
module Pool
|
||||
def pool
|
||||
@pool ||= Pool.find(params[:id])
|
||||
@pool ||= ::Pool.find(params[:id])
|
||||
end
|
||||
|
||||
def tags
|
||||
@@ -19,7 +19,7 @@ module PostSets
|
||||
end
|
||||
|
||||
def posts
|
||||
@posts ||= pool.posts(pagination_options)
|
||||
@posts ||= pool.posts(pagination_options).limit(limit).all
|
||||
end
|
||||
|
||||
def reload
|
||||
|
||||
@@ -5,7 +5,7 @@ module PostSets
|
||||
attr_accessor :tags, :count, :wiki_page, :artist, :suggestions
|
||||
|
||||
def tags
|
||||
@tags ||= Tag.normalize(params[:tags])
|
||||
@tags ||= ::Tag.normalize(params[:tags])
|
||||
end
|
||||
|
||||
def count
|
||||
@@ -13,7 +13,7 @@ module PostSets
|
||||
end
|
||||
|
||||
def posts
|
||||
@posts ||= slice(::Post.tag_match(tags).limit(limit))
|
||||
@posts ||= slice(::Post.tag_match(tags))
|
||||
end
|
||||
|
||||
def reload
|
||||
@@ -42,7 +42,7 @@ module PostSets
|
||||
end
|
||||
|
||||
def tag_array
|
||||
@tag_array ||= Tag.scan_query(tags)
|
||||
@tag_array ||= ::Tag.scan_query(tags)
|
||||
end
|
||||
|
||||
def validate
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
module PostSets
|
||||
module Sequential
|
||||
attr_reader :before_id, :after_id
|
||||
def before_id
|
||||
params[:before_id]
|
||||
end
|
||||
|
||||
def initialize(params)
|
||||
super
|
||||
@before_id = params[:before_id]
|
||||
@after_id = params[:after_id]
|
||||
def after_id
|
||||
params[:after_id]
|
||||
end
|
||||
|
||||
def slice(relation)
|
||||
if before_id
|
||||
relation.where("id < ?", before_id).all
|
||||
relation.where("id < ?", before_id).limit(limit).all
|
||||
elsif after_id
|
||||
relation.where("id > ?", after_id).order("id asc").all.reverse
|
||||
relation.where("id > ?", after_id).order("id asc").limit(limit).all.reverse
|
||||
else
|
||||
relation.all
|
||||
relation.limit(limit).all
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ module PostSets
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags ||= Tag.normalize(wiki_page.title)
|
||||
@tags ||= ::Tag.normalize(wiki_page.title)
|
||||
end
|
||||
|
||||
def posts
|
||||
|
||||
Reference in New Issue
Block a user