Make VCR disallow unexpected HTTP requests.
This makes it so that tests fail when they make HTTP requests they aren't expected to. Update these tests so that they use VCR like they should.
This commit is contained in:
@@ -100,5 +100,5 @@ MEMCACHE = MockMemcache.new
|
||||
VCR.configure do |c|
|
||||
c.cassette_library_dir = "test/fixtures/vcr_cassettes"
|
||||
c.hook_into :webmock
|
||||
c.allow_http_connections_when_no_cassette = true
|
||||
# c.allow_http_connections_when_no_cassette = true
|
||||
end
|
||||
|
||||
@@ -27,28 +27,38 @@ module Downloads
|
||||
end
|
||||
|
||||
should "stream a file from an HTTP source" do
|
||||
VCR.use_cassette("download-file-http", :record => :once) do
|
||||
@download.http_get_streaming do |resp|
|
||||
assert_equal("200", resp.code)
|
||||
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "throw an exception when the file is larger than the maximum" do
|
||||
assert_raise(Downloads::File::Error) do
|
||||
VCR.use_cassette("download-file-http", :record => :once) do
|
||||
@download.http_get_streaming(:max_size => 1) do |resp|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "store the file in the tempfile path" do
|
||||
VCR.use_cassette("download-file-http", :record => :once) do
|
||||
@download.download!
|
||||
end
|
||||
|
||||
assert_equal(@source, @download.source)
|
||||
assert(::File.exists?(@tempfile.path), "temp file should exist")
|
||||
assert(::File.size(@tempfile.path) > 0, "should have data")
|
||||
end
|
||||
|
||||
should "initialize the content type" do
|
||||
VCR.use_cassette("download-file-http", :record => :once) do
|
||||
@download.download!
|
||||
end
|
||||
|
||||
assert_match(/image\/gif/, @download.content_type)
|
||||
end
|
||||
end
|
||||
@@ -65,6 +75,7 @@ module Downloads
|
||||
end
|
||||
|
||||
should "stream a file from an HTTPS source" do
|
||||
VCR.use_cassette("download-file-https", :record => :once) do
|
||||
@download.http_get_streaming do |resp|
|
||||
assert_equal("200", resp.code)
|
||||
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
|
||||
@@ -73,3 +84,4 @@ module Downloads
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -104,12 +104,15 @@ class UploadTest < ActiveSupport::TestCase
|
||||
should "initialize the final path after downloading a file" do
|
||||
@upload = FactoryGirl.create(:source_upload)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
|
||||
VCR.use_cassette("upload-test-file", :record => :once) do
|
||||
assert_nothing_raised {@upload.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
assert_equal(8558, File.size(path))
|
||||
assert_equal(path, @upload.file_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "determining if a file is downloadable" do
|
||||
should "classify HTTP sources as downloadable" do
|
||||
|
||||
Reference in New Issue
Block a user