File: fog_spec.rb

package info (click to toggle)
ruby-carrierwave 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,692 kB
  • sloc: ruby: 9,881; sh: 26; makefile: 5
file content (51 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
require 'spec_helper'
require 'fog/aws'
require 'fog/google'
require 'fog/local'
require 'fog/rackspace'
require 'carrierwave/storage/fog'

unless ENV['REMOTE'] == 'true'
  Fog.mock!
end

require_relative './fog_credentials' # after Fog.mock!
require_relative './fog_helper'

FOG_CREDENTIALS.each do |credential|
  fog_tests(credential)
end

describe CarrierWave::Storage::Fog::File do
  subject(:file) { CarrierWave::Storage::Fog::File.new(nil, nil, nil) }

  describe "#filename" do
    subject(:filename) { file.filename }

    before { allow(file).to receive(:url).and_return(url) }

    context "with normal url" do
      let(:url) { 'http://example.com/path/to/foo.txt' }

      it "extracts filename from url" do
        is_expected.to eq('foo.txt')
      end
    end

    context "when url contains '/' in query string" do
      let(:url){ 'http://example.com/path/to/foo.txt?bar=baz/fubar' }

      it "extracts correct part" do
        is_expected.to eq('foo.txt')
      end
    end

    context "when url contains multi-byte characters" do
      let(:url) { 'http://example.com/path/to/%E6%97%A5%E6%9C%AC%E8%AA%9E.txt' }

      it "decodes multi-byte characters" do
        is_expected.to eq('日本語.txt')
      end
    end
  end
end