ban fixes
This commit is contained in:
@@ -19,13 +19,12 @@ class BansController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@ban = Ban.new(params[:ban])
|
||||
@ban.banner_id = CurrentUser.id
|
||||
@ban = Ban.create(params[:ban])
|
||||
|
||||
if @ban.save
|
||||
redirect_to ban_path(@ban), :notice => "Ban created"
|
||||
else
|
||||
if @ban.errors.any?
|
||||
render :action => "new"
|
||||
else
|
||||
redirect_to ban_path(@ban), :notice => "Ban created"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,6 +33,7 @@ class BansController < ApplicationController
|
||||
if @ban.update_attributes(params[:ban])
|
||||
redirect_to ban_path(@ban), :notice => "Ban updated"
|
||||
else
|
||||
puts @ban.errors.full_messages
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,11 +5,16 @@ class Ban < ActiveRecord::Base
|
||||
attr_accessible :reason, :duration, :user_id, :user_name
|
||||
validate :user_is_inferior
|
||||
validates_presence_of :user_id, :reason, :duration
|
||||
before_validation :initialize_banner_id, :on => :create
|
||||
|
||||
def self.is_banned?(user)
|
||||
exists?(["user_id = ? AND expires_at > ?", user.id, Time.now])
|
||||
end
|
||||
|
||||
def initialize_banner_id
|
||||
self.banner_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def user_is_inferior
|
||||
if user
|
||||
if user.is_admin?
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
Factory.define(:ban) do |f|
|
||||
f.user {|x| x.association(:user)}
|
||||
f.banner {|x| x.association(:admin_user)}
|
||||
f.reason {Faker::Lorem.words.join(" ")}
|
||||
f.duration 60
|
||||
end
|
||||
|
||||
@@ -3,10 +3,11 @@ require 'test_helper'
|
||||
class BansControllerTest < ActionController::TestCase
|
||||
context "A bans controller" do
|
||||
setup do
|
||||
CurrentUser.user = Factory.create(:user)
|
||||
@mod = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@ban = Factory.create(:ban)
|
||||
@user = Factory.create(:moderator_user)
|
||||
@user = Factory.create(:user)
|
||||
@ban = Factory.create(:ban, :user_id => @user.id)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -15,12 +16,12 @@ class BansControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
should "get the new page" do
|
||||
get :new, {}, {:user_id => @user.id}
|
||||
get :new, {}, {:user_id => @mod.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "get the edit page" do
|
||||
get :edit, {:id => @ban.id}, {:user_id => @user.id}
|
||||
get :edit, {:id => @ban.id}, {:user_id => @mod.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -36,22 +37,22 @@ class BansControllerTest < ActionController::TestCase
|
||||
|
||||
should "create a ban" do
|
||||
assert_difference("Ban.count", 1) do
|
||||
post :create, {:ban => Factory.attributes_for(:ban)}, {:user_id => @user.id}
|
||||
post :create, {:ban => {:duration => 60, :reason => "xxx", :user_id => @user.id}}, {:user_id => @mod.id}
|
||||
end
|
||||
ban = Ban.last
|
||||
assert_redirected_to(ban_path(ban))
|
||||
end
|
||||
|
||||
should "update a ban" do
|
||||
post :update, {:id => @ban.id, :ban => {:reason => "xxx"}}, {:user_id => @user.id}
|
||||
ban = Ban.last
|
||||
assert_equal("xxx", ban.reason)
|
||||
assert_redirected_to(ban_path(ban))
|
||||
post :update, {:id => @ban.id, :ban => {:reason => "xxx", :duration => 60}}, {:user_id => @mod.id}
|
||||
@ban.reload
|
||||
assert_equal("xxx", @ban.reason)
|
||||
assert_redirected_to(ban_path(@ban))
|
||||
end
|
||||
|
||||
should "destroy a ban" do
|
||||
assert_difference("Ban.count", -1) do
|
||||
post :destroy, {:id => @ban.id}, {:user_id => @user.id}
|
||||
post :destroy, {:id => @ban.id}, {:user_id => @mod.id}
|
||||
end
|
||||
assert_redirected_to(bans_path)
|
||||
end
|
||||
|
||||
@@ -31,8 +31,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
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))
|
||||
assert(!Post.available_for_moderation(false).map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation(false).map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,8 +43,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
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))
|
||||
assert(Post.available_for_moderation(false).map(&:id).include?(@post_1.id))
|
||||
assert(Post.available_for_moderation(false).map(&:id).include?(@post_2.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,7 +109,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "resizer" do
|
||||
teardown do
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/thumb/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/preview/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/medium/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/large/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/original/test.*.jpg"))
|
||||
@@ -121,11 +121,11 @@ class UploadTest < ActiveSupport::TestCase
|
||||
@upload.calculate_dimensions(@upload.file_path)
|
||||
assert_nothing_raised {@upload.generate_resizes(@upload.file_path)}
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert_equal(5613, File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert_equal(5677, File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert_equal(42990, File.size(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert_equal(43470, File.size(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert_equal(197046, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert_equal(198695, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user