asset_sync 2.8.1 → 2.15.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
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 = 'Backblaze'
11
+ config.b2_key_id = 'aaaa'
12
+ config.b2_key_token = 'bbbb'
13
+ config.b2_bucket_id = '4567'
14
+ config.fog_directory = 'mybucket'
15
+ config.existing_remote_files = "keep"
16
+ end
17
+ end
18
+
19
+ it "should configure provider as Backblaze" do
20
+ expect(AssetSync.config.fog_provider).to eq('Backblaze')
21
+ end
22
+
23
+ it "should should keep existing remote files" do
24
+ expect(AssetSync.config.existing_remote_files?).to eq(true)
25
+ end
26
+
27
+ it "should configure b2_key_id" do
28
+ expect(AssetSync.config.b2_key_id).to eq("aaaa")
29
+ end
30
+
31
+ it "should configure b2_key_token" do
32
+ expect(AssetSync.config.b2_key_token).to eq("bbbb")
33
+ end
34
+
35
+ it "should configure b2_bucket_id" do
36
+ expect(AssetSync.config.b2_bucket_id).to eq("4567")
37
+ end
38
+
39
+ it "should configure fog_directory" do
40
+ expect(AssetSync.config.fog_directory).to eq("mybucket")
41
+ end
42
+
43
+ it "should configure existing_remote_files" do
44
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
45
+ end
46
+
47
+ it "should default gzip_compression to false" do
48
+ expect(AssetSync.config.gzip_compression).to be_falsey
49
+ end
50
+
51
+ it "should default manifest to false" do
52
+ expect(AssetSync.config.manifest).to be_falsey
53
+ end
54
+ end
55
+
56
+ describe 'from yml' do
57
+ before(:each) do
58
+ set_rails_root('backblaze_with_yml')
59
+ AssetSync.config = AssetSync::Config.new
60
+ end
61
+
62
+ it "should configure b2_key_id" do
63
+ expect(AssetSync.config.b2_key_id).to eq("xxxx")
64
+ end
65
+
66
+ it "should configure b2_key_token" do
67
+ expect(AssetSync.config.b2_key_token).to eq("zzzz")
68
+ end
69
+
70
+ it "should configure b2_bucket_id" do
71
+ expect(AssetSync.config.b2_bucket_id).to eq("1234")
72
+ end
73
+
74
+ it "should configure fog_directory" do
75
+ expect(AssetSync.config.fog_directory).to eq("rails_app_test")
76
+ end
77
+
78
+ it "should configure existing_remote_files" do
79
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
80
+ end
81
+
82
+ it "should default gzip_compression to false" do
83
+ expect(AssetSync.config.gzip_compression).to be_falsey
84
+ end
85
+
86
+ it "should default manifest to false" do
87
+ expect(AssetSync.config.manifest).to be_falsey
88
+ end
89
+ end
90
+
91
+ describe 'with no configuration' do
92
+ before(:each) do
93
+ AssetSync.config = AssetSync::Config.new
94
+ end
95
+
96
+ it "should be invalid" do
97
+ expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
98
+ end
99
+ end
100
+
101
+ describe 'with fail_silent configuration' do
102
+ before(:each) do
103
+ allow(AssetSync).to receive(:stderr).and_return(StringIO.new)
104
+ AssetSync.config = AssetSync::Config.new
105
+ AssetSync.configure do |config|
106
+ config.fail_silently = true
107
+ end
108
+ end
109
+
110
+ it "should not raise an invalid exception" do
111
+ expect{ AssetSync.sync }.not_to raise_error
112
+ end
113
+ end
114
+
115
+ describe 'with gzip_compression enabled' do
116
+ before(:each) do
117
+ AssetSync.config = AssetSync::Config.new
118
+ AssetSync.config.gzip_compression = true
119
+ end
120
+
121
+ it "config.gzip? should be true" do
122
+ expect(AssetSync.config.gzip?).to be_truthy
123
+ end
124
+ end
125
+
126
+ describe 'with manifest enabled' do
127
+ before(:each) do
128
+ AssetSync.config = AssetSync::Config.new
129
+ AssetSync.config.manifest = true
130
+ end
131
+
132
+ it "config.manifest should be true" do
133
+ expect(AssetSync.config.manifest).to be_truthy
134
+ end
135
+
136
+ it "config.manifest_path should default to public/assets.." do
137
+ expect(AssetSync.config.manifest_path).to match(/public\/assets\/manifest.yml/)
138
+ end
139
+
140
+ it "config.manifest_path should default to public/assets.." do
141
+ Rails.application.config.assets.manifest = "/var/assets"
142
+ expect(AssetSync.config.manifest_path).to eq("/var/assets/manifest.yml")
143
+ end
144
+
145
+ it "config.manifest_path should default to public/custom_assets.." do
146
+ Rails.application.config.assets.prefix = 'custom_assets'
147
+ expect(AssetSync.config.manifest_path).to match(/public\/custom_assets\/manifest.yml/)
148
+ end
149
+ end
150
+ end
@@ -99,6 +99,28 @@ describe AssetSync do
99
99
  end
100
100
  end
101
101
 
102
+ describe "when using service account with JSON key string" do
103
+ before(:each) do
104
+ AssetSync.configure do |config|
105
+ config.google_json_key_string = 'a-google-json-key-string'
106
+ config.google_project = 'a-google-project-name'
107
+ end
108
+ end
109
+
110
+ it "should configure google_json_key_string" do
111
+ expect(AssetSync.config.google_json_key_string).to eq("a-google-json-key-string")
112
+ end
113
+
114
+ it "should return the correct fog_options" do
115
+ expected_fog_options = { google_json_key_string: "a-google-json-key-string",
116
+ google_project: 'a-google-project-name',
117
+ provider: "Google"}
118
+ expect(AssetSync.config.fog_options).to eq(expected_fog_options)
119
+ end
120
+ it "should not require that google_storage_secret_access_key or access_key_id be set" do
121
+ expect(AssetSync.config.valid?).to eq(true)
122
+ end
123
+ end
102
124
  end
103
125
 
104
126
  describe 'from yml' do
@@ -14,7 +14,7 @@ describe AssetSync do
14
14
  config.fog_region = 'eu-west-1'
15
15
  config.existing_remote_files = "keep"
16
16
  config.prefix = "assets"
17
- config.public_path = Pathname("./public")
17
+ config.public_path = "./public"
18
18
  end
19
19
  end
20
20
 
@@ -22,8 +22,9 @@ describe AssetSync do
22
22
  expect(AssetSync.config.prefix).to eq("assets")
23
23
  end
24
24
 
25
- it "should have prefix of assets" do
26
- expect(AssetSync.config.public_path.to_s).to eq("./public")
25
+ it "should have public_path" do
26
+ expect(AssetSync.config.public_path.to_s).to be_end_with("/public")
27
+ expect(AssetSync.config.public_path).to be_absolute
27
28
  end
28
29
 
29
30
  it "should default AssetSync to enabled" do
@@ -54,19 +54,105 @@ describe AssetSync::Storage do
54
54
  storage.upload_files
55
55
  end
56
56
 
57
+ it 'should upload files concurrently if enabled' do
58
+ @config.concurrent_uploads = true
59
+ storage = AssetSync::Storage.new(@config)
60
+
61
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
62
+ allow(storage).to receive(:get_remote_files).and_return(@remote_files)
63
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
64
+
65
+ expect(Thread).to receive(:new).exactly(3).times.and_call_original
66
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
67
+ expect(storage).to receive(:upload_file).with(file)
68
+ end
69
+
70
+ storage.upload_files
71
+ end
72
+
73
+ it 'should allow custom number of threads' do
74
+ @config.concurrent_uploads = true
75
+ @config.concurrent_uploads_max_threads = 2
76
+ storage = AssetSync::Storage.new(@config)
77
+
78
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
79
+ allow(storage).to receive(:get_remote_files).and_return(@remote_files)
80
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
81
+
82
+ expect(Thread).to receive(:new).exactly(2).times.and_call_original
83
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
84
+ expect(storage).to receive(:upload_file).with(file)
85
+ end
86
+
87
+ storage.upload_files
88
+ end
89
+
90
+ it 'should allow remote_file_list_cache_file_path configuration' do
91
+ file_path = './foo.json'
92
+ @config.remote_file_list_cache_file_path = file_path
93
+ storage = AssetSync::Storage.new(@config)
94
+
95
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
96
+ File.write(file_path, @remote_files.to_json)
97
+ expect(storage).not_to receive(:get_remote_files)
98
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
99
+
100
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
101
+ expect(storage).to receive(:upload_file).with(file)
102
+ end
103
+
104
+ expect(storage).not_to receive(:warn)
105
+ storage.upload_files
106
+
107
+ # update remote_file_list_cache corretly
108
+ updated = JSON.parse(File.read(file_path))
109
+ expect(updated.sort.uniq).to eq (@remote_files + @local_files + storage.always_upload_files).sort.uniq
110
+
111
+ File.delete(file_path)
112
+ end
113
+
114
+ it 'should work with broken cache' do
115
+ file_path = './foo.json'
116
+ @config.remote_file_list_cache_file_path = file_path
117
+
118
+ storage = AssetSync::Storage.new(@config)
119
+
120
+ File.write(file_path, 'some non-json text file content')
121
+
122
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
123
+ allow(storage).to receive(:get_remote_files).and_return(@remote_files)
124
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
125
+
126
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
127
+ expect(storage).to receive(:upload_file).with(file)
128
+ end
129
+
130
+ # when broken, warning message should be prompted
131
+ expect(storage).to receive(:warn)
132
+
133
+ storage.upload_files
134
+
135
+ File.delete(file_path)
136
+ end
137
+
57
138
  it 'should upload updated non-fingerprinted files' do
58
139
  @local_files = [
59
- 'public/image.png',
60
- 'public/image-82389298328.png',
61
- 'public/image-a8389f9h324.png',
140
+ 'public/great-image.png',
141
+ 'public/great-image-82389298328.png',
142
+ 'public/great-image-a8389f9h324.png',
143
+ "public/new\nline.js",
144
+ "public/new\nline-aaaaaaaaaaa.js",
145
+ "public/new\nline-bbbbbbbbbbb.js",
62
146
  'public/application.js',
63
147
  'public/application-b3389d983k1.js',
64
148
  'public/application-ac387d53f31.js',
65
149
  'public',
66
150
  ]
67
151
  @remote_files = [
68
- 'public/image.png',
69
- 'public/image-a8389f9h324.png',
152
+ 'public/great-image.png',
153
+ 'public/great-image-a8389f9h324.png',
154
+ "public/new\nline.js",
155
+ "public/new\nline-aaaaaaaaaaa.js",
70
156
  'public/application.js',
71
157
  'public/application-b3389d983k1.js',
72
158
  ]
@@ -77,7 +163,8 @@ describe AssetSync::Storage do
77
163
  allow(File).to receive(:file?).and_return(true) # Pretend they all exist
78
164
 
79
165
  updated_nonfingerprinted_files = [
80
- 'public/image.png',
166
+ 'public/great-image.png',
167
+ "public/new\nline.js",
81
168
  'public/application.js',
82
169
  ]
83
170
  (@local_files - @remote_files + updated_nonfingerprinted_files).each do |file|
@@ -125,7 +212,7 @@ describe AssetSync::Storage do
125
212
  end
126
213
  end
127
214
 
128
- it 'should upload additonal files' do
215
+ it 'should upload additonal files' do
129
216
  @local_files = [
130
217
  'public/image.png',
131
218
  'public/image-82389298328.png',
@@ -307,4 +394,60 @@ describe AssetSync::Storage do
307
394
  storage.upload_file('assets/some_longer_path/local_image2.jpg')
308
395
  end
309
396
  end
397
+
398
+ describe '#delete_extra_remote_files' do
399
+ it 'should delete the files in bulk' do
400
+ remote_files = ['public/image.png']
401
+ connection = double
402
+ config = double
403
+
404
+ storage = AssetSync::Storage.new(@config)
405
+
406
+ [:local_files, :ignored_files, :always_upload_files].each do |method|
407
+ expect(storage).to receive(method).and_return([])
408
+ end
409
+
410
+ allow(storage).to receive(:get_remote_files).and_return(remote_files)
411
+ allow(storage).to receive(:connection).and_return(connection).twice
412
+ allow(storage).to receive(:config).and_return(config).twice
413
+ allow(config).to receive(:aws?).and_return(true)
414
+ allow(config).to receive(:fog_directory).and_return('foo')
415
+ expect(connection).to receive(:delete_multiple_objects).with('foo', remote_files)
416
+
417
+ storage.delete_extra_remote_files
418
+ end
419
+
420
+ context 'when not aws' do
421
+ it 'deletes files sequentially' do
422
+ remote_files = ['public/image.png']
423
+ connection = double
424
+ config = double
425
+ directories = double
426
+ directory = double
427
+ file = double
428
+
429
+ storage = AssetSync::Storage.new(@config)
430
+
431
+ [:local_files, :ignored_files, :always_upload_files].each do |method|
432
+ expect(storage).to receive(method).and_return([])
433
+ end
434
+
435
+ allow(storage).to receive(:get_remote_files).and_return(remote_files)
436
+ allow(storage).to receive(:connection).and_return(connection).twice
437
+ allow(storage).to receive(:config).and_return(config)
438
+ allow(config).to receive(:aws?).and_return(false)
439
+ allow(config).to receive(:fog_directory).and_return('foo')
440
+ allow(config).to receive(:assets_prefix).and_return('foo')
441
+ allow(directories).to receive(:get).and_return(directory)
442
+ allow(directory).to receive(:files).and_return([file])
443
+ allow(file).to receive(:key).and_return('public/image.png')
444
+ allow(connection).to receive(:directories).and_return(directories)
445
+ allow(config).to receive(:backblaze?).and_return(false)
446
+ expect(connection).not_to receive(:delete_multiple_objects)
447
+ expect(file).to receive(:destroy)
448
+
449
+ storage.delete_extra_remote_files
450
+ end
451
+ end
452
+ end
310
453
  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: 2.8.1
4
+ version: 2.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-07-25 00:00:00.000000000 Z
14
+ date: 2022-06-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core
@@ -140,7 +140,21 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: fog-azure-rm
143
+ name: gitlab-fog-azure-rm
144
+ requirement: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ type: :development
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: fog-backblaze
144
158
  requirement: !ruby/object:Gem::Requirement
145
159
  requirements:
146
160
  - - ">="
@@ -181,6 +195,20 @@ dependencies:
181
195
  - - ">="
182
196
  - !ruby/object:Gem::Version
183
197
  version: '0'
198
+ - !ruby/object:Gem::Dependency
199
+ name: gem-release
200
+ requirement: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ type: :development
206
+ prerelease: false
207
+ version_requirements: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
184
212
  description: After you run assets:precompile your compiled assets will be synchronised
185
213
  with your S3 bucket.
186
214
  email:
@@ -193,6 +221,7 @@ extensions: []
193
221
  extra_rdoc_files: []
194
222
  files:
195
223
  - ".editorconfig"
224
+ - ".github/workflows/tests.yaml"
196
225
  - ".gitignore"
197
226
  - ".travis.yml"
198
227
  - Appraisals
@@ -203,11 +232,9 @@ files:
203
232
  - UPGRADING.md
204
233
  - asset_sync.gemspec
205
234
  - docs/heroku.md
206
- - gemfiles/rails_4_2.gemfile
207
- - gemfiles/rails_5_0.gemfile
208
- - gemfiles/rails_5_1.gemfile
209
235
  - gemfiles/rails_5_2.gemfile
210
236
  - gemfiles/rails_6_0.gemfile
237
+ - gemfiles/rails_6_1.gemfile
211
238
  - lib/asset_sync.rb
212
239
  - lib/asset_sync/asset_sync.rb
213
240
  - lib/asset_sync/config.rb
@@ -224,15 +251,18 @@ files:
224
251
  - spec/dummy_app/app/assets/javascripts/application.js
225
252
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
226
253
  - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
254
+ - spec/fixtures/backblaze_with_yml/config/asset_sync.yml
227
255
  - spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
228
256
  - spec/fixtures/google_with_yml/config/asset_sync.yml
229
257
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
230
258
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
231
259
  - spec/integration/aws_integration_spec.rb
232
260
  - spec/integration/azure_rm_integration_spec.rb
261
+ - spec/integration/backblaze_intergration_spec.rb
233
262
  - spec/spec_helper.rb
234
263
  - spec/unit/asset_sync_spec.rb
235
264
  - spec/unit/azure_rm_spec.rb
265
+ - spec/unit/backblaze_spec.rb
236
266
  - spec/unit/google_spec.rb
237
267
  - spec/unit/multi_mime_spec.rb
238
268
  - spec/unit/rackspace_spec.rb
@@ -257,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
287
  - !ruby/object:Gem::Version
258
288
  version: '0'
259
289
  requirements: []
260
- rubygems_version: 3.0.4
290
+ rubygems_version: 3.3.15
261
291
  signing_key:
262
292
  specification_version: 4
263
293
  summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and
@@ -267,15 +297,18 @@ test_files:
267
297
  - spec/dummy_app/app/assets/javascripts/application.js
268
298
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
269
299
  - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
300
+ - spec/fixtures/backblaze_with_yml/config/asset_sync.yml
270
301
  - spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
271
302
  - spec/fixtures/google_with_yml/config/asset_sync.yml
272
303
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
273
304
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
274
305
  - spec/integration/aws_integration_spec.rb
275
306
  - spec/integration/azure_rm_integration_spec.rb
307
+ - spec/integration/backblaze_intergration_spec.rb
276
308
  - spec/spec_helper.rb
277
309
  - spec/unit/asset_sync_spec.rb
278
310
  - spec/unit/azure_rm_spec.rb
311
+ - spec/unit/backblaze_spec.rb
279
312
  - spec/unit/google_spec.rb
280
313
  - spec/unit/multi_mime_spec.rb
281
314
  - spec/unit/rackspace_spec.rb
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rcov", platforms: :mri_18, group: [:development, :test]
6
- gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
7
- gem "jruby-openssl", platform: :jruby
8
- gem "rails", "~> 5.0.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rcov", platforms: :mri_18, group: [:development, :test]
6
- gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
7
- gem "jruby-openssl", platform: :jruby
8
- gem "rails", "~> 5.1.0"
9
-
10
- gemspec path: "../"