s3_form_presenter 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3_form_presenter (0.0.3)
4
+ s3_form_presenter (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module S3FormPresenter
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,6 +7,7 @@ module S3FormPresenter
7
7
  HIDDEN_FIELD_NAMES = :key, :access_key, :secret_key, :acl, :redirect_url, :policy, :signature
8
8
  ACCESSOR_FIELDS = HIDDEN_FIELD_NAMES - [:policy, :signature]
9
9
  RENAMED_FIELDS = {:redirect_url => "success_action_redirect", :access_key => "AWSAccessKeyId"}
10
+ REQUIRED_ATTRIBUTES = [:bucket] + HIDDEN_FIELD_NAMES
10
11
  attr_accessor :bucket, :inner_content, :extra_form_attributes
11
12
 
12
13
  def initialize(key, redirect_url, options={}, &block)
@@ -26,7 +27,7 @@ module S3FormPresenter
26
27
  end
27
28
 
28
29
  def header
29
- %Q(<form action="http://#{bucket}.s3.amazonaws.com/" method="post" enctype="multipart/form-data"#{extra_form_attributes}>)
30
+ %Q(<form action="https://#{bucket}.s3.amazonaws.com/" method="post" enctype="multipart/form-data"#{extra_form_attributes}>)
30
31
  end
31
32
 
32
33
  def footer
@@ -44,6 +45,7 @@ module S3FormPresenter
44
45
  end
45
46
 
46
47
  def to_html
48
+ validate_required
47
49
  content = ""
48
50
  content += header
49
51
  content += hidden_fields.join
@@ -82,5 +84,11 @@ module S3FormPresenter
82
84
  self.class.send(:attr_accessor, field) unless self.class.respond_to?(field)
83
85
  end
84
86
  end
87
+
88
+ def validate_required
89
+ REQUIRED_ATTRIBUTES.each do |attr|
90
+ raise "#{attr} has not been specified." unless send(attr)
91
+ end
92
+ end
85
93
  end
86
94
  end
data/test/form_test.rb CHANGED
@@ -4,6 +4,10 @@ include S3FormPresenter
4
4
 
5
5
  describe S3FormPresenter::Form do
6
6
  before do
7
+ ENV["AWS_ACCESS_KEY_ID"] = nil
8
+ ENV["AWS_SECRET_ACCESS_KEY"] = nil
9
+ ENV["AWS_S3_BUCKET"] = nil
10
+
7
11
  @form = Form.new("some/test/key.ext", "http://www.someurl.com/comeback") do
8
12
  %Q(<input name="file" type="file"><input type="submit" value="Upload File" class="btn btn-primary">)
9
13
  end
@@ -48,8 +52,8 @@ describe S3FormPresenter::Form do
48
52
  end
49
53
 
50
54
  describe "header" do
51
- it "generates a multi-part post form with the correct path" do
52
- @form.header.must_equal %Q(<form action="http://test_bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">)
55
+ it "generates a multi-part post form with the correct path (https protocol)" do
56
+ @form.header.must_equal %Q(<form action="https://test_bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">)
53
57
  end
54
58
  end
55
59
 
@@ -76,7 +80,24 @@ describe S3FormPresenter::Form do
76
80
 
77
81
  describe "hidden_fields" do
78
82
  it "generates HTML for each hidden_field" do
79
- #@form.hidden_fields.must_equal []
83
+ fields = @form.hidden_fields
84
+ {
85
+ "key" => "some/test/key.ext",
86
+ "access_key" => "test_access_key",
87
+ "secret_key" => "test_secret_key",
88
+ "acl" => "private",
89
+ "redirect_url" => "http://www.some-test-redirect.com/some/path",
90
+ "policy" => 332,
91
+ "signature" => 75
92
+ }.each_with_index do |field, i|
93
+ name = field.first
94
+ value = field.last
95
+ if value.is_a? String
96
+ fields[i].must_equal %Q(<input type="hidden" name="#{name}" value="#{value}">)
97
+ elsif value.is_a? Integer
98
+ fields[i].length.must_equal value
99
+ end
100
+ end
80
101
  end
81
102
  end
82
103
 
@@ -111,6 +132,12 @@ describe S3FormPresenter::Form do
111
132
  end
112
133
 
113
134
  describe "to_html" do
135
+ it "raise an exception if required attributes are not specified" do
136
+ proc { Form.new("some/key", "somepath").to_html }.must_raise RuntimeError
137
+ proc { Form.new("some/key", "somepath", :bucket => 'test-bucket').to_html }.must_raise RuntimeError
138
+ proc { Form.new("some/key", "somepath", :bucket => 'test-bucket', :access_key => 'access-key').to_html }.must_raise RuntimeError
139
+ end
140
+
114
141
  it "generates the full html of the form" do
115
142
  content = @form.header + @form.hidden_fields.join + @form.inner_content + @form.footer
116
143
  #content = "" # comment out if you want to see real output
@@ -120,7 +147,7 @@ describe S3FormPresenter::Form do
120
147
 
121
148
  describe "extra_form_attributes" do
122
149
  it "generates extra form attributes when provided in options" do
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">)
150
+ Form.new("some/key.ext", "http://www.someurl.com/comeback", :bucket => "test-bucket", :extra_form_attributes => %Q( class="form-horizontal")).header.must_equal %Q(<form action="https://test-bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data" class="form-horizontal">)
124
151
  end
125
152
  end
126
153
  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.3
4
+ version: 0.0.4
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: 3980563017398046619
47
+ hash: -656444126701832416
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: 3980563017398046619
56
+ hash: -656444126701832416
57
57
  requirements: []
58
58
  rubyforge_project: s3_form_presenter
59
59
  rubygems_version: 1.8.15