storage 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: debdbb389e3c318ff68a502dc87ac52fbd047894
4
- data.tar.gz: 1857d2fa6a260d0862400d519d2ac0c34c4f1a51
3
+ metadata.gz: d0d83caa2e0340dd5a4c32e7c0959c915878cb92
4
+ data.tar.gz: 5ca85b4b43b9ea5f62dfd3f0fef6416ca6a81fe9
5
5
  SHA512:
6
- metadata.gz: 8a1e73f719687b06f538a307b7caaa06ee3f598d44f0b2baa2e6f4c4233281e91235d6d426f2e90bf45479af58ee047f815e5eba82e30e7b5c314e904c240cce
7
- data.tar.gz: 8338bc57f95931f7e6db01c5ae8ba0c8ee9d7339b38e0bb57fde7051afb2a4f68e8cc5554228d2b4b72f800fde66f0025e20cfc4b36846cfe3e9f74cf084267e
6
+ metadata.gz: 4d1a51dcaa5d1b0255112d1016c933f1bfb4a0eba94544edf9c00bbee0d3d9602077f316a19b3f5ad0bf1ea718e1c2543e8de11ca116d3c321176184ab88c1eb
7
+ data.tar.gz: e5ae7cc620bf92784a4c375d1ea2fdbc1d9678af32907ccf10bcfdb6b08ac01d4a58ff8b0e9e9201e08c8a32b052f369a97d0ffd5cd095125d52cbb475eb5dd3
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ tmp
2
2
  pkg
3
3
  *.gem
4
4
  *.log
5
- coverage
5
+ coverage
6
+ *.lock
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
- require "rspec/core/rake_task"
5
- RSpec::Core::RakeTask.new
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.warning = false
8
+ end
9
+
10
+ task :default => :test
@@ -5,7 +5,7 @@ module Storage
5
5
  #
6
6
  # Storage::Config.strategy = :s3
7
7
  #
8
- attr_accessor :strategy
8
+ attr_reader :strategy
9
9
 
10
10
  # Set a storage class.
11
11
  #
@@ -35,8 +35,6 @@ module Storage
35
35
  file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
36
36
  path = fullpath(options[:name])
37
37
 
38
- raise Storage::FileAlreadyExistsError if File.file?(path)
39
-
40
38
  File.open(path, "wb") do |handler|
41
39
  while line = file.gets
42
40
  handler.write line
@@ -2,7 +2,7 @@ module Storage
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 2
5
+ PATCH = 3
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -20,4 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency "rspec"
22
22
  s.add_development_dependency "pry-meta"
23
+ s.add_development_dependency "minitest-utils"
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "mocha"
23
26
  end
File without changes
@@ -1,17 +1,28 @@
1
1
  require "bundler/setup"
2
- Bundler.require(:default, :development)
3
2
 
4
3
  require "storage"
5
4
  require "pathname"
6
5
 
6
+ require "minitest/utils"
7
+ require "minitest/autorun"
8
+ require "mocha"
9
+ require "mocha/mini_test"
10
+
7
11
  TMP = Pathname.new(File.expand_path(File.dirname(__FILE__) + "/tmp"))
8
12
  RESOURCES = Pathname.new(File.expand_path(File.dirname(__FILE__) + "/resources"))
9
13
 
10
- RSpec.configure do |config|
11
- cleaner = proc do
14
+ class Minitest::Test
15
+ setup do
12
16
  FileUtils.rm_rf(TMP) rescue nil
13
17
  FileUtils.mkdir_p(TMP) rescue nil
14
18
  end
19
+ end
15
20
 
16
- config.before(:each, &cleaner)
21
+ class NullObject
22
+ def initialize(*)
23
+ end
24
+
25
+ def method_missing(*)
26
+ self
27
+ end
17
28
  end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class DelegationTest < Minitest::Test
4
+ setup do
5
+ @strategy = mock("strategy")
6
+ Storage.expects(:strategy).returns(@strategy)
7
+ end
8
+
9
+ test "delegate save method" do
10
+ @strategy.expects(:store).with("some/file")
11
+ Storage.store "some/file"
12
+ end
13
+
14
+ test "delegate destroy method" do
15
+ @strategy.expects(:remove).with("some/file")
16
+ Storage.remove "some/file"
17
+ end
18
+
19
+ test "delegate get method" do
20
+ @strategy.expects(:get).with("some/file")
21
+ Storage.get "some/file"
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ require "test_helper"
2
+
3
+ class FileSystemStrategyTest < Minitest::Test
4
+ let(:source) { RESOURCES.join("file.txt") }
5
+ let(:destiny) { TMP.join("lorem.txt") }
6
+
7
+ setup do
8
+ Storage.setup do |c|
9
+ c.strategy = :file
10
+ c.path = TMP
11
+ end
12
+ end
13
+
14
+ test "saves a file using file handler" do
15
+ handler = File.open(source)
16
+ Storage.store(handler, name: "lorem.txt")
17
+
18
+ assert File.file?(destiny)
19
+ assert_equal File.read(source), File.read(destiny)
20
+ end
21
+
22
+ test "save a file using a path" do
23
+ Storage.store(source, name: "lorem.txt")
24
+
25
+ assert File.file?(destiny)
26
+ assert_equal File.read(source), File.read(destiny)
27
+ end
28
+
29
+ test "remove an existing file" do
30
+ Storage.store(source, name: "lorem.txt")
31
+
32
+ assert Storage.remove("lorem.txt")
33
+ refute File.file?(destiny)
34
+ end
35
+
36
+ test "raise when trying to removing an unexesting file" do
37
+ assert_raises(Storage::MissingFileError) {
38
+ Storage.remove("invalid")
39
+ }
40
+ end
41
+
42
+ test "retrieve an existing file" do
43
+ Storage.store(source, name: "lorem.txt")
44
+ assert_equal File.expand_path(TMP.join("lorem.txt")), Storage.get("lorem.txt")
45
+ end
46
+
47
+ test "raise when trying to retrieve an unexesting file" do
48
+ assert_raises(Storage::MissingFileError) {
49
+ Storage.get("invalid")
50
+ }
51
+ end
52
+ end
@@ -0,0 +1,192 @@
1
+ require "test_helper"
2
+
3
+ module S3StrategyTest
4
+ class RegionTest < Minitest::Test
5
+ setup do
6
+ Storage.setup do |c|
7
+ c.strategy = :s3
8
+ c.access_key = "AKIAIOSFODNN7EXAMPLE"
9
+ c.secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
10
+ end
11
+ end
12
+
13
+ test "sets default region" do
14
+ Storage::Config.region = nil
15
+ assert_equal "us-east-1", Storage::Strategies::S3.connection.region
16
+ end
17
+
18
+ test "sets custom region" do
19
+ Storage::Config.region = "eu-west-1"
20
+ assert_equal "eu-west-1", Storage::Strategies::S3.connection.region
21
+ end
22
+ end
23
+
24
+ class GeneralTest < Minitest::Test
25
+ let(:adapter) { Storage::Strategies::S3 }
26
+ let(:source) { RESOURCES.join("file.txt") }
27
+ let(:destiny) { TMP.join("lorem.txt") }
28
+ let(:connection) { mock("connection") }
29
+ let(:bucket) { mock("bucket") }
30
+
31
+ setup do
32
+ adapter.stubs(:connection).returns(connection)
33
+
34
+ Storage.setup do |c|
35
+ c.strategy = :s3
36
+ c.access_key = "abc"
37
+ c.secret_key = "123"
38
+ c.region = "us-east-1"
39
+ end
40
+ end
41
+
42
+ test "saves a file using file handler" do
43
+ handler = File.open(source)
44
+ setup_create_object
45
+
46
+ Storage.store(handler, name: "lorem.txt", bucket: "files")
47
+ end
48
+
49
+ test "saves a file using a path" do
50
+ setup_create_object
51
+ Storage.store(source, name: "lorem.txt", bucket: "files")
52
+ end
53
+
54
+ test "removes an existing file" do
55
+ object = mock("object")
56
+
57
+ setup_get_object object: object
58
+ object.expects(:destroy).returns(true)
59
+
60
+ assert Storage.remove("lorem.txt", bucket: "files")
61
+ end
62
+
63
+ test "raises when trying to removing an nonexisting file" do
64
+ setup_get_object object: nil
65
+
66
+ assert_raises(Storage::MissingFileError) {
67
+ Storage.remove("lorem.txt", bucket: "files")
68
+ }
69
+ end
70
+
71
+ test "retrieves an existing file (public url)" do
72
+ object = mock("object", public_url: "PUBLIC_URL")
73
+
74
+ setup_get_object object: object
75
+
76
+ assert_equal "PUBLIC_URL", Storage.get("lorem.txt", bucket: "files")
77
+ end
78
+
79
+ test "retrieves an existing file with default expiration [private url]" do
80
+ Time.stubs(:now).returns(Time.now)
81
+
82
+ object = mock("object", public_url: nil)
83
+ object.expects(:url).with(Time.now.to_i + 3600).returns("PRIVATE_URL")
84
+
85
+ Storage::Strategies::S3.stubs(:find_object).returns(object)
86
+
87
+ assert_equal "PRIVATE_URL", Storage.get("lorem.txt", bucket: "files")
88
+ end
89
+
90
+ test "retrieves an existing file with custom expiration [private url]" do
91
+ Time.stubs(:now).returns(Time.now)
92
+
93
+ object = mock("object", public_url: nil)
94
+ object.expects(:url).with(Time.now.to_i + 60).returns("PRIVATE_URL")
95
+
96
+ Storage::Strategies::S3.stubs(:find_object).returns(object)
97
+
98
+ private_url = Storage.get("lorem.txt",
99
+ bucket: "files",
100
+ expires: Time.now.to_i + 60)
101
+
102
+ assert_equal "PRIVATE_URL", private_url
103
+ end
104
+
105
+ test "raises when trying to retrieve an missing file" do
106
+ setup_get_object object: nil
107
+
108
+ assert_raises(Storage::MissingFileError) {
109
+ Storage.get("lorem.txt", bucket: "files")
110
+ }
111
+ end
112
+
113
+ test "raises when trying to retrieve an missing bucket" do
114
+ setup_get_bucket bucket: nil
115
+
116
+ assert_raises(Storage::MissingFileError) {
117
+ Storage.get("lorem.txt", bucket: "files")
118
+ }
119
+ end
120
+
121
+ test "creates a bucket when trying to store a file on a missing bucket" do
122
+ null_object = NullObject.new
123
+ bucket.stubs(:files).returns(null_object)
124
+ setup_create_bucket
125
+
126
+ Storage.store(source, name: "lorem.txt", bucket: "files")
127
+ end
128
+
129
+ test "sets file permission to public" do
130
+ setup_create_object public: true
131
+ Storage.store(source, name: "lorem.txt", bucket: "files", public: true)
132
+ end
133
+
134
+ test "sets file permission to private (default)" do
135
+ setup_create_object public: false
136
+ Storage.store(source, name: "lorem.txt", bucket: "files")
137
+ end
138
+
139
+ test "sets file permission to private" do
140
+ setup_create_object public: false
141
+ Storage.store(source, name: "lorem.txt", bucket: "files", public: false)
142
+ end
143
+
144
+ test "sets file permission to private (access option)" do
145
+ setup_create_object public: false
146
+ Storage.store(source, name: "lorem.txt", bucket: "files", access: :private)
147
+ end
148
+
149
+ test "sets file permission to public (access option)" do
150
+ setup_create_object public: true
151
+ Storage.store(source, name: "lorem.txt", bucket: "files", access: :public_read)
152
+ end
153
+
154
+ def setup_create_object(bucket: self.bucket, object: nil, public: false, file_name: "lorem.txt")
155
+ # 1. first find bucket.
156
+ setup_get_bucket(bucket: bucket)
157
+
158
+ # 2. create file
159
+ params = {key: file_name, body: instance_of(File), public: public}
160
+
161
+ files = stub("files")
162
+ files.expects(:create).with(has_entries(params)).returns(object)
163
+ bucket.stubs(:files).returns(files)
164
+ end
165
+
166
+ def setup_get_object(bucket: self.bucket, file_name: "lorem.txt", object: nil)
167
+ # 1. Set up connection.directories.get
168
+ setup_get_bucket(bucket: bucket)
169
+
170
+ # 2. Set up bucket.files.get
171
+ files = stub("files")
172
+ files.expects(:get).with(file_name).returns(object)
173
+ bucket.expects(:files).returns(files)
174
+ end
175
+
176
+ def setup_create_bucket(bucket: nil)
177
+ get = stub("get")
178
+ get.expects(:get).with("files").returns(bucket)
179
+
180
+ create = stub("create")
181
+ create.expects(:create).with(key: "files", public: false).returns(self.bucket)
182
+
183
+ connection.stubs(:directories).returns(get, create)
184
+ end
185
+
186
+ def setup_get_bucket(bucket: self.bucket)
187
+ dir = stub("directories")
188
+ dir.expects(:get).with("files").returns(bucket)
189
+ connection.expects(:directories).at_least_once.returns(dir)
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+
3
+ class StorageTest < Minitest::Test
4
+ test "returns the strategy" do
5
+ strategy = mock("strategy")
6
+ Storage::Config.strategy_class = strategy
7
+
8
+ assert_equal strategy, Storage.strategy
9
+ end
10
+
11
+ test "returns the config" do
12
+ Storage::Strategies::S3.stubs(:prepare!)
13
+ config = nil
14
+
15
+ Storage.setup do |actual_config|
16
+ actual_config.strategy = :s3
17
+ config = actual_config
18
+ end
19
+
20
+ assert_equal Storage::Config, config
21
+ end
22
+
23
+ test "sets strategy class based on its name" do
24
+ Storage::Config.strategy_class = nil
25
+ Storage::Config.strategy = :s3
26
+
27
+ assert_equal Storage::Strategies::S3, Storage::Config.strategy_class
28
+ end
29
+
30
+ test "prepares strategy after setting its configuration" do
31
+ Storage::Strategies::S3.expects(:prepare!).once
32
+ Storage.setup {|config| config.strategy = :s3 }
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-utils
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: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  description: 'This gem provides a simple API for multiple storage backends. Supported
70
112
  storages: Amazon S3 and FileSystem.'
71
113
  email:
@@ -77,7 +119,6 @@ files:
77
119
  - ".gitignore"
78
120
  - ".rspec"
79
121
  - Gemfile
80
- - Gemfile.lock
81
122
  - README.md
82
123
  - Rakefile
83
124
  - lib/storage.rb
@@ -87,12 +128,13 @@ files:
87
128
  - lib/storage/strategies/file_system.rb
88
129
  - lib/storage/strategies/s3.rb
89
130
  - lib/storage/version.rb
90
- - spec/resources/file.txt
91
- - spec/spec_helper.rb
92
- - spec/storage/strategies/file_system_spec.rb
93
- - spec/storage/strategies/s3_spec.rb
94
- - spec/storage_spec.rb
95
131
  - storage.gemspec
132
+ - test/resources/file.txt
133
+ - test/test_helper.rb
134
+ - test/unit/delegation_test.rb
135
+ - test/unit/file_system_strategy_test.rb
136
+ - test/unit/s3_strategy_test.rb
137
+ - test/unit/storage_test.rb
96
138
  homepage: http://github.com/fnando/storage
97
139
  licenses: []
98
140
  metadata: {}
@@ -118,8 +160,9 @@ specification_version: 4
118
160
  summary: 'This gem provides a simple API for multiple storage backends. Supported
119
161
  storages: Amazon S3 and FileSystem.'
120
162
  test_files:
121
- - spec/resources/file.txt
122
- - spec/spec_helper.rb
123
- - spec/storage/strategies/file_system_spec.rb
124
- - spec/storage/strategies/s3_spec.rb
125
- - spec/storage_spec.rb
163
+ - test/resources/file.txt
164
+ - test/test_helper.rb
165
+ - test/unit/delegation_test.rb
166
+ - test/unit/file_system_strategy_test.rb
167
+ - test/unit/s3_strategy_test.rb
168
+ - test/unit/storage_test.rb
@@ -1,185 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- storage (0.3.2)
5
- fog
6
- mime-types
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- CFPropertyList (2.3.2)
12
- awesome_print (1.6.1)
13
- builder (3.2.2)
14
- byebug (8.2.2)
15
- coderay (1.1.1)
16
- diff-lcs (1.2.5)
17
- excon (0.47.0)
18
- fission (0.5.0)
19
- CFPropertyList (~> 2.2)
20
- fog (1.37.0)
21
- fog-aliyun (>= 0.1.0)
22
- fog-atmos
23
- fog-aws (>= 0.6.0)
24
- fog-brightbox (~> 0.4)
25
- fog-core (~> 1.32)
26
- fog-dynect (~> 0.0.2)
27
- fog-ecloud (~> 0.1)
28
- fog-google (<= 0.1.0)
29
- fog-json
30
- fog-local
31
- fog-powerdns (>= 0.1.1)
32
- fog-profitbricks
33
- fog-radosgw (>= 0.0.2)
34
- fog-riakcs
35
- fog-sakuracloud (>= 0.0.4)
36
- fog-serverlove
37
- fog-softlayer
38
- fog-storm_on_demand
39
- fog-terremark
40
- fog-vmfusion
41
- fog-voxel
42
- fog-vsphere (>= 0.4.0)
43
- fog-xenserver
44
- fog-xml (~> 0.1.1)
45
- ipaddress (~> 0.5)
46
- fog-aliyun (0.1.0)
47
- fog-core (~> 1.27)
48
- fog-json (~> 1.0)
49
- ipaddress (~> 0.8)
50
- xml-simple (~> 1.1)
51
- fog-atmos (0.1.0)
52
- fog-core
53
- fog-xml
54
- fog-aws (0.8.1)
55
- fog-core (~> 1.27)
56
- fog-json (~> 1.0)
57
- fog-xml (~> 0.1)
58
- ipaddress (~> 0.8)
59
- fog-brightbox (0.10.1)
60
- fog-core (~> 1.22)
61
- fog-json
62
- inflecto (~> 0.0.2)
63
- fog-core (1.36.0)
64
- builder
65
- excon (~> 0.45)
66
- formatador (~> 0.2)
67
- fog-dynect (0.0.2)
68
- fog-core
69
- fog-json
70
- fog-xml
71
- fog-ecloud (0.3.0)
72
- fog-core
73
- fog-xml
74
- fog-google (0.1.0)
75
- fog-core
76
- fog-json
77
- fog-xml
78
- fog-json (1.0.2)
79
- fog-core (~> 1.0)
80
- multi_json (~> 1.10)
81
- fog-local (0.2.1)
82
- fog-core (~> 1.27)
83
- fog-powerdns (0.1.1)
84
- fog-core (~> 1.27)
85
- fog-json (~> 1.0)
86
- fog-xml (~> 0.1)
87
- fog-profitbricks (0.0.5)
88
- fog-core
89
- fog-xml
90
- nokogiri
91
- fog-radosgw (0.0.5)
92
- fog-core (>= 1.21.0)
93
- fog-json
94
- fog-xml (>= 0.0.1)
95
- fog-riakcs (0.1.0)
96
- fog-core
97
- fog-json
98
- fog-xml
99
- fog-sakuracloud (1.7.5)
100
- fog-core
101
- fog-json
102
- fog-serverlove (0.1.2)
103
- fog-core
104
- fog-json
105
- fog-softlayer (1.1.0)
106
- fog-core
107
- fog-json
108
- fog-storm_on_demand (0.1.1)
109
- fog-core
110
- fog-json
111
- fog-terremark (0.1.0)
112
- fog-core
113
- fog-xml
114
- fog-vmfusion (0.1.0)
115
- fission
116
- fog-core
117
- fog-voxel (0.1.0)
118
- fog-core
119
- fog-xml
120
- fog-vsphere (0.6.0)
121
- fog-core
122
- rbvmomi (~> 1.8)
123
- fog-xenserver (0.2.3)
124
- fog-core
125
- fog-xml
126
- fog-xml (0.1.2)
127
- fog-core
128
- nokogiri (~> 1.5, >= 1.5.11)
129
- formatador (0.2.5)
130
- inflecto (0.0.2)
131
- ipaddress (0.8.3)
132
- method_source (0.8.2)
133
- mime-types (3.0)
134
- mime-types-data (~> 3.2015)
135
- mime-types-data (3.2016.0221)
136
- mini_portile2 (2.0.0)
137
- multi_json (1.11.2)
138
- nokogiri (1.6.7.2)
139
- mini_portile2 (~> 2.0.0.rc2)
140
- pry (0.10.3)
141
- coderay (~> 1.1.0)
142
- method_source (~> 0.8.1)
143
- slop (~> 3.4)
144
- pry-byebug (3.3.0)
145
- byebug (~> 8.0)
146
- pry (~> 0.10)
147
- pry-meta (0.0.10)
148
- awesome_print
149
- pry
150
- pry-byebug
151
- pry-remote
152
- pry-remote (0.1.8)
153
- pry (~> 0.9)
154
- slop (~> 3.0)
155
- rbvmomi (1.8.2)
156
- builder
157
- nokogiri (>= 1.4.1)
158
- trollop
159
- rspec (3.4.0)
160
- rspec-core (~> 3.4.0)
161
- rspec-expectations (~> 3.4.0)
162
- rspec-mocks (~> 3.4.0)
163
- rspec-core (3.4.3)
164
- rspec-support (~> 3.4.0)
165
- rspec-expectations (3.4.0)
166
- diff-lcs (>= 1.2.0, < 2.0)
167
- rspec-support (~> 3.4.0)
168
- rspec-mocks (3.4.1)
169
- diff-lcs (>= 1.2.0, < 2.0)
170
- rspec-support (~> 3.4.0)
171
- rspec-support (3.4.1)
172
- slop (3.6.0)
173
- trollop (2.1.2)
174
- xml-simple (1.1.5)
175
-
176
- PLATFORMS
177
- ruby
178
-
179
- DEPENDENCIES
180
- pry-meta
181
- rspec
182
- storage!
183
-
184
- BUNDLED WITH
185
- 1.11.2
@@ -1,59 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Storage::Strategies::FileSystem do
4
- before do
5
- @source = RESOURCES.join("file.txt")
6
- @destiny = TMP.join("lorem.txt")
7
-
8
- Storage.setup do |c|
9
- c.strategy = :file
10
- c.path = TMP
11
- end
12
- end
13
-
14
- it "should save a file using file handler" do
15
- handler = File.open(@source)
16
- Storage.store(handler, :name => "lorem.txt")
17
-
18
- expect(File).to be_file(@destiny)
19
- expect(File.read(@destiny)).to eq(File.read(@source))
20
- end
21
-
22
- it "should save a file using a path" do
23
- Storage.store(@source, :name => "lorem.txt")
24
-
25
- expect(File).to be_file(@destiny)
26
- expect(File.read(@destiny)).to eq(File.read(@source))
27
- end
28
-
29
- it "should remove an existing file" do
30
- Storage.store(@source, :name => "lorem.txt")
31
- expect(Storage.remove("lorem.txt")).to be_truthy
32
- expect(File).not_to be_file(@destiny)
33
- end
34
-
35
- it "should raise when trying to removing an unexesting file" do
36
- expect {
37
- Storage.remove("invalid")
38
- }.to raise_error(Storage::MissingFileError)
39
- end
40
-
41
- it "should retrieve an existing file" do
42
- Storage.store(@source, :name => "lorem.txt")
43
- expect(Storage.get("lorem.txt")).to eq(File.expand_path(TMP.join("lorem.txt")))
44
- end
45
-
46
- it "should raise when trying to retrieve an unexesting file" do
47
- expect {
48
- Storage.get("invalid")
49
- }.to raise_error(Storage::MissingFileError)
50
- end
51
-
52
- it "should raise when saving a file that already exists" do
53
- Storage.store(@source, :name => "lorem.txt")
54
-
55
- expect {
56
- Storage.store(@source, :name => "lorem.txt")
57
- }.to raise_error(Storage::FileAlreadyExistsError)
58
- end
59
- end
@@ -1,155 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Storage::Strategies::S3 do
4
- context "region" do
5
- before do
6
- Storage.setup do |c|
7
- c.strategy = :s3
8
- c.access_key = "AKIAIOSFODNN7EXAMPLE"
9
- c.secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
10
- end
11
- end
12
-
13
- it "sets default region" do
14
- Storage::Config.region = nil
15
- expect(Storage::Strategies::S3.connection.region).to eq("us-east-1")
16
- end
17
-
18
- it "sets custom region" do
19
- Storage::Config.region = "eu-west-1"
20
- expect(Storage::Strategies::S3.connection.region).to eq("eu-west-1")
21
- end
22
- end
23
-
24
- context "general" do
25
- let(:adapter) { Storage::Strategies::S3 }
26
- let(:source) { RESOURCES.join("file.txt") }
27
- let(:destiny) { TMP.join("lorem.txt") }
28
- let(:connection) { double("connection") }
29
- let(:bucket) { double("bucket") }
30
-
31
- before do
32
- allow(adapter).to receive(:connection).and_return(connection)
33
-
34
- Storage.setup do |c|
35
- c.strategy = :s3
36
- c.access_key = "abc"
37
- c.secret_key = "123"
38
- c.region = "us-east-1"
39
- end
40
- end
41
-
42
- it "should save a file using file handler" do
43
- handler = File.open(source)
44
- setup_create_object
45
-
46
- Storage.store(handler, name: "lorem.txt", bucket: "files")
47
- end
48
-
49
- it "should save a file using a path" do
50
- setup_create_object
51
- Storage.store(source, name: "lorem.txt", bucket: "files")
52
- end
53
-
54
- it "should remove an existing file" do
55
- object = double("object")
56
-
57
- setup_get_object object: object
58
- expect(object).to receive(:destroy).and_return(true)
59
-
60
- expect(Storage.remove("lorem.txt", bucket: "files")).to be_truthy
61
- end
62
-
63
- it "should raise when trying to removing an nonexisting file" do
64
- setup_get_object object: nil
65
-
66
- expect {
67
- Storage.remove("lorem.txt", bucket: "files")
68
- }.to raise_error(Storage::MissingFileError)
69
- end
70
-
71
- it "should retrieve an existing file (public url)" do
72
- object = double("object", public_url: "PUBLIC_URL")
73
-
74
- setup_get_object object: object
75
-
76
- expect(Storage.get("lorem.txt", bucket: "files")).to eq("PUBLIC_URL")
77
- end
78
-
79
- it "should retrieve an existing file (private url)" do
80
- object = double("object", public_url: nil)
81
-
82
- expect(object).to receive_message_chain("url").with(Time.now.to_i + 3600).and_return("PRIVATE_URL")
83
- setup_get_object object: object
84
-
85
- expect(Storage.get("lorem.txt", bucket: "files")).to eq("PRIVATE_URL")
86
- end
87
-
88
- it "should raise when trying to retrieve an missing file" do
89
- setup_get_object object: nil
90
-
91
- expect {
92
- Storage.get("lorem.txt", bucket: "files")
93
- }.to raise_error(Storage::MissingFileError)
94
- end
95
-
96
- it "should raise when trying to retrieve an missing bucket" do
97
- setup_get_bucket bucket: nil
98
-
99
- expect {
100
- Storage.get("lorem.txt", bucket: "files")
101
- }.to raise_error(Storage::MissingFileError)
102
- end
103
-
104
- it "should create a bucket when trying to store a file on a missing bucket" do
105
- bucket.as_null_object
106
- setup_create_bucket
107
-
108
- Storage.store(source, name: "lorem.txt", bucket: "files")
109
- end
110
-
111
- it "should set file permission to public" do
112
- setup_create_object public: true
113
- Storage.store(source, name: "lorem.txt", bucket: "files", public: true)
114
- end
115
-
116
- it "should set file permission to private (default)" do
117
- setup_create_object public: false
118
- Storage.store(source, name: "lorem.txt", bucket: "files")
119
- end
120
-
121
- it "should set file permission to private" do
122
- setup_create_object public: false
123
- Storage.store(source, name: "lorem.txt", bucket: "files", public: false)
124
- end
125
-
126
- it "should set file permission to private (access option)" do
127
- setup_create_object public: false
128
- Storage.store(source, name: "lorem.txt", bucket: "files", access: :private)
129
- end
130
-
131
- it "should set file permission to public (access option)" do
132
- setup_create_object public: true
133
- Storage.store(source, name: "lorem.txt", bucket: "files", access: :public_read)
134
- end
135
-
136
- def setup_create_object(bucket: self.bucket, object: nil, public: false, file_name: "lorem.txt")
137
- allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
138
- expect(bucket).to receive_message_chain("files.create").with(key: file_name, body: kind_of(File), public: public)
139
- end
140
-
141
- def setup_get_object(bucket: self.bucket, file_name: "lorem.txt", object: nil)
142
- expect(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
143
- expect(bucket).to receive_message_chain("files.get").with(file_name).and_return(object)
144
- end
145
-
146
- def setup_create_bucket(bucket: nil)
147
- allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
148
- expect(connection).to receive_message_chain("directories.create").with(key: "files", public: false).and_return(self.bucket)
149
- end
150
-
151
- def setup_get_bucket(bucket: self.bucket)
152
- allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
153
- end
154
- end
155
- end
@@ -1,53 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Storage do
4
- it "should return the strategy" do
5
- @strategy = double("strategy")
6
- Storage::Config.strategy_class = @strategy
7
-
8
- expect(Storage.strategy).to be(@strategy)
9
- end
10
-
11
- it "should return the config" do
12
- allow(Storage::Strategies::S3).to receive :prepare!
13
-
14
- Storage.setup do |config|
15
- config.strategy = :s3
16
- expect(config).to be(Storage::Config)
17
- end
18
- end
19
-
20
- it "should set strategy class based on its name" do
21
- Storage::Config.strategy_class = nil
22
- Storage::Config.strategy = :s3
23
-
24
- expect(Storage::Config.strategy_class).to eq(Storage::Strategies::S3)
25
- end
26
-
27
- it "prepare strategy after setting its configuration" do
28
- expect(Storage::Strategies::S3).to receive(:prepare!).once
29
- Storage.setup {|config| config.strategy = :s3}
30
- end
31
-
32
- context "delegation" do
33
- before do
34
- @strategy = double("strategy")
35
- expect(Storage).to receive(:strategy).and_return(@strategy)
36
- end
37
-
38
- it "should delegate save method" do
39
- expect(@strategy).to receive(:store).with("some/file")
40
- Storage.store "some/file"
41
- end
42
-
43
- it "should delegate destroy method" do
44
- expect(@strategy).to receive(:remove).with("some/file")
45
- Storage.remove "some/file"
46
- end
47
-
48
- it "should delegate get method" do
49
- expect(@strategy).to receive(:get).with("some/file")
50
- Storage.get "some/file"
51
- end
52
- end
53
- end