omnistore 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,8 @@ module OmniStore
15
15
  @name
16
16
  end
17
17
 
18
- def url
19
- "file://#{dir}/"
18
+ def url(key = nil, options = {})
19
+ "file://#{dir}/#{key}"
20
20
  end
21
21
 
22
22
  def exist?(path)
@@ -17,8 +17,12 @@ module OmniStore
17
17
  @name
18
18
  end
19
19
 
20
- def url
21
- bucket.url
20
+ def url(key = nil, options = {})
21
+ if key
22
+ bucket.objects[key].public_url(:secure => options[:secure] != false).to_s
23
+ else
24
+ bucket.url
25
+ end
22
26
  end
23
27
 
24
28
  def exist?(key)
@@ -1,3 +1,3 @@
1
1
  module OmniStore
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -90,6 +90,20 @@ describe OmniStore::Storage::Local do
90
90
  its(:url) { should eq "file://#{File.expand_path(TMPDIR)}/" }
91
91
  end
92
92
 
93
+ describe '#url' do
94
+ let(:key) { nil }
95
+ subject { OmniStore::Storage::Local.mountpoint.url(key) }
96
+
97
+ context 'when key is not specified' do
98
+ it { should eq "file://#{File.expand_path(MOUNTPOINT)}/" }
99
+ end
100
+
101
+ context 'when key specified' do
102
+ let(:key) { 'test' }
103
+ it { should eq "file://#{File.expand_path(MOUNTPOINT)}/#{key}" }
104
+ end
105
+ end
106
+
93
107
  describe '#move' do
94
108
  let(:src) { t = Tempfile.new(TEST_FILENAME, MOUNTPOINT); File.basename(t.path) }
95
109
  let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
@@ -3,30 +3,154 @@ require 'fileutils'
3
3
 
4
4
  describe "OmniStore::Storage::S3" do
5
5
 
6
+ def create_object(src, key = AWS_BUCKET)
7
+ OmniStore::Storage::S3.mountpoint(key).bucket.objects[src].write('Hello World!')
8
+ end
9
+
10
+ def delete_object(src, key = AWS_BUCKET)
11
+ OmniStore::Storage::S3.mountpoint(key).bucket.objects[src].delete
12
+ end
13
+
6
14
  before(:each) do
7
15
  OmniStore::Config.storage = 's3'
8
16
  OmniStore::Config.mountpoint = AWS_BUCKET
9
17
  OmniStore::Storage.remount!
10
18
  end
11
19
 
12
- it 'should mount' do
13
- OmniStore::Storage::S3.mount!.should_not be_nil
20
+ describe '#mount!' do
21
+ subject { lambda { OmniStore::Storage::S3.mount! } }
22
+
23
+ context 'when specified a bucket name that exists' do
24
+ it { should_not raise_error }
25
+ end
26
+
27
+ context 'when specified two bucket names that exists' do
28
+ before { OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET } }
29
+ it { should_not raise_error }
30
+ end
31
+
32
+ context 'when specified a bucket name that does not exists' do
33
+ before { OmniStore::Config.mountpoint = AWS_BUCKET + Time.new.to_i.to_s }
34
+ it { should raise_error OmniStore::Errors::InvalidMountpoint }
35
+ end
36
+ end
37
+
38
+ describe '#mountpoint' do
39
+ subject { OmniStore::Storage::S3.mountpoint }
40
+ it { should be_a OmniStore::Storage::S3::Mountpoint }
14
41
  end
15
42
 
16
- it 'should raise error when mount fails' do
17
- OmniStore::Config.mountpoint = "a"
18
- lambda { OmniStore::Storage::S3.mount! }.should raise_error(OmniStore::Errors::InvalidMountpoint)
43
+ describe '#exist?' do
44
+ let(:src) { TEST_FILENAME }
45
+ subject { OmniStore::Storage::S3.exist?(src) }
46
+
47
+ context 'when specified a object that does not exist' do
48
+ it { should be_false }
49
+ end
50
+
51
+ context 'when specified a object that exist' do
52
+ before { create_object(src) }
53
+ after { delete_object(src) }
54
+ it { should be_true }
55
+ end
19
56
  end
20
57
 
21
- it 'should exist' do
22
- key = 'test.txt'
23
- OmniStore::Storage::S3.write(key, '')
24
- begin
25
- OmniStore::Storage::S3.exist?(key).should be_true
26
- OmniStore::Storage::S3.exist?(key+'.bk').should be_false
27
- ensure
28
- OmniStore::Storage::S3.delete(key)
58
+ describe '#delete' do
59
+ let(:src) { TEST_FILENAME }
60
+ subject { lambda { OmniStore::Storage::S3.delete(src) } }
61
+
62
+ context 'when specified a object that does not exist' do
63
+ it { should_not raise_error }
64
+ end
65
+
66
+ context 'when specified a object path that exist' do
67
+ before { create_object(src) }
68
+ it 'should delete object' do
69
+ should_not raise_error
70
+ OmniStore::Storage::S3.exist?(src).should be_false
71
+ end
29
72
  end
30
73
  end
31
74
 
75
+ describe '#each' do
76
+ subject { OmniStore::Storage::S3.each }
77
+ it { should be_a Enumerator }
78
+ end
79
+
80
+ describe 'OmniStore::Storage::S3::Mountpoint' do
81
+ subject { OmniStore::Storage::S3.mountpoint }
82
+
83
+ context 'when single mountpoit' do
84
+ its(:name) { should eq AWS_BUCKET }
85
+ its(:url) { should match "#{AWS_BUCKET}" }
86
+ end
87
+
88
+ context 'when double mountpoint' do
89
+ before do
90
+ OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET }
91
+ OmniStore::Storage.remount!
92
+ end
93
+ subject { OmniStore::Storage::S3.mountpoint(:b) }
94
+
95
+ its(:name) { should eq :b }
96
+ its(:url) { should match "#{AWS_BUCKET}" }
97
+ end
98
+
99
+ describe '#url' do
100
+ let(:key) { nil }
101
+ let(:options) { {} }
102
+ subject { OmniStore::Storage::S3.mountpoint.url(key, options) }
103
+
104
+ context 'when key is not specified' do
105
+ it { should match "#{AWS_BUCKET}" }
106
+ end
107
+
108
+ context 'when key specified' do
109
+ let(:key) { 'test' }
110
+ it { should match "#{AWS_BUCKET}.+/#{key}" }
111
+ end
112
+
113
+ context 'when secure is true' do
114
+ let(:key) { 'test' }
115
+ let(:options) { { :secure => true } }
116
+ it { should match "^https://.*#{AWS_BUCKET}.*/#{key}" }
117
+ end
118
+
119
+ context 'when secure is false' do
120
+ let(:key) { 'test' }
121
+ let(:options) { { :secure => false } }
122
+ it { should match "^http://.*#{AWS_BUCKET}.*/#{key}" }
123
+ end
124
+
125
+ end
126
+
127
+ describe '#move' do
128
+ let(:src) { TEST_FILENAME }
129
+ let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
130
+ let(:other) { OmniStore::Storage::S3.mountpoint(:a) }
131
+ subject { lambda { OmniStore::Storage::S3.mountpoint.move(src, dst, other) } }
132
+
133
+ before do
134
+ OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET }
135
+ OmniStore::Storage.remount!
136
+ end
137
+
138
+ context 'when specified a object that does not exist' do
139
+ it { should raise_error AWS::S3::Errors::NoSuchKey }
140
+ end
141
+
142
+ context 'when specified a object that exist' do
143
+ before { create_object(src, :a) }
144
+ after { delete_object(dst, :a) }
145
+ it { should_not raise_error }
146
+ end
147
+
148
+ context 'when move to another mountpoint' do
149
+ before { create_object(src, :a) }
150
+ after { delete_object(dst, :b) }
151
+ let(:other) { OmniStore::Storage::S3.mountpoint(:b) }
152
+ it { should_not raise_error }
153
+ end
154
+ end
155
+ end
32
156
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnistore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -1053533393
122
+ hash: -71898321
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -1053533393
131
+ hash: -71898321
132
132
  requirements: []
133
133
  rubyforge_project:
134
134
  rubygems_version: 1.8.24