carrierwave-azure 0.0.2 → 0.0.3
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/README.md +6 -5
- data/carrierwave-azure.gemspec +2 -1
- data/lib/carrierwave-azure.rb +3 -2
- data/lib/carrierwave/azure/version.rb +1 -1
- data/lib/carrierwave/storage/azure.rb +5 -5
- data/spec/carrierwave-azure_spec.rb +5 -4
- data/spec/carrierwave/storage/azure_file_spec.rb +38 -0
- data/spec/carrierwave/storage/azure_spec.rb +29 -46
- data/spec/environment.rb.sample +2 -4
- metadata +29 -14
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2e0a56c09c0ae1636071257a539bee848f732bf8
         | 
| 4 | 
            +
              data.tar.gz: c5aac6ae83e8fb9332a61cfd560816a21b27ff4a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3b936fa3d28be01ca38afe6963349c768285e9543e109da57e0ead9115b1220f42d90b117c75030c1177ef3dc6c27e3efa957fe1921b146d1f3ccc164c69eb6d
         | 
| 7 | 
            +
              data.tar.gz: c771bb6be7a4d94e7a86bca5095faf6ded36734a6b79ad4a0c33eb175265f47a33d7d929fac87312c2dd7ed585c3a2a4ee5308ab5e805d07686f0235a2ec13f4
         | 
    
        data/README.md
    CHANGED
    
    | @@ -16,14 +16,15 @@ And then execute: | |
| 16 16 |  | 
| 17 17 | 
             
            First configure CarrierWave with your Azure storage credentials
         | 
| 18 18 |  | 
| 19 | 
            +
            see [Azure/azure-sdk-for-ruby](https://github.com/Azure/azure-sdk-for-ruby#via-code)
         | 
| 20 | 
            +
             | 
| 19 21 | 
             
            ```ruby
         | 
| 20 22 | 
             
            CarrierWave.configure do |config|
         | 
| 21 | 
            -
              config. | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
              }
         | 
| 23 | 
            +
              config.azure_storage_account_name = 'YOUR STORAGE ACCOUNT NAME'
         | 
| 24 | 
            +
              config.azure_storage_access_key = 'YOUR STORAGE ACCESS KEY'
         | 
| 25 | 
            +
              config.azure_storage_blob_host = 'YOUR STORAGE BLOB HOST' # optional
         | 
| 25 26 | 
             
              config.azure_container = 'YOUR CONTAINER NAME'
         | 
| 26 | 
            -
              config. | 
| 27 | 
            +
              config.asset_host = 'YOUR CDN HOST' # optional
         | 
| 27 28 | 
             
            end
         | 
| 28 29 | 
             
            ```
         | 
| 29 30 |  | 
    
        data/carrierwave-azure.gemspec
    CHANGED
    
    
    
        data/lib/carrierwave-azure.rb
    CHANGED
    
    | @@ -3,8 +3,9 @@ require 'carrierwave/azure/version' | |
| 3 3 | 
             
            require 'carrierwave/storage/azure'
         | 
| 4 4 |  | 
| 5 5 | 
             
            class CarrierWave::Uploader::Base
         | 
| 6 | 
            -
              add_config : | 
| 7 | 
            -
              add_config : | 
| 6 | 
            +
              add_config :azure_storage_account_name
         | 
| 7 | 
            +
              add_config :azure_storage_access_key
         | 
| 8 | 
            +
              add_config :azure_storage_blob_host
         | 
| 8 9 | 
             
              add_config :azure_container
         | 
| 9 10 |  | 
| 10 11 | 
             
              configure do |config|
         | 
| @@ -15,9 +15,9 @@ module CarrierWave | |
| 15 15 |  | 
| 16 16 | 
             
                  def connection
         | 
| 17 17 | 
             
                    @connection ||= begin
         | 
| 18 | 
            -
                       | 
| 19 | 
            -
                        ::Azure.config.send("#{key}=",  | 
| 20 | 
            -
                      end | 
| 18 | 
            +
                      %i(storage_account_name storage_access_key storage_blob_host).each do |key|
         | 
| 19 | 
            +
                        ::Azure.config.send("#{key}=", uploader.send("azure_#{key}"))
         | 
| 20 | 
            +
                      end
         | 
| 21 21 | 
             
                      ::Azure::BlobService.new
         | 
| 22 22 | 
             
                    end
         | 
| 23 23 | 
             
                  end
         | 
| @@ -40,8 +40,8 @@ module CarrierWave | |
| 40 40 |  | 
| 41 41 | 
             
                    def url(options = {})
         | 
| 42 42 | 
             
                      path = ::File.join @uploader.azure_container, @path
         | 
| 43 | 
            -
                      if @uploader. | 
| 44 | 
            -
                        "#{@uploader. | 
| 43 | 
            +
                      if @uploader.asset_host
         | 
| 44 | 
            +
                        "#{@uploader.asset_host}/#{path}"
         | 
| 45 45 | 
             
                      else
         | 
| 46 46 | 
             
                        @connection.generate_uri(path).to_s
         | 
| 47 47 | 
             
                      end
         | 
| @@ -2,12 +2,13 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe CarrierWave::Uploader::Base do
         | 
| 4 4 | 
             
              it 'should define azure as a storage engine' do
         | 
| 5 | 
            -
                described_class.storage_engines[:azure]. | 
| 5 | 
            +
                expect(described_class.storage_engines[:azure]).to eq 'CarrierWave::Storage::Azure'
         | 
| 6 6 | 
             
              end
         | 
| 7 7 |  | 
| 8 8 | 
             
              it 'should define azure options' do
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                is_expected.to respond_to(:azure_storage_account_name)
         | 
| 10 | 
            +
                is_expected.to respond_to(:azure_storage_access_key)
         | 
| 11 | 
            +
                is_expected.to respond_to(:azure_storage_blob_host)
         | 
| 12 | 
            +
                is_expected.to respond_to(:azure_container)
         | 
| 12 13 | 
             
              end
         | 
| 13 14 | 
             
            end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe CarrierWave::Storage::Azure::File do
         | 
| 4 | 
            +
              class TestUploader < CarrierWave::Uploader::Base
         | 
| 5 | 
            +
                storage :azure
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              let(:uploader) { TestUploader.new }
         | 
| 9 | 
            +
              let(:storage)  { CarrierWave::Storage::Azure.new uploader }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              describe '#url' do
         | 
| 12 | 
            +
                before do
         | 
| 13 | 
            +
                  allow(uploader).to receive(:azure_container).and_return('test')
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                subject { CarrierWave::Storage::Azure::File.new(uploader, storage.connection, 'dummy.txt').url }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                context 'with storage_blob_host' do
         | 
| 19 | 
            +
                  before do
         | 
| 20 | 
            +
                    allow(uploader).to receive(:azure_storage_blob_host).and_return('http://example.com')
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  it 'should return on asset_host' do
         | 
| 24 | 
            +
                    expect(subject).to eq 'http://example.com/test/dummy.txt'
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                context 'with asset_host' do
         | 
| 29 | 
            +
                  before do
         | 
| 30 | 
            +
                    allow(uploader).to receive(:asset_host).and_return('http://example.com')
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  it 'should return on asset_host' do
         | 
| 34 | 
            +
                    expect(subject).to eq 'http://example.com/test/dummy.txt'
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| @@ -11,85 +11,68 @@ describe CarrierWave::Storage::Azure do | |
| 11 11 | 
             
              let(:storage)  { CarrierWave::Storage::Azure.new uploader }
         | 
| 12 12 |  | 
| 13 13 | 
             
              shared_examples_for 'an expected return value' do
         | 
| 14 | 
            +
                let(:stored_file) do
         | 
| 15 | 
            +
                  allow(uploader).to receive(:store_path).and_return('test/dummy.png')
         | 
| 16 | 
            +
                  tempfile = Tempfile.new 'test.jpg'
         | 
| 17 | 
            +
                  open(tempfile.path, 'w') do |f|
         | 
| 18 | 
            +
                    f.print '1234567890'
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  storage.store! CarrierWave::SanitizedFile.new(
         | 
| 21 | 
            +
                    tempfile:     tempfile,
         | 
| 22 | 
            +
                    filename:     'test.jpg',
         | 
| 23 | 
            +
                    content_type: 'image/png'
         | 
| 24 | 
            +
                  )
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                let(:retrieved_file) do
         | 
| 28 | 
            +
                  storage.retrieve! stored_file.path
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 14 31 | 
             
                it 'should have a path' do
         | 
| 15 | 
            -
                  expect( | 
| 32 | 
            +
                  expect(subject.path).to eq 'test/dummy.png'
         | 
| 16 33 | 
             
                end
         | 
| 17 34 |  | 
| 18 35 | 
             
                it 'should have a url' do
         | 
| 19 | 
            -
                  url =  | 
| 36 | 
            +
                  url = subject.url
         | 
| 20 37 | 
             
                  expect(url).to match /^https?:\/\//
         | 
| 21 | 
            -
                  expect(open(url).read).to eq  | 
| 38 | 
            +
                  expect(open(url).read).to eq '1234567890'
         | 
| 22 39 | 
             
                end
         | 
| 23 40 |  | 
| 24 41 | 
             
                it 'should have a content' do
         | 
| 25 | 
            -
                  expect( | 
| 42 | 
            +
                  expect(subject.read).to eq '1234567890'
         | 
| 26 43 | 
             
                end
         | 
| 27 44 |  | 
| 28 45 | 
             
                it 'should have a content_type' do
         | 
| 29 | 
            -
                  expect( | 
| 46 | 
            +
                  expect(subject.content_type).to eq 'image/png'
         | 
| 30 47 | 
             
                end
         | 
| 31 48 |  | 
| 32 49 | 
             
                it 'should have a size' do
         | 
| 33 | 
            -
                  expect( | 
| 50 | 
            +
                  expect(subject.size).to eq 10
         | 
| 34 51 | 
             
                end
         | 
| 35 52 |  | 
| 36 53 | 
             
                it 'should have a filename' do
         | 
| 37 | 
            -
                  expect( | 
| 54 | 
            +
                  expect(subject.filename).to eq 'dummy.png'
         | 
| 38 55 | 
             
                end
         | 
| 39 56 |  | 
| 40 57 | 
             
                it 'should have an extension' do
         | 
| 41 | 
            -
                  expect( | 
| 58 | 
            +
                  expect(subject.extension).to eq 'png'
         | 
| 42 59 | 
             
                end
         | 
| 43 60 |  | 
| 44 61 | 
             
                it 'should be deletable' do
         | 
| 45 | 
            -
                   | 
| 46 | 
            -
                  expect{open  | 
| 62 | 
            +
                  subject.delete
         | 
| 63 | 
            +
                  expect{open subject.url}.to raise_error OpenURI::HTTPError
         | 
| 47 64 | 
             
                end
         | 
| 48 65 | 
             
              end
         | 
| 49 66 |  | 
| 50 67 | 
             
              describe '#store!' do
         | 
| 51 | 
            -
                before do
         | 
| 52 | 
            -
                  uploader.stub!(:store_path).and_return('test/dummy1.png')
         | 
| 53 | 
            -
                  tempfile = Tempfile.new 'test.jpg'
         | 
| 54 | 
            -
                  open(tempfile.path, 'w') do |f|
         | 
| 55 | 
            -
                    f.print '1234567890'
         | 
| 56 | 
            -
                  end
         | 
| 57 | 
            -
                  @azure_file = storage.store! CarrierWave::SanitizedFile.new(
         | 
| 58 | 
            -
                    tempfile:     tempfile,
         | 
| 59 | 
            -
                    filename:     'test.jpg',
         | 
| 60 | 
            -
                    content_type: 'image/png'
         | 
| 61 | 
            -
                  )
         | 
| 62 | 
            -
                end
         | 
| 63 | 
            -
             | 
| 64 68 | 
             
                it_should_behave_like 'an expected return value' do
         | 
| 65 | 
            -
                   | 
| 66 | 
            -
                  let(:expect_content)      { '1234567890' }
         | 
| 67 | 
            -
                  let(:expect_content_type) { 'image/png' }
         | 
| 68 | 
            -
                  let(:expect_size)         { 10 }
         | 
| 69 | 
            -
                  let(:expect_filename)     { 'dummy1.png' }
         | 
| 70 | 
            -
                  let(:expect_extension)    { 'png' }
         | 
| 69 | 
            +
                  subject { stored_file }
         | 
| 71 70 | 
             
                end
         | 
| 72 71 | 
             
              end
         | 
| 73 72 |  | 
| 74 73 | 
             
              describe '#retrieve' do
         | 
| 75 | 
            -
                before do
         | 
| 76 | 
            -
                  uploader.stub!(:store_path).and_return('test/dummy2.png')
         | 
| 77 | 
            -
                  storage.connection.create_block_blob(
         | 
| 78 | 
            -
                    uploader.azure_container,
         | 
| 79 | 
            -
                    'test/dummy2.png',
         | 
| 80 | 
            -
                    '0123456789ABCDEF',
         | 
| 81 | 
            -
                    content_type: 'text/plain'
         | 
| 82 | 
            -
                  )
         | 
| 83 | 
            -
                  @azure_file = storage.retrieve! 'test/dummy2.png'
         | 
| 84 | 
            -
                end
         | 
| 85 | 
            -
             | 
| 86 74 | 
             
                it_should_behave_like 'an expected return value' do
         | 
| 87 | 
            -
                   | 
| 88 | 
            -
                  let(:expect_content_type) { 'text/plain' }
         | 
| 89 | 
            -
                  let(:expect_content)      { "0123456789ABCDEF" }
         | 
| 90 | 
            -
                  let(:expect_size)         { 16 }
         | 
| 91 | 
            -
                  let(:expect_filename)     { 'dummy2.png' }
         | 
| 92 | 
            -
                  let(:expect_extension)    { 'png' }
         | 
| 75 | 
            +
                  subject { retrieved_file }
         | 
| 93 76 | 
             
                end
         | 
| 94 77 | 
             
              end
         | 
| 95 78 | 
             
            end
         | 
    
        data/spec/environment.rb.sample
    CHANGED
    
    | @@ -1,7 +1,5 @@ | |
| 1 1 | 
             
            CarrierWave.configure do |config|
         | 
| 2 | 
            -
              config. | 
| 3 | 
            -
             | 
| 4 | 
            -
                storage_access_key:   'YOUR STORAGE ACCESS KEY'
         | 
| 5 | 
            -
              }
         | 
| 2 | 
            +
              config.azure_storage_account_name = 'YOUR STORAGE ACCOUNT NAME'
         | 
| 3 | 
            +
              config.azure_storage_access_key = 'YOUR STORAGE ACCESS KEY'
         | 
| 6 4 | 
             
              config.azure_container = 'YOUR CONTAINER NAME'
         | 
| 7 5 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,57 +1,71 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: carrierwave-azure
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yusuke Shibahara
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2015-01-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: carrierwave
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '0'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 24 | 
            +
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '0'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: azure
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '0'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name:  | 
| 42 | 
            +
              name: rake
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: '0'
         | 
| 48 48 | 
             
              type: :development
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rspec
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '3'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '3'
         | 
| 55 69 | 
             
            description: Allows file upload to Azure with the officail sdk
         | 
| 56 70 | 
             
            email:
         | 
| 57 71 | 
             
            - yusuke.shibahara@heathrow.co.jp
         | 
| @@ -59,8 +73,8 @@ executables: [] | |
| 59 73 | 
             
            extensions: []
         | 
| 60 74 | 
             
            extra_rdoc_files: []
         | 
| 61 75 | 
             
            files:
         | 
| 62 | 
            -
            - .gitignore
         | 
| 63 | 
            -
            - .rspec
         | 
| 76 | 
            +
            - ".gitignore"
         | 
| 77 | 
            +
            - ".rspec"
         | 
| 64 78 | 
             
            - Gemfile
         | 
| 65 79 | 
             
            - LICENSE.txt
         | 
| 66 80 | 
             
            - README.md
         | 
| @@ -70,6 +84,7 @@ files: | |
| 70 84 | 
             
            - lib/carrierwave/azure/version.rb
         | 
| 71 85 | 
             
            - lib/carrierwave/storage/azure.rb
         | 
| 72 86 | 
             
            - spec/carrierwave-azure_spec.rb
         | 
| 87 | 
            +
            - spec/carrierwave/storage/azure_file_spec.rb
         | 
| 73 88 | 
             
            - spec/carrierwave/storage/azure_spec.rb
         | 
| 74 89 | 
             
            - spec/environment.rb.sample
         | 
| 75 90 | 
             
            - spec/spec_helper.rb
         | 
| @@ -83,17 +98,17 @@ require_paths: | |
| 83 98 | 
             
            - lib
         | 
| 84 99 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 85 100 | 
             
              requirements:
         | 
| 86 | 
            -
              - -  | 
| 101 | 
            +
              - - ">="
         | 
| 87 102 | 
             
                - !ruby/object:Gem::Version
         | 
| 88 103 | 
             
                  version: '0'
         | 
| 89 104 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 90 105 | 
             
              requirements:
         | 
| 91 | 
            -
              - -  | 
| 106 | 
            +
              - - ">="
         | 
| 92 107 | 
             
                - !ruby/object:Gem::Version
         | 
| 93 108 | 
             
                  version: '0'
         | 
| 94 109 | 
             
            requirements: []
         | 
| 95 110 | 
             
            rubyforge_project: 
         | 
| 96 | 
            -
            rubygems_version: 2. | 
| 111 | 
            +
            rubygems_version: 2.4.5
         | 
| 97 112 | 
             
            signing_key: 
         | 
| 98 113 | 
             
            specification_version: 4
         | 
| 99 114 | 
             
            summary: Windows Azure blob storage support for CarrierWave
         |