diff --git a/app/controllers/post_disapprovals_controller.rb b/app/controllers/post_disapprovals_controller.rb index 747f3ad31..7a9195608 100644 --- a/app/controllers/post_disapprovals_controller.rb +++ b/app/controllers/post_disapprovals_controller.rb @@ -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 diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index 76540365a..4f9a7a7b9 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index cd2c37479..3b98cefde 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -205,7 +205,7 @@ Rails.application.routes.draw do resources :post_appeals resources :post_flags resources :post_approvals, only: [:index] - resources :post_disapprovals, only: [:create, :index] + resources :post_disapprovals, only: [:create, :show, :index] resources :post_versions, :only => [:index, :search] do member do put :undo diff --git a/test/factories/post_disapproval.rb b/test/factories/post_disapproval.rb index 156ac1edb..686746198 100644 --- a/test/factories/post_disapproval.rb +++ b/test/factories/post_disapproval.rb @@ -1,5 +1,6 @@ FactoryBot.define do factory(:post_disapproval) do + user reason { %w(breaks_rules poor_quality disinterest).sample } message { FFaker::Lorem.sentence } end diff --git a/test/functional/post_disapprovals_controller_test.rb b/test/functional/post_disapprovals_controller_test.rb index 9789061b1..5a0e5f18b 100644 --- a/test/functional/post_disapprovals_controller_test.rb +++ b/test/functional/post_disapprovals_controller_test.rb @@ -14,7 +14,7 @@ class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest context "create action" do should "render" do assert_difference("PostDisapproval.count", 1) do - post_auth moderator_post_disapprovals_path, @admin, params: { post_disapproval: { post_id: @post.id, reason: "breaks_rules" }, format: "js" } + post_auth post_disapprovals_path, @admin, params: { post_disapproval: { post_id: @post.id, reason: "breaks_rules" }, format: "js" } end assert_response :success end @@ -22,7 +22,7 @@ class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest context "for json" do should "render" do assert_difference("PostDisapproval.count", 1) do - post_auth moderator_post_disapprovals_path, @admin, params: { post_disapproval: { post_id: @post.id, reason: "breaks_rules" }, format: "json" } + post_auth post_disapprovals_path, @admin, params: { post_disapproval: { post_id: @post.id, reason: "breaks_rules" }, format: "json" } end assert_response :success end @@ -32,7 +32,7 @@ class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest context "index action" do should "render" do disapproval = FactoryBot.create(:post_disapproval, post: @post) - get_auth moderator_post_disapprovals_path, @admin + get_auth post_disapprovals_path, @admin assert_response :success end