s3_form_presenter 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 +1 -1
- data/README.md +3 -3
- data/lib/s3_form_presenter/version.rb +1 -1
- data/lib/s3_form_presenter.rb +3 -2
- data/test/form_test.rb +21 -10
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,10 +4,10 @@ Generates a simple form that is compatible with S3's form API. You can upload S3
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
```
|
8
|
-
<% S3FormPresenter::Form.new("some/key/path.ext") do %>
|
7
|
+
```
|
8
|
+
<% S3FormPresenter::Form.new("some/key/path.ext", "http://www.theredirecttowebsite.com/redirect/to/this/path") do %>
|
9
9
|
<input name="file" type="file">
|
10
|
-
|
10
|
+
<input type="submit" value="Save File">
|
11
11
|
<% end %>
|
12
12
|
```
|
13
13
|
|
data/lib/s3_form_presenter.rb
CHANGED
@@ -9,13 +9,14 @@ module S3FormPresenter
|
|
9
9
|
RENAMED_FIELDS = {:redirect_url => "success_action_redirect", :access_key => "AWSAccessKeyId"}
|
10
10
|
attr_accessor :bucket, :inner_content, :extra_form_attributes
|
11
11
|
|
12
|
-
def initialize(key, options={}, &block)
|
12
|
+
def initialize(key, redirect_url, options={}, &block)
|
13
13
|
@key = key
|
14
14
|
@access_key = options[:access_key] || ENV["AWS_ACCESS_KEY_ID"]
|
15
15
|
@secret_key = options[:secret_key] || ENV["AWS_SECRET_ACCESS_KEY"]
|
16
16
|
@bucket = options[:bucket] || ENV["AWS_S3_BUCKET"]
|
17
|
-
@acl = options[:acl]
|
17
|
+
@acl = options[:acl] || :private
|
18
18
|
@extra_form_attributes = options[:extra_form_attributes]
|
19
|
+
@redirect_url = redirect_url
|
19
20
|
if block_given?
|
20
21
|
@inner_content = block.call
|
21
22
|
else
|
data/test/form_test.rb
CHANGED
@@ -4,7 +4,7 @@ include S3FormPresenter
|
|
4
4
|
|
5
5
|
describe S3FormPresenter::Form do
|
6
6
|
before do
|
7
|
-
@form = Form.new("some/test/key.ext") do
|
7
|
+
@form = Form.new("some/test/key.ext", "http://www.someurl.com/comeback") do
|
8
8
|
%Q(<input name="file" type="file"><input type="submit" value="Upload File" class="btn btn-primary">)
|
9
9
|
end
|
10
10
|
@form.bucket = "test_bucket"
|
@@ -15,24 +15,35 @@ describe S3FormPresenter::Form do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "initializer" do
|
18
|
+
describe "defaults" do
|
19
|
+
before do
|
20
|
+
@form = Form.new("some/test/key", "http://www.someurl.com/comeback")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should specify some defaults" do
|
24
|
+
@form.acl.must_equal :private
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
18
28
|
it "allows an empty block and provides a sane default" do
|
19
|
-
@form = Form.new("some/test/key.ext").inner_content.must_equal %Q(<input name="file" type="file"><input type="submit" value="Upload File" class="btn btn-primary">)
|
29
|
+
@form = Form.new("some/test/key.ext", "http://www.someurl.com/comeback").inner_content.must_equal %Q(<input name="file" type="file"><input type="submit" value="Upload File" class="btn btn-primary">)
|
20
30
|
end
|
21
31
|
|
22
32
|
it "should let you override access_key, secret_key and bucket with ENV" do
|
23
33
|
ENV["AWS_ACCESS_KEY_ID"] = "overridden_env_access_key"
|
24
34
|
ENV["AWS_SECRET_ACCESS_KEY"] = "overridden_env_secret_key"
|
25
35
|
ENV["AWS_S3_BUCKET"] = "overridden_env_bucket"
|
26
|
-
@form = Form.new("some/test/key.ext"
|
27
|
-
@form
|
28
|
-
@form
|
36
|
+
@form = Form.new("some/test/key.ext", "http://www.someurl.com/comeback")
|
37
|
+
@form.access_key.must_equal "overridden_env_access_key"
|
38
|
+
@form.secret_key.must_equal "overridden_env_secret_key"
|
39
|
+
@form.bucket.must_equal "overridden_env_bucket"
|
29
40
|
end
|
30
41
|
|
31
42
|
it "should let you override access_key, secret_key and bucket and acl with options in the initializer" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
Form.new("some/test/key.ext", "http://www.someurl.com/comeback", :access_key => "overridden_options_access_key").access_key.must_equal "overridden_options_access_key"
|
44
|
+
Form.new("some/test/key.ext", "http://www.someurl.com/comeback", :secret_key => "overridden_options_secret_key").secret_key.must_equal "overridden_options_secret_key"
|
45
|
+
Form.new("some/test/key.ext", "http://www.someurl.com/comeback", :bucket => "overridden_options_bucket").bucket.must_equal "overridden_options_bucket"
|
46
|
+
Form.new("some/test/key.ext", "http://www.someurl.com/comeback", :acl => "overridden_options_acl").acl.must_equal "overridden_options_acl"
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
@@ -109,7 +120,7 @@ describe S3FormPresenter::Form do
|
|
109
120
|
|
110
121
|
describe "extra_form_attributes" do
|
111
122
|
it "generates extra form attributes when provided in options" do
|
112
|
-
Form.new("some/key.ext", :extra_form_attributes => %Q( class="form-horizontal")).header.must_equal %Q(<form action="http://.s3.amazonaws.com/" method="post" enctype="multipart/form-data" class="form-horizontal">)
|
123
|
+
Form.new("some/key.ext", "http://www.someurl.com/comeback", :extra_form_attributes => %Q( class="form-horizontal")).header.must_equal %Q(<form action="http://.s3.amazonaws.com/" method="post" enctype="multipart/form-data" class="form-horizontal">)
|
113
124
|
end
|
114
125
|
end
|
115
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_form_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
hash:
|
47
|
+
hash: 3980563017398046619
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
segments:
|
55
55
|
- 0
|
56
|
-
hash:
|
56
|
+
hash: 3980563017398046619
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project: s3_form_presenter
|
59
59
|
rubygems_version: 1.8.15
|