fix upload controller test
This commit is contained in:
@@ -17,7 +17,7 @@ class Upload < ActiveRecord::Base
|
|||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def uploader_is_not_limited
|
def uploader_is_not_limited
|
||||||
if !uploader.can_upload?
|
if !uploader.can_upload?
|
||||||
update_column(:status, "error: uploader has reached their daily limit")
|
update_attribute(:status, "error: uploader has reached their daily limit")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -29,19 +29,19 @@ class Upload < ActiveRecord::Base
|
|||||||
|
|
||||||
def validate_file_exists
|
def validate_file_exists
|
||||||
unless File.exists?(file_path)
|
unless File.exists?(file_path)
|
||||||
update_column(:status, "error: file does not exist")
|
update_attribute(:status, "error: file does not exist")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_file_content_type
|
def validate_file_content_type
|
||||||
unless is_valid_content_type?
|
unless is_valid_content_type?
|
||||||
update_column(:status, "error: invalid content type (#{file_ext} not allowed)")
|
update_attribute(:status, "error: invalid content type (#{file_ext} not allowed)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_md5_confirmation
|
def validate_md5_confirmation
|
||||||
if !md5_confirmation.blank? && md5_confirmation != md5
|
if !md5_confirmation.blank? && md5_confirmation != md5
|
||||||
update_column(:status, "error: md5 mismatch")
|
update_attribute(:status, "error: md5 mismatch")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -49,7 +49,7 @@ class Upload < ActiveRecord::Base
|
|||||||
module ConversionMethods
|
module ConversionMethods
|
||||||
def process!
|
def process!
|
||||||
CurrentUser.scoped(uploader, uploader_ip_addr) do
|
CurrentUser.scoped(uploader, uploader_ip_addr) do
|
||||||
update_column(:status, "processing")
|
update_attribute(:status, "processing")
|
||||||
if is_downloadable?
|
if is_downloadable?
|
||||||
download_from_source(temp_file_path)
|
download_from_source(temp_file_path)
|
||||||
end
|
end
|
||||||
@@ -67,12 +67,12 @@ class Upload < ActiveRecord::Base
|
|||||||
if post.save
|
if post.save
|
||||||
update_attributes(:status => "completed", :post_id => post.id)
|
update_attributes(:status => "completed", :post_id => post.id)
|
||||||
else
|
else
|
||||||
update_column(:status, "error: " + post.errors.full_messages.join(", "))
|
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => x
|
rescue Exception => x
|
||||||
raise
|
raise
|
||||||
update_column(:status, "error: #{x} - #{x.message}")
|
update_attribute(:status, "error: #{x} - #{x.message}")
|
||||||
ensure
|
ensure
|
||||||
delete_temp_file
|
delete_temp_file
|
||||||
end
|
end
|
||||||
@@ -99,7 +99,7 @@ class Upload < ActiveRecord::Base
|
|||||||
def merge_tags(post)
|
def merge_tags(post)
|
||||||
post.tag_string += " #{tag_string}"
|
post.tag_string += " #{tag_string}"
|
||||||
post.save
|
post.save
|
||||||
update_column(:status, "duplicate: #{post.id}")
|
update_attribute(:status, "duplicate: #{post.id}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
|||||||
class UploadsControllerTest < ActionController::TestCase
|
class UploadsControllerTest < ActionController::TestCase
|
||||||
context "The uploads controller" do
|
context "The uploads controller" do
|
||||||
setup do
|
setup do
|
||||||
@user = Factory.create(:user)
|
@user = Factory.create(:contributor_user)
|
||||||
CurrentUser.user = @user
|
CurrentUser.user = @user
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
tmp/test.jpg
BIN
tmp/test.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB |
Reference in New Issue
Block a user