ungulate 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
data/lib/ungulate.rb CHANGED
@@ -4,8 +4,7 @@ require 'ungulate/server'
4
4
  module Ungulate
5
5
  end
6
6
 
7
- if defined? Rails
8
- return if ActionView::Base.instance_methods.include_method? :ungulate_upload_form_for
7
+ if defined? ActionView::Base
9
8
  require 'ungulate/view_helpers'
10
9
  ActionView::Base.send :include, ViewHelpers
11
10
  end
@@ -1,4 +1,4 @@
1
- require 'active_support'
1
+ require 'active_support/all'
2
2
  class Ungulate::FileUpload
3
3
  attr_accessor(
4
4
  :bucket_url,
@@ -1,15 +1,29 @@
1
1
  module ViewHelpers
2
2
  def ungulate_upload_form_for(upload, &block)
3
- concat(%Q(<form action="#{upload.bucket_url}" enctype="multipart/form-data" method="post">\n))
4
- concat("<div>\n")
5
- concat(%Q(<input name="key" type="hidden" value="#{upload.key}" />\n))
6
- concat(%Q(<input name="AWSAccessKeyId" type="hidden" value="#{upload.access_key_id}" />\n))
7
- concat(%Q(<input name="acl" type="hidden" value="#{upload.acl}" />\n))
8
- concat(%Q(<input name="policy" type="hidden" value="#{upload.policy}" />\n))
9
- concat(%Q(<input name="signature" type="hidden" value="#{upload.signature}" />\n))
10
- concat(%Q(<input name="success_action_redirect" type="hidden" value="#{upload.success_action_redirect}" />\n))
11
- yield
12
- concat("\n</div>\n")
13
- concat("</form>\n")
3
+ open_form = <<HTML
4
+ <form action="#{upload.bucket_url}" enctype="multipart/form-data" method="post">
5
+ <div>
6
+ <input name="key" type="hidden" value="#{upload.key}" />
7
+ <input name="AWSAccessKeyId" type="hidden" value="#{upload.access_key_id}" />
8
+ <input name="acl" type="hidden" value="#{upload.acl}" />
9
+ <input name="policy" type="hidden" value="#{upload.policy}" />
10
+ <input name="signature" type="hidden" value="#{upload.signature}" />
11
+ <input name="success_action_redirect" type="hidden" value="#{upload.success_action_redirect}" />
12
+ HTML
13
+
14
+ close_form = "\n</div>\n</form>\n"
15
+
16
+ if respond_to?(:safe_concat)
17
+ debugger if $debug
18
+ content = capture(&block)
19
+ output = ActiveSupport::SafeBuffer.new
20
+ output.safe_concat(open_form.html_safe)
21
+ output << content
22
+ output.safe_concat(close_form.html_safe)
23
+ else
24
+ concat(open_form)
25
+ yield
26
+ concat(close_form)
27
+ end
14
28
  end
15
29
  end
data/spec/spec.opts CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --debugger
3
+ -b
@@ -1,7 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'ungulate/view_helpers'
3
+ require 'active_support/all'
3
4
 
4
- class Includer
5
+ class Rails2Includer
5
6
  include ViewHelpers
6
7
  attr_accessor :output_buffer
7
8
 
@@ -10,13 +11,13 @@ class Includer
10
11
  end
11
12
  end
12
13
 
14
+ class Rails3Includer
15
+ include ViewHelpers
16
+ end
17
+
13
18
  module Ungulate
14
19
  describe ViewHelpers do
15
20
  describe "ungulate_upload_form_for" do
16
- def helper
17
- @helper ||= Includer.new
18
- end
19
-
20
21
  before do
21
22
  @file_upload = mock('Ungulate::FileUpload',
22
23
  :access_key_id => 'awsaccesskeyid',
@@ -26,14 +27,22 @@ module Ungulate
26
27
  :policy => 'thepolicy',
27
28
  :signature => 'thesignature',
28
29
  :success_action_redirect => '/some/place')
29
- helper.output_buffer = ''
30
- helper.ungulate_upload_form_for(@file_upload) do
31
- helper.concat('text in the middle')
32
- end
33
30
  end
34
31
 
35
- it "should have a complete form" do
36
- helper.output_buffer.should == <<-HTML
32
+ context "rails 2.3.x style" do
33
+ def helper
34
+ @helper ||= Rails2Includer.new
35
+ end
36
+
37
+ before do
38
+ helper.output_buffer = ''
39
+ helper.ungulate_upload_form_for(@file_upload) do
40
+ helper.concat('text in the middle')
41
+ end
42
+ end
43
+
44
+ it "should have a complete form" do
45
+ helper.output_buffer.should == <<-HTML
37
46
  <form action="http://static.test.s3.amazonaws.com/" enctype="multipart/form-data" method="post">
38
47
  <div>
39
48
  <input name="key" type="hidden" value="some/key" />
@@ -45,7 +54,30 @@ module Ungulate
45
54
  text in the middle
46
55
  </div>
47
56
  </form>
48
- HTML
57
+ HTML
58
+ end
59
+ end
60
+
61
+ context "rails 3 style" do
62
+ def helper
63
+ @helper ||= Rails3Includer.new
64
+ end
65
+
66
+ before do
67
+ helper.stub(:respond_to?).with(:safe_concat).and_return(true)
68
+ helper.stub(:capture)
69
+ @safe_buffer = mock('SafeBuffer', :<< => nil, :safe_concat => nil)
70
+ ActiveSupport::SafeBuffer.stub(:new).and_return(@safe_buffer)
71
+ end
72
+
73
+ it "should use a SafeBuffer" do
74
+ @safe_buffer.should_receive(:safe_concat).ordered
75
+ @safe_buffer.should_receive(:<<).ordered
76
+ @safe_buffer.should_receive(:safe_concat).ordered
77
+ helper.ungulate_upload_form_for(@file_upload) do
78
+ helper.safe_concat('text in the middle')
79
+ end
80
+ end
49
81
  end
50
82
  end
51
83
  end
data/ungulate.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ungulate}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Bruce"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-11-29}
13
13
  s.default_executable = %q{ungulate_server.rb}
14
14
  s.description = %q{WIP}
15
15
  s.email = %q{andrew@camelpunch.com}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ungulate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Bruce
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-03 00:00:00 +00:00
18
+ date: 2010-11-29 00:00:00 +00:00
19
19
  default_executable: ungulate_server.rb
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency