paperclip 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +5 -16
- data/.travis.yml +14 -15
- data/Appraisals +3 -23
- data/Gemfile +1 -0
- data/NEWS +36 -1
- data/README.md +58 -10
- data/Rakefile +1 -1
- data/UPGRADING +1 -1
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -22
- data/features/step_definitions/s3_steps.rb +1 -1
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/{4.2.awsv2.0.gemfile → 4.2.gemfile} +1 -1
- data/gemfiles/{5.0.awsv2.1.gemfile → 5.0.gemfile} +2 -2
- data/lib/paperclip.rb +12 -10
- data/lib/paperclip/attachment.rb +10 -4
- data/lib/paperclip/io_adapters/abstract_adapter.rb +24 -2
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +9 -5
- data/lib/paperclip/io_adapters/uri_adapter.rb +13 -11
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +7 -4
- data/lib/paperclip/storage/s3.rb +31 -3
- data/lib/paperclip/thumbnail.rb +14 -4
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +17 -3
- data/paperclip.gemspec +3 -3
- data/spec/paperclip/attachment_spec.rb +39 -8
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +44 -21
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +6 -1
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +3 -3
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +6 -1
- data/spec/paperclip/storage/fog_spec.rb +16 -0
- data/spec/paperclip/storage/s3_live_spec.rb +12 -10
- data/spec/paperclip/storage/s3_spec.rb +85 -4
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +35 -32
- data/spec/spec_helper.rb +3 -1
- data/spec/support/assertions.rb +5 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- metadata +31 -135
- data/gemfiles/4.2.awsv2.1.gemfile +0 -17
- data/gemfiles/4.2.awsv2.gemfile +0 -20
- data/gemfiles/5.0.awsv2.0.gemfile +0 -17
- data/gemfiles/5.0.awsv2.gemfile +0 -20
| @@ -13,7 +13,8 @@ describe Paperclip::AttachmentAdapter do | |
| 13 13 |  | 
| 14 14 | 
             
                  @attachment.assign(@file)
         | 
| 15 15 | 
             
                  @attachment.save
         | 
| 16 | 
            -
                  @subject = Paperclip.io_adapters.for(@attachment | 
| 16 | 
            +
                  @subject = Paperclip.io_adapters.for(@attachment,
         | 
| 17 | 
            +
                                                       hash_digest: Digest::MD5)
         | 
| 17 18 | 
             
                end
         | 
| 18 19 |  | 
| 19 20 | 
             
                after do
         | 
| @@ -65,7 +66,8 @@ describe Paperclip::AttachmentAdapter do | |
| 65 66 |  | 
| 66 67 | 
             
                  @attachment.assign(@file)
         | 
| 67 68 | 
             
                  @attachment.save
         | 
| 68 | 
            -
                  @subject = Paperclip.io_adapters.for(@attachment | 
| 69 | 
            +
                  @subject = Paperclip.io_adapters.for(@attachment,
         | 
| 70 | 
            +
                                                       hash_digest: Digest::MD5)
         | 
| 69 71 | 
             
                end
         | 
| 70 72 |  | 
| 71 73 | 
             
                after do
         | 
| @@ -92,7 +94,8 @@ describe Paperclip::AttachmentAdapter do | |
| 92 94 | 
             
                  FileUtils.cp @attachment.queued_for_write[:thumb].path, @thumb.path
         | 
| 93 95 |  | 
| 94 96 | 
             
                  @attachment.save
         | 
| 95 | 
            -
                  @subject = Paperclip.io_adapters.for(@attachment.styles[:thumb] | 
| 97 | 
            +
                  @subject = Paperclip.io_adapters.for(@attachment.styles[:thumb],
         | 
| 98 | 
            +
                                                       hash_digest: Digest::MD5)
         | 
| 96 99 | 
             
                end
         | 
| 97 100 |  | 
| 98 101 | 
             
                after do
         | 
| @@ -1,7 +1,13 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Paperclip::DataUriAdapter do
         | 
| 4 | 
            +
              before do
         | 
| 5 | 
            +
                Paperclip::DataUriAdapter.register
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 4 8 | 
             
              after do
         | 
| 9 | 
            +
                Paperclip.io_adapters.unregister(described_class)
         | 
| 10 | 
            +
             | 
| 5 11 | 
             
                if @subject
         | 
| 6 12 | 
             
                  @subject.close
         | 
| 7 13 | 
             
                end
         | 
| @@ -20,7 +26,7 @@ describe Paperclip::DataUriAdapter do | |
| 20 26 | 
             
              context "a new instance" do
         | 
| 21 27 | 
             
                before do
         | 
| 22 28 | 
             
                  @contents = "data:image/png;base64,#{original_base64_content}"
         | 
| 23 | 
            -
                  @subject = Paperclip.io_adapters.for(@contents)
         | 
| 29 | 
            +
                  @subject = Paperclip.io_adapters.for(@contents, hash_digest: Digest::MD5)
         | 
| 24 30 | 
             
                end
         | 
| 25 31 |  | 
| 26 32 | 
             
                it "returns a nondescript file name" do
         | 
| @@ -15,7 +15,7 @@ describe Paperclip::FileAdapter do | |
| 15 15 |  | 
| 16 16 | 
             
                  context 'doing normal things' do
         | 
| 17 17 | 
             
                    before do
         | 
| 18 | 
            -
                      @subject = Paperclip.io_adapters.for(@file)
         | 
| 18 | 
            +
                      @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
         | 
| 19 19 | 
             
                    end
         | 
| 20 20 |  | 
| 21 21 | 
             
                    it 'uses the original filename to generate the tempfile' do
         | 
| @@ -61,7 +61,7 @@ describe Paperclip::FileAdapter do | |
| 61 61 | 
             
                  context "file with multiple possible content type" do
         | 
| 62 62 | 
             
                    before do
         | 
| 63 63 | 
             
                      MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')])
         | 
| 64 | 
            -
                      @subject = Paperclip.io_adapters.for(@file)
         | 
| 64 | 
            +
                      @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
         | 
| 65 65 | 
             
                    end
         | 
| 66 66 |  | 
| 67 67 | 
             
                    it "prefers officially registered mime type" do
         | 
| @@ -7,12 +7,17 @@ describe Paperclip::HttpUrlProxyAdapter do | |
| 7 7 | 
             
                @open_return.stubs(:meta).returns({})
         | 
| 8 8 | 
             
                Paperclip::HttpUrlProxyAdapter.any_instance.
         | 
| 9 9 | 
             
                  stubs(:download_content).returns(@open_return)
         | 
| 10 | 
            +
                Paperclip::HttpUrlProxyAdapter.register
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              after do
         | 
| 14 | 
            +
                Paperclip.io_adapters.unregister(described_class)
         | 
| 10 15 | 
             
              end
         | 
| 11 16 |  | 
| 12 17 | 
             
              context "a new instance" do
         | 
| 13 18 | 
             
                before do
         | 
| 14 19 | 
             
                  @url = "http://thoughtbot.com/images/thoughtbot-logo.png"
         | 
| 15 | 
            -
                  @subject = Paperclip.io_adapters.for(@url)
         | 
| 20 | 
            +
                  @subject = Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5)
         | 
| 16 21 | 
             
                end
         | 
| 17 22 |  | 
| 18 23 | 
             
                after do
         | 
| @@ -4,7 +4,7 @@ describe Paperclip::AttachmentRegistry do | |
| 4 4 | 
             
              context "for" do
         | 
| 5 5 | 
             
                before do
         | 
| 6 6 | 
             
                  class AdapterTest
         | 
| 7 | 
            -
                    def initialize( | 
| 7 | 
            +
                    def initialize(_target, _ = {}); end
         | 
| 8 8 | 
             
                  end
         | 
| 9 9 | 
             
                  @subject = Paperclip::AdapterRegistry.new
         | 
| 10 10 | 
             
                  @subject.register(AdapterTest){|t| Symbol === t }
         | 
| @@ -18,7 +18,7 @@ describe Paperclip::AttachmentRegistry do | |
| 18 18 | 
             
              context "registered?" do
         | 
| 19 19 | 
             
                before do
         | 
| 20 20 | 
             
                  class AdapterTest
         | 
| 21 | 
            -
                    def initialize( | 
| 21 | 
            +
                    def initialize(_target, _ = {}); end
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 | 
             
                  @subject = Paperclip::AdapterRegistry.new
         | 
| 24 24 | 
             
                  @subject.register(AdapterTest){|t| Symbol === t }
         | 
| @@ -5,7 +5,7 @@ describe Paperclip::StringioAdapter do | |
| 5 5 | 
             
                before do
         | 
| 6 6 | 
             
                  @contents = "abc123"
         | 
| 7 7 | 
             
                  @stringio = StringIO.new(@contents)
         | 
| 8 | 
            -
                  @subject = Paperclip.io_adapters.for(@stringio)
         | 
| 8 | 
            +
                  @subject = Paperclip.io_adapters.for(@stringio, hash_digest: Digest::MD5)
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 11 | 
             
                it "returns a file name" do
         | 
| @@ -17,7 +17,7 @@ describe Paperclip::UploadedFileAdapter do | |
| 17 17 | 
             
                      tempfile: tempfile,
         | 
| 18 18 | 
             
                      path: tempfile.path
         | 
| 19 19 | 
             
                    )
         | 
| 20 | 
            -
                    @subject = Paperclip.io_adapters.for(@file)
         | 
| 20 | 
            +
                    @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
         | 
| 21 21 | 
             
                  end
         | 
| 22 22 |  | 
| 23 23 | 
             
                  it "gets the right filename" do
         | 
| @@ -63,7 +63,7 @@ describe Paperclip::UploadedFileAdapter do | |
| 63 63 | 
             
                      head: "",
         | 
| 64 64 | 
             
                      path: fixture_file("5k.png")
         | 
| 65 65 | 
             
                    )
         | 
| 66 | 
            -
                    @subject = Paperclip.io_adapters.for(@file)
         | 
| 66 | 
            +
                    @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
         | 
| 67 67 | 
             
                  end
         | 
| 68 68 |  | 
| 69 69 | 
             
                  it "does not generate paths that include restricted characters" do
         | 
| @@ -86,7 +86,7 @@ describe Paperclip::UploadedFileAdapter do | |
| 86 86 | 
             
                      head: "",
         | 
| 87 87 | 
             
                      path: fixture_file("5k.png")
         | 
| 88 88 | 
             
                    )
         | 
| 89 | 
            -
                    @subject = Paperclip.io_adapters.for(@file)
         | 
| 89 | 
            +
                    @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
         | 
| 90 90 | 
             
                  end
         | 
| 91 91 |  | 
| 92 92 | 
             
                  it "gets the right filename" do
         | 
| @@ -8,6 +8,11 @@ describe Paperclip::UriAdapter do | |
| 8 8 | 
             
                @open_return = StringIO.new("xxx")
         | 
| 9 9 | 
             
                @open_return.stubs(:content_type).returns(content_type)
         | 
| 10 10 | 
             
                @open_return.stubs(:meta).returns(meta)
         | 
| 11 | 
            +
                Paperclip::UriAdapter.register
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              after do
         | 
| 15 | 
            +
                Paperclip.io_adapters.unregister(described_class)
         | 
| 11 16 | 
             
              end
         | 
| 12 17 |  | 
| 13 18 | 
             
              context "a new instance" do
         | 
| @@ -16,7 +21,7 @@ describe Paperclip::UriAdapter do | |
| 16 21 | 
             
                    stubs(:download_content).returns(@open_return)
         | 
| 17 22 |  | 
| 18 23 | 
             
                  @uri = URI.parse("http://thoughtbot.com/images/thoughtbot-logo.png")
         | 
| 19 | 
            -
                  @subject = Paperclip.io_adapters.for(@uri)
         | 
| 24 | 
            +
                  @subject = Paperclip.io_adapters.for(@uri, hash_digest: Digest::MD5)
         | 
| 20 25 | 
             
                end
         | 
| 21 26 |  | 
| 22 27 | 
             
                it "returns a file name" do
         | 
| @@ -273,6 +273,22 @@ describe Paperclip::Storage::Fog do | |
| 273 273 | 
             
                    end
         | 
| 274 274 | 
             
                  end
         | 
| 275 275 |  | 
| 276 | 
            +
                  context "with fog_public as a proc" do
         | 
| 277 | 
            +
                    let(:proc) { ->(attachment) { !attachment } }
         | 
| 278 | 
            +
             | 
| 279 | 
            +
                    before do
         | 
| 280 | 
            +
                      rebuild_model(@options.merge(fog_public: proc))
         | 
| 281 | 
            +
                      @dummy = Dummy.new
         | 
| 282 | 
            +
                      @dummy.avatar = StringIO.new(".")
         | 
| 283 | 
            +
                      @dummy.save
         | 
| 284 | 
            +
                    end
         | 
| 285 | 
            +
             | 
| 286 | 
            +
                    it "sets the @fog_public instance variable to false" do
         | 
| 287 | 
            +
                      assert_equal proc, @dummy.avatar.instance_variable_get("@options")[:fog_public]
         | 
| 288 | 
            +
                      assert_equal false, @dummy.avatar.fog_public
         | 
| 289 | 
            +
                    end
         | 
| 290 | 
            +
                  end
         | 
| 291 | 
            +
             | 
| 276 292 | 
             
                  context "with styles set and fog_public set to false" do
         | 
| 277 293 | 
             
                    before do
         | 
| 278 294 | 
             
                      rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
         | 
| @@ -10,8 +10,8 @@ unless ENV["S3_BUCKET"].blank? | |
| 10 10 | 
             
                                  path: ":class/:attachment/:id/:style.:extension",
         | 
| 11 11 | 
             
                                  s3_region: ENV["S3_REGION"],
         | 
| 12 12 | 
             
                                  s3_credentials: {
         | 
| 13 | 
            -
                                     | 
| 14 | 
            -
                                     | 
| 13 | 
            +
                                    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
         | 
| 14 | 
            +
                                    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
         | 
| 15 15 | 
             
                                  }
         | 
| 16 16 |  | 
| 17 17 | 
             
                    @file = File.new(fixture_file("5k.png"))
         | 
| @@ -48,8 +48,8 @@ unless ENV["S3_BUCKET"].blank? | |
| 48 48 | 
             
                                  path: ":class/:attachment/:id/:style.:extension",
         | 
| 49 49 | 
             
                                  s3_region: ENV["S3_REGION"],
         | 
| 50 50 | 
             
                                  s3_credentials: {
         | 
| 51 | 
            -
                                     | 
| 52 | 
            -
                                     | 
| 51 | 
            +
                                    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
         | 
| 52 | 
            +
                                    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
         | 
| 53 53 | 
             
                                  }
         | 
| 54 54 |  | 
| 55 55 | 
             
                    @dummy = Dummy.new
         | 
| @@ -68,8 +68,8 @@ unless ENV["S3_BUCKET"].blank? | |
| 68 68 | 
             
                                  path: ":class/:attachment/:id/:style.:extension",
         | 
| 69 69 | 
             
                                  s3_region: ENV["S3_REGION"],
         | 
| 70 70 | 
             
                                  s3_credentials: {
         | 
| 71 | 
            -
                                     | 
| 72 | 
            -
                                     | 
| 71 | 
            +
                                    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
         | 
| 72 | 
            +
                                    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
         | 
| 73 73 | 
             
                                  }
         | 
| 74 74 |  | 
| 75 75 | 
             
                    Dummy.delete_all
         | 
| @@ -109,9 +109,11 @@ unless ENV["S3_BUCKET"].blank? | |
| 109 109 | 
             
                      storage: :s3,
         | 
| 110 110 | 
             
                      bucket: ENV["S3_BUCKET"],
         | 
| 111 111 | 
             
                      s3_region: ENV["S3_REGION"],
         | 
| 112 | 
            +
                      url: ":s3_domain_url",
         | 
| 113 | 
            +
                      path: "/:class/:attachment/:id_partition/:style/:filename",
         | 
| 112 114 | 
             
                      s3_credentials: {
         | 
| 113 | 
            -
                         | 
| 114 | 
            -
                         | 
| 115 | 
            +
                        access_key_id: ENV['AWS_ACCESS_KEY_ID'],
         | 
| 116 | 
            +
                        secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
         | 
| 115 117 | 
             
                      }
         | 
| 116 118 |  | 
| 117 119 | 
             
                    Dummy.delete_all
         | 
| @@ -152,8 +154,8 @@ unless ENV["S3_BUCKET"].blank? | |
| 152 154 | 
             
                                  path: ":class/:attachment/:id/:style.:extension",
         | 
| 153 155 | 
             
                                  s3_region: ENV["S3_REGION"],
         | 
| 154 156 | 
             
                                  s3_credentials: {
         | 
| 155 | 
            -
                                     | 
| 156 | 
            -
                                     | 
| 157 | 
            +
                                    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
         | 
| 158 | 
            +
                                    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
         | 
| 157 159 | 
             
                                  },
         | 
| 158 160 | 
             
                                  s3_server_side_encryption: "AES256"
         | 
| 159 161 | 
             
                    Dummy.delete_all
         | 
| @@ -256,7 +256,7 @@ describe Paperclip::Storage::S3 do | |
| 256 256 | 
             
                end
         | 
| 257 257 |  | 
| 258 258 | 
             
                it "uses the S3 bucket with the correct host name" do
         | 
| 259 | 
            -
                  assert_equal "s3 | 
| 259 | 
            +
                  assert_equal "s3.ap-northeast-1.amazonaws.com",
         | 
| 260 260 | 
             
                    @dummy.avatar.s3_bucket.client.config.endpoint.host
         | 
| 261 261 | 
             
                end
         | 
| 262 262 | 
             
              end
         | 
| @@ -282,6 +282,59 @@ describe Paperclip::Storage::S3 do | |
| 282 282 | 
             
                end
         | 
| 283 283 | 
             
              end
         | 
| 284 284 |  | 
| 285 | 
            +
              context "use_accelerate_endpoint", if: aws_accelerate_available? do
         | 
| 286 | 
            +
                context "defaults to false" do
         | 
| 287 | 
            +
                  before do
         | 
| 288 | 
            +
                    rebuild_model(
         | 
| 289 | 
            +
                      storage: :s3,
         | 
| 290 | 
            +
                      s3_credentials: {},
         | 
| 291 | 
            +
                      bucket: "bucket",
         | 
| 292 | 
            +
                      path: ":attachment/:basename:dotextension",
         | 
| 293 | 
            +
                      s3_host_name: "s3-ap-northeast-1.amazonaws.com",
         | 
| 294 | 
            +
                      s3_region: "ap-northeast-1",
         | 
| 295 | 
            +
                    )
         | 
| 296 | 
            +
                    @dummy = Dummy.new
         | 
| 297 | 
            +
                    @dummy.avatar = stringy_file
         | 
| 298 | 
            +
                    @dummy.stubs(:new_record?).returns(false)
         | 
| 299 | 
            +
                  end
         | 
| 300 | 
            +
             | 
| 301 | 
            +
                  it "returns a url based on an :s3_host_name path" do
         | 
| 302 | 
            +
                    assert_match %r{^//s3-ap-northeast-1.amazonaws.com/bucket/avatars/data[^\.]},
         | 
| 303 | 
            +
                      @dummy.avatar.url
         | 
| 304 | 
            +
                  end
         | 
| 305 | 
            +
             | 
| 306 | 
            +
                  it "uses the S3 client with the use_accelerate_endpoint config is false" do
         | 
| 307 | 
            +
                    expect(@dummy.avatar.s3_bucket.client.config.use_accelerate_endpoint).to be(false)
         | 
| 308 | 
            +
                  end
         | 
| 309 | 
            +
                end
         | 
| 310 | 
            +
             | 
| 311 | 
            +
                context "set to true", if: aws_accelerate_available? do
         | 
| 312 | 
            +
                  before do
         | 
| 313 | 
            +
                    rebuild_model(
         | 
| 314 | 
            +
                      storage: :s3,
         | 
| 315 | 
            +
                      s3_credentials: {},
         | 
| 316 | 
            +
                      bucket: "bucket",
         | 
| 317 | 
            +
                      path: ":attachment/:basename:dotextension",
         | 
| 318 | 
            +
                      s3_host_name: "s3-accelerate.amazonaws.com",
         | 
| 319 | 
            +
                      s3_region: "ap-northeast-1",
         | 
| 320 | 
            +
                      use_accelerate_endpoint: true,
         | 
| 321 | 
            +
                    )
         | 
| 322 | 
            +
                    @dummy = Dummy.new
         | 
| 323 | 
            +
                    @dummy.avatar = stringy_file
         | 
| 324 | 
            +
                    @dummy.stubs(:new_record?).returns(false)
         | 
| 325 | 
            +
                  end
         | 
| 326 | 
            +
             | 
| 327 | 
            +
                  it "returns a url based on an :s3_host_name path" do
         | 
| 328 | 
            +
                    assert_match %r{^//s3-accelerate.amazonaws.com/bucket/avatars/data[^\.]},
         | 
| 329 | 
            +
                      @dummy.avatar.url
         | 
| 330 | 
            +
                  end
         | 
| 331 | 
            +
             | 
| 332 | 
            +
                  it "uses the S3 client with the use_accelerate_endpoint config is true" do
         | 
| 333 | 
            +
                    expect(@dummy.avatar.s3_bucket.client.config.use_accelerate_endpoint).to be(true)
         | 
| 334 | 
            +
                  end
         | 
| 335 | 
            +
                end
         | 
| 336 | 
            +
              end
         | 
| 337 | 
            +
             | 
| 285 338 | 
             
              context "An attachment that uses S3 for storage and has styles that return different file types" do
         | 
| 286 339 | 
             
                before do
         | 
| 287 340 | 
             
                  rebuild_model (aws2_add_region).merge storage: :s3,
         | 
| @@ -458,7 +511,7 @@ describe Paperclip::Storage::S3 do | |
| 458 511 | 
             
                      "question?mark.png"
         | 
| 459 512 | 
             
                    end
         | 
| 460 513 | 
             
                  end
         | 
| 461 | 
            -
                  file = Paperclip.io_adapters.for(stringio)
         | 
| 514 | 
            +
                  file = Paperclip.io_adapters.for(stringio, hash_digest: Digest::MD5)
         | 
| 462 515 | 
             
                  @dummy = Dummy.new
         | 
| 463 516 | 
             
                  @dummy.avatar = file
         | 
| 464 517 | 
             
                  @dummy.save
         | 
| @@ -514,6 +567,33 @@ describe Paperclip::Storage::S3 do | |
| 514 567 | 
             
                end
         | 
| 515 568 | 
             
              end
         | 
| 516 569 |  | 
| 570 | 
            +
              context "generating a url with a prefixed host alias" do
         | 
| 571 | 
            +
                before do
         | 
| 572 | 
            +
                  rebuild_model(
         | 
| 573 | 
            +
                    aws2_add_region.merge(
         | 
| 574 | 
            +
                      storage: :s3,
         | 
| 575 | 
            +
                      s3_credentials: {
         | 
| 576 | 
            +
                        production: { bucket: "prod_bucket" },
         | 
| 577 | 
            +
                        development: { bucket: "dev_bucket" },
         | 
| 578 | 
            +
                      },
         | 
| 579 | 
            +
                      bucket: "bucket",
         | 
| 580 | 
            +
                      s3_host_alias: "something.something.com",
         | 
| 581 | 
            +
                      s3_prefixes_in_alias: 2,
         | 
| 582 | 
            +
                      path: "prefix1/prefix2/:attachment/:basename:dotextension",
         | 
| 583 | 
            +
                      url: ":s3_alias_url",
         | 
| 584 | 
            +
                    )
         | 
| 585 | 
            +
                  )
         | 
| 586 | 
            +
                  @dummy = Dummy.new
         | 
| 587 | 
            +
                  @dummy.avatar = stringy_file
         | 
| 588 | 
            +
                  @dummy.stubs(:new_record?).returns(false)
         | 
| 589 | 
            +
                end
         | 
| 590 | 
            +
             | 
| 591 | 
            +
                it "returns a url with the prefixes removed" do
         | 
| 592 | 
            +
                  assert_match %r{^//something.something.com/avatars/data[^\.]},
         | 
| 593 | 
            +
                               @dummy.avatar.url
         | 
| 594 | 
            +
                end
         | 
| 595 | 
            +
              end
         | 
| 596 | 
            +
             | 
| 517 597 | 
             
              context "generating a url with a proc as the host alias" do
         | 
| 518 598 | 
             
                before do
         | 
| 519 599 | 
             
                  rebuild_model (aws2_add_region).merge storage: :s3,
         | 
| @@ -741,8 +821,9 @@ describe Paperclip::Storage::S3 do | |
| 741 821 |  | 
| 742 822 | 
             
                it "gets the right s3_host_name in development" do
         | 
| 743 823 | 
             
                  rails_env("development") do
         | 
| 744 | 
            -
                    assert_match %r{^s3 | 
| 745 | 
            -
             | 
| 824 | 
            +
                    assert_match %r{^s3.ap-northeast-1.amazonaws.com},
         | 
| 825 | 
            +
                      @dummy.avatar.s3_host_name
         | 
| 826 | 
            +
                    assert_match %r{^s3.ap-northeast-1.amazonaws.com},
         | 
| 746 827 | 
             
                      @dummy.avatar.s3_bucket.client.config.endpoint.host
         | 
| 747 828 | 
             
                  end
         | 
| 748 829 | 
             
                end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Paperclip::Tempfile do
         | 
| 4 | 
            +
              context "A Paperclip Tempfile" do
         | 
| 5 | 
            +
                before do
         | 
| 6 | 
            +
                  @tempfile = described_class.new(["file", ".jpg"])
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                after { @tempfile.close }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "has its path contain a real extension" do
         | 
| 12 | 
            +
                  assert_equal ".jpg", File.extname(@tempfile.path)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                it "is a real Tempfile" do
         | 
| 16 | 
            +
                  assert @tempfile.is_a?(::Tempfile)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              context "Another Paperclip Tempfile" do
         | 
| 21 | 
            +
                before do
         | 
| 22 | 
            +
                  @tempfile = described_class.new("file")
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                after { @tempfile.close }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it "does not have an extension if not given one" do
         | 
| 28 | 
            +
                  assert_equal "", File.extname(@tempfile.path)
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                it "is a real Tempfile" do
         | 
| 32 | 
            +
                  assert @tempfile.is_a?(::Tempfile)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -1,38 +1,6 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Paperclip::Thumbnail do
         | 
| 4 | 
            -
              context "A Paperclip Tempfile" do
         | 
| 5 | 
            -
                before do
         | 
| 6 | 
            -
                  @tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                after { @tempfile.close }
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                it "has its path contain a real extension" do
         | 
| 12 | 
            -
                  assert_equal ".jpg", File.extname(@tempfile.path)
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                it "is a real Tempfile" do
         | 
| 16 | 
            -
                  assert @tempfile.is_a?(::Tempfile)
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              context "Another Paperclip Tempfile" do
         | 
| 21 | 
            -
                before do
         | 
| 22 | 
            -
                  @tempfile = Paperclip::Tempfile.new("file")
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                after { @tempfile.close }
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                it "does not have an extension if not given one" do
         | 
| 28 | 
            -
                  assert_equal "", File.extname(@tempfile.path)
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                it "is a real Tempfile" do
         | 
| 32 | 
            -
                  assert @tempfile.is_a?(::Tempfile)
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 4 | 
             
              context "An image" do
         | 
| 37 5 | 
             
                before do
         | 
| 38 6 | 
             
                  @file = File.new(fixture_file("5k.png"), 'rb')
         | 
| @@ -480,6 +448,41 @@ describe Paperclip::Thumbnail do | |
| 480 448 | 
             
                    assert_equal "50x50", `#{cmd}`.chomp
         | 
| 481 449 | 
             
                  end
         | 
| 482 450 | 
             
                end
         | 
| 451 | 
            +
             | 
| 452 | 
            +
                context "with a specified frame_index" do
         | 
| 453 | 
            +
                  before do
         | 
| 454 | 
            +
                    @thumb = Paperclip::Thumbnail.new(
         | 
| 455 | 
            +
                      @file,
         | 
| 456 | 
            +
                      geometry: "50x50",
         | 
| 457 | 
            +
                      frame_index: 5,
         | 
| 458 | 
            +
                      format: :jpg,
         | 
| 459 | 
            +
                    )
         | 
| 460 | 
            +
                  end
         | 
| 461 | 
            +
             | 
| 462 | 
            +
                  it "creates the thumbnail from the frame index when sent #make" do
         | 
| 463 | 
            +
                    @thumb.make
         | 
| 464 | 
            +
                    assert_equal 5, @thumb.frame_index
         | 
| 465 | 
            +
                  end
         | 
| 466 | 
            +
                end
         | 
| 467 | 
            +
             | 
| 468 | 
            +
                context "with a specified frame_index out of bounds" do
         | 
| 469 | 
            +
                  before do
         | 
| 470 | 
            +
                    @thumb = Paperclip::Thumbnail.new(
         | 
| 471 | 
            +
                      @file,
         | 
| 472 | 
            +
                      geometry: "50x50",
         | 
| 473 | 
            +
                      frame_index: 20,
         | 
| 474 | 
            +
                      format: :jpg,
         | 
| 475 | 
            +
                    )
         | 
| 476 | 
            +
                  end
         | 
| 477 | 
            +
             | 
| 478 | 
            +
                  it "errors when trying to create the thumbnail" do
         | 
| 479 | 
            +
                    assert_raises(Paperclip::Error) do
         | 
| 480 | 
            +
                      silence_stream(STDERR) do
         | 
| 481 | 
            +
                        @thumb.make
         | 
| 482 | 
            +
                      end
         | 
| 483 | 
            +
                    end
         | 
| 484 | 
            +
                  end
         | 
| 485 | 
            +
                end
         | 
| 483 486 | 
             
              end
         | 
| 484 487 |  | 
| 485 488 | 
             
              context "with a really long file name" do
         |