carrierwave_direct 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -69,31 +69,51 @@ Remove the line `storage :file` and replace it with `include CarrierWaveDirect::
69
69
 
70
70
  This adds the extra functionality for direct uploading.
71
71
 
72
- If you're *not* using Rails you can generate a direct upload form to S3 similar to this (see also [http://doc.s3.amazonaws.com/proposals/post.html#A_Sample_Form](http://doc.s3.amazonaws.com/proposals/post.html#A_Sample_Form)):
73
-
74
- <form action="https://s3-bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
75
- <input type="hidden" name="key" value="uploads/${filename}">
76
- <input type="hidden" name="AWSAccessKeyId" value="YOUR_AWS_ACCESS_KEY">
77
- <input type="hidden" name="acl" value="private">
78
- <input type="hidden" name="success_action_redirect" value="http://localhost/">
79
- <input type="hidden" name="policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED">
80
- <input type="hidden" name="signature" value="YOUR_CALCULATED_SIGNATURE">
81
- <input name="file" type="file">
82
- <input type="submit" value="Upload to S3">
83
- </form>
84
-
85
- by making use of the following methods in your uploader:
86
-
87
- uploader = AvatarUploader.new
88
-
89
- uploader.direct_fog_url # return the url to post to based off your bucket name
90
- uploader.key # returns a key based off your store_dir
91
- uploader.aws_access_key_id # returns your aws_access_key_id from your fog configuration
92
- uploader.acl # returns your acl from your fog configuration
93
- uploader.success_action_redirect= # sets the success action redirect url
94
- uploader.success_action_redirect # gets the success action redirect url
95
- uploader.policy # a base 64 encoded policy document
96
- uploader.signature # your signature
72
+ Finally, remove the `store_dir` method in order to default CarrierWaveDirect to its own storage directory.
73
+
74
+ If you're *not* using Rails you can generate a direct upload form to S3 similar to [this example](http://doc.s3.amazonaws.com/proposals/post.html#A_Sample_Form)) by making use of the CarrierWaveDirect helper methods.
75
+
76
+ ### Sinatra
77
+
78
+ Here is an example using Sinatra and Haml
79
+
80
+ # uploader_test.rb
81
+
82
+ CarrierWave.configure do |config|
83
+ config.fog_credentials = {
84
+ :provider => 'AWS',
85
+ :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
86
+ :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
87
+ }
88
+ config.fog_directory = ENV['AWS_FOG_DIRECTORY'] # bucket name
89
+ end
90
+
91
+ class ImageUploader < CarrierWave::Uploader::Base
92
+ include CarrierWaveDirect::Uploader
93
+ end
94
+
95
+ class UploaderTest < Sinatra::Base
96
+ get "/" do
97
+ @uploader = ImageUploader.new
98
+ @uploader.success_action_redirect = request.url
99
+ haml :index
100
+ end
101
+ end
102
+
103
+ # index.haml
104
+
105
+ %form{:action => @uploader.direct_fog_url, :method => "post", :enctype => "multipart/form-data"}
106
+ %input{:name => "utf8", :type => "hidden"}
107
+ %input{:type => "hidden", :name => "key", :value => @uploader.key}
108
+ %input{:type => "hidden", :name => "AWSAccessKeyId", :value => @uploader.aws_access_key_id}
109
+ %input{:type => "hidden", :name => "acl", :value => @uploader.acl}
110
+ %input{:type => "hidden", :name => "success_action_redirect", :value => @uploader.success_action_redirect}
111
+ %input{:type => "hidden", :name => "policy", :value => @uploader.policy}
112
+ %input{:type => "hidden", :name => "signature", :value => @uploader.signature}
113
+ %input{:name => "file", :type => "file"}
114
+ %input{:type => "submit", :value => "Upload to S3"}
115
+
116
+ ### Rails
97
117
 
98
118
  If you *are* using Rails and you've mounted your uploader like this:
99
119
 
@@ -217,7 +237,7 @@ Your users may find it convenient to upload a file from a location on the Intern
217
237
 
218
238
  <%= form_for @user do |f| %>
219
239
  <%= f.hidden_field :key %>
220
- <% unless @hangover.has_avatar_upload? %>
240
+ <% unless @user.has_avatar_upload? %>
221
241
  <%= f.label :remote_avatar_net_url %>
222
242
  <%= f.text_field :remote_avatar_net_url %>
223
243
  <%= f.submit %>
@@ -308,13 +328,13 @@ To attach a file to the direct upload form you can use
308
328
 
309
329
  To simulate a successful upload and redirect to S3 you can use
310
330
 
311
- upload_directly(AvatarUploader, "Upload to S3")
331
+ upload_directly(AvatarUploader.new, "Upload to S3")
312
332
 
313
333
  This will click the Upload to S3 button on the form and redirect you to the `success_action_redirect` url (in the form) with a sample response from S3
314
334
 
315
335
  To simulate an unsuccessful upload you can pass `:success => false` and you'll remain on the upload page e.g.
316
336
 
317
- upload_directly(AvatarUploader, "Upload to S3", :success => false)
337
+ upload_directly(AvatarUploader.new, "Upload to S3", :success => false)
318
338
 
319
339
  You can also use `find_key` and `find_upload_path` to get the key and upload path from the form
320
340
 
@@ -356,8 +376,8 @@ The Active Record validations use the Rails i18n framework. Add these keys to yo
356
376
  carrierwave_direct_filename_taken: filename was already taken
357
377
  carrierwave_direct_upload_missing: upload is missing
358
378
  carrierwave_direct_attachment_missing: attachment is missing
359
- carrierwave_direct_filename_invalid: is invalid. Allowed file types are ${extension_white_list}
360
- carrierwave_direct_remote_net_url_invalid: is invalid. Allowed file types are ${extension_white_list}. Allowed url schemes are ${url_scheme_white_list}
379
+ carrierwave_direct_filename_invalid: is invalid. Allowed file types are %{extension_white_list}
380
+ carrierwave_direct_remote_net_url_invalid: is invalid. Allowed file types are %{extension_white_list}. Allowed url schemes are %{url_scheme_white_list}
361
381
 
362
382
  ## Caveats
363
383
 
@@ -381,3 +401,5 @@ You should now be able to run the tests
381
401
  * [tylr (Tyler Love)](https://github.com/tylr) - Bug fix
382
402
  * [vlado (Vlado Cingel)](https://github.com/vlado) - Properly sanitize filename
383
403
  * [travisp (Travis Pew)](https://github.com/travisp) - Compatibility for CarrierWave 0.6.0
404
+ * [jgorset (Johannes Gorset)](https://github.com/jgorset) - Added note about removing 'store_dir' in README
405
+ * [frahugo (Hugo Frappier)](https://github.com/frahugo) - Fix bug where CarrierWaveDirect Validations were being added to non CarrierWaveDirect ActiveRecord models
@@ -1,5 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # This file tests that a ActiveRecord class that uses a standard CarrierWave uploader
4
+ # does not get CarrierWaveDirect validators.
5
+
3
6
  require 'active_record'
4
7
  require 'carrierwave_direct/validations/active_model'
5
8
 
@@ -10,6 +13,9 @@ module CarrierWaveDirect
10
13
  def mount_uploader(column, uploader=nil, options={}, &block)
11
14
  super
12
15
 
16
+ # Don't go further unless the class included CarrierWaveDirect::Uploader
17
+ return unless uploader.ancestors.include?(CarrierWaveDirect::Uploader)
18
+
13
19
  uploader.instance_eval <<-RUBY, __FILE__, __LINE__+1
14
20
  include ActiveModel::Conversion
15
21
  extend ActiveModel::Naming
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CarrierwaveDirect
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
6
6
 
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'carrierwave/orm/activerecord'
5
+ require 'carrierwave_direct/orm/activerecord'
6
+
7
+ describe CarrierWave::ActiveRecord do
8
+ dbconfig = {
9
+ :adapter => 'sqlite3',
10
+ :database => ':memory:'
11
+ }
12
+
13
+ class OtherTestMigration < ActiveRecord::Migration
14
+ def self.up
15
+ create_table :other_parties, :force => true do |t|
16
+ t.column :video, :string
17
+ end
18
+ end
19
+
20
+ def self.down
21
+ drop_table :other_parties
22
+ end
23
+ end
24
+
25
+ class StandardUploader < CarrierWave::Uploader::Base
26
+ end
27
+
28
+ class OtherParty < ActiveRecord::Base
29
+ # mount_uploader :video, StandardUploader
30
+ end
31
+
32
+ ActiveRecord::Base.establish_connection(dbconfig)
33
+
34
+ # turn off migration output
35
+ ActiveRecord::Migration.verbose = false
36
+
37
+ before(:all) { OtherTestMigration.up }
38
+ after(:all) { OtherTestMigration.down }
39
+ after { OtherParty.delete_all }
40
+
41
+ describe "class OtherParty < ActiveRecord::Base; mount_uploader :video, StandardUploader; end" do
42
+ $arclass = 0
43
+
44
+ let(:party_class) do
45
+ Class.new(OtherParty)
46
+ end
47
+
48
+ let(:subject) do
49
+ party = party_class.new
50
+ end
51
+
52
+ before do
53
+ # see https://github.com/jnicklas/carrierwave/blob/master/spec/orm/activerecord_spec.rb
54
+ $arclass += 1
55
+ Object.const_set("OtherParty#{$arclass}", party_class)
56
+ party_class.table_name = "other_parties"
57
+ end
58
+
59
+ describe "#mount_uploader" do
60
+ it "does not inject CarrierWaveDirect validation into ActiveRecord class" do
61
+ subject.class.mount_uploader :video, StandardUploader
62
+
63
+ subject.class.ancestors.should_not include(CarrierWaveDirect::Validations::ActiveModel)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000Z
12
+ date: 2012-07-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
16
- requirement: &75422450 !ruby/object:Gem::Requirement
16
+ requirement: &71299690 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75422450
24
+ version_requirements: *71299690
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: uuid
27
- requirement: &75422160 !ruby/object:Gem::Requirement
27
+ requirement: &71299200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *75422160
35
+ version_requirements: *71299200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fog
38
- requirement: &75421880 !ruby/object:Gem::Requirement
38
+ requirement: &71298880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *75421880
46
+ version_requirements: *71298880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &75421510 !ruby/object:Gem::Requirement
49
+ requirement: &71298350 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *75421510
57
+ version_requirements: *71298350
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: timecop
60
- requirement: &75421180 !ruby/object:Gem::Requirement
60
+ requirement: &71297740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *75421180
68
+ version_requirements: *71297740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rails
71
- requirement: &75420760 !ruby/object:Gem::Requirement
71
+ requirement: &71297330 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *75420760
79
+ version_requirements: *71297330
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sqlite3
82
- requirement: &75420100 !ruby/object:Gem::Requirement
82
+ requirement: &71296950 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *75420100
90
+ version_requirements: *71296950
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: capybara
93
- requirement: &75419660 !ruby/object:Gem::Requirement
93
+ requirement: &71296410 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *75419660
101
+ version_requirements: *71296410
102
102
  description: Process your uploads in the background by uploading directly to S3
103
103
  email:
104
104
  - dwilkie@gmail.com
@@ -130,6 +130,7 @@ files:
130
130
  - spec/form_builder_spec.rb
131
131
  - spec/mount_spec.rb
132
132
  - spec/orm/activerecord_spec.rb
133
+ - spec/orm/indirect_activerecord_spec.rb
133
134
  - spec/spec_helper.rb
134
135
  - spec/support/carrier_wave_config.rb
135
136
  - spec/support/direct_uploader.rb
@@ -156,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  segments:
158
159
  - 0
159
- hash: 300511313
160
+ hash: -508082893
160
161
  required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  none: false
162
163
  requirements:
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  version: '0'
166
167
  segments:
167
168
  - 0
168
- hash: 300511313
169
+ hash: -508082893
169
170
  requirements: []
170
171
  rubyforge_project: carrierwave_direct
171
172
  rubygems_version: 1.8.10