s3_form_presenter 0.0.5 → 0.0.6
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.
- data/Gemfile.lock +1 -1
- data/lib/s3_form_presenter.rb +8 -2
- data/lib/s3_form_presenter/version.rb +1 -1
- data/test/form_test.rb +15 -3
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/s3_form_presenter.rb
CHANGED
@@ -8,7 +8,7 @@ module S3FormPresenter
|
|
8
8
|
ACCESSOR_FIELDS = HIDDEN_FIELD_NAMES - [:policy, :signature]
|
9
9
|
RENAMED_FIELDS = {:redirect_url => "success_action_redirect", :access_key => "AWSAccessKeyId"}
|
10
10
|
REQUIRED_ATTRIBUTES = [:bucket] + HIDDEN_FIELD_NAMES
|
11
|
-
attr_accessor :bucket, :inner_content, :extra_form_attributes
|
11
|
+
attr_accessor :bucket, :inner_content, :extra_form_attributes, :starts_with
|
12
12
|
|
13
13
|
def initialize(key, redirect_url, options={}, &block)
|
14
14
|
@key = key
|
@@ -67,13 +67,19 @@ module S3FormPresenter
|
|
67
67
|
"expiration" => policy_expiration,
|
68
68
|
"conditions" => [
|
69
69
|
{"bucket" => bucket},
|
70
|
-
["starts-with", "$key", "#{
|
70
|
+
["starts-with", "$key", "#{starts_with}"],
|
71
71
|
{"acl" => acl},
|
72
72
|
{"success_action_redirect" => redirect_url}
|
73
73
|
]
|
74
74
|
}
|
75
75
|
end
|
76
76
|
|
77
|
+
def starts_with
|
78
|
+
dirs = key.split("/")
|
79
|
+
dirs.pop
|
80
|
+
dirs.join("/")
|
81
|
+
end
|
82
|
+
|
77
83
|
private
|
78
84
|
|
79
85
|
def policy_expiration
|
data/test/form_test.rb
CHANGED
@@ -87,7 +87,7 @@ describe S3FormPresenter::Form do
|
|
87
87
|
"secret_key" => "test_secret_key",
|
88
88
|
"acl" => "private",
|
89
89
|
"success_action_redirect" => "http://www.some-test-redirect.com/some/path",
|
90
|
-
"policy" =>
|
90
|
+
"policy" => 324,
|
91
91
|
"signature" => 75
|
92
92
|
}.each_with_index do |field, i|
|
93
93
|
name = field.first
|
@@ -107,7 +107,7 @@ describe S3FormPresenter::Form do
|
|
107
107
|
conditions = obj["conditions"]
|
108
108
|
obj["expiration"].must_equal (Time.now + (10*60*60)).utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
109
109
|
conditions[0]["bucket"].must_equal "test_bucket"
|
110
|
-
conditions[1].must_equal ["starts-with", "$key", "some/test
|
110
|
+
conditions[1].must_equal ["starts-with", "$key", "some/test"]
|
111
111
|
conditions[2]["acl"].must_equal :private
|
112
112
|
conditions[3]["success_action_redirect"].must_equal "http://www.some-test-redirect.com/some/path"
|
113
113
|
end
|
@@ -115,7 +115,7 @@ describe S3FormPresenter::Form do
|
|
115
115
|
|
116
116
|
describe "policy" do
|
117
117
|
it "generates the base64 encoded policy used in the form" do
|
118
|
-
@form.policy.length.must_equal
|
118
|
+
@form.policy.length.must_equal 280
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -131,6 +131,18 @@ describe S3FormPresenter::Form do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
+
describe "starts_with" do
|
135
|
+
it "returns the key's path only when a dollar sign is passed" do
|
136
|
+
@form.key = "some/key/path/${filename}"
|
137
|
+
@form.starts_with.must_equal "some/key/path"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns the key's path only when an explicit path is passed" do
|
141
|
+
@form.key = "some/key/path/filename"
|
142
|
+
@form.starts_with.must_equal "some/key/path"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
134
146
|
describe "to_html" do
|
135
147
|
it "raise an exception if required attributes are not specified" do
|
136
148
|
proc { Form.new("some/key", "somepath").to_html }.must_raise RuntimeError
|
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.6
|
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: -1143773170301607079
|
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: -1143773170301607079
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project: s3_form_presenter
|
59
59
|
rubygems_version: 1.8.15
|