carrierwave_direct 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/Changelog.md +10 -0
- data/README.md +25 -3
- data/carrierwave_direct.gemspec +2 -3
- data/gemfiles/3.2.gemfile +0 -1
- data/gemfiles/4.0.gemfile +0 -1
- data/gemfiles/4.1.gemfile +0 -1
- data/lib/carrierwave_direct/form_builder.rb +2 -0
- data/lib/carrierwave_direct/mount.rb +16 -4
- data/lib/carrierwave_direct/orm/activerecord.rb +1 -1
- data/lib/carrierwave_direct/test/capybara_helpers.rb +4 -2
- data/lib/carrierwave_direct/uploader.rb +13 -9
- data/lib/carrierwave_direct/validations/active_model.rb +1 -1
- data/lib/carrierwave_direct/version.rb +1 -1
- data/lib/carrierwave_direct.rb +1 -2
- data/spec/mount_spec.rb +1 -1
- data/spec/orm/activerecord_spec.rb +41 -10
- data/spec/support/view_helpers.rb +1 -1
- data/spec/test/capybara_helpers_spec.rb +3 -4
- data/spec/uploader/direct_url_spec.rb +2 -3
- data/spec/uploader_spec.rb +37 -26
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c51cb71409e58177ac38cc749d3f596766f0ab8e
|
4
|
+
data.tar.gz: 98aeee5a704ec4221825bad26fe3a379c2b65049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42a18d958215b315f02c644842750bef8466cfefa9410c5fd72011350e09035bc22bf86b20672c3fa5273fd6989bdbf8c090a217982b1257d60b37eed6633fdb
|
7
|
+
data.tar.gz: 419fb4c392fa4eb322e1105bf1c6ca815c85fb7c4b3841ef96f10b2a03760ec2322ba1df82ae565671fdba338e23062dd520b5248411afe032b74b042414212b
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.9.3
|
3
2
|
- 2.0.0
|
4
3
|
- 2.1.0
|
4
|
+
- 2.2.0
|
5
5
|
install:
|
6
6
|
- 'travis_retry bundle install'
|
7
7
|
script: 'bundle exec rspec spec'
|
@@ -10,3 +10,5 @@ gemfile:
|
|
10
10
|
- gemfiles/3.2.gemfile
|
11
11
|
- gemfiles/4.0.gemfile
|
12
12
|
- gemfiles/4.1.gemfile
|
13
|
+
# Move to containerized travis, see http://docs.travis-ci.com/user/migrating-from-legacy
|
14
|
+
sudo: false
|
data/Changelog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### Unreleased changes
|
2
|
+
|
3
|
+
Bug Fixes:
|
4
|
+
* Allow uploader columns to be named `file` (Diego Plentz @plentz and Moisés Viloria @mois3x)
|
5
|
+
* `["starts-with", "$utf8", ""]` is not needed as condition (Rocco Galluzzo @byterussian)
|
6
|
+
|
7
|
+
Misc:
|
8
|
+
* Dropped support for ruby 1.9, it has [reached its end of life](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)
|
9
|
+
* Add 2.2.0 support to travis.
|
10
|
+
|
1
11
|
### 0.0.15
|
2
12
|
|
3
13
|
[Full Changes](https://github.com/dwilkie/carrierwave_direct/compare/v0.0.14...v0.0.15)
|
data/README.md
CHANGED
@@ -156,7 +156,7 @@ end
|
|
156
156
|
After uploading to S3, You'll need to update the uploader object with the returned key in the controller action that corresponds to `new_user_url`:
|
157
157
|
|
158
158
|
```ruby
|
159
|
-
@uploader.update_attribute :
|
159
|
+
@uploader.update_attribute :avatar_key, params[:key]
|
160
160
|
```
|
161
161
|
|
162
162
|
You can also pass html options like this:
|
@@ -429,6 +429,29 @@ CarrierWave.configure do |config|
|
|
429
429
|
end
|
430
430
|
```
|
431
431
|
|
432
|
+
## Bucket CORS configuration and usage with CloudFront
|
433
|
+
|
434
|
+
If you are using a javascript uploader (e.g. Dropzone, jQuery Upload, Uploadify, etc.) you will need to add CORS configuration to your bucket, otherwise default bucket configuration will deny CORS requests. To do that open your bucket in Amazon console, click on its properties and add a CORS configuration similar to this
|
435
|
+
|
436
|
+
```xml
|
437
|
+
<CORSConfiguration>
|
438
|
+
<CORSRule>
|
439
|
+
<!-- Optionally change this with your domain, it should not be an issue since your bucket accepts only signed writes -->
|
440
|
+
<AllowedOrigin>*</AllowedOrigin>
|
441
|
+
<AllowedMethod>GET</AllowedMethod>
|
442
|
+
<AllowedMethod>POST</AllowedMethod>
|
443
|
+
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
444
|
+
<AllowedHeader>Authorization</AllowedHeader>
|
445
|
+
<AllowedHeader>Content-Type</AllowedHeader>
|
446
|
+
<AllowedHeader>Origin</AllowedHeader>
|
447
|
+
</CORSRule>
|
448
|
+
</CORSConfiguration>
|
449
|
+
```
|
450
|
+
|
451
|
+
When you use this gem in conjunction with CloudFront you'll need an additional step otherwise it won't work as expected. This is strictly necessary if you configured CarrierWave `asset_host` to use a CloudFront in front of your bucket because your forms will be posted to that url.
|
452
|
+
|
453
|
+
To solve this issue you must enable POST requests in your CloudFront distribution settings. Here is a [step by step walkthrough](http://blog.celingest.com/en/2014/10/02/tutorial-using-cors-with-cloudfront-and-s3/) that explain this setup. It also explain CORS configuration.
|
454
|
+
|
432
455
|
## Testing with CarrierWaveDirect
|
433
456
|
|
434
457
|
CarrierWaveDirect provides a couple of helpers to help with integration and unit testing. You don't want to contact the Internet during your tests as this is slow, expensive and unreliable. You should first put fog into mock mode by doing something like this.
|
@@ -531,8 +554,6 @@ en:
|
|
531
554
|
|
532
555
|
## Caveats
|
533
556
|
|
534
|
-
Don't name your string column `file`. It will result in a stack level too deep exception. See [this issue](https://github.com/dwilkie/carrierwave_direct/issues/10) for more info.
|
535
|
-
|
536
557
|
If you're Rails app was newly generated *after* version 3.2.3 and your testing this in development you may run into an issue where an `ActiveModel::MassAssignmentSecurity::Error` is raised when being redirected from S3. You can fix this by setting `config.active_record.mass_assignment_sanitizer = :logger` in your `config/environments/development.rb` file.
|
537
558
|
|
538
559
|
## Contributing to CarrierWaveDirect
|
@@ -575,3 +596,4 @@ Thank you to everybody who has contributed to [CarrierWaveDirect](https://github
|
|
575
596
|
* [colinyoung (Colin Young)](https://github.com/colinyoung) - Content-Type support
|
576
597
|
* [jkamenik (John Kamenik)](https://github.com/jkamenik) - Content-Type support
|
577
598
|
* [filiptepper (Filip Tepper)](https://github.com/filiptepper) - Autoload UUID on heroku
|
599
|
+
* [mois3x (Moisés Viloria)](https://github.com/mois3x) and [plentz (Diego Plentz)](https://github.com/plentz) - Allow uploader columns to be named `file`
|
data/carrierwave_direct.gemspec
CHANGED
@@ -10,13 +10,12 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/dwilkie/carrierwave_direct"
|
11
11
|
s.summary = %q{Upload direct to S3 using CarrierWave}
|
12
12
|
s.description = %q{Process your uploads in the background by uploading directly to S3}
|
13
|
-
s.required_ruby_version = ">=
|
13
|
+
s.required_ruby_version = ">= 2.0.0"
|
14
14
|
|
15
15
|
s.rubyforge_project = "carrierwave_direct"
|
16
16
|
|
17
17
|
s.add_dependency "carrierwave"
|
18
|
-
s.add_dependency "
|
19
|
-
s.add_dependency "fog"
|
18
|
+
s.add_dependency "fog-aws"
|
20
19
|
|
21
20
|
s.add_development_dependency "rspec"
|
22
21
|
s.add_development_dependency "timecop"
|
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/4.0.gemfile
CHANGED
data/gemfiles/4.1.gemfile
CHANGED
@@ -9,10 +9,12 @@ module CarrierWaveDirect
|
|
9
9
|
# Don't go further unless the class included CarrierWaveDirect::Uploader
|
10
10
|
return unless uploader.ancestors.include?(CarrierWaveDirect::Uploader)
|
11
11
|
|
12
|
-
uploader.
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
unless uploader.instance_methods.include?(column)
|
13
|
+
uploader.class_eval <<-RUBY, __FILE__, __LINE__+1
|
14
|
+
def #{column}; self; end
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
16
18
|
self.instance_eval <<-RUBY, __FILE__, __LINE__+1
|
17
19
|
attr_accessor :remote_#{column}_net_url
|
18
20
|
RUBY
|
@@ -22,10 +24,20 @@ module CarrierWaveDirect
|
|
22
24
|
mod.class_eval <<-RUBY, __FILE__, __LINE__+1
|
23
25
|
|
24
26
|
def key
|
27
|
+
warn "key method is deprecated, please use column_key method instead."
|
25
28
|
send(:#{column}).key
|
26
29
|
end
|
27
30
|
|
28
31
|
def key=(k)
|
32
|
+
warn "key= method is deprecated, please use column_key= method instead."
|
33
|
+
send(:#{column}).key = k
|
34
|
+
end
|
35
|
+
|
36
|
+
def #{column}_key
|
37
|
+
send(:#{column}).key
|
38
|
+
end
|
39
|
+
|
40
|
+
def #{column}_key=(k)
|
29
41
|
send(:#{column}).key = k
|
30
42
|
end
|
31
43
|
|
@@ -32,7 +32,7 @@ module CarrierWaveDirect
|
|
32
32
|
self.instance_eval <<-RUBY, __FILE__, __LINE__+1
|
33
33
|
attr_accessor :skip_is_attached_validations
|
34
34
|
unless defined?(ActiveModel::ForbiddenAttributesProtection) && ancestors.include?(ActiveModel::ForbiddenAttributesProtection)
|
35
|
-
attr_accessible
|
35
|
+
attr_accessible :#{column}_key, :remote_#{column}_net_url
|
36
36
|
end
|
37
37
|
RUBY
|
38
38
|
|
@@ -33,12 +33,14 @@ module CarrierWaveDirect
|
|
33
33
|
sample_key_args.unshift(uploader) if method(:sample_key).arity == -2
|
34
34
|
options[:redirect_key] = sample_key(*sample_key_args)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
|
+
redirect_url_params = Rack::Utils.parse_nested_query(redirect_url.query)
|
38
|
+
|
37
39
|
redirect_url.query = Rack::Utils.build_nested_query({
|
38
40
|
:bucket => uploader.fog_directory,
|
39
41
|
:key => options[:redirect_key],
|
40
42
|
:etag => "\"d41d8cd98f00b204e9800998ecf8427\""
|
41
|
-
})
|
43
|
+
}.merge(redirect_url_params))
|
42
44
|
|
43
45
|
# click the button
|
44
46
|
click_button button_locator
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require "securerandom"
|
3
4
|
require "carrierwave_direct/uploader/content_type"
|
4
5
|
require "carrierwave_direct/uploader/direct_url"
|
5
6
|
|
@@ -29,12 +30,12 @@ module CarrierWaveDirect
|
|
29
30
|
fog_public ? 'public-read' : 'private'
|
30
31
|
end
|
31
32
|
|
32
|
-
def policy(options = {})
|
33
|
+
def policy(options = {}, &block)
|
33
34
|
options[:expiration] ||= upload_expiration
|
34
35
|
options[:min_file_size] ||= min_file_size
|
35
36
|
options[:max_file_size] ||= max_file_size
|
36
37
|
|
37
|
-
@policy ||= generate_policy(options)
|
38
|
+
@policy ||= generate_policy(options, &block)
|
38
39
|
end
|
39
40
|
|
40
41
|
def clear_policy!
|
@@ -61,7 +62,8 @@ module CarrierWaveDirect
|
|
61
62
|
def key
|
62
63
|
return @key if @key.present?
|
63
64
|
if present?
|
64
|
-
|
65
|
+
identifier = model.send("#{mounted_as}_identifier")
|
66
|
+
self.key = "#{store_dir}/#{identifier}"
|
65
67
|
else
|
66
68
|
@key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
|
67
69
|
end
|
@@ -74,7 +76,7 @@ module CarrierWaveDirect
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def guid
|
77
|
-
|
79
|
+
SecureRandom.uuid
|
78
80
|
end
|
79
81
|
|
80
82
|
def has_key?
|
@@ -133,10 +135,10 @@ module CarrierWaveDirect
|
|
133
135
|
end
|
134
136
|
|
135
137
|
def generate_policy(options)
|
136
|
-
conditions = [
|
137
|
-
|
138
|
-
|
139
|
-
]
|
138
|
+
conditions = []
|
139
|
+
|
140
|
+
conditions << ["starts-with", "$utf8", ""] if options[:enforce_utf8]
|
141
|
+
conditions << ["starts-with", "$key", key.sub(/#{Regexp.escape(FILENAME_WILDCARD)}\z/, "")]
|
140
142
|
|
141
143
|
conditions << ["starts-with", "$Content-Type", ""] if will_include_content_type
|
142
144
|
conditions << {"bucket" => fog_directory}
|
@@ -150,9 +152,11 @@ module CarrierWaveDirect
|
|
150
152
|
|
151
153
|
conditions << ["content-length-range", options[:min_file_size], options[:max_file_size]]
|
152
154
|
|
155
|
+
yield conditions if block_given?
|
156
|
+
|
153
157
|
Base64.encode64(
|
154
158
|
{
|
155
|
-
'expiration' => Time.now
|
159
|
+
'expiration' => (Time.now + options[:expiration]).utc.iso8601,
|
156
160
|
'conditions' => conditions
|
157
161
|
}.to_json
|
158
162
|
).gsub("\n","")
|
@@ -22,7 +22,7 @@ module CarrierWaveDirect
|
|
22
22
|
|
23
23
|
class FilenameFormatValidator < ::ActiveModel::EachValidator
|
24
24
|
def validate_each(record, attribute, value)
|
25
|
-
if record.send("has_#{attribute}_upload?") && record.
|
25
|
+
if record.send("has_#{attribute}_upload?") && record.send("#{attribute}_key") !~ record.send(attribute).key_regexp
|
26
26
|
extensions = record.send(attribute).extension_white_list
|
27
27
|
message = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
|
28
28
|
|
data/lib/carrierwave_direct.rb
CHANGED
data/spec/mount_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe CarrierWaveDirect::Mount do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
it_should_delegate(:
|
43
|
+
it_should_delegate(:video_key, :to => "video#key", :accessible => { "has_video_upload?" => false })
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -19,6 +19,9 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
19
19
|
create_table :dances, :force => true do |t|
|
20
20
|
t.column :location, :string
|
21
21
|
end
|
22
|
+
create_table :resources, :force => true do |t|
|
23
|
+
t.column :file, :string
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
def self.down
|
@@ -34,6 +37,10 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
34
37
|
class Dance < ActiveRecord::Base
|
35
38
|
end
|
36
39
|
|
40
|
+
class Resource < ActiveRecord::Base
|
41
|
+
mount_uploader :file, DirectUploader
|
42
|
+
end
|
43
|
+
|
37
44
|
ActiveRecord::Base.establish_connection(dbconfig)
|
38
45
|
|
39
46
|
# turn off migration output
|
@@ -111,7 +118,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
111
118
|
shared_examples_for "without an upload" do
|
112
119
|
before do
|
113
120
|
subject.remote_video_net_url = remote_video_net_url
|
114
|
-
subject.
|
121
|
+
subject.video_key = upload_path
|
115
122
|
end
|
116
123
|
|
117
124
|
it "should not be valid on create" do
|
@@ -162,7 +169,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
162
169
|
let(:dance) { Dance.new }
|
163
170
|
|
164
171
|
before { Dance.mount_uploader(:non_existing_column, DirectUploader, mount_on: :location) }
|
165
|
-
before { dance.
|
172
|
+
before { dance.non_existing_column_key = sample_key}
|
166
173
|
|
167
174
|
it "uses the column it's mounted on for checking uniqueness" do
|
168
175
|
expect { dance.valid? }.to_not raise_error
|
@@ -212,7 +219,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
212
219
|
context "where the file upload is" do
|
213
220
|
context "nil" do
|
214
221
|
before do
|
215
|
-
subject.
|
222
|
+
subject.video_key = nil
|
216
223
|
end
|
217
224
|
|
218
225
|
it "should be valid" do
|
@@ -222,7 +229,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
222
229
|
|
223
230
|
context "blank" do
|
224
231
|
before do
|
225
|
-
subject.
|
232
|
+
subject.video_key = ""
|
226
233
|
end
|
227
234
|
|
228
235
|
it "should be valid" do
|
@@ -238,7 +245,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
238
245
|
|
239
246
|
context "and the uploaded file's extension is included in the list" do
|
240
247
|
before do
|
241
|
-
subject.
|
248
|
+
subject.video_key = sample_key(:extension => "avi")
|
242
249
|
end
|
243
250
|
|
244
251
|
it "should be valid" do
|
@@ -248,7 +255,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
248
255
|
|
249
256
|
context "but uploaded file's extension is not included in the list" do
|
250
257
|
before do
|
251
|
-
subject.
|
258
|
+
subject.video_key = sample_key(:extension => "mp3")
|
252
259
|
end
|
253
260
|
|
254
261
|
it_should_behave_like "an invalid filename"
|
@@ -468,7 +475,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
468
475
|
|
469
476
|
context "with an upload by file" do
|
470
477
|
before do
|
471
|
-
subject.
|
478
|
+
subject.video_key = sample_key
|
472
479
|
end
|
473
480
|
|
474
481
|
it "should be valid" do
|
@@ -520,7 +527,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
520
527
|
|
521
528
|
describe "#key" do
|
522
529
|
it "should be accessible" do
|
523
|
-
party_class.new(:
|
530
|
+
party_class.new(:video_key => "some key").video_key.should == "some key"
|
524
531
|
end
|
525
532
|
end
|
526
533
|
|
@@ -554,7 +561,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
554
561
|
context "has an upload" do
|
555
562
|
context "with a valid filename" do
|
556
563
|
before do
|
557
|
-
subject.
|
564
|
+
subject.video_key = sample_key(:model_class => subject.class)
|
558
565
|
end
|
559
566
|
|
560
567
|
it "should be true" do
|
@@ -565,7 +572,7 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
565
572
|
end
|
566
573
|
|
567
574
|
context "with an invalid filename" do
|
568
|
-
before { subject.
|
575
|
+
before { subject.video_key = sample_key(:model_class => subject.class, :valid => false) }
|
569
576
|
|
570
577
|
it "should be false" do
|
571
578
|
subject.filename_valid?.should be false
|
@@ -582,4 +589,28 @@ describe CarrierWaveDirect::ActiveRecord do
|
|
582
589
|
end
|
583
590
|
end
|
584
591
|
end
|
592
|
+
|
593
|
+
describe "class Resource < ActiveRecord::Base; mount_uploader :file, DirectUploader; end" do
|
594
|
+
include UploaderHelpers
|
595
|
+
include ModelHelpers
|
596
|
+
|
597
|
+
let(:resource_class) do
|
598
|
+
Class.new(Resource)
|
599
|
+
end
|
600
|
+
|
601
|
+
let(:subject) do
|
602
|
+
resource = resource_class.new
|
603
|
+
end
|
604
|
+
|
605
|
+
def mount_uploader
|
606
|
+
resource_class.mount_uploader :file, DirectUploader
|
607
|
+
end
|
608
|
+
|
609
|
+
#See resource table migration
|
610
|
+
it "should be valid still when a file column exists in table" do
|
611
|
+
expect(subject).to be_valid
|
612
|
+
end
|
613
|
+
|
614
|
+
|
615
|
+
end
|
585
616
|
end
|
@@ -44,7 +44,7 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
|
|
44
44
|
|
45
45
|
def stub_common
|
46
46
|
stub_page
|
47
|
-
find_element_value("input[name='success_action_redirect']", "http://example.com", visible: false)
|
47
|
+
find_element_value("input[name='success_action_redirect']", "http://example.com?custom_param=value", visible: false)
|
48
48
|
allow(subject).to receive(:visit)
|
49
49
|
end
|
50
50
|
|
@@ -79,8 +79,8 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
|
|
79
79
|
|
80
80
|
it_should_behave_like "submitting the form"
|
81
81
|
|
82
|
-
it "should redirect to the page's success_action_redirect url" do
|
83
|
-
expect(subject).to receive(:visit).with(/^http:\/\/example.com/)
|
82
|
+
it "should redirect to the page's success_action_redirect url and preserve custom parameters" do
|
83
|
+
expect(subject).to receive(:visit).with(/^http:\/\/example.com\?.*custom_param=value/)
|
84
84
|
upload_directly
|
85
85
|
end
|
86
86
|
|
@@ -160,4 +160,3 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
163
|
-
|
@@ -7,6 +7,8 @@ describe CarrierWaveDirect::Uploader::DirectUrl do
|
|
7
7
|
|
8
8
|
let(:subject) { DirectUploader.new }
|
9
9
|
|
10
|
+
let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
|
11
|
+
|
10
12
|
describe "#direct_fog_url" do
|
11
13
|
it "should return the result from CarrierWave::Storage::Fog::File#public_url" do
|
12
14
|
expect(subject.direct_fog_url).to eq CarrierWave::Storage::Fog::File.new(
|
@@ -22,6 +24,3 @@ describe CarrierWaveDirect::Uploader::DirectUrl do
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
data/spec/uploader_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe CarrierWaveDirect::Uploader do
|
|
7
7
|
include ModelHelpers
|
8
8
|
|
9
9
|
let(:subject) { DirectUploader.new }
|
10
|
-
let(:mounted_model) { double(sample(:mounted_model_name)) }
|
10
|
+
let(:mounted_model) { double(sample(:mounted_model_name), video_identifier: sample(:stored_filename)) }
|
11
11
|
let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
|
12
12
|
let(:direct_subject) { DirectUploader.new }
|
13
13
|
|
@@ -73,6 +73,7 @@ describe CarrierWaveDirect::Uploader do
|
|
73
73
|
|
74
74
|
context "but the uploaders url is '#{sample(:s3_file_url)}'" do
|
75
75
|
before do
|
76
|
+
allow(mounted_subject).to receive(:store_dir).and_return(sample(:store_dir))
|
76
77
|
allow(mounted_subject).to receive(:url).and_return(sample(:s3_file_url))
|
77
78
|
allow(mounted_subject).to receive(:present?).and_return(true)
|
78
79
|
end
|
@@ -253,19 +254,6 @@ describe CarrierWaveDirect::Uploader do
|
|
253
254
|
end
|
254
255
|
end
|
255
256
|
|
256
|
-
context "and the model's remote url contains already escaped characters" do
|
257
|
-
before do
|
258
|
-
subject.key = nil
|
259
|
-
allow(subject).to receive(:present?).and_return(:true)
|
260
|
-
allow(subject).to receive(:url).and_return("http://anyurl.com/any_path/video_dir/filename%20%28%29%2B%5B%5D2.avi")
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should not double escape already escaped characters" do
|
264
|
-
expect(subject.key).to match /filename \(\)\+\[\]2.avi/
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
257
|
context "and the model's remote #{sample(:mounted_as)} url is blank" do
|
270
258
|
before do
|
271
259
|
allow(mounted_model).to receive(
|
@@ -288,9 +276,28 @@ describe CarrierWaveDirect::Uploader do
|
|
288
276
|
|
289
277
|
# http://aws.amazon.com/articles/1434?_encoding=UTF8
|
290
278
|
describe "#policy" do
|
291
|
-
|
279
|
+
|
280
|
+
|
281
|
+
def decoded_policy(options = {}, &block)
|
292
282
|
instance = options.delete(:subject) || subject
|
293
|
-
JSON.parse(Base64.decode64(instance.policy(options)))
|
283
|
+
JSON.parse(Base64.decode64(instance.policy(options, &block)))
|
284
|
+
end
|
285
|
+
|
286
|
+
context "policy is given a block" do
|
287
|
+
it "should yield the options to the block" do
|
288
|
+
number = 0
|
289
|
+
subject.policy do |conditions|
|
290
|
+
number+=1
|
291
|
+
end
|
292
|
+
expect(number).to eq 1
|
293
|
+
end
|
294
|
+
it "should include new options in the conditions" do
|
295
|
+
policy = subject.policy do |conditions|
|
296
|
+
conditions << {"x-aws-storage-class" => "STANDARD"}
|
297
|
+
end
|
298
|
+
decoded = JSON.parse(Base64.decode64(policy))
|
299
|
+
expect(decoded['conditions'].last['x-aws-storage-class']).to eq "STANDARD"
|
300
|
+
end
|
294
301
|
end
|
295
302
|
|
296
303
|
it "should return Base64-encoded JSON" do
|
@@ -316,14 +323,15 @@ describe CarrierWaveDirect::Uploader do
|
|
316
323
|
decoded_policy(options)["expiration"]
|
317
324
|
end
|
318
325
|
|
326
|
+
# JSON times have no seconds, so accept upto one second inaccuracy
|
319
327
|
def have_expiration(expires_in = DirectUploader.upload_expiration)
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
)
|
328
|
+
be_within(1.second).of (Time.now + expires_in)
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should be valid ISO8601 and not use default Time#to_json" do
|
332
|
+
Time.any_instance.stub(:to_json) { '"Invalid time"' } # JSON gem
|
333
|
+
Time.any_instance.stub(:as_json) { '"Invalid time"' } # Active Support
|
334
|
+
expect { Time.iso8601(expiration) }.to_not raise_error
|
327
335
|
end
|
328
336
|
|
329
337
|
it "should be #{DirectUploader.upload_expiration / 3600} hours from now" do
|
@@ -353,9 +361,12 @@ describe CarrierWaveDirect::Uploader do
|
|
353
361
|
end
|
354
362
|
|
355
363
|
context "should include" do
|
356
|
-
|
357
|
-
|
358
|
-
|
364
|
+
it "'utf8' if enforce_ut8 is set" do
|
365
|
+
expect(conditions(enforce_utf8: true)).to have_condition(:utf8)
|
366
|
+
end
|
367
|
+
|
368
|
+
it "'utf8' if enforce_ut8 is set" do
|
369
|
+
expect(conditions).to_not have_condition(:utf8)
|
359
370
|
end
|
360
371
|
|
361
372
|
# S3 conditions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Wilkie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -25,21 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fog
|
28
|
+
name: fog-aws
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
@@ -187,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
173
|
requirements:
|
188
174
|
- - ">="
|
189
175
|
- !ruby/object:Gem::Version
|
190
|
-
version:
|
176
|
+
version: 2.0.0
|
191
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
178
|
requirements:
|
193
179
|
- - ">="
|
@@ -195,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
181
|
version: '0'
|
196
182
|
requirements: []
|
197
183
|
rubyforge_project: carrierwave_direct
|
198
|
-
rubygems_version: 2.2.
|
184
|
+
rubygems_version: 2.5.2.3
|
199
185
|
signing_key:
|
200
186
|
specification_version: 4
|
201
187
|
summary: Upload direct to S3 using CarrierWave
|