jam-cloud/ruby/spec/jam_ruby/models/max_mind_releases_spec.rb

71 lines
2.3 KiB
Ruby

require 'spec_helper'
describe MaxMindRelease do
include UsesTempFiles
GEOISP_124 = 'geoisp_124.csv'
in_directory_with_file(GEOISP_124)
before(:all) do
@original_storage = MaxMindReleaseUploader.storage = :fog
end
after(:all) do
MaxMindReleaseUploader.storage = @original_storage
end
let(:zipfile) {fake_geo_124_zip(File.new(GEOISP_124))}
let(:release) {FactoryGirl.create(:max_mind_release)}
before(:each) do
content_for_file('abc')
Dir.mkdir(APP_CONFIG.max_mind_working_dir) unless Dir.exists?(APP_CONFIG.max_mind_working_dir)
end
it "unzip" do
result = release.unzip(APP_CONFIG.max_mind_working_dir, zipfile.path)
result.include?('GeoIPISP.csv').should be_true
output = result['GeoIPISP.csv']
File.exists?(output).should be_true
IO.read(output).should == 'abc'
end
it "downloads", aws: true do
uploader = MaxMindReleaseUploader.new(release, :geo_ip_124_url)
zipfile.open
uploader.store!(zipfile) # uploads the file to s3
release.save!
release[:geo_ip_124_url].should == File.join(release.store_dir, 'geo_ip_124_url.zip')
release[:geo_ip_124_md5].should == Digest::MD5.file(zipfile).hexdigest
release[:geo_ip_124_size].should == zipfile.size
downloaded_filename = release.download(release.dated_working_dir, :geo_ip_124_url, release[:geo_ip_124_md5])
Digest::MD5.file(downloaded_filename ).hexdigest.should == Digest::MD5.file(zipfile).hexdigest
end
#it "uploads to s3 with correct name, and then downloads via signed URL" do
# pending "use"
# jam_track = FactoryGirl.create(:jam_track)
# uploader = JamTrackUploader.new(jam_track, :url)
# uploader.store!(File.open(JKA_NAME)) # uploads file
# jam_track.save!
#
# # verify that the uploader stores the correct path
# jam_track[:url].should == jam_track.store_dir + '/' + jam_track.filename
#
# # verify it's on S3
# s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
# s3.exists?(jam_track[:url]).should be_true
# s3.length(jam_track[:url]).should == 'abc'.length
#
# # download it via signed URL, and check contents
# url = jam_track.sign_url
# downloaded_contents = open(url).read
# downloaded_contents.should == 'abc'
#end
end