diff --git a/app/logical/downloads/file.rb b/app/logical/downloads/file.rb index 9d4162b3b..b6e1b71f6 100644 --- a/app/logical/downloads/file.rb +++ b/app/logical/downloads/file.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 2c7f31f08..d0841190e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index d40cbfb78..593c9bd67 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -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 diff --git a/db/migrate/20130321144736_remove_up_score_from_posts.rb b/db/migrate/20130321144736_remove_up_score_from_posts.rb deleted file mode 100644 index 849ffee90..000000000 --- a/db/migrate/20130321144736_remove_up_score_from_posts.rb +++ /dev/null @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 1d0a27c8b..1d2d346b5 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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 ); diff --git a/test/factories/user.rb b/test/factories/user.rb index 8a9557936..4cd2e00d4 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -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 diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 7cda4d76b..ceebc59f5 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -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 diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 23a2ba1e8..c24a395ba 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 886a738d1..dc9da92a7 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -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)