rack-s3 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-s3 (0.0.1)
4
+ rack-s3 (0.0.3)
5
5
  aws-s3
6
6
  rack
7
7
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class S3
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/rack/s3.rb CHANGED
@@ -4,13 +4,19 @@ require 'aws/s3'
4
4
  module Rack
5
5
  class S3
6
6
 
7
- def initialize(app, options={})
8
- @app = app
7
+ def initialize(options={})
9
8
  @bucket = options[:bucket]
10
9
 
10
+ establish_aws_connection(options[:access_key_id],
11
+ options[:secret_access_key])
12
+ end
13
+
14
+ def establish_aws_connection(access_key_id, secret_access_key)
15
+ return unless access_key_id && secret_access_key
16
+
11
17
  AWS::S3::Base.establish_connection!(
12
- :access_key_id => options[:access_key_id],
13
- :secret_access_key => options[:secret_access_key])
18
+ :access_key_id => access_key_id,
19
+ :secret_access_key => secret_access_key)
14
20
  end
15
21
 
16
22
  def call(env)
data/test/rack_s3_test.rb CHANGED
@@ -2,33 +2,25 @@ require 'test_helper'
2
2
 
3
3
  class RackS3Test < Test::Unit::TestCase
4
4
 
5
- def app
6
- options = { :bucket => 'rack-s3',
7
- :access_key_id => 'abc123',
8
- :secret_access_key => 'abc123' }
9
-
10
- Rack::Builder.new do
11
- use Rack::S3, options
12
- run lambda { [ 200, {}, [ "Hello World" ]] }
13
- end
5
+ def mock_request(path)
6
+ Rack::MockRequest.new(app).get path, :lint => true
14
7
  end
15
8
 
16
- def mapped_app
17
- # #app isn't available inside the block below.
18
- unmapped_app = app
9
+ def app
10
+ Rack::S3.new :bucket => 'rack-s3',
11
+ :access_key_id => 'abc123',
12
+ :secret_access_key => 'abc123'
13
+ end
19
14
 
20
- Rack::Builder.new do
21
- map '/mapped/app' do
22
- run unmapped_app
23
- end
24
- end
15
+ def teardown
16
+ AWS::S3::Base.disconnect!
25
17
  end
26
18
 
27
19
 
28
20
  context 'A request for a nonexistent key' do
29
21
  subject do
30
22
  VCR.use_cassette 'not_found' do
31
- Rack::MockRequest.new(app).get '/not_found.png'
23
+ mock_request '/not_found.png'
32
24
  end
33
25
  end
34
26
 
@@ -44,7 +36,7 @@ class RackS3Test < Test::Unit::TestCase
44
36
  context 'A request for a key' do
45
37
  subject do
46
38
  VCR.use_cassette 'clear' do
47
- Rack::MockRequest.new(app).get '/clear.png'
39
+ mock_request '/clear.png'
48
40
  end
49
41
  end
50
42
 
@@ -62,7 +54,7 @@ class RackS3Test < Test::Unit::TestCase
62
54
  context 'A request for a nested key' do
63
55
  subject do
64
56
  VCR.use_cassette 'nested_clear' do
65
- Rack::MockRequest.new(app).get '/very/important/files/clear.png'
57
+ mock_request '/very/important/files/clear.png'
66
58
  end
67
59
  end
68
60
 
@@ -80,6 +72,13 @@ class RackS3Test < Test::Unit::TestCase
80
72
  context 'A request to a mapped app' do
81
73
  subject do
82
74
  VCR.use_cassette 'clear' do
75
+ unmapped_app = app
76
+ mapped_app = Rack::Builder.new do
77
+ map '/mapped/app' do
78
+ run unmapped_app
79
+ end
80
+ end
81
+
83
82
  Rack::MockRequest.new(mapped_app).get '/mapped/app/clear.png'
84
83
  end
85
84
  end
@@ -89,4 +88,18 @@ class RackS3Test < Test::Unit::TestCase
89
88
  end
90
89
  end
91
90
 
91
+ context 'Without AWS credentials' do
92
+ subject do
93
+ app = Rack::S3.new :bucket => 'rack-s3'
94
+
95
+ Rack::MockRequest.new(app).get '/clear.png'
96
+ end
97
+
98
+ should 'not attempt to establish a connection to AWS' do
99
+ assert_raise AWS::S3::NoConnectionEstablished do
100
+ subject
101
+ end
102
+ end
103
+ end
104
+
92
105
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-s3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Larry Marburger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-26 00:00:00 -05:00
18
+ date: 2011-01-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency