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
|
require File.dirname(__FILE__) + '/../spec_helper'
require "fog/aws"
def bucket(name)
options = {
:provider => 'AWS',
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
connection = Fog::Storage.new(options)
connection.directories.get(ENV['FOG_DIRECTORY'], :prefix => name)
end
def execute(command)
app_path = File.expand_path("../../dummy_app", __FILE__)
Dir.chdir app_path
`#{command}`
end
describe "AssetSync" do
before(:each) do
@prefix = SecureRandom.hex(6)
end
let(:app_js_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js$/
}
let(:app_js_gz_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
}
let(:files){ bucket(@prefix).files }
after(:each) do
@directory = bucket(@prefix)
@directory.files.each do |f|
f.destroy
end
end
xit "sync" do
execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"
files = bucket(@prefix).files
app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
app_js_gz_path = files.select{ |f| f.key =~ app_js_gz_regex }.first
app_js = files.get( app_js_path.key )
expect(app_js.content_type).to eq("text/javascript")
app_js_gz = files.get( app_js_gz_path.key )
expect(app_js_gz.content_type).to eq("text/javascript")
expect(app_js_gz.content_encoding).to eq("gzip")
end
xit "sync with enabled=false" do
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile"
expect(bucket(@prefix).files.size).to eq(0)
end
xit "sync with gzip_compression=true" do
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile"
# bucket(@prefix).files.size.should == 3
app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
app_js = files.get( app_js_path.key )
expect(app_js.content_type).to eq("text/javascript")
end
end
|