Welcome to mirror list, hosted at ThFree Co, Russian Federation.

carrierwave_patch_spec.rb « initializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c4a7bfa59c61c086e3aa71190410b2c227eadbe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'CarrierWave::Storage::Fog::File' do
  let(:uploader_class) { Class.new(CarrierWave::Uploader::Base) }
  let(:uploader) { uploader_class.new }
  let(:storage) { CarrierWave::Storage::Fog.new(uploader) }
  let(:azure_options) do
    {
      azure_storage_account_name: 'AZURE_ACCOUNT_NAME',
      azure_storage_access_key: 'AZURE_ACCESS_KEY',
      provider: 'AzureRM'
    }
  end

  subject { CarrierWave::Storage::Fog::File.new(uploader, storage, 'test') }

  before do
    require 'fog/azurerm'
    allow(uploader).to receive(:fog_credentials).and_return(azure_options)
    Fog.mock!
  end

  describe '#authenticated_url' do
    context 'with Azure' do
      it 'has an authenticated URL' do
        expect(subject.authenticated_url).to eq("https://sa.blob.core.windows.net/test_container/test_blob?token")
      end
    end

    context 'with custom expire_at' do
      it 'properly sets expires param' do
        expire_at = 24.hours.from_now

        expect_next_instance_of(Fog::Storage::AzureRM::File) do |file|
          expect(file).to receive(:url).with(expire_at).and_call_original
        end

        expect(subject.authenticated_url(expire_at: expire_at)).to eq("https://sa.blob.core.windows.net/test_container/test_blob?token")
      end
    end
  end
end