post disapprovals: fix tests and API create action.
* Fix tests. * Fix create action in API (couldn't redirect to show action). * Clean up user initialization.
This commit is contained in:
@@ -5,7 +5,7 @@ class PostDisapprovalsController < ApplicationController
|
||||
|
||||
def create
|
||||
cookies.permanent[:moderated] = Time.now.to_i
|
||||
@post_disapproval = PostDisapproval.create(post_disapproval_params)
|
||||
@post_disapproval = PostDisapproval.create(user: CurrentUser.user, **post_disapproval_params)
|
||||
respond_with(@post_disapproval)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ class PostDisapproval < ApplicationRecord
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
||||
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
||||
|
||||
@@ -13,10 +12,6 @@ class PostDisapproval < ApplicationRecord
|
||||
scope :poor_quality, -> {where(:reason => "poor_quality")}
|
||||
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
end
|
||||
|
||||
def self.prune!
|
||||
PostDisapproval.where("post_id in (select _.post_id from post_disapprovals _ where _.created_at < ?)", DELETION_THRESHOLD.ago).delete_all
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user