From a285089f7a003a400e743f40c456ca8d740682c5 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 13 Feb 2014 11:30:35 -0800 Subject: [PATCH] potential fix for #1926 --- app/models/upload.rb | 2 +- test/unit/user_test.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 5ad614442..2ac39c06d 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -11,7 +11,7 @@ class Upload < ActiveRecord::Base before_validation :initialize_status, :on => :create before_create :convert_cgi_file after_destroy :delete_temp_file - validate :uploader_is_not_limited + validate :uploader_is_not_limited, :on => :create validate :file_or_source_is_present, :on => :create module ValidationMethods diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 7f2f33bee..26255e5fb 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -65,11 +65,16 @@ class UserTest < ActiveSupport::TestCase @user.update_column(:level, User::Levels::CONTRIBUTOR) assert(@user.can_upload?) @user.update_column(:level, User::Levels::MEMBER) + @user.update_column(:created_at, 1.month.ago) + assert_equal(10, @user.upload_limit) - 40.times do - FactoryGirl.create(:post, :uploader => @user, :is_deleted => true) + 9.times do + FactoryGirl.create(:post, :uploader => @user, :is_pending => true) end + assert_equal(1, @user.upload_limit) + assert(@user.can_upload?) + FactoryGirl.create(:post, :uploader => @user, :is_pending => true) assert(!@user.can_upload?) end