fix tests and typo bugs
This commit is contained in:
@@ -51,39 +51,41 @@ module Downloads
|
|||||||
}
|
}
|
||||||
@source, headers = before_download(source, headers)
|
@source, headers = before_download(source, headers)
|
||||||
|
|
||||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
begin
|
||||||
http.read_timeout = 10
|
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||||
http.request_get(url.request_uri, headers) do |res|
|
http.read_timeout = 10
|
||||||
case res
|
http.request_get(url.request_uri, headers) do |res|
|
||||||
when Net::HTTPSuccess then
|
case res
|
||||||
if max_size
|
when Net::HTTPSuccess then
|
||||||
len = res["Content-Length"]
|
if max_size
|
||||||
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
len = res["Content-Length"]
|
||||||
end
|
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
||||||
yield(res)
|
end
|
||||||
return
|
yield(res)
|
||||||
|
return
|
||||||
|
|
||||||
when Net::HTTPRedirection then
|
when Net::HTTPRedirection then
|
||||||
if limit == 0 then
|
if limit == 0 then
|
||||||
raise Error.new("Too many redirects")
|
raise Error.new("Too many redirects")
|
||||||
end
|
end
|
||||||
source = res["location"]
|
source = res["location"]
|
||||||
limit -= 1
|
limit -= 1
|
||||||
|
|
||||||
else
|
else
|
||||||
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
||||||
end
|
end
|
||||||
end # http.request_get
|
end # http.request_get
|
||||||
end # http.start
|
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
|
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
|
end # def
|
||||||
|
|
||||||
def fix_image_board_sources
|
def fix_image_board_sources
|
||||||
|
|||||||
@@ -349,7 +349,9 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_per_page
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ class UserPresenter
|
|||||||
return "none"
|
return "none"
|
||||||
end
|
end
|
||||||
|
|
||||||
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 1.month.ago).count
|
deleted_count = Post.for_user(user.id).deleted.where("created_at >= ?", 1.month.ago).count
|
||||||
pending_count = Post.for_user(id).pending.where("created_at >= ?", 3.days.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 >= ?", id, 1.month.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
|
if user.base_upload_limit
|
||||||
string = "max(base_upload_limit:#{base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
string = "max(base_upload_limit:#{user.base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||||
else
|
else
|
||||||
string = "max(10 + min(approved_count:#{approved_count} / 2, 30) - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
string = "max(10 + min(approved_count:#{approved_count} / 2, 30) - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||||
end
|
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,
|
image_height integer NOT NULL,
|
||||||
parent_id integer,
|
parent_id integer,
|
||||||
has_children boolean DEFAULT false NOT NULL,
|
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
|
level 30
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory(:platinum_user) do
|
||||||
|
level 31
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:builder_user) do
|
||||||
|
level 32
|
||||||
|
end
|
||||||
|
|
||||||
factory(:contributor_user) do
|
factory(:contributor_user) do
|
||||||
level 33
|
level 33
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
|||||||
class TagsControllerTest < ActionController::TestCase
|
class TagsControllerTest < ActionController::TestCase
|
||||||
context "The tags controller" do
|
context "The tags controller" do
|
||||||
setup do
|
setup do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:builder_user)
|
||||||
CurrentUser.user = @user
|
CurrentUser.user = @user
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class UploadTest < ActiveSupport::TestCase
|
|||||||
should "fail creation" do
|
should "fail creation" do
|
||||||
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
||||||
@upload.save
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,22 +39,6 @@ class UserTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
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
|
should "not validate if the originating ip address is banned" do
|
||||||
FactoryGirl.create(:ip_ban)
|
FactoryGirl.create(:ip_ban)
|
||||||
user = FactoryGirl.build(:user)
|
user = FactoryGirl.build(:user)
|
||||||
|
|||||||
Reference in New Issue
Block a user