asset_sync 0.5.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/.travis.yml +27 -12
- data/Appraisals +11 -0
- data/Gemfile +3 -3
- data/README.md +50 -20
- data/Rakefile +8 -0
- data/asset_sync.gemspec +4 -4
- data/docs/heroku.md +2 -2
- 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/lib/asset_sync/asset_sync.rb +18 -2
- data/lib/asset_sync/config.rb +46 -14
- data/lib/asset_sync/engine.rb +20 -19
- data/lib/asset_sync/storage.rb +88 -24
- data/lib/asset_sync/version.rb +1 -1
- data/lib/generators/asset_sync/templates/asset_sync.rb +8 -2
- data/lib/generators/asset_sync/templates/asset_sync.yml +4 -2
- data/lib/tasks/asset_sync.rake +19 -2
- data/spec/dummy_app/Rakefile +2 -1
- data/spec/fixtures/aws_with_yml/config/asset_sync.yml +1 -0
- data/spec/fixtures/with_invalid_yml/config/asset_sync.yml +24 -0
- data/spec/integration/aws_integration_spec.rb +22 -5
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/asset_sync_spec.rb +56 -4
- data/spec/unit/google_spec.rb +2 -2
- data/spec/unit/multi_mime_spec.rb +17 -15
- data/spec/unit/storage_spec.rb +141 -0
- metadata +15 -9
@@ -16,6 +16,10 @@ describe AssetSync do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
it "should default to running on precompile" do
|
20
|
+
AssetSync.config.run_on_precompile.should be_true
|
21
|
+
end
|
22
|
+
|
19
23
|
it "should default AssetSync to enabled" do
|
20
24
|
AssetSync.config.enabled?.should be_true
|
21
25
|
AssetSync.enabled?.should be_true
|
@@ -57,6 +61,18 @@ describe AssetSync do
|
|
57
61
|
it "should default manifest to false" do
|
58
62
|
AssetSync.config.manifest.should be_false
|
59
63
|
end
|
64
|
+
|
65
|
+
it "should default log_silently to true" do
|
66
|
+
AssetSync.config.log_silently.should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should default cdn_distribution_id to nil" do
|
70
|
+
AssetSync.config.cdn_distribution_id.should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should default invalidate to empty array" do
|
74
|
+
AssetSync.config.invalidate.should == []
|
75
|
+
end
|
60
76
|
end
|
61
77
|
|
62
78
|
describe 'from yml' do
|
@@ -70,6 +86,10 @@ describe AssetSync do
|
|
70
86
|
AssetSync.enabled?.should be_true
|
71
87
|
end
|
72
88
|
|
89
|
+
it "should configure run_on_precompile" do
|
90
|
+
AssetSync.config.run_on_precompile.should be_false
|
91
|
+
end
|
92
|
+
|
73
93
|
it "should configure aws_access_key_id" do
|
74
94
|
AssetSync.config.aws_access_key_id.should == "xxxx"
|
75
95
|
end
|
@@ -107,7 +127,7 @@ describe AssetSync do
|
|
107
127
|
end
|
108
128
|
|
109
129
|
it "should be disabled" do
|
110
|
-
|
130
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
111
131
|
end
|
112
132
|
|
113
133
|
after(:each) do
|
@@ -121,7 +141,7 @@ describe AssetSync do
|
|
121
141
|
end
|
122
142
|
|
123
143
|
it "should be invalid" do
|
124
|
-
|
144
|
+
expect{ AssetSync.sync }.to raise_error()
|
125
145
|
end
|
126
146
|
end
|
127
147
|
|
@@ -134,7 +154,7 @@ describe AssetSync do
|
|
134
154
|
end
|
135
155
|
|
136
156
|
it "should do nothing, without complaining" do
|
137
|
-
|
157
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
138
158
|
end
|
139
159
|
end
|
140
160
|
|
@@ -148,7 +168,7 @@ describe AssetSync do
|
|
148
168
|
end
|
149
169
|
|
150
170
|
it "should not raise an invalid exception" do
|
151
|
-
|
171
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
152
172
|
end
|
153
173
|
|
154
174
|
it "should output a warning to stderr" do
|
@@ -157,6 +177,20 @@ describe AssetSync do
|
|
157
177
|
end
|
158
178
|
end
|
159
179
|
|
180
|
+
describe 'with disabled config' do
|
181
|
+
before(:each) do
|
182
|
+
AssetSync.stub(:stderr).and_return(@stderr = StringIO.new)
|
183
|
+
AssetSync.config = AssetSync::Config.new
|
184
|
+
AssetSync.configure do |config|
|
185
|
+
config.enabled = false
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should not raise an invalid exception" do
|
190
|
+
lambda{ AssetSync.sync }.should_not raise_error()
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
160
194
|
describe 'with gzip_compression enabled' do
|
161
195
|
before(:each) do
|
162
196
|
AssetSync.config = AssetSync::Config.new
|
@@ -193,4 +227,22 @@ describe AssetSync do
|
|
193
227
|
end
|
194
228
|
end
|
195
229
|
|
230
|
+
describe 'with invalid yml' do
|
231
|
+
|
232
|
+
before(:each) do
|
233
|
+
set_rails_root('with_invalid_yml')
|
234
|
+
AssetSync.config = AssetSync::Config.new
|
235
|
+
end
|
236
|
+
|
237
|
+
it "config should be invalid" do
|
238
|
+
AssetSync.config.valid?.should be_false
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should raise a config invalid error" do
|
242
|
+
expect{ AssetSync.sync }.to raise_error()
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
end
|
247
|
+
|
196
248
|
end
|
data/spec/unit/google_spec.rb
CHANGED
@@ -86,7 +86,7 @@ describe AssetSync do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should be invalid" do
|
89
|
-
|
89
|
+
expect{ AssetSync.sync }.to raise_error()
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -100,7 +100,7 @@ describe AssetSync do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should not raise an invalid exception" do
|
103
|
-
|
103
|
+
expect{ AssetSync.sync }.not_to raise_error()
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -2,19 +2,30 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe AssetSync::MultiMime do
|
4
4
|
|
5
|
+
before(:each) do
|
6
|
+
Object.send(:remove_const, :Rails) if defined?(Rails)
|
7
|
+
Object.send(:remove_const, :Mime) if defined?(Mime)
|
8
|
+
Object.send(:remove_const, :Rack) if defined?(Rack)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
Object.send(:remove_const, :Rails) if defined?(Rails)
|
13
|
+
Object.send(:remove_const, :Mime) if defined?(Mime)
|
14
|
+
Object.send(:remove_const, :Rack) if defined?(Rack)
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
require 'mime/types'
|
19
|
+
end
|
20
|
+
|
5
21
|
describe 'Mime::Type' do
|
6
22
|
|
7
23
|
it 'should detect mime type' do
|
8
|
-
|
24
|
+
pending "Fails on Travis CI only as of https://travis-ci.org/rumblelabs/asset_sync/builds/4188196"
|
9
25
|
require 'rails'
|
10
26
|
AssetSync::MultiMime.lookup('css').should == "text/css"
|
11
27
|
end
|
12
28
|
|
13
|
-
after(:each) do
|
14
|
-
Object.send(:remove_const, :Rails) if defined?(Rails)
|
15
|
-
Object.send(:remove_const, :Mime) if defined?(Mime)
|
16
|
-
end
|
17
|
-
|
18
29
|
end
|
19
30
|
|
20
31
|
describe 'Rack::Mime' do
|
@@ -24,24 +35,15 @@ describe AssetSync::MultiMime do
|
|
24
35
|
AssetSync::MultiMime.lookup('css').should == "text/css"
|
25
36
|
end
|
26
37
|
|
27
|
-
after(:each) do
|
28
|
-
Object.send(:remove_const, :Rack) if defined?(Rack)
|
29
|
-
end
|
30
|
-
|
31
38
|
end
|
32
39
|
|
33
40
|
describe 'MIME::Types' do
|
34
41
|
|
35
42
|
it 'should detect mime type' do
|
36
|
-
Object.send(:remove_const, :MIME) if defined?(MIME)
|
37
43
|
require 'mime/types'
|
38
44
|
AssetSync::MultiMime.lookup('css').should == "text/css"
|
39
45
|
end
|
40
46
|
|
41
|
-
after(:each) do
|
42
|
-
Object.send(:remove_const, :MIME) if defined?(MIME)
|
43
|
-
end
|
44
|
-
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
data/spec/unit/storage_spec.rb
CHANGED
@@ -49,5 +49,146 @@ describe AssetSync::Storage do
|
|
49
49
|
end
|
50
50
|
storage.upload_files
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'should upload updated non-fingerprinted files' do
|
54
|
+
@local_files = [
|
55
|
+
'public/image.png',
|
56
|
+
'public/image-82389298328.png',
|
57
|
+
'public/image-a8389f9h324.png',
|
58
|
+
'public/application.js',
|
59
|
+
'public/application-b3389d983k1.js',
|
60
|
+
'public/application-ac387d53f31.js',
|
61
|
+
'public',
|
62
|
+
]
|
63
|
+
@remote_files = [
|
64
|
+
'public/image.png',
|
65
|
+
'public/image-a8389f9h324.png',
|
66
|
+
'public/application.js',
|
67
|
+
'public/application-b3389d983k1.js',
|
68
|
+
]
|
69
|
+
|
70
|
+
storage = AssetSync::Storage.new(@config)
|
71
|
+
storage.stub(:local_files).and_return(@local_files)
|
72
|
+
storage.stub(:get_remote_files).and_return(@remote_files)
|
73
|
+
File.stub(:file?).and_return(true) # Pretend they all exist
|
74
|
+
|
75
|
+
updated_nonfingerprinted_files = [
|
76
|
+
'public/image.png',
|
77
|
+
'public/application.js',
|
78
|
+
]
|
79
|
+
(@local_files - @remote_files + updated_nonfingerprinted_files).each do |file|
|
80
|
+
storage.should_receive(:upload_file).with(file)
|
81
|
+
end
|
82
|
+
storage.upload_files
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
it 'should correctly set expire date' do
|
87
|
+
local_files = ['file1.jpg', 'file1-1234567890abcdef1234567890abcdef.jpg']
|
88
|
+
local_files += ['dir1/dir2/file2.jpg', 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg']
|
89
|
+
remote_files = []
|
90
|
+
storage = AssetSync::Storage.new(@config)
|
91
|
+
storage.stub(:local_files).and_return(local_files)
|
92
|
+
storage.stub(:get_remote_files).and_return(remote_files)
|
93
|
+
File.stub(:file?).and_return(true)
|
94
|
+
File.stub(:open).and_return(nil)
|
95
|
+
|
96
|
+
def check_file(file)
|
97
|
+
case file[:key]
|
98
|
+
when 'file1.jpg'
|
99
|
+
when 'dir1/dir2/file2.jpg'
|
100
|
+
!file.should_not include(:cache_control, :expires)
|
101
|
+
when 'file1-1234567890abcdef1234567890abcdef.jpg'
|
102
|
+
when 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg'
|
103
|
+
file.should include(:cache_control, :expires)
|
104
|
+
else
|
105
|
+
fail
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
files = double()
|
110
|
+
local_files.count.times do
|
111
|
+
files.should_receive(:create) { |file| check_file(file) }
|
112
|
+
end
|
113
|
+
storage.stub_chain(:bucket, :files).and_return(files)
|
114
|
+
storage.upload_files
|
115
|
+
end
|
116
|
+
|
117
|
+
it "shoud invalidate files" do
|
118
|
+
@config.cdn_distribution_id = "1234"
|
119
|
+
@config.invalidate = ['local_image1.jpg']
|
120
|
+
@config.fog_provider = 'AWS'
|
121
|
+
|
122
|
+
storage = AssetSync::Storage.new(@config)
|
123
|
+
storage.stub(:local_files).and_return(@local_files)
|
124
|
+
storage.stub(:get_remote_files).and_return(@remote_files)
|
125
|
+
storage.stub(:upload_file).and_return(true)
|
126
|
+
|
127
|
+
mock_cdn = mock
|
128
|
+
Fog::CDN.should_receive(:new).and_return(mock_cdn)
|
129
|
+
mock_cdn.should_receive(:post_invalidation).with("1234", ["/assets/local_image1.jpg"]).and_return(stub({:body => {:id => '1234'}}))
|
130
|
+
|
131
|
+
storage.upload_files
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#upload_file' do
|
136
|
+
before(:each) do
|
137
|
+
# Object#remove_const does not remove the loaded
|
138
|
+
# file from the $" variable
|
139
|
+
Object.send(:remove_const, :MIME) if defined?(MIME)
|
140
|
+
mime_types = $".grep(/mime\/types/).first
|
141
|
+
$".delete(mime_types)
|
142
|
+
require 'mime/types'
|
143
|
+
@config = AssetSync::Config.new
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'accepts custom headers per file' do
|
147
|
+
@config.custom_headers = {
|
148
|
+
"local_image2.jpg" => {
|
149
|
+
:cache_control => 'max-age=0'
|
150
|
+
}
|
151
|
+
}
|
152
|
+
storage = AssetSync::Storage.new(@config)
|
153
|
+
storage.stub(:local_files).and_return(@local_files)
|
154
|
+
storage.stub(:get_remote_files).and_return(@remote_files)
|
155
|
+
File.stub(:open).and_return('file') # Pretend they all exist
|
156
|
+
|
157
|
+
bucket = double
|
158
|
+
files = double
|
159
|
+
|
160
|
+
storage.stub(:bucket).and_return(bucket)
|
161
|
+
bucket.stub(:files).and_return(files)
|
162
|
+
|
163
|
+
files.should_receive(:create) do |argument|
|
164
|
+
argument[:cache_control].should == 'max-age=0'
|
165
|
+
end
|
166
|
+
storage.upload_file('assets/local_image2.jpg')
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'accepts custom headers with a regular expression' do
|
170
|
+
@config.custom_headers = {
|
171
|
+
".*\.jpg" => {
|
172
|
+
:cache_control => 'max-age=0'
|
173
|
+
}
|
174
|
+
}
|
175
|
+
storage = AssetSync::Storage.new(@config)
|
176
|
+
storage.stub(:local_files).and_return(@local_files)
|
177
|
+
storage.stub(:get_remote_files).and_return(@remote_files)
|
178
|
+
File.stub(:open).and_return('file') # Pretend they all exist
|
179
|
+
bucket = mock
|
180
|
+
files = mock
|
181
|
+
storage.stub(:bucket).and_return(bucket)
|
182
|
+
bucket.stub(:files).and_return(files)
|
183
|
+
|
184
|
+
files.should_receive(:create) do |argument|
|
185
|
+
argument[:cache_control].should == 'max-age=0'
|
186
|
+
end
|
187
|
+
storage.upload_file('assets/some_longer_path/local_image2.jpg')
|
188
|
+
end
|
189
|
+
|
190
|
+
after(:each) do
|
191
|
+
Object.send(:remove_const, :MIME) if defined?(MIME)
|
192
|
+
end
|
52
193
|
end
|
53
194
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.8.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ! '>='
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
31
|
+
version: 1.8.0
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
33
|
name: activemodel
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
|
-
name:
|
97
|
+
name: uglifier
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: asset_sync
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
116
116
|
requirements:
|
@@ -126,7 +126,7 @@ dependencies:
|
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
128
|
- !ruby/object:Gem::Dependency
|
129
|
-
name:
|
129
|
+
name: appraisal
|
130
130
|
requirement: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|
132
132
|
requirements:
|
@@ -153,12 +153,16 @@ extra_rdoc_files: []
|
|
153
153
|
files:
|
154
154
|
- .gitignore
|
155
155
|
- .travis.yml
|
156
|
+
- Appraisals
|
156
157
|
- CHANGELOG.md
|
157
158
|
- Gemfile
|
158
159
|
- README.md
|
159
160
|
- Rakefile
|
160
161
|
- asset_sync.gemspec
|
161
162
|
- docs/heroku.md
|
163
|
+
- gemfiles/rails_3.1.gemfile
|
164
|
+
- gemfiles/rails_3.2.gemfile
|
165
|
+
- gemfiles/rails_4.0.gemfile
|
162
166
|
- lib/asset_sync.rb
|
163
167
|
- lib/asset_sync/asset_sync.rb
|
164
168
|
- lib/asset_sync/config.rb
|
@@ -176,6 +180,7 @@ files:
|
|
176
180
|
- spec/fixtures/aws_with_yml/config/asset_sync.yml
|
177
181
|
- spec/fixtures/google_with_yml/config/asset_sync.yml
|
178
182
|
- spec/fixtures/rackspace_with_yml/config/asset_sync.yml
|
183
|
+
- spec/fixtures/with_invalid_yml/config/asset_sync.yml
|
179
184
|
- spec/integration/aws_integration_spec.rb
|
180
185
|
- spec/spec_helper.rb
|
181
186
|
- spec/unit/asset_sync_spec.rb
|
@@ -198,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
203
|
version: '0'
|
199
204
|
segments:
|
200
205
|
- 0
|
201
|
-
hash:
|
206
|
+
hash: -395743351028852648
|
202
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
208
|
none: false
|
204
209
|
requirements:
|
@@ -207,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
212
|
version: '0'
|
208
213
|
segments:
|
209
214
|
- 0
|
210
|
-
hash:
|
215
|
+
hash: -395743351028852648
|
211
216
|
requirements: []
|
212
217
|
rubyforge_project: asset_sync
|
213
218
|
rubygems_version: 1.8.24
|
@@ -221,6 +226,7 @@ test_files:
|
|
221
226
|
- spec/fixtures/aws_with_yml/config/asset_sync.yml
|
222
227
|
- spec/fixtures/google_with_yml/config/asset_sync.yml
|
223
228
|
- spec/fixtures/rackspace_with_yml/config/asset_sync.yml
|
229
|
+
- spec/fixtures/with_invalid_yml/config/asset_sync.yml
|
224
230
|
- spec/integration/aws_integration_spec.rb
|
225
231
|
- spec/spec_helper.rb
|
226
232
|
- spec/unit/asset_sync_spec.rb
|