cloud_crooner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +142 -0
- data/Rakefile +6 -0
- data/cloud_crooner.gemspec +30 -0
- data/lib/cloud_crooner.rb +3 -0
- data/lib/cloud_crooner/cloud_crooner.rb +212 -0
- data/lib/cloud_crooner/storage.rb +104 -0
- data/lib/cloud_crooner/version.rb +3 -0
- data/spec/cloud_crooner_spec.rb +320 -0
- data/spec/spec_helper.rb +122 -0
- data/spec/storage_spec.rb +239 -0
- metadata +175 -0
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe CloudCrooner::Storage do
|
5
|
+
describe 'initialization' do
|
6
|
+
before(:each) do
|
7
|
+
CloudCrooner.configure do |config|
|
8
|
+
config.bucket_name = SecureRandom.hex
|
9
|
+
config.prefix = 'static'
|
10
|
+
end
|
11
|
+
stub_env_vars
|
12
|
+
@storage = CloudCrooner::Storage.new
|
13
|
+
end # before each
|
14
|
+
|
15
|
+
it 'sets the bucket name' do
|
16
|
+
expect(@storage.instance_variable_get(:@bucket_name)).to eq(CloudCrooner.bucket_name)
|
17
|
+
end # it
|
18
|
+
|
19
|
+
it 'sets the prefix' do
|
20
|
+
expect(@storage.instance_variable_get(:@prefix)).to eq(CloudCrooner.prefix)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets the manifest' do
|
24
|
+
expect(@storage.instance_variable_get(:@manifest)).to eq(CloudCrooner.manifest)
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:each) do
|
28
|
+
reload_crooner
|
29
|
+
end # after each
|
30
|
+
end # describe
|
31
|
+
|
32
|
+
describe 'connects to S3' do
|
33
|
+
before(:each) do
|
34
|
+
CloudCrooner.configure do |config|
|
35
|
+
config.bucket_name = SecureRandom.hex
|
36
|
+
config.prefix = 'static'
|
37
|
+
end
|
38
|
+
stub_env_vars
|
39
|
+
@storage = CloudCrooner::Storage.new
|
40
|
+
mock_fog(@storage)
|
41
|
+
end # before each
|
42
|
+
|
43
|
+
it 'creates a connection to the AWS account' do
|
44
|
+
expect(@storage.connection.directories).to be_an_instance_of(Fog::Storage::AWS::Directories)
|
45
|
+
end # it
|
46
|
+
|
47
|
+
it 'can see the empty bucket' do
|
48
|
+
expect(@storage.bucket.versions.first).to be_nil
|
49
|
+
end # it
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
reload_crooner
|
53
|
+
end # after each
|
54
|
+
end # connects to S3
|
55
|
+
|
56
|
+
describe 'interacting with files' do
|
57
|
+
it 'should gather the precompiled files to upload from the manifest' do
|
58
|
+
within_construct do |c|
|
59
|
+
mock_environment(c)
|
60
|
+
CloudCrooner.manifest.compile('a.js', 'b.js')
|
61
|
+
@storage = CloudCrooner::Storage.new
|
62
|
+
mock_fog(@storage)
|
63
|
+
|
64
|
+
expect(@storage.local_compiled_assets).to include(File.join('assets/', CloudCrooner.sprockets['a.js'].digest_path))
|
65
|
+
expect(@storage.local_compiled_assets).to include(File.join('assets/', CloudCrooner.sprockets['b.js'].digest_path))
|
66
|
+
end #construct
|
67
|
+
end #it
|
68
|
+
|
69
|
+
after(:each) do
|
70
|
+
reload_crooner
|
71
|
+
end # after each
|
72
|
+
end #describe
|
73
|
+
|
74
|
+
describe 'interacting with remote files' do
|
75
|
+
it 'should upload a file to an empty bucket' do
|
76
|
+
within_construct do |c|
|
77
|
+
|
78
|
+
mock_environment(c)
|
79
|
+
CloudCrooner.manifest.compile('a.css')
|
80
|
+
@storage = CloudCrooner::Storage.new
|
81
|
+
mock_fog(@storage)
|
82
|
+
|
83
|
+
expect(@storage.remote_assets).to eq([])
|
84
|
+
|
85
|
+
@storage.upload_file(File.join( 'assets', CloudCrooner.sprockets['a.css'].digest_path))
|
86
|
+
|
87
|
+
expect(@storage.remote_assets).to include(File.join('assets/', CloudCrooner.sprockets['a.css'].digest_path))
|
88
|
+
end # construct
|
89
|
+
end # it
|
90
|
+
|
91
|
+
it 'should set assets to expire in one year' do
|
92
|
+
within_construct do |c|
|
93
|
+
mock_environment(c)
|
94
|
+
CloudCrooner.manifest.compile('a.css')
|
95
|
+
@storage = CloudCrooner::Storage.new
|
96
|
+
mock_fog(@storage)
|
97
|
+
|
98
|
+
expect(@storage.remote_assets).to eq([])
|
99
|
+
|
100
|
+
filename = File.join( 'assets', CloudCrooner.sprockets['a.css'].digest_path)
|
101
|
+
|
102
|
+
@storage.upload_file(filename)
|
103
|
+
|
104
|
+
expect(@storage.bucket.files.get(filename).cache_control).to eq("public, max-age=31557600")
|
105
|
+
end # construct
|
106
|
+
end # it
|
107
|
+
|
108
|
+
it 'should set the proper mime type' do
|
109
|
+
within_construct do |c|
|
110
|
+
|
111
|
+
mock_environment(c)
|
112
|
+
CloudCrooner.manifest.compile('a.css')
|
113
|
+
@storage = CloudCrooner::Storage.new
|
114
|
+
mock_fog(@storage)
|
115
|
+
|
116
|
+
expect(@storage.remote_assets).to eq([])
|
117
|
+
|
118
|
+
filename = File.join( 'assets', CloudCrooner.sprockets['a.css'].digest_path)
|
119
|
+
|
120
|
+
@storage.upload_file(filename)
|
121
|
+
|
122
|
+
expect(@storage.bucket.files.get(filename).content_type).to eq('text/css')
|
123
|
+
end # construct
|
124
|
+
end # it
|
125
|
+
|
126
|
+
it 'should upload the gzip version of a file when available and gzip is smaller' do
|
127
|
+
within_construct do |c|
|
128
|
+
|
129
|
+
mock_environment(c)
|
130
|
+
CloudCrooner.manifest.compile('c.css')
|
131
|
+
@storage = CloudCrooner::Storage.new
|
132
|
+
mock_fog(@storage)
|
133
|
+
|
134
|
+
expect(@storage.remote_assets).to eq([])
|
135
|
+
|
136
|
+
filename = File.join( 'assets', CloudCrooner.sprockets['c.css'].digest_path)
|
137
|
+
|
138
|
+
@storage.upload_file(filename)
|
139
|
+
expect(@storage.remote_assets).to include(filename)
|
140
|
+
expect(@storage.bucket.files.get(filename).content_encoding).to eq('gzip')
|
141
|
+
end # construct
|
142
|
+
end # it
|
143
|
+
|
144
|
+
it 'should not upload both the uncompressed and gzip version of a file' do
|
145
|
+
within_construct do |c|
|
146
|
+
|
147
|
+
mock_environment(c)
|
148
|
+
CloudCrooner.manifest.compile('c.css')
|
149
|
+
@storage = CloudCrooner::Storage.new
|
150
|
+
mock_fog(@storage)
|
151
|
+
|
152
|
+
expect(@storage.remote_assets).to eq([])
|
153
|
+
|
154
|
+
@storage.upload_file(File.join( 'assets', CloudCrooner.sprockets['c.css'].digest_path))
|
155
|
+
|
156
|
+
expect(@storage.remote_assets.count).to eq(1)
|
157
|
+
end # construct
|
158
|
+
end # it
|
159
|
+
|
160
|
+
it 'should upload the uncompressed file when the gzip is not smaller' do
|
161
|
+
within_construct do |c|
|
162
|
+
|
163
|
+
mock_environment(c)
|
164
|
+
CloudCrooner.manifest.compile('b.css')
|
165
|
+
@storage = CloudCrooner::Storage.new
|
166
|
+
mock_fog(@storage)
|
167
|
+
|
168
|
+
expect(@storage.remote_assets).to eq([])
|
169
|
+
|
170
|
+
filename = File.join( 'assets', CloudCrooner.sprockets['b.css'].digest_path)
|
171
|
+
|
172
|
+
@storage.upload_file(filename)
|
173
|
+
expect(File.exist?(File.join(c, "public", filename + ".gz"))).to be_true
|
174
|
+
expect(@storage.remote_assets).to include(filename)
|
175
|
+
expect(@storage.bucket.files.get(filename).content_encoding).to be_nil
|
176
|
+
end # construct
|
177
|
+
end # it
|
178
|
+
|
179
|
+
it 'uploads all files from the manifest' do
|
180
|
+
within_construct do |c|
|
181
|
+
|
182
|
+
mock_environment(c)
|
183
|
+
@storage = CloudCrooner::Storage.new
|
184
|
+
mock_fog(@storage)
|
185
|
+
CloudCrooner.manifest.compile(Dir[uncompiled_assets_dir(c) + "/*"])
|
186
|
+
CloudCrooner.manifest.files.count.should eq(7)
|
187
|
+
@storage.upload_files
|
188
|
+
expect(local_equals_remote?(@storage)).to be_true
|
189
|
+
|
190
|
+
end # construct
|
191
|
+
end #it
|
192
|
+
|
193
|
+
it 'does not re-upload existing files' do
|
194
|
+
# this could be tested better, maybe by checking log messages sent
|
195
|
+
within_construct do |c|
|
196
|
+
|
197
|
+
mock_environment(c)
|
198
|
+
@storage = CloudCrooner::Storage.new
|
199
|
+
mock_fog(@storage)
|
200
|
+
|
201
|
+
CloudCrooner.manifest.compile(Dir[uncompiled_assets_dir(c) + "/*"])
|
202
|
+
CloudCrooner.manifest.files.count.should eq(7)
|
203
|
+
|
204
|
+
@storage.upload_file(File.join(@storage.instance_variable_get(:@prefix), CloudCrooner.sprockets['a.js'].digest_path))
|
205
|
+
@storage.upload_files
|
206
|
+
expect(local_equals_remote?(@storage)).to be_true
|
207
|
+
end # construct
|
208
|
+
end # it
|
209
|
+
|
210
|
+
it 'deletes remote files not in manifest' do
|
211
|
+
within_construct do |c|
|
212
|
+
|
213
|
+
mock_environment(c)
|
214
|
+
@storage = CloudCrooner::Storage.new
|
215
|
+
mock_fog(@storage)
|
216
|
+
|
217
|
+
CloudCrooner.manifest.compile(Dir[uncompiled_assets_dir(c) + "/*"])
|
218
|
+
CloudCrooner.manifest.files.count.should eq(7)
|
219
|
+
|
220
|
+
# upload a non-manifest tracked file
|
221
|
+
@storage.bucket.files.create(
|
222
|
+
:key => 'assets/fake-file.html',
|
223
|
+
:body => 'meowmeow',
|
224
|
+
:public => true
|
225
|
+
)
|
226
|
+
|
227
|
+
expect(@storage.remote_assets).to include('assets/fake-file.html')
|
228
|
+
@storage.clean_remote
|
229
|
+
expect(@storage.remote_assets).to_not include('assets/fake-file.html')
|
230
|
+
|
231
|
+
end #construct
|
232
|
+
end # it
|
233
|
+
|
234
|
+
after(:each) do
|
235
|
+
reload_crooner
|
236
|
+
end
|
237
|
+
|
238
|
+
end # describe
|
239
|
+
end # describe
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloud_crooner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bambery
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-construct
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sprockets
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.10'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fog
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.12'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sprockets-helpers
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Manage assets on Sinatra apps with Sprockets and S3
|
126
|
+
email:
|
127
|
+
- lwszolek@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- .rspec
|
134
|
+
- .rvmrc
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- cloud_crooner.gemspec
|
140
|
+
- lib/cloud_crooner.rb
|
141
|
+
- lib/cloud_crooner/cloud_crooner.rb
|
142
|
+
- lib/cloud_crooner/storage.rb
|
143
|
+
- lib/cloud_crooner/version.rb
|
144
|
+
- spec/cloud_crooner_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/storage_spec.rb
|
147
|
+
homepage: https://github.com/bambery/cloud_crooner
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.0.5
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Manage assets with Sprockets, precompile them into static assets, then upload
|
171
|
+
them to S3
|
172
|
+
test_files:
|
173
|
+
- spec/cloud_crooner_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
- spec/storage_spec.rb
|