sq-asset_sync 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.ruby-version +1 -0
- data/.travis.yml +42 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +738 -0
- data/Gemfile +7 -0
- data/README.md +466 -0
- data/Rakefile +44 -0
- data/asset_sync.gemspec +38 -0
- data/docs/heroku.md +36 -0
- data/gemfiles/rails_3.1.gemfile +10 -0
- data/gemfiles/rails_3.2.gemfile +10 -0
- data/gemfiles/rails_4.0.gemfile +10 -0
- data/gemfiles/rails_4.1.gemfile +10 -0
- data/kochiku.yml +7 -0
- data/lib/asset_sync.rb +15 -0
- data/lib/asset_sync/asset_sync.rb +73 -0
- data/lib/asset_sync/config.rb +226 -0
- data/lib/asset_sync/engine.rb +53 -0
- data/lib/asset_sync/multi_mime.rb +16 -0
- data/lib/asset_sync/railtie.rb +5 -0
- data/lib/asset_sync/storage.rb +291 -0
- data/lib/asset_sync/version.rb +3 -0
- data/lib/generators/asset_sync/install_generator.rb +67 -0
- data/lib/generators/asset_sync/templates/asset_sync.rb +41 -0
- data/lib/generators/asset_sync/templates/asset_sync.yml +43 -0
- data/lib/tasks/asset_sync.rake +30 -0
- data/script/ci +31 -0
- data/spec/dummy_app/Rakefile +30 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +1 -0
- data/spec/fixtures/aws_with_yml/config/asset_sync.yml +25 -0
- data/spec/fixtures/google_with_yml/config/asset_sync.yml +19 -0
- data/spec/fixtures/rackspace_with_yml/config/asset_sync.yml +20 -0
- data/spec/fixtures/with_invalid_yml/config/asset_sync.yml +24 -0
- data/spec/integration/aws_integration_spec.rb +77 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/unit/asset_sync_spec.rb +257 -0
- data/spec/unit/google_spec.rb +142 -0
- data/spec/unit/multi_mime_spec.rb +48 -0
- data/spec/unit/rackspace_spec.rb +90 -0
- data/spec/unit/railsless_spec.rb +72 -0
- data/spec/unit/storage_spec.rb +244 -0
- metadata +248 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
<%- if aws? -%>
|
3
|
+
fog_provider: 'AWS'
|
4
|
+
aws_access_key_id: "<%= aws_access_key_id %>"
|
5
|
+
aws_secret_access_key: "<%= aws_secret_access_key %>"
|
6
|
+
# To use AWS reduced redundancy storage.
|
7
|
+
# aws_reduced_redundancy: true
|
8
|
+
<%- elsif google? -%>
|
9
|
+
fog_provider: 'Google'
|
10
|
+
google_storage_access_key_id: "<%= google_storage_access_key_id %>"
|
11
|
+
google_storage_secret_access_key: "<%= google_storage_secret_access_key %>"
|
12
|
+
<%- elsif rackspace? -%>
|
13
|
+
fog_provider: 'Rackspace'
|
14
|
+
rackspace_username: "<%= rackspace_username %>"
|
15
|
+
rackspace_api_key: "<%= rackspace_api_key %>"
|
16
|
+
# if you need to change rackspace_auth_url (e.g. if you need to use Rackspace London)
|
17
|
+
# rackspace_auth_url: "https://lon.identity.api.rackspacecloud.com/v2.0"
|
18
|
+
<%- end -%>
|
19
|
+
fog_directory: "<%= app_name %>-assets"
|
20
|
+
# You may need to specify what region your storage bucket is in
|
21
|
+
# fog_region: "eu-west-1"
|
22
|
+
existing_remote_files: keep
|
23
|
+
# To delete existing remote files.
|
24
|
+
# existing_remote_files: delete
|
25
|
+
# Automatically replace files with their equivalent gzip compressed version
|
26
|
+
# gzip_compression: true
|
27
|
+
# Fail silently. Useful for environments such as Heroku
|
28
|
+
# fail_silently: true
|
29
|
+
|
30
|
+
development:
|
31
|
+
<<: *defaults
|
32
|
+
enabled: false
|
33
|
+
|
34
|
+
test:
|
35
|
+
<<: *defaults
|
36
|
+
enabled: false
|
37
|
+
|
38
|
+
staging:
|
39
|
+
<<: *defaults
|
40
|
+
fog_directory: "<%= app_name %>-staging-assets"
|
41
|
+
|
42
|
+
production:
|
43
|
+
<<: *defaults
|
@@ -0,0 +1,30 @@
|
|
1
|
+
namespace :assets do
|
2
|
+
|
3
|
+
desc 'Synchronize assets to remote (assumes assets are already compiled)'
|
4
|
+
task :sync => :environment do
|
5
|
+
AssetSync.sync
|
6
|
+
end
|
7
|
+
namespace :sync do
|
8
|
+
desc 'Delete out-of-sync files on remote'
|
9
|
+
task :clean => :environment do
|
10
|
+
AssetSync.clean
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
if Rake::Task.task_defined?("assets:precompile:nondigest")
|
17
|
+
Rake::Task["assets:precompile:nondigest"].enhance do
|
18
|
+
# Conditional execution needs to be inside the enhance block because the enhance block
|
19
|
+
# will get executed before yaml or Rails initializers.
|
20
|
+
Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Rake::Task["assets:precompile"].enhance do
|
24
|
+
# rails 3.1.1 will clear out Rails.application.config if the env vars
|
25
|
+
# RAILS_GROUP and RAILS_ENV are not defined. We need to reload the
|
26
|
+
# assets environment in this case.
|
27
|
+
# Rake::Task["assets:environment"].invoke if Rake::Task.task_defined?("assets:environment")
|
28
|
+
Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
|
29
|
+
end
|
30
|
+
end
|
data/script/ci
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
export RAILS_ENV="test"
|
6
|
+
|
7
|
+
ensure_app_dependencies_installed() {
|
8
|
+
install_bundler_if_needed
|
9
|
+
update_gems_if_needed
|
10
|
+
}
|
11
|
+
|
12
|
+
install_bundler_if_needed() {
|
13
|
+
echo "Checking for Bundler..."
|
14
|
+
gem install bundler --conservative
|
15
|
+
}
|
16
|
+
|
17
|
+
update_gems_if_needed() {
|
18
|
+
echo "Installing gems..."
|
19
|
+
bundle check || bundle install
|
20
|
+
}
|
21
|
+
|
22
|
+
run_specs() {
|
23
|
+
bundle exec rspec $(echo $RUN_LIST | tr , ' ')
|
24
|
+
}
|
25
|
+
|
26
|
+
run_full_build() {
|
27
|
+
ensure_app_dependencies_installed &&
|
28
|
+
run_specs
|
29
|
+
}
|
30
|
+
|
31
|
+
run_full_build
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
# require "rake"
|
3
|
+
ENV['RAILS_ROOT'] = File.dirname(__FILE__)
|
4
|
+
# Set up gems listed in the Gemfile.
|
5
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
6
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
7
|
+
# require 'rails/all'
|
8
|
+
require "action_controller/railtie"
|
9
|
+
require "sprockets/railtie"
|
10
|
+
if defined?(Bundler)
|
11
|
+
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
12
|
+
end
|
13
|
+
module AssetSyncTest
|
14
|
+
class Application < Rails::Application
|
15
|
+
config.encoding = "utf-8"
|
16
|
+
config.filter_parameters += [:password]
|
17
|
+
config.eager_load = false
|
18
|
+
config.assets.enabled = true
|
19
|
+
config.assets.version = '1.0'
|
20
|
+
config.secret_token = 'bf196b4383deefa4e0120a6ef1d9af1cc45f5c4ebd04405'
|
21
|
+
config.session_store :cookie_store, :key => '_asset_sync_test_session', :secret => 'xxxx'
|
22
|
+
config.active_support.deprecation = :log
|
23
|
+
config.assets.compress = true
|
24
|
+
config.assets.digest = true
|
25
|
+
config.assets.prefix = ENV['ASSET_SYNC_PREFIX']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
AssetSyncTest::Application.initialize!
|
29
|
+
AssetSyncTest::Application.load_tasks
|
30
|
+
# Rake::Task['assets:precompile:all'].invoke
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log("hello");
|
@@ -0,0 +1,25 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: "AWS"
|
3
|
+
aws_access_key_id: "xxxx"
|
4
|
+
aws_secret_access_key: "zzzz"
|
5
|
+
region: "eu-west-1"
|
6
|
+
run_on_precompile: false
|
7
|
+
|
8
|
+
development:
|
9
|
+
<<: *defaults
|
10
|
+
fog_directory: "rails_app_development"
|
11
|
+
existing_remote_files: keep
|
12
|
+
|
13
|
+
test:
|
14
|
+
<<: *defaults
|
15
|
+
fog_directory: "rails_app_test"
|
16
|
+
existing_remote_files: keep
|
17
|
+
|
18
|
+
production:
|
19
|
+
<<: *defaults
|
20
|
+
fog_directory: "rails_app_production"
|
21
|
+
existing_remote_files: delete
|
22
|
+
|
23
|
+
hybrid:
|
24
|
+
<<: *defaults
|
25
|
+
enabled: false
|
@@ -0,0 +1,19 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: "Google"
|
3
|
+
google_storage_access_key_id: 'xxxx'
|
4
|
+
google_storage_secret_access_key: 'zzzz'
|
5
|
+
|
6
|
+
development:
|
7
|
+
<<: *defaults
|
8
|
+
fog_directory: "rails_app_development"
|
9
|
+
existing_remote_files: keep
|
10
|
+
|
11
|
+
test:
|
12
|
+
<<: *defaults
|
13
|
+
fog_directory: "rails_app_test"
|
14
|
+
existing_remote_files: keep
|
15
|
+
|
16
|
+
production:
|
17
|
+
<<: *defaults
|
18
|
+
fog_directory: "rails_app_production"
|
19
|
+
existing_remote_files: delete
|
@@ -0,0 +1,20 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: "Rackspace"
|
3
|
+
rackspace_username: "xxxx"
|
4
|
+
rackspace_api_key: "zzzz"
|
5
|
+
region: "eu-west-1"
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *defaults
|
9
|
+
fog_directory: "rails_app_development"
|
10
|
+
existing_remote_files: keep
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
fog_directory: "rails_app_test"
|
15
|
+
existing_remote_files: keep
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *defaults
|
19
|
+
fog_directory: "rails_app_production"
|
20
|
+
existing_remote_files: delete
|
@@ -0,0 +1,24 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider= "AWS"
|
3
|
+
aws_access_key_id: "xxxx"
|
4
|
+
aws_secret_access_key: "zzzz"
|
5
|
+
region: "eu-west-1"
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *defaults
|
9
|
+
fog_directory: "rails_app_development"
|
10
|
+
existing_remote_files: keep
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
fog_directory: "rails_app_test"
|
15
|
+
existing_remote_files: keep
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *defaults
|
19
|
+
fog_directory: "rails_app_production"
|
20
|
+
existing_remote_files: delete
|
21
|
+
|
22
|
+
hybrid:
|
23
|
+
<<: *defaults
|
24
|
+
enabled: false
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require "fog/aws"
|
4
|
+
|
5
|
+
def bucket(name)
|
6
|
+
options = {
|
7
|
+
:provider => 'AWS',
|
8
|
+
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
|
9
|
+
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
|
10
|
+
}
|
11
|
+
|
12
|
+
connection = Fog::Storage.new(options)
|
13
|
+
connection.directories.get(ENV['FOG_DIRECTORY'], :prefix => name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(command)
|
17
|
+
app_path = File.expand_path("../../dummy_app", __FILE__)
|
18
|
+
Dir.chdir app_path
|
19
|
+
`#{command}`
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "AssetSync" do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@prefix = SecureRandom.hex(6)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:app_js_regex){
|
29
|
+
/#{@prefix}\/application-[a-zA-Z0-9]*.js$/
|
30
|
+
}
|
31
|
+
|
32
|
+
let(:app_js_gz_regex){
|
33
|
+
/#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:files){ bucket(@prefix).files }
|
37
|
+
|
38
|
+
|
39
|
+
after(:each) do
|
40
|
+
@directory = bucket(@prefix)
|
41
|
+
@directory.files.each do |f|
|
42
|
+
f.destroy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sync" do
|
47
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"
|
48
|
+
|
49
|
+
files = bucket(@prefix).files
|
50
|
+
|
51
|
+
app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
|
52
|
+
app_js_gz_path = files.select{ |f| f.key =~ app_js_gz_regex }.first
|
53
|
+
|
54
|
+
app_js = files.get( app_js_path.key )
|
55
|
+
expect(app_js.content_type).to eq("text/javascript")
|
56
|
+
|
57
|
+
app_js_gz = files.get( app_js_gz_path.key )
|
58
|
+
expect(app_js_gz.content_type).to eq("text/javascript")
|
59
|
+
expect(app_js_gz.content_encoding).to eq("gzip")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sync with enabled=false" do
|
63
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile"
|
64
|
+
expect(bucket(@prefix).files.size).to eq(0)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "sync with gzip_compression=true" do
|
68
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile"
|
69
|
+
# bucket(@prefix).files.size.should == 3
|
70
|
+
|
71
|
+
app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
|
72
|
+
app_js = files.get( app_js_path.key )
|
73
|
+
expect(app_js.content_type).to eq("text/javascript")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter 'spec'
|
8
|
+
end
|
9
|
+
rescue LoadError
|
10
|
+
# SimpleCov ain't available - continue
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:default, :development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
$stderr.puts e.message
|
17
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
22
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
23
|
+
require 'asset_sync'
|
24
|
+
|
25
|
+
require 'rspec'
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.mock_framework = :rspec
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_context "mock without Rails" do
|
31
|
+
before(:each) do
|
32
|
+
if defined? Rails
|
33
|
+
Object.send(:remove_const, :Rails)
|
34
|
+
end
|
35
|
+
allow(AssetSync).to receive(:log)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
shared_context "mock Rails" do
|
41
|
+
before(:each) do
|
42
|
+
Object.send(:remove_const, :Rails) if defined? Rails
|
43
|
+
Rails = double 'Rails'
|
44
|
+
allow(Rails).to receive(:env).and_return('test')
|
45
|
+
allow(Rails).to receive_messages :application => double('application')
|
46
|
+
allow(Rails.application).to receive_messages :config => double('config')
|
47
|
+
allow(Rails.application.config).to receive_messages :assets => ActiveSupport::OrderedOptions.new
|
48
|
+
Rails.application.config.assets.prefix = '/assets'
|
49
|
+
allow(AssetSync).to receive(:log)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
shared_context "mock Rails without_yml" do
|
54
|
+
include_context "mock Rails"
|
55
|
+
|
56
|
+
before(:each) do
|
57
|
+
set_rails_root('without_yml')
|
58
|
+
allow(Rails).to receive(:public_path).and_return(Rails.root.join('public').to_s)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_rails_root(path)
|
63
|
+
allow(Rails).to receive(:root).and_return(Pathname.new(File.join(File.dirname(__FILE__), 'fixtures', path)))
|
64
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe AssetSync do
|
4
|
+
include_context "mock Rails without_yml"
|
5
|
+
|
6
|
+
describe 'with initializer' do
|
7
|
+
before(:each) do
|
8
|
+
AssetSync.config = AssetSync::Config.new
|
9
|
+
AssetSync.configure do |config|
|
10
|
+
config.fog_provider = 'AWS'
|
11
|
+
config.aws_access_key_id = 'aaaa'
|
12
|
+
config.aws_secret_access_key = 'bbbb'
|
13
|
+
config.fog_directory = 'mybucket'
|
14
|
+
config.fog_region = 'eu-west-1'
|
15
|
+
config.existing_remote_files = "keep"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should default to running on precompile" do
|
20
|
+
expect(AssetSync.config.run_on_precompile).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should default AssetSync to enabled" do
|
24
|
+
expect(AssetSync.config.enabled?).to be_truthy
|
25
|
+
expect(AssetSync.enabled?).to be_truthy
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should configure provider as AWS" do
|
29
|
+
expect(AssetSync.config.fog_provider).to eq('AWS')
|
30
|
+
expect(AssetSync.config).to be_aws
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should should keep existing remote files" do
|
34
|
+
expect(AssetSync.config.existing_remote_files?).to eq(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should configure aws_access_key" do
|
38
|
+
expect(AssetSync.config.aws_access_key_id).to eq("aaaa")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should configure aws_secret_access_key" do
|
42
|
+
expect(AssetSync.config.aws_secret_access_key).to eq("bbbb")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should configure aws_access_key" do
|
46
|
+
expect(AssetSync.config.fog_directory).to eq("mybucket")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should configure fog_region" do
|
50
|
+
expect(AssetSync.config.fog_region).to eq("eu-west-1")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should configure existing_remote_files" do
|
54
|
+
expect(AssetSync.config.existing_remote_files).to eq("keep")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should default gzip_compression to false" do
|
58
|
+
expect(AssetSync.config.gzip_compression).to be_falsey
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should default manifest to false" do
|
62
|
+
expect(AssetSync.config.manifest).to be_falsey
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should default log_silently to true" do
|
66
|
+
expect(AssetSync.config.log_silently).to be_truthy
|
67
|
+
end
|
68
|
+
|
69
|
+
it "log_silently? should reflect the configuration" do
|
70
|
+
AssetSync.config.log_silently = false
|
71
|
+
expect(AssetSync.config.log_silently?).to eq(false)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "log_silently? should always be true if ENV['RAILS_GROUPS'] == 'assets'" do
|
75
|
+
AssetSync.config.log_silently = false
|
76
|
+
# make sure ENV is actually being checked ...
|
77
|
+
expect(ENV).to receive(:[]).with('RAILS_GROUPS').and_return('assets')
|
78
|
+
expect(AssetSync.config.log_silently?).to eq(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should default cdn_distribution_id to nil" do
|
82
|
+
expect(AssetSync.config.cdn_distribution_id).to be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should default invalidate to empty array" do
|
86
|
+
expect(AssetSync.config.invalidate).to eq([])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'from yml' do
|
91
|
+
before(:each) do
|
92
|
+
set_rails_root('aws_with_yml')
|
93
|
+
AssetSync.config = AssetSync::Config.new
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should default AssetSync to enabled" do
|
97
|
+
expect(AssetSync.config.enabled?).to be_truthy
|
98
|
+
expect(AssetSync.enabled?).to be_truthy
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should configure run_on_precompile" do
|
102
|
+
expect(AssetSync.config.run_on_precompile).to be_falsey
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should configure aws_access_key_id" do
|
106
|
+
expect(AssetSync.config.aws_access_key_id).to eq("xxxx")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should configure aws_secret_access_key" do
|
110
|
+
expect(AssetSync.config.aws_secret_access_key).to eq("zzzz")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should configure fog_directory" do
|
114
|
+
expect(AssetSync.config.fog_directory).to eq("rails_app_test")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should configure fog_region" do
|
118
|
+
expect(AssetSync.config.fog_region).to eq("eu-west-1")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should configure existing_remote_files" do
|
122
|
+
expect(AssetSync.config.existing_remote_files).to eq("keep")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should default gzip_compression to false" do
|
126
|
+
expect(AssetSync.config.gzip_compression).to be_falsey
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should default manifest to false" do
|
130
|
+
expect(AssetSync.config.manifest).to be_falsey
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'from yml, exporting to a mobile hybrid development directory' do
|
135
|
+
before(:each) do
|
136
|
+
Rails.env.replace('hybrid')
|
137
|
+
set_rails_root('aws_with_yml')
|
138
|
+
AssetSync.config = AssetSync::Config.new
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should be disabled" do
|
142
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
143
|
+
end
|
144
|
+
|
145
|
+
after(:each) do
|
146
|
+
Rails.env.replace('test')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'with no configuration' do
|
151
|
+
before(:each) do
|
152
|
+
AssetSync.config = AssetSync::Config.new
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be invalid" do
|
156
|
+
expect{ AssetSync.sync }.to raise_error()
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "with no other configuration than enabled = false" do
|
161
|
+
before(:each) do
|
162
|
+
AssetSync.config = AssetSync::Config.new
|
163
|
+
AssetSync.configure do |config|
|
164
|
+
config.enabled = false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should do nothing, without complaining" do
|
169
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'with fail_silent configuration' do
|
174
|
+
before(:each) do
|
175
|
+
allow(AssetSync).to receive(:stderr).and_return(@stderr = StringIO.new)
|
176
|
+
AssetSync.config = AssetSync::Config.new
|
177
|
+
AssetSync.configure do |config|
|
178
|
+
config.fail_silently = true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should not raise an invalid exception" do
|
183
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should output a warning to stderr" do
|
187
|
+
AssetSync.sync
|
188
|
+
expect(@stderr.string).to match(/can't be blank/)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe 'with disabled config' do
|
193
|
+
before(:each) do
|
194
|
+
allow(AssetSync).to receive(:stderr).and_return(@stderr = StringIO.new)
|
195
|
+
AssetSync.config = AssetSync::Config.new
|
196
|
+
AssetSync.configure do |config|
|
197
|
+
config.enabled = false
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should not raise an invalid exception" do
|
202
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'with gzip_compression enabled' do
|
207
|
+
before(:each) do
|
208
|
+
AssetSync.config = AssetSync::Config.new
|
209
|
+
AssetSync.config.gzip_compression = true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "config.gzip? should be true" do
|
213
|
+
expect(AssetSync.config.gzip?).to be_truthy
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'with manifest enabled' do
|
218
|
+
before(:each) do
|
219
|
+
AssetSync.config = AssetSync::Config.new
|
220
|
+
AssetSync.config.manifest = true
|
221
|
+
end
|
222
|
+
|
223
|
+
it "config.manifest should be true" do
|
224
|
+
expect(AssetSync.config.manifest).to be_truthy
|
225
|
+
end
|
226
|
+
|
227
|
+
it "config.manifest_path should default to public/assets.." do
|
228
|
+
expect(AssetSync.config.manifest_path).to match(/public\/assets\/manifest.yml/)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "config.manifest_path should default to public/assets.." do
|
232
|
+
Rails.application.config.assets.manifest = "/var/assets"
|
233
|
+
expect(AssetSync.config.manifest_path).to eq("/var/assets/manifest.yml")
|
234
|
+
end
|
235
|
+
|
236
|
+
it "config.manifest_path should default to public/custom_assets.." do
|
237
|
+
Rails.application.config.assets.prefix = 'custom_assets'
|
238
|
+
expect(AssetSync.config.manifest_path).to match(/public\/custom_assets\/manifest.yml/)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe 'with invalid yml' do
|
243
|
+
|
244
|
+
before(:each) do
|
245
|
+
set_rails_root('with_invalid_yml')
|
246
|
+
AssetSync.config = AssetSync::Config.new
|
247
|
+
end
|
248
|
+
|
249
|
+
it "config should be invalid" do
|
250
|
+
expect(AssetSync.config.valid?).to be_falsey
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should raise a config invalid error" do
|
254
|
+
expect{ AssetSync.sync }.to raise_error()
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|