fixes #108
This commit is contained in:
@@ -77,7 +77,11 @@ class Upload < ActiveRecord::Base
|
|||||||
validate_md5_uniqueness
|
validate_md5_uniqueness
|
||||||
validate_md5_confirmation
|
validate_md5_confirmation
|
||||||
calculate_file_size(file_path)
|
calculate_file_size(file_path)
|
||||||
calculate_dimensions(file_path) if has_dimensions?
|
add_file_size_tags!(file_path)
|
||||||
|
if has_dimensions?
|
||||||
|
calculate_dimensions(file_path)
|
||||||
|
add_dimension_tags!
|
||||||
|
end
|
||||||
generate_resizes(file_path)
|
generate_resizes(file_path)
|
||||||
move_file
|
move_file
|
||||||
post = convert_to_post
|
post = convert_to_post
|
||||||
@@ -172,7 +176,17 @@ class Upload < ActiveRecord::Base
|
|||||||
self.image_width = image_size.get_width
|
self.image_width = image_size.get_width
|
||||||
self.image_height = image_size.get_height
|
self.image_height = image_size.get_height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_dimension_tags!
|
||||||
|
if image_width >= 10_000 || image_height >= 10_000
|
||||||
|
self.tag_string = "#{tag_string} insanely_absurdres".strip
|
||||||
|
elsif image_width >= 3200 || image_height >= 2400
|
||||||
|
self.tag_string = "#{tag_string} absurdres".strip
|
||||||
|
elsif image_width >= 1600 && image_height >= 1200
|
||||||
|
self.tag_string = "#{tag_string} highres".strip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Does this file have image dimensions?
|
# Does this file have image dimensions?
|
||||||
def has_dimensions?
|
def has_dimensions?
|
||||||
%w(jpg gif png swf).include?(file_ext)
|
%w(jpg gif png swf).include?(file_ext)
|
||||||
@@ -363,6 +377,12 @@ class Upload < ActiveRecord::Base
|
|||||||
include UploaderMethods
|
include UploaderMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
|
||||||
|
def add_file_size_tags!(file_path)
|
||||||
|
if file_size >= 10.megabytes
|
||||||
|
self.tag_string = "#{tag_string} huge_filesize".strip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def presenter
|
def presenter
|
||||||
@presenter ||= UploadPresenter.new(self)
|
@presenter ||= UploadPresenter.new(self)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,6 +22,31 @@ class UploadTest < ActiveSupport::TestCase
|
|||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
|
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "that has insanely absurd res dimensions" do
|
||||||
|
setup do
|
||||||
|
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
||||||
|
@upload.image_width = 10_000
|
||||||
|
@upload.image_height = 10
|
||||||
|
@upload.add_dimension_tags!
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the insanely_absurdres tag" do
|
||||||
|
assert_match(/insanely_absurdres/, @upload.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "that has a large flie size" do
|
||||||
|
setup do
|
||||||
|
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
||||||
|
@upload.file_size = 11.megabytes
|
||||||
|
@upload.add_file_size_tags!(@upload.file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the huge_filesize tag" do
|
||||||
|
assert_match(/huge_filesize/, @upload.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "image size calculator" do
|
context "image size calculator" do
|
||||||
should "discover the dimensions for a JPG" do
|
should "discover the dimensions for a JPG" do
|
||||||
@@ -81,17 +106,17 @@ class UploadTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "determining if a file is downloadable" do
|
context "determining if a file is downloadable" do
|
||||||
should "classify HTTP sources as downloadable" do
|
should "classify HTTP sources as downloadable" do
|
||||||
@upload = FactoryGirl.create(:source_upload, source: "http://www.example.com/1.jpg")
|
@upload = FactoryGirl.create(:source_upload, :source => "http://www.example.com/1.jpg")
|
||||||
assert_not_nil(@upload.is_downloadable?)
|
assert_not_nil(@upload.is_downloadable?)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "classify HTTPS sources as downloadable" do
|
should "classify HTTPS sources as downloadable" do
|
||||||
@upload = FactoryGirl.create(:source_upload, source: "https://www.example.com/1.jpg")
|
@upload = FactoryGirl.create(:source_upload, :source => "https://www.example.com/1.jpg")
|
||||||
assert_not_nil(@upload.is_downloadable?)
|
assert_not_nil(@upload.is_downloadable?)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "classify non-HTTP/HTTPS sources as not downloadable" do
|
should "classify non-HTTP/HTTPS sources as not downloadable" do
|
||||||
@upload = FactoryGirl.create(:source_upload, source: "ftp://www.example.com/1.jpg")
|
@upload = FactoryGirl.create(:source_upload, :source => "ftp://www.example.com/1.jpg")
|
||||||
assert_nil(@upload.is_downloadable?)
|
assert_nil(@upload.is_downloadable?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user