File: uploaded_file_spec.rb

package info (click to toggle)
ruby-rack-test 0.7.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 296 kB
  • sloc: ruby: 1,900; makefile: 5
file content (60 lines) | stat: -rw-r--r-- 1,816 bytes parent folder | download | duplicates (3)
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
require "spec_helper"

describe Rack::Test::UploadedFile do
  def test_file_path
    File.dirname(__FILE__) + "/../../fixtures/foo.txt"
  end

  it "returns an instance of `Rack::Test::UploadedFile`" do
    uploaded_file = Rack::Test::UploadedFile.new(test_file_path)

    expect(uploaded_file).to be_a(Rack::Test::UploadedFile)
  end

  it "responds to things that Tempfile responds to" do
    uploaded_file = Rack::Test::UploadedFile.new(test_file_path)

    expect(uploaded_file).to respond_to(:close)
    expect(uploaded_file).to respond_to(:close!)
    expect(uploaded_file).to respond_to(:delete)
    expect(uploaded_file).to respond_to(:length)
    expect(uploaded_file).to respond_to(:open)
    expect(uploaded_file).to respond_to(:path)
    expect(uploaded_file).to respond_to(:size)
    expect(uploaded_file).to respond_to(:unlink)
    expect(uploaded_file).to respond_to(:read)
    expect(uploaded_file).to respond_to(:original_filename)
    expect(uploaded_file).to respond_to(:tempfile) # Allows calls to params[:file].tempfile
  end

  it "creates Tempfiles with original file's extension" do
    uploaded_file = Rack::Test::UploadedFile.new(test_file_path)

    expect(File.extname(uploaded_file.path)).to eq(".txt")
  end

  context "it should call its destructor" do
    it "calls the destructor" do
      expect(Rack::Test::UploadedFile).to receive(:actually_finalize).at_least(:once)

      if RUBY_PLATFORM == 'java'
        require 'java'
        java_import 'java.lang.System'

        50.times do |i|
          uploaded_file = Rack::Test::UploadedFile.new(test_file_path)

          uploaded_file = nil

          System.gc()
        end
      else
        uploaded_file = Rack::Test::UploadedFile.new(test_file_path)

        uploaded_file = nil

        GC.start
      end
    end
  end
end