cloud_tempfile 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +2 -0
- data/.travis.yml +30 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +15 -0
- data/LICENSE +20 -0
- data/README.md +232 -0
- data/Rakefile +43 -0
- data/cloud_tempfile.gemspec +38 -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/lib/cloud_tempfile/cloud_tempfile.rb +106 -0
- data/lib/cloud_tempfile/config.rb +206 -0
- data/lib/cloud_tempfile/engine.rb +53 -0
- data/lib/cloud_tempfile/multi_mime.rb +22 -0
- data/lib/cloud_tempfile/railtie.rb +11 -0
- data/lib/cloud_tempfile/storage.rb +151 -0
- data/lib/cloud_tempfile/version.rb +9 -0
- data/lib/cloud_tempfile.rb +11 -0
- data/lib/ext/fog/aws/models/storage/file.rb +19 -0
- data/lib/generators/cloud_tempfile/install_generator.rb +71 -0
- data/lib/generators/cloud_tempfile/templates/cloud_tempfile.rb +41 -0
- data/lib/generators/cloud_tempfile/templates/cloud_tempfile.yml +52 -0
- data/lib/tasks/cloud_tempfile_tasks.rake +7 -0
- data/spec/dummy_app/Rakefile +27 -0
- data/spec/fixtures/assets/TEST.doc +0 -0
- data/spec/fixtures/assets/TEST.docx +0 -0
- data/spec/fixtures/assets/TEST.pdf +0 -0
- data/spec/fixtures/assets/TEST.rtf +1 -0
- data/spec/fixtures/aws_with_yml/config/cloud_tempfile.yml +22 -0
- data/spec/fixtures/google_with_yml/config/.gitkeep +0 -0
- data/spec/fixtures/rackspace_with_yml/config/.gitkeep +0 -0
- data/spec/fixtures/with_invalid_yml/config/cloud_tempfile.yml +22 -0
- data/spec/fixtures/without_yml/public/.gitkeep +0 -0
- data/spec/integration/.gitkeep +0 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/unit/cloud_tempfile_spec.rb +208 -0
- data/spec/unit/multi_mime_spec.rb +48 -0
- data/spec/unit/railsless_spec.rb +50 -0
- data/spec/unit/storage_spec.rb +260 -0
- metadata +189 -0
@@ -0,0 +1,27 @@
|
|
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.exists?(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 CloudTempfileTest
|
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 => '_cloud_tempfile_test_session', :secret => 'xxxx'
|
22
|
+
config.active_support.deprecation = :log
|
23
|
+
config.assets.compress = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
CloudTempfileTest::Application.initialize!
|
27
|
+
CloudTempfileTest::Application.load_tasks
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
{\rtf1\adeflang1025\ansi\ansicpg10000\uc1\adeff0\deff0\stshfdbch15\stshfloch36\stshfhich36\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe1041\themelangcs0{\fonttbl{\f0\fbidi \fnil\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: "AWS"
|
3
|
+
aws_access_key_id: "xxxx"
|
4
|
+
aws_secret_access_key: "zzzz"
|
5
|
+
fog_region: "us-east-1"
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *defaults
|
9
|
+
fog_directory: "rails_app_development"
|
10
|
+
|
11
|
+
test:
|
12
|
+
<<: *defaults
|
13
|
+
fog_directory: "rails_app_test"
|
14
|
+
|
15
|
+
staging:
|
16
|
+
<<: *defaults
|
17
|
+
enabled: false
|
18
|
+
fog_directory: "rails_app_staging"
|
19
|
+
|
20
|
+
production:
|
21
|
+
<<: *defaults
|
22
|
+
fog_directory: "rails_app_production"
|
File without changes
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider= "AWS"
|
3
|
+
aws_access_key_id: "xxxx"
|
4
|
+
aws_secret_access_key: "zzzz"
|
5
|
+
fog_region: "us-east-1"
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *defaults
|
9
|
+
enabled: false
|
10
|
+
fog_directory: "rails_app_development"
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
fog_directory: "rails_app_test"
|
15
|
+
|
16
|
+
staging:
|
17
|
+
<<: *defaults
|
18
|
+
fog_directory: "rails_app_staging"
|
19
|
+
|
20
|
+
production:
|
21
|
+
<<: *defaults
|
22
|
+
fog_directory: "rails_app_production"
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
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 'cloud_tempfile'
|
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
|
+
CloudTempfile.stub(:log)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
shared_context "mock Rails" do
|
41
|
+
before(:each) do
|
42
|
+
unless defined? Rails
|
43
|
+
Rails = double 'Rails'
|
44
|
+
end
|
45
|
+
Rails.stub(:env).and_return('test')
|
46
|
+
Rails.stub :application => double('application')
|
47
|
+
Rails.application.stub :config => double('config')
|
48
|
+
CloudTempfile.stub(:log)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
shared_context "mock Rails without_yml" do
|
53
|
+
include_context "mock Rails"
|
54
|
+
|
55
|
+
before(:each) do
|
56
|
+
set_rails_root('without_yml')
|
57
|
+
Rails.stub(:public_path).and_return(Rails.root.join('public').to_s)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_rails_root(path)
|
62
|
+
Rails.stub(:root).and_return(Pathname.new(File.join(File.dirname(__FILE__), 'fixtures', path)))
|
63
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CloudTempfile do
|
4
|
+
include_context "mock Rails without_yml"
|
5
|
+
|
6
|
+
describe 'with initializer' do
|
7
|
+
before(:each) do
|
8
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
9
|
+
CloudTempfile.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
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should default CloudTempfile to disabled" do
|
19
|
+
CloudTempfile.config.enabled?.should be_false
|
20
|
+
CloudTempfile.enabled?.should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should configure provider as AWS" do
|
24
|
+
CloudTempfile.config.fog_provider.should == 'AWS'
|
25
|
+
CloudTempfile.config.should be_aws
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should configure clean up remote files" do
|
29
|
+
CloudTempfile.config.clean_up?.should == false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should configure aws_access_key" do
|
33
|
+
CloudTempfile.config.aws_access_key_id.should == "aaaa"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should configure aws_secret_access_key" do
|
37
|
+
CloudTempfile.config.aws_secret_access_key.should == "bbbb"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should configure aws_access_key" do
|
41
|
+
CloudTempfile.config.fog_directory.should == "mybucket"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should configure fog_region" do
|
45
|
+
CloudTempfile.config.fog_region.should == "eu-west-1"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should default log_silently to true" do
|
49
|
+
CloudTempfile.config.log_silently.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'from yml' do
|
54
|
+
before(:each) do
|
55
|
+
set_rails_root('aws_with_yml')
|
56
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should default CloudTempfile to disabled" do
|
60
|
+
CloudTempfile.config.enabled?.should be_false
|
61
|
+
CloudTempfile.enabled?.should be_false
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should configure aws_access_key_id" do
|
65
|
+
CloudTempfile.config.aws_access_key_id.should == "xxxx"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should configure aws_secret_access_key" do
|
69
|
+
CloudTempfile.config.aws_secret_access_key.should == "zzzz"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should configure fog_directory" do
|
73
|
+
CloudTempfile.config.fog_directory.should == "rails_app_test"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should configure fog_region" do
|
77
|
+
CloudTempfile.config.fog_region.should == "us-east-1"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should configure clean up remote files" do
|
81
|
+
CloudTempfile.config.clean_up?.should == false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'from yml, overriding to stagging envrionment (disabled)' do
|
86
|
+
before(:each) do
|
87
|
+
Rails.env.replace('staging')
|
88
|
+
set_rails_root('aws_with_yml')
|
89
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be disabled" do
|
93
|
+
expect{ CloudTempfile.clear }.not_to raise_error()
|
94
|
+
end
|
95
|
+
|
96
|
+
after(:each) do
|
97
|
+
Rails.env.replace('test')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'with no configuration' do
|
102
|
+
before(:each) do
|
103
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be invalid" do
|
107
|
+
expect{ CloudTempfile.sync }.to raise_error()
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "with no other configuration than enabled = false" do
|
112
|
+
before(:each) do
|
113
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
114
|
+
CloudTempfile.configure do |config|
|
115
|
+
config.enabled = false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should do nothing, without complaining" do
|
120
|
+
expect{ CloudTempfile.clear }.not_to raise_error()
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'with fail_silent configuration' do
|
125
|
+
before(:each) do
|
126
|
+
CloudTempfile.stub(:stderr).and_return(@stderr = StringIO.new)
|
127
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
128
|
+
CloudTempfile.configure do |config|
|
129
|
+
config.fail_silently = true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not raise an invalid exception" do
|
134
|
+
expect{ CloudTempfile.clear }.not_to raise_error()
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'with disabled config' do
|
139
|
+
before(:each) do
|
140
|
+
CloudTempfile.stub(:stderr).and_return(@stderr = StringIO.new)
|
141
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
142
|
+
CloudTempfile.configure do |config|
|
143
|
+
config.enabled = false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not raise an invalid exception" do
|
148
|
+
lambda{ CloudTempfile.clear }.should_not raise_error()
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'with aws_reduced_redundancy enabled' do
|
153
|
+
before(:each) do
|
154
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
155
|
+
CloudTempfile.config.aws_reduced_redundancy = true
|
156
|
+
end
|
157
|
+
|
158
|
+
it "config.aws_rrs? should be true" do
|
159
|
+
CloudTempfile.config.aws_rrs?.should be_true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'with prefix set' do
|
164
|
+
before(:each) do
|
165
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
166
|
+
CloudTempfile.config.prefix = "dev/tmp/"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "config.prefix should be set" do
|
170
|
+
CloudTempfile.config.prefix.should == "dev/tmp/"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'with public enabled' do
|
175
|
+
before(:each) do
|
176
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
177
|
+
CloudTempfile.config.public = true
|
178
|
+
end
|
179
|
+
|
180
|
+
it "config.public? should be true" do
|
181
|
+
CloudTempfile.config.public?.should be_true
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'with clean_up enabled' do
|
186
|
+
before(:each) do
|
187
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
188
|
+
CloudTempfile.config.clean_up = true
|
189
|
+
end
|
190
|
+
|
191
|
+
it "config.clean_up? should be true" do
|
192
|
+
CloudTempfile.config.clean_up?.should be_true
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'with invalid yml' do
|
197
|
+
|
198
|
+
before(:each) do
|
199
|
+
set_rails_root('with_invalid_yml')
|
200
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
201
|
+
end
|
202
|
+
|
203
|
+
it "config should be invalid" do
|
204
|
+
CloudTempfile.config.valid?.should be_false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CloudTempfile::MultiMime do
|
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
|
+
|
21
|
+
describe 'Mime::Type' do
|
22
|
+
|
23
|
+
it 'should detect mime type' do
|
24
|
+
#require 'rails'
|
25
|
+
#CloudTempfile::MultiMime.lookup('css').should == "text/css"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'Rack::Mime' do
|
31
|
+
|
32
|
+
it 'should detect mime type' do
|
33
|
+
require 'rack/mime'
|
34
|
+
CloudTempfile::MultiMime.lookup('css').should == "text/css"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'MIME::Types' do
|
40
|
+
|
41
|
+
it 'should detect mime type' do
|
42
|
+
require 'mime/types'
|
43
|
+
CloudTempfile::MultiMime.lookup('css').should == "text/css"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CloudTempfile do
|
4
|
+
include_context "mock without Rails"
|
5
|
+
|
6
|
+
describe 'with initializer' do
|
7
|
+
before(:each) do
|
8
|
+
CloudTempfile.config = CloudTempfile::Config.new
|
9
|
+
CloudTempfile.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.public_path = Pathname("./public")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have prefix of assets" do
|
20
|
+
CloudTempfile.config.public_path.to_s.should == "./public"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should default CloudTempfile to disabled" do
|
24
|
+
CloudTempfile.config.enabled?.should be_false
|
25
|
+
CloudTempfile.enabled?.should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should configure provider as AWS" do
|
29
|
+
CloudTempfile.config.fog_provider.should == 'AWS'
|
30
|
+
CloudTempfile.config.should be_aws
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should configure aws_access_key" do
|
34
|
+
CloudTempfile.config.aws_access_key_id.should == "aaaa"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should configure aws_secret_access_key" do
|
38
|
+
CloudTempfile.config.aws_secret_access_key.should == "bbbb"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should configure aws_access_key" do
|
42
|
+
CloudTempfile.config.fog_directory.should == "mybucket"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should configure fog_region" do
|
46
|
+
CloudTempfile.config.fog_region.should == "eu-west-1"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|