forked from e621ng/e621ng
some fixes to janitor trials, implemented jan trial controller test
This commit is contained in:
parent
dceda1b073
commit
3d5873c182
@ -1,19 +1,36 @@
|
||||
class JanitorTrialsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def new
|
||||
@janitor_trial = JanitorTrial.new
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def edit
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
@search = JanitorTrial.search(params[:search])
|
||||
@janitor_trials = @search.paginate(:page => params[:page])
|
||||
respond_with(@janitor_trials)
|
||||
end
|
||||
|
||||
def create
|
||||
@janitor_trial = JanitorTrial.create(params[:janitor_trial])
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
def promote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.promote!
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
def demote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.demote!
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,33 @@
|
||||
class JanitorTrial < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
after_create :send_dmail
|
||||
after_create :promote_user
|
||||
after_destroy :create_feedback
|
||||
validates_presence_of :user
|
||||
|
||||
def send_dmail
|
||||
body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are quality uploads, then you will be promoted to full janitor status which grants you the ability to delete and undelete posts, ban users, and revert tag changes from vandals. If you fail the trial period, you will be demoted back to your original level and you'll receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 5 approvals a week to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
|
||||
|
||||
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
|
||||
end
|
||||
|
||||
def promote_user
|
||||
user.update_attribute(:is_janitor, true)
|
||||
end
|
||||
|
||||
def create_feedback
|
||||
user.feedback.create(
|
||||
:is_positive => false,
|
||||
:body => "Demoted from janitor trial"
|
||||
)
|
||||
end
|
||||
|
||||
def promote!
|
||||
destroy
|
||||
end
|
||||
|
||||
def demote!
|
||||
user.update_attribute(:is_janitor, false)
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
@ -2,10 +2,15 @@ class UserFeedback < ActiveRecord::Base
|
||||
set_table_name "user_feedback"
|
||||
belongs_to :user
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
attr_accessible :body, :user_id, :is_positive
|
||||
validates_presence_of :user_id, :creator_id, :body
|
||||
validates_presence_of :user, :creator, :body
|
||||
validate :creator_is_privileged
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def creator_is_privileged
|
||||
if !creator.is_privileged?
|
||||
errors[:creator] << "must be privileged"
|
||||
|
@ -0,0 +1,22 @@
|
||||
<h1>IP Bans</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP Address</th>
|
||||
<th>Banner</th>
|
||||
<th>Reason</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @ip_bans.each do |ip_ban| %>
|
||||
<tr>
|
||||
<td><%= ip_ban.ip_addr %></td>
|
||||
<td><%= ip_ban.creator.name %></td>
|
||||
<td><%= ip_ban.reason %></td>
|
||||
<td><%= link_to "Unban", ip_ban_path(ip_ban), :remote => true, :method => :delete, :confirm => "Do your really want to unban #{ip_ban.creator.name}?" %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
@ -0,0 +1,7 @@
|
||||
<h1>New IP Ban</h1>
|
||||
|
||||
<%= simple_form_for(@ip_ban) do |f| %>
|
||||
<%= f.input :ip_addr %>
|
||||
<%= f.input :reason %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
0
app/views/janitor_trials/edit.html.erb
Normal file
0
app/views/janitor_trials/edit.html.erb
Normal file
0
app/views/janitor_trials/index.html.erb
Normal file
0
app/views/janitor_trials/index.html.erb
Normal file
0
app/views/janitor_trials/new.html.erb
Normal file
0
app/views/janitor_trials/new.html.erb
Normal file
@ -18,7 +18,12 @@ Danbooru::Application.routes.draw do
|
||||
resources :favorites
|
||||
resources :forum_posts
|
||||
resources :forum_topics
|
||||
resources :janitor_trials
|
||||
resources :janitor_trials do
|
||||
member do
|
||||
put :promote
|
||||
put :demote
|
||||
end
|
||||
end
|
||||
resources :jobs
|
||||
resources :ip_bans
|
||||
resources :notes
|
||||
|
@ -2,7 +2,6 @@ class CreateJanitorTrials < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :janitor_trials do |t|
|
||||
t.column :user_id, :integer, :null => false
|
||||
t.column :promoted_at, :datetime
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
|
3
test/factories/janitor_trial.rb
Normal file
3
test/factories/janitor_trial.rb
Normal file
@ -0,0 +1,3 @@
|
||||
Factory.define(:janitor_trial) do |f|
|
||||
f.user {|x| x.association(:user)}
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
Factory.define(:user) do |f|
|
||||
f.name {Faker::Name.first_name}
|
||||
f.name {rand(1_000_000).to_s}
|
||||
f.password "password"
|
||||
f.password_hash {User.sha1("password")}
|
||||
f.email {Faker::Internet.email}
|
||||
|
@ -1,6 +1,4 @@
|
||||
Factory.define(:user_feedback) do |f|
|
||||
f.user {|x| x.association(:user)}
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.is_positive true
|
||||
f.body {Faker::Lorem.words}
|
||||
end
|
||||
|
@ -1,8 +1,73 @@
|
||||
require 'test_helper'
|
||||
|
||||
class JanitorTrialsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The janitor trials controller" do
|
||||
setup do
|
||||
@admin = Factory.create(:admin_user)
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, {:user_id => @admin.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a new janitor trial" do
|
||||
assert_difference("JanitorTrial.count", 1) do
|
||||
post :create, {:janitor_trial => {:user_id => @user.id}}, {:user_id => @admin.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "promote action" do
|
||||
setup do
|
||||
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "promote the janitor trial" do
|
||||
assert_difference("JanitorTrial.count", -1) do
|
||||
post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
|
||||
end
|
||||
@user.reload
|
||||
assert(@user.is_janitor?)
|
||||
end
|
||||
end
|
||||
|
||||
context "demote action" do
|
||||
setup do
|
||||
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "demote the janitor trial" do
|
||||
assert_difference("JanitorTrial.count", -1) do
|
||||
post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
|
||||
end
|
||||
@user.reload
|
||||
assert(!@user.is_janitor?)
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
Factory.create(:janitor_trial)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get :index, {}, {:user_id => @admin.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "with search parameters" do
|
||||
should "render" do
|
||||
get :index, {:search => {:user_name_equals => @user.name}}, {:user_id => @admin.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,23 +1,56 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class JanitorTrialTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = Factory.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
context "A janitor trial" do
|
||||
setup do
|
||||
@admin = Factory.create(:admin_user)
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
should "create a dmail when testing a new janitor" do
|
||||
admin = Factory.create(:admin_user)
|
||||
user = Factory.create(:user)
|
||||
assert_difference("Dmail.count", 2) do
|
||||
JanitorTrial.create(:user_id => user.id)
|
||||
context "upon creation" do
|
||||
should "create a dmail when testing a new janitor" do
|
||||
assert_difference("Dmail.count", 2) do
|
||||
JanitorTrial.create(:user_id => @user.id)
|
||||
end
|
||||
end
|
||||
|
||||
should "toggle the janitor flag on the user" do
|
||||
janitor_trial = JanitorTrial.create(:user_id => @user.id)
|
||||
@user.reload
|
||||
assert(@user.is_janitor?)
|
||||
end
|
||||
end
|
||||
|
||||
context "upon demotion" do
|
||||
setup do
|
||||
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "create a negative feedback record" do
|
||||
assert_difference("UserFeedback.count", 1) do
|
||||
@janitor_trial.demote!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "upon promotion" do
|
||||
setup do
|
||||
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "destroy the trial object" do
|
||||
assert_difference("JanitorTrial.count", -1) do
|
||||
@janitor_trial.promote!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user