fix tests and typo bugs
This commit is contained in:
@@ -51,39 +51,41 @@ module Downloads
|
||||
}
|
||||
@source, headers = before_download(source, headers)
|
||||
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 10
|
||||
http.request_get(url.request_uri, headers) do |res|
|
||||
case res
|
||||
when Net::HTTPSuccess then
|
||||
if max_size
|
||||
len = res["Content-Length"]
|
||||
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
||||
end
|
||||
yield(res)
|
||||
return
|
||||
begin
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 10
|
||||
http.request_get(url.request_uri, headers) do |res|
|
||||
case res
|
||||
when Net::HTTPSuccess then
|
||||
if max_size
|
||||
len = res["Content-Length"]
|
||||
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
||||
end
|
||||
yield(res)
|
||||
return
|
||||
|
||||
when Net::HTTPRedirection then
|
||||
if limit == 0 then
|
||||
raise Error.new("Too many redirects")
|
||||
end
|
||||
source = res["location"]
|
||||
limit -= 1
|
||||
when Net::HTTPRedirection then
|
||||
if limit == 0 then
|
||||
raise Error.new("Too many redirects")
|
||||
end
|
||||
source = res["location"]
|
||||
limit -= 1
|
||||
|
||||
else
|
||||
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
||||
end
|
||||
end # http.request_get
|
||||
end # http.start
|
||||
else
|
||||
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
||||
end
|
||||
end # http.request_get
|
||||
end # http.start
|
||||
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => x
|
||||
puts x.inspect
|
||||
@tries += 1
|
||||
if @tries < 3
|
||||
retry
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
end # while
|
||||
|
||||
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError
|
||||
@tries += 1
|
||||
if @tries < 3
|
||||
retry
|
||||
else
|
||||
raise
|
||||
end
|
||||
end # def
|
||||
|
||||
def fix_image_board_sources
|
||||
|
||||
@@ -349,7 +349,9 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def set_per_page
|
||||
self.per_page = Danbooru.config.posts_per_page unless is_privileged?
|
||||
if per_page.nil? || !is_privileged?
|
||||
self.per_page = Danbooru.config.posts_per_page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ class UserPresenter
|
||||
return "none"
|
||||
end
|
||||
|
||||
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 1.month.ago).count
|
||||
pending_count = Post.for_user(id).pending.where("created_at >= ?", 3.days.ago).count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", id, 1.month.ago).count
|
||||
deleted_count = Post.for_user(user.id).deleted.where("created_at >= ?", 1.month.ago).count
|
||||
pending_count = Post.for_user(user.id).pending.where("created_at >= ?", 3.days.ago).count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", user.id, 1.month.ago).count
|
||||
|
||||
if base_upload_limit
|
||||
string = "max(base_upload_limit:#{base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
if user.base_upload_limit
|
||||
string = "max(base_upload_limit:#{user.base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
else
|
||||
string = "max(10 + min(approved_count:#{approved_count} / 2, 30) - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
end
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
class RemoveUpScoreFromPosts < ActiveRecord::Migration
|
||||
def up
|
||||
execute "set statement_timeout = 0"
|
||||
remove_column :posts, :up_score
|
||||
remove_column :posts, :down_score
|
||||
end
|
||||
|
||||
def down
|
||||
execute "set statement_timeout = 0"
|
||||
add_column :posts, :up_score, :integer
|
||||
add_column :posts, :up_score, :integer
|
||||
end
|
||||
end
|
||||
@@ -2283,7 +2283,9 @@ CREATE TABLE posts (
|
||||
image_height integer NOT NULL,
|
||||
parent_id integer,
|
||||
has_children boolean DEFAULT false NOT NULL,
|
||||
is_banned boolean DEFAULT false NOT NULL
|
||||
is_banned boolean DEFAULT false NOT NULL,
|
||||
up_score integer,
|
||||
down_score integer
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,14 @@ FactoryGirl.define do
|
||||
level 30
|
||||
end
|
||||
|
||||
factory(:platinum_user) do
|
||||
level 31
|
||||
end
|
||||
|
||||
factory(:builder_user) do
|
||||
level 32
|
||||
end
|
||||
|
||||
factory(:contributor_user) do
|
||||
level 33
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class TagsControllerTest < ActionController::TestCase
|
||||
context "The tags controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:builder_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
should "fail creation" do
|
||||
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
||||
@upload.save
|
||||
assert_equal(["You can only upload 0 posts a day"], @upload.errors.full_messages)
|
||||
assert_equal(["You can not upload until your pending posts have been approved"], @upload.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,22 +39,6 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "who has negeative feedback and is trying to change their name" do
|
||||
setup do
|
||||
@mod = FactoryGirl.create(:moderator_user)
|
||||
|
||||
CurrentUser.scoped(@mod, "127.0.0.1") do
|
||||
FactoryGirl.create(:user_feedback, :user => @user, :category => "negative")
|
||||
end
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@user.reload
|
||||
@user.update_attributes(:name => "fanfarlo")
|
||||
assert_equal(["You can not change your name if you have any negative feedback"], @user.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
should "not validate if the originating ip address is banned" do
|
||||
FactoryGirl.create(:ip_ban)
|
||||
user = FactoryGirl.build(:user)
|
||||
|
||||
Reference in New Issue
Block a user