* Added note version controller and test
* Added pool version controller and test * Refactored unit tests for post disapprovals * Renamed PostModerationDetail to PostDisapproval
This commit is contained in:
10
app/controllers/note_versions_controller.rb
Normal file
10
app/controllers/note_versions_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class NoteVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
|
||||
def index
|
||||
@search = NoteVersion.search(params[:search])
|
||||
@note_versions = @search.paginate(:page => params[:page])
|
||||
respond_with(@note_versions)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class PoolVersionsController < ApplicationController
|
||||
def index
|
||||
@search = PoolVersion.search(params[:search])
|
||||
@pool_versions = @search.paginate(:page => params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
class PostModerationController < ApplicationController
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :janitor_only
|
||||
|
||||
def moderate
|
||||
@search = Post.pending.available_for_moderation.search(params[:search]).order("id asc")
|
||||
@posts = @search.paginate(:page => params[:page])
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
def update
|
||||
def approve
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.approve!
|
||||
respond_with(@post, :location => post_moderation_moderate_path)
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
def disapprove
|
||||
@post = Post.find(params[:post_id])
|
||||
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
|
||||
respond_with(@post_disapproval, :location => post_moderation_moderate_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
class NoteVersion < ActiveRecord::Base
|
||||
before_validation :initialize_updater
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
@@ -26,8 +26,11 @@ class Post < ActiveRecord::Base
|
||||
validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?}
|
||||
validate :validate_parent_does_not_have_a_parent
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at
|
||||
scope :pending, where(["is_pending = ?", true])
|
||||
scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)}
|
||||
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
|
||||
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
|
||||
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
|
||||
|
||||
module FileMethods
|
||||
def delete_files
|
||||
|
||||
11
app/models/post_disapproval.rb
Normal file
11
app/models/post_disapproval.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class PostDisapproval < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id]
|
||||
|
||||
def self.prune!
|
||||
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").select("post_disapprovals.*").each do |post_disapproval|
|
||||
post_disapproval.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
class PostModerationDetail < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
|
||||
def self.filter(posts, user, select_hidden = false)
|
||||
hidden = where(:user_id => user.id).select("post_id").map(&:post_id)
|
||||
if select_hidden
|
||||
posts.select {|x| hidden.include?(x.id)}
|
||||
else
|
||||
posts.reject {|x| hidden.include?(x.id)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.prune!
|
||||
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").each do |hidden_post|
|
||||
hidden_post.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
0
app/views/note_versions/index.html.erb
Normal file
0
app/views/note_versions/index.html.erb
Normal file
0
app/views/pool_versions/index.html.erb
Normal file
0
app/views/pool_versions/index.html.erb
Normal file
0
app/views/post_moderation/moderate.html.erb
Normal file
0
app/views/post_moderation/moderate.html.erb
Normal file
@@ -47,8 +47,8 @@ Danbooru::Application.routes.draw do
|
||||
put :revert
|
||||
end
|
||||
end
|
||||
|
||||
resources :post_histories, :only => [:index]
|
||||
resource :post_moderation, :controller => "post_moderation"
|
||||
resource :session
|
||||
resources :tags
|
||||
resources :tag_aliases do
|
||||
@@ -69,6 +69,9 @@ Danbooru::Application.routes.draw do
|
||||
end
|
||||
resources :wiki_page_versions, :only => [:index]
|
||||
|
||||
match '/post_moderation/moderate' => 'post_moderation#moderate'
|
||||
match '/post_moderation/disapprove' => 'post_moderation#disapprove', :via => :put
|
||||
match '/post_moderation/approve' => 'post_moderation#approve', :via => :put
|
||||
match '/dtext/preview' => 'dtext#preview', :via => :post
|
||||
match "/site_map" => "static#site_map", :as => "site_map"
|
||||
match "/terms_of_service" => "static#terms_of_service", :as => "terms_of_service"
|
||||
|
||||
@@ -840,8 +840,8 @@ ALTER SEQUENCE ip_bans_id_seq OWNED BY ip_bans.id;
|
||||
|
||||
CREATE TABLE janitor_trials (
|
||||
id integer NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
promoted_at timestamp without time zone,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
);
|
||||
@@ -987,7 +987,6 @@ CREATE TABLE pools (
|
||||
name character varying(255),
|
||||
creator_id integer NOT NULL,
|
||||
description text,
|
||||
is_public boolean DEFAULT true NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
post_ids text DEFAULT ''::text NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
@@ -1014,6 +1013,38 @@ CREATE SEQUENCE pools_id_seq
|
||||
ALTER SEQUENCE pools_id_seq OWNED BY pools.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_disapprovals; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE post_disapprovals (
|
||||
id integer NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_disapprovals_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE post_disapprovals_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_disapprovals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE post_disapprovals_id_seq OWNED BY post_disapprovals.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -1046,38 +1077,6 @@ CREATE SEQUENCE post_histories_id_seq
|
||||
ALTER SEQUENCE post_histories_id_seq OWNED BY post_histories.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE post_moderation_details (
|
||||
id integer NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE post_moderation_details_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE post_moderation_details_id_seq OWNED BY post_moderation_details.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -1132,7 +1131,6 @@ CREATE TABLE posts (
|
||||
approver_string character varying(255) DEFAULT ''::character varying NOT NULL,
|
||||
fav_string text DEFAULT ''::text NOT NULL,
|
||||
pool_string text DEFAULT ''::text NOT NULL,
|
||||
view_count integer DEFAULT 0 NOT NULL,
|
||||
last_noted_at timestamp without time zone,
|
||||
last_commented_at timestamp without time zone,
|
||||
tag_string text DEFAULT ''::text NOT NULL,
|
||||
@@ -1809,14 +1807,14 @@ ALTER TABLE pools ALTER COLUMN id SET DEFAULT nextval('pools_id_seq'::regclass);
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE post_histories ALTER COLUMN id SET DEFAULT nextval('post_histories_id_seq'::regclass);
|
||||
ALTER TABLE post_disapprovals ALTER COLUMN id SET DEFAULT nextval('post_disapprovals_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE post_moderation_details ALTER COLUMN id SET DEFAULT nextval('post_moderation_details_id_seq'::regclass);
|
||||
ALTER TABLE post_histories ALTER COLUMN id SET DEFAULT nextval('post_histories_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
@@ -2134,6 +2132,14 @@ ALTER TABLE ONLY pools
|
||||
ADD CONSTRAINT pools_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_disapprovals_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY post_disapprovals
|
||||
ADD CONSTRAINT post_disapprovals_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2142,14 +2148,6 @@ ALTER TABLE ONLY post_histories
|
||||
ADD CONSTRAINT post_histories_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY post_moderation_details
|
||||
ADD CONSTRAINT post_moderation_details_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2660,6 +2658,13 @@ CREATE INDEX index_note_versions_on_note_id ON note_versions USING btree (note_i
|
||||
CREATE INDEX index_note_versions_on_updater_id ON note_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_note_versions_on_updater_ip_addr; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_note_versions_on_updater_ip_addr ON note_versions USING btree (updater_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_notes_on_creator_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2702,6 +2707,20 @@ CREATE INDEX index_pools_on_creator_id ON pools USING btree (creator_id);
|
||||
CREATE INDEX index_pools_on_name ON pools USING btree (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_disapprovals_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_disapprovals_on_post_id ON post_disapprovals USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_disapprovals_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_disapprovals_on_user_id ON post_disapprovals USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_histories_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2709,20 +2728,6 @@ CREATE INDEX index_pools_on_name ON pools USING btree (name);
|
||||
CREATE INDEX index_post_histories_on_post_id ON post_histories USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_moderation_details_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_moderation_details_on_post_id ON post_moderation_details USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_moderation_details_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_moderation_details_on_user_id ON post_moderation_details USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_posts_on_created_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2800,13 +2805,6 @@ CREATE INDEX index_posts_on_source ON posts USING btree (source);
|
||||
CREATE INDEX index_posts_on_tags_index ON posts USING gin (tag_index);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_posts_on_view_count; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_posts_on_view_count ON posts USING btree (view_count);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_removed_posts_on_created_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
@@ -28,7 +28,6 @@ class CreatePosts < ActiveRecord::Migration
|
||||
t.column :pool_string, :text, :null => false, :default => ""
|
||||
|
||||
# Cached
|
||||
t.column :view_count, :integer, :null => false, :default => 0
|
||||
t.column :last_noted_at, :datetime
|
||||
t.column :last_commented_at, :datetime
|
||||
|
||||
@@ -60,7 +59,6 @@ class CreatePosts < ActiveRecord::Migration
|
||||
add_index :posts, :image_width
|
||||
add_index :posts, :image_height
|
||||
add_index :posts, :source
|
||||
add_index :posts, :view_count
|
||||
add_index :posts, :parent_id
|
||||
|
||||
execute "CREATE INDEX index_posts_on_mpixels ON posts (((image_width * image_height)::numeric / 1000000.0))"
|
||||
|
||||
16
db/migrate/20100223001012_create_post_disapprovals.rb
Normal file
16
db/migrate/20100223001012_create_post_disapprovals.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class CreatePostDisapprovals < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :post_disapprovals do |t|
|
||||
t.column :user_id, :integer, :null => false
|
||||
t.column :post_id, :integer, :null => false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :post_disapprovals, :user_id
|
||||
add_index :post_disapprovals, :post_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :post_disapprovals
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
class CreatePostModerationDetails < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :post_moderation_details do |t|
|
||||
t.column :user_id, :integer, :null => false
|
||||
t.column :post_id, :integer, :null => false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :post_moderation_details, :user_id
|
||||
add_index :post_moderation_details, :post_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :post_moderation_details
|
||||
end
|
||||
end
|
||||
42
test/functional/note_versions_controller_test.rb
Normal file
42
test/functional/note_versions_controller_test.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
require 'test_helper'
|
||||
|
||||
class NoteVersionsControllerTest < ActionController::TestCase
|
||||
context "The note versions controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@note = Factory.create(:note)
|
||||
CurrentUser.id = 20
|
||||
@note.body = "1 2"
|
||||
@note.create_version
|
||||
CurrentUser.id = 30
|
||||
@note.body = "1 2 3"
|
||||
@note.create_version
|
||||
end
|
||||
|
||||
should "list all versions" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:note_versions))
|
||||
assert_equal(3, assigns(:note_versions).size)
|
||||
end
|
||||
|
||||
should "list all versions that match the search criteria" do
|
||||
get :index, {:search => {:updater_id_equals => "20"}}
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:note_versions))
|
||||
assert_equal(1, assigns(:note_versions).size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,40 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PoolVersionsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The pool versions controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@pool = Factory.create(:pool)
|
||||
CurrentUser.id = 20
|
||||
@pool.versions.create(:post_ids => "1 2")
|
||||
CurrentUser.id = 30
|
||||
@pool.versions.create(:post_ids => "1 2 3 4")
|
||||
end
|
||||
|
||||
should "list all versions" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:pool_versions))
|
||||
assert_equal(3, assigns(:pool_versions).size)
|
||||
end
|
||||
|
||||
should "list all versions that match the search criteria" do
|
||||
get :index, {:search => {:updater_id_equals => "20"}}
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:pool_versions))
|
||||
assert_equal(1, assigns(:pool_versions).size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,37 +1,51 @@
|
||||
require "test_helper"
|
||||
|
||||
class PostModerationControllerTest < ActionController::TestCase
|
||||
context "A post moderation controller" do
|
||||
should "" do
|
||||
ModQueuePost.destroy_all
|
||||
context "The post moderation controller" do
|
||||
setup do
|
||||
@mod = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "moderate action" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
should "list all pending posts" do
|
||||
get :moderate, {}, {:user_id => @mod.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "approve action" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
should "approve a post" do
|
||||
post :approve, {:post_id => @post.id}, {:user_id => @mod.id}
|
||||
@post.reload
|
||||
assert(!@post.is_pending?)
|
||||
end
|
||||
end
|
||||
|
||||
context "disapprove action" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
p1 = create_post("hoge", :status => "pending")
|
||||
p2 = create_post("hoge", :status => "active")
|
||||
p3 = create_post("moge", :status => "active")
|
||||
|
||||
p2.flag!("sage", User.find(1))
|
||||
p2.reload
|
||||
assert_not_nil(p2.flag_detail)
|
||||
|
||||
get :moderate, {}, {:user_id => 1}
|
||||
assert_response :success
|
||||
|
||||
get :moderate, {:query => "moge"}, {:user_id => 1}
|
||||
assert_response :success
|
||||
|
||||
post :moderate, {:id => p1.id, :commit => "Approve"}, {:user_id => 1}
|
||||
p1.reload
|
||||
assert_equal("active", p1.status)
|
||||
|
||||
post :moderate, {:id => p3.id, :reason => "sage", :commit => "Delete"}, {:user_id => 1}
|
||||
p3.reload
|
||||
assert_equal("deleted", p3.status)
|
||||
assert_not_nil(p3.flag_detail)
|
||||
assert_equal("sage", p3.flag_detail.reason)
|
||||
|
||||
assert_equal(0, ModQueuePost.count)
|
||||
post :moderate, {:id => "3", :commit => "Hide"}, {:user_id => 1}
|
||||
assert_equal(1, ModQueuePost.count)
|
||||
should "disapprove a post" do
|
||||
assert_difference("PostDisapproval.count", 1) do
|
||||
post :disapprove, {:post_id => @post.id}, {:user_id => @mod.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
105
test/functional/posts_controller_test.rb
Normal file
105
test/functional/posts_controller_test.rb
Normal file
@@ -0,0 +1,105 @@
|
||||
require "test_helper"
|
||||
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
context "The posts controller" do
|
||||
setup do
|
||||
@users = {}
|
||||
@users[:anon] = AnonymousUser.new
|
||||
@users[:member] = Factory.create(:user)
|
||||
CurrentUser.user = @users[:member]
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@users[:banned] = Factory.create(:banned_user)
|
||||
@users[:priv] = Factory.create(:privileged_user)
|
||||
@users[:contrib] = Factory.create(:contributor_user)
|
||||
@users[:janitor] = Factory.create(:janitor_user)
|
||||
@users[:mod] = Factory.create(:moderator_user)
|
||||
@users[:admin] = Factory.create(:admin_user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@users = nil
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, {:user_id => @users[:member]}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a post" do
|
||||
post :create, {:post => {:source => "", :file => upload_jpeg("#{Rails.root}/test/files/test.jpg"), :tag_string => "hoge", :rating => "s"}}, {:user_id => @users[:member].id}
|
||||
p = Post.last
|
||||
assert_equal("hoge", p.tag_string)
|
||||
assert_equal("jpg", p.file_ext)
|
||||
assert_equal("s", p.rating)
|
||||
assert_equal("uploader:#{@users[:member].name}", p.uploader_string)
|
||||
assert_equal(true, File.exists?(p.file_path))
|
||||
assert_equal(true, File.exists?(p.preview_path))
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@p1 = Factory.create(:post, :tag_string => "hoge")
|
||||
end
|
||||
|
||||
should "update a post" do
|
||||
put :update, {:post => {:tags => "moge", :rating => "Explicit"}, :id => @p1.id}, {:user_id => @users[:member].id}
|
||||
@p1.reload
|
||||
assert_equal("moge", p1.cached_tags)
|
||||
assert_equal("e", p1.rating)
|
||||
|
||||
assert_equal(2, p1.tag_history.size)
|
||||
post :update, {:post => {:rating => "Safe"}, :id => p1.id}, {:user_id => 3}
|
||||
assert_equal(3, p1.tag_history.size)
|
||||
|
||||
p1.update_attribute(:is_rating_locked, true)
|
||||
post :update, {:post => {:rating => "Questionable"}, :id => p1.id}, {:user_id => 3}
|
||||
p1.reload
|
||||
assert_equal("s", p1.rating)
|
||||
end
|
||||
end
|
||||
|
||||
should "update a post" do
|
||||
end
|
||||
|
||||
should "list posts" do
|
||||
get :index, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:tags => "tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:format => "json"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:format => "xml"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:tags => "-tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list posts through an atom feed" do
|
||||
get :atom, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :atom, {:tags => "tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "display a post" do
|
||||
get :show, {:id => 1}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
def test_popular
|
||||
get :popular_by_day, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
67
test/unit/post_disapproval_test.rb
Normal file
67
test/unit/post_disapproval_test.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "A post disapproval" do
|
||||
setup do
|
||||
@post_1 = Factory.create(:post, :is_pending => true)
|
||||
@post_2 = Factory.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
context "made by alice" do
|
||||
setup do
|
||||
@disapproval = PostDisapproval.create(:user => @alice, :post => @post_1)
|
||||
end
|
||||
|
||||
context "when the current user is alice" do
|
||||
setup do
|
||||
CurrentUser.user = @alice
|
||||
end
|
||||
|
||||
should "remove the associated post from alice's moderation queue" do
|
||||
assert(!Post.available_for_moderation.map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
|
||||
context "when the current user is brittony" do
|
||||
setup do
|
||||
@brittony = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @brittony
|
||||
end
|
||||
|
||||
should "not remove the associated post from brittony's moderation queue" do
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation.map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a post that has been approved" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@user = Factory.create(:user)
|
||||
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
|
||||
end
|
||||
|
||||
should "be pruned" do
|
||||
assert_difference("PostDisapproval.count", -1) do
|
||||
PostDisapproval.prune!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostModerationDetailTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = Factory.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "A post moderation detail" do
|
||||
should "hide posts" do
|
||||
posts = []
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => posts[0])
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(2, results.size)
|
||||
assert(results.all? {|x| x.id != posts[0].id})
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(1, results.size)
|
||||
assert_equal(posts[0].id, results[0].id)
|
||||
user = Factory.create(:user)
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(3, results.size)
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(0, results.size)
|
||||
end
|
||||
|
||||
should "prune itself" do
|
||||
post = Factory.create(:post, :is_flagged => true)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => post)
|
||||
assert_difference("PostModerationDetail.count", 0) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
post.is_flagged = false
|
||||
post.save
|
||||
assert(post.errors.empty?)
|
||||
assert_difference("PostModerationDetail.count", -1) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -175,12 +175,11 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "An unapproved post" do
|
||||
context "An unapproved post" do
|
||||
should "preserve the approver's identity when approved" do
|
||||
user = CurrentUser.user
|
||||
post = Factory.create(:post, :is_pending => true)
|
||||
post.approve!
|
||||
assert_equal("approver:#{user.name}", post.approver_string)
|
||||
assert_equal("approver:#{CurrentUser.name}", post.approver_string)
|
||||
end
|
||||
|
||||
should "preserve the unapproval association even when removed" do
|
||||
|
||||
Reference in New Issue
Block a user