remote_files 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,11 +66,22 @@ module RemoteFiles
66
66
  end
67
67
 
68
68
  def directory
69
- @directory ||= connection.directories.new(
70
- :key => options[:directory],
71
- :public => options[:public]
72
- )
69
+ @directory ||= lookup_directory || create_directory
70
+ end
71
+
72
+ protected
73
+
74
+ def lookup_directory
75
+ connection.directories.get(options[:directory])
73
76
  end
74
77
 
78
+ def create_directory
79
+ connection.directories.new(
80
+ :key => options[:directory],
81
+ :public => options[:public]
82
+ ).tap do |dir|
83
+ dir.save
84
+ end
85
+ end
75
86
  end
76
87
  end
@@ -1,3 +1,3 @@
1
1
  module RemoteFiles
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
3
3
  end
@@ -8,8 +8,6 @@ describe RemoteFiles::FogStore do
8
8
  :aws_secret_access_key => 'secret_access_key'
9
9
  })
10
10
 
11
- @directory = @connection.directories.create(:key => 'directory')
12
-
13
11
  @store = RemoteFiles::FogStore.new(:fog)
14
12
  @store[:provider] = 'AWS'
15
13
  @store[:aws_access_key_id] = 'access_key_id'
@@ -32,6 +30,16 @@ describe RemoteFiles::FogStore do
32
30
 
33
31
  directory.key.must_equal('directory')
34
32
  end
33
+
34
+ it 'should create the remote directory if it does not exist' do
35
+ assert_nil @connection.directories.get('directory')
36
+
37
+ directory = @store.directory
38
+ assert directory
39
+ assert_equal 'directory', directory.key
40
+
41
+ assert @connection.directories.get('directory')
42
+ end
35
43
  end
36
44
 
37
45
  describe '#store!' do
@@ -42,7 +50,7 @@ describe RemoteFiles::FogStore do
42
50
  it 'should store the file in the directory' do
43
51
  @store.store!(@file)
44
52
 
45
- fog_file = @directory.files.get('identifier')
53
+ fog_file = @store.directory.files.get('identifier')
46
54
 
47
55
  fog_file.must_be_instance_of(Fog::Storage::AWS::File)
48
56
  fog_file.content_type.must_equal('text/plain')
@@ -50,14 +58,14 @@ describe RemoteFiles::FogStore do
50
58
  end
51
59
 
52
60
  it 'should raise a RemoteFiles::Error when an error happens' do
53
- @directory.destroy
61
+ @store.directory.destroy
54
62
  proc { @store.store!(@file) }.must_raise(RemoteFiles::Error)
55
63
  end
56
64
  end
57
65
 
58
66
  describe '#retrieve!' do
59
67
  it 'should return a RemoteFiles::File when found' do
60
- @directory.files.create(
68
+ @store.directory.files.create(
61
69
  :body => 'content',
62
70
  :content_type => 'text/plain',
63
71
  :key => 'identifier'
@@ -75,7 +83,7 @@ describe RemoteFiles::FogStore do
75
83
  end
76
84
 
77
85
  it 'should raise a RemoteFiles::Error when error' do
78
- @directory.destroy
86
+ @store.directory.destroy
79
87
  proc { @store.retrieve!('identifier') }.must_raise(RemoteFiles::Error)
80
88
  end
81
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  segments:
148
148
  - 0
149
- hash: 2511634523792852721
149
+ hash: 3219444270301945371
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: 2511634523792852721
158
+ hash: 3219444270301945371
159
159
  requirements: []
160
160
  rubyforge_project:
161
161
  rubygems_version: 1.8.24