File: azure_rm_integration_spec.rb

package info (click to toggle)
ruby-asset-sync 2.11.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 420 kB
  • sloc: ruby: 2,080; makefile: 3; javascript: 1
file content (74 lines) | stat: -rw-r--r-- 1,977 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.dirname(__FILE__) + '/../spec_helper'
require "fog/azurerm"

def bucket(name)
  options = {
    :provider => 'AzureRM',
    :azure_storage_account_name => ENV['AZURE_STORAGE_ACCOUNT_NAME'],
    :azure_storage_access_key => ENV['AZURE_STORAGE_ACCESS_KEY']
  }
  options.merge!({ :environment => ENV['FOG_REGION'] }) if ENV.has_key?('FOG_REGION')

  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

  it "sync" do
    execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"

    files = bucket(@prefix).files

    app_js = files.select{ |f| f.key =~ app_js_regex }.first
    expect(app_js.content_type).to eq("application/javascript")

    app_js_gz = files.select{ |f| f.key =~ app_js_gz_regex }.first
    expect(app_js_gz.content_type).to eq("application/javascript")
    expect(app_js_gz.content_encoding).to eq("gzip")
  end

  it "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

  it "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("application/javascript")
  end

end