File: proxy_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 (79 lines) | stat: -rw-r--r-- 1,775 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'spec_helper'

describe CarrierWave::Uploader do
  let(:uploader_class) { Class.new(CarrierWave::Uploader::Base) }
  let(:uploader) { uploader_class.new }
  let(:test_file_name) { 'test.jpg' }
  let(:test_file) { File.open(file_path(test_file_name)) }
  let(:path) { '1369894322-345-1234-2255/test.jpeg' }

  after { FileUtils.rm_rf(public_path) }

  describe '#blank?' do
    subject { uploader }

    context "when nothing has been done" do
      it { is_expected.to be_blank }
    end

    context "when file is empty" do
      before { uploader.retrieve_from_cache!(path) }

      it { is_expected.to be_blank }
    end

    context "when file has been cached" do
      before { uploader.cache!(test_file) }

      it { is_expected.not_to be_blank }
    end
  end

  describe '#read' do
    subject { uploader.read }

    describe "default behavior" do
      it { is_expected.to be nil }
    end

    context "when file is cached" do
      before { uploader.cache!(test_file) }

      it { is_expected.to eq("this is stuff") }
    end
  end

  describe '#size' do
    subject { uploader.size }

    describe "default behavior" do
      it { is_expected.to be 0 }
    end

    context "when file is cached" do
      before { uploader.cache!(test_file) }

      it { is_expected.to be 13 }
    end
  end

  describe '#content_type' do
    subject { uploader.content_type }

    context "when nothing has been done" do
      it { is_expected.to be_nil }
    end

    context "when the file has been cached" do
      before { uploader.cache!(test_file) }

      it { is_expected.to eq('image/jpeg') }
    end

    context "when the file is empty" do
      before { uploader.retrieve_from_cache!(path) }

      it { is_expected.to eq('image/jpeg') }
    end
  end
end