diff --git a/app/models/upload.rb b/app/models/upload.rb index 489f968ba..4d598f897 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -77,7 +77,11 @@ class Upload < ActiveRecord::Base validate_md5_uniqueness validate_md5_confirmation 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) move_file post = convert_to_post @@ -172,7 +176,17 @@ class Upload < ActiveRecord::Base self.image_width = image_size.get_width self.image_height = image_size.get_height 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? def has_dimensions? %w(jpg gif png swf).include?(file_ext) @@ -363,6 +377,12 @@ class Upload < ActiveRecord::Base include UploaderMethods 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 @presenter ||= UploadPresenter.new(self) end diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 44518811c..7b43ec9ae 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -22,6 +22,31 @@ class UploadTest < ActiveSupport::TestCase teardown do FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*")) 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 should "discover the dimensions for a JPG" do @@ -81,17 +106,17 @@ class UploadTest < ActiveSupport::TestCase context "determining if a file is 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?) end 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?) end 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?) end end