carrierwave_direct 2.1.0 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc82b1086314ce00c9bda47de03a897ecd59f1e3dca2f0b7617de586c572e129
4
- data.tar.gz: dea3d79dfd532cf823f49eb22790c39aeffa5d273b3010763345f0ccb00fb201
3
+ metadata.gz: bf462a9da6254f9a1b404f03443be9d9c21800aa378cbab7135da3ab08e2d1a5
4
+ data.tar.gz: 36e88bdcdc5f8e904109845546c47928eaf24dac894ba15a47820a131efd9576
5
5
  SHA512:
6
- metadata.gz: f489411ef1403569962e800e548e0511a258d1861b577c13d822d26a3d662e216694c213f43ba07898feabc47d2f5b9e6b3ac2b4df27a11a2826e97b07ea685f
7
- data.tar.gz: b604ac58fe82f7d10077855f562665f93f7edf54261bc2f3556b9ed6fd7f378c5626dc9f7a0fad9218b8fa05802b4cc8d2a29023c20f6f18b760b4b8b66a816d
6
+ metadata.gz: 3472e79f169583c76665f9c6a18cebe4b1f8b842e94d57dc4cfadba365382124d358243c229dd5bfcde36e23f9748cf278863f2b9283897e0f8c901b69866ef7
7
+ data.tar.gz: 180ef968f4d13946a93108e782f029b3c2de25509e7f321933a5203b3d06599e739b999ef1254da69b7153fe02205c72ea0679a4147251f572bdd4967d5cded1
data/.travis.yml CHANGED
@@ -1,13 +1,18 @@
1
1
  rvm:
2
- - 2.3
3
- - 2.4
4
- - 2.5
2
+ - 2.6
3
+ - 2.7
5
4
 
6
5
  script: 'bundle exec rspec spec'
7
6
  gemfile:
8
- - gemfiles/4.2.gemfile
9
7
  - gemfiles/5.1.gemfile
10
8
  - gemfiles/5.2.gemfile
9
+ - gemfiles/6.0.gemfile
10
+ - gemfiles/6.1.gemfile
11
+
12
+ matrix:
13
+ exclude:
14
+ - rvm: 2.4
15
+ gemfile: gemfiles/6.0.gemfile
11
16
 
12
17
  # Move to containerized travis, see http://docs.travis-ci.com/user/migrating-from-legacy
13
18
  sudo: false
data/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### Unreleased
2
+
3
+ ### 3.0.0
4
+ * Fixed Ruby 3 deprecation warnings
5
+ * [BREAKING CHANGE] Drop support for Carrierwave < 2.2.1 which renamed
6
+ extension_whitelist to extension_allowlist.
7
+
1
8
  ### 2.1.0
2
9
 
3
10
  Features:
data/README.md CHANGED
@@ -20,7 +20,9 @@ Please be aware that this gem (and S3 in general) only support single file uploa
20
20
 
21
21
  Install the latest release:
22
22
 
23
- gem install carrierwave_direct
23
+ ```bash
24
+ gem install carrierwave_direct
25
+ ```
24
26
 
25
27
  In Rails, add it to your Gemfile:
26
28
 
@@ -52,11 +54,15 @@ end
52
54
 
53
55
  If you haven't already done so generate an uploader
54
56
 
55
- rails generate uploader Avatar
57
+ ```bash
58
+ rails generate uploader Avatar
59
+ ```
56
60
 
57
61
  this should give you a file in:
58
62
 
59
- app/uploaders/avatar_uploader.rb
63
+ ```bash
64
+ app/uploaders/avatar_uploader.rb
65
+ ```
60
66
 
61
67
  Check out this file for some hints on how you can customize your uploader. It should look something like this:
62
68
 
@@ -111,21 +117,17 @@ class UploaderTest < Sinatra::Base
111
117
  end
112
118
  end
113
119
  ```
120
+
114
121
  ```haml
115
122
  # index.haml
116
123
  # Now using AWS POST authentication V4
117
124
  # See http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html for more information
118
125
 
119
126
  %form{:action => @uploader.direct_fog_url, :method => "post", :enctype => "multipart/form-data"}
120
- %input{:name => "utf8", :type => "hidden"}
121
- %input{:type => "hidden", :name => "key", :value => @uploader.key}
122
- %input{:type => "hidden", :name => "acl", :value => @uploader.acl}
127
+ - @uploader.direct_fog_hash.each do |key, value|
128
+ - if key != :uri
129
+ %input{:type => "hidden", :name => key, :value => value}
123
130
  %input{:type => "hidden", :name => "success_action_redirect", :value => @uploader.success_action_redirect}
124
- %input{:type => "hidden", :name => "policy", :value => @uploader.policy}
125
- %input{:type => "hidden", :name => "x-amz-algorithm", :value => @uploader.algorithm}
126
- %input{:type => "hidden", :name => "x-amz-credential", :value => @uploader.credential}
127
- %input{:type => "hidden", :name => "x-amz-date", :value => @uploader.date}
128
- %input{:type => "hidden", :name => "x-amz-signature", :value => @uploader.signature}
129
131
  %input{:name => "file", :type => "file"}
130
132
  %input{:type => "submit", :value => "Upload to S3"}
131
133
  ```
@@ -280,7 +282,7 @@ If your upload was successful then you will be redirected to the `success_action
280
282
 
281
283
  The `key` is the most important piece of information as we can use it for validating the file extension, downloading the file from S3, processing it and re-uploading it.
282
284
 
283
- If you're using ActiveRecord, CarrierWaveDirect will by default validate the file extension based off your `extension_whitelist` in your uploader. See the [CarrierWave readme](https://github.com/jnicklas/carrierwave) for more info. You can then use the helper `filename_valid?` to check if the filename is valid. e.g.
285
+ If you're using ActiveRecord, CarrierWaveDirect will by default validate the file extension based off your `extension_allowlist` in your uploader. See the [CarrierWave readme](https://github.com/jnicklas/carrierwave) for more info. You can then use the helper `filename_valid?` to check if the filename is valid. e.g.
284
286
 
285
287
  ```ruby
286
288
  class UsersController < ApplicationController
@@ -304,6 +306,7 @@ CarrierWaveDirect automatically gives you an accessible `key` attribute in your
304
306
  <%= f.submit %>
305
307
  <% end %>
306
308
  ```
309
+
307
310
  then in your controller you can do something like this:
308
311
 
309
312
  ```ruby
@@ -359,6 +362,7 @@ Your users may find it convenient to upload a file from a location on the Intern
359
362
  <%= f.submit %>
360
363
  <% end %>
361
364
  ```
365
+
362
366
  ```ruby
363
367
  class User < ActiveRecord::Base
364
368
  def save_and_process_avatar(options = {})
@@ -371,6 +375,7 @@ class User < ActiveRecord::Base
371
375
  end
372
376
  end
373
377
  ```
378
+
374
379
  The methods `has_avatar_upload?`, `remote_avatar_net_url` and `has_remote_avatar_net_url?` are automatically added to your mounted model
375
380
 
376
381
  ## Validations
@@ -399,13 +404,13 @@ Validates that the filename in the database is unique. Turned *on* by default
399
404
  validates :avatar, :filename_format => true
400
405
  ```
401
406
 
402
- Validates that the uploaded filename is valid. As well as validating the extension against the `extension_whitelist` it also validates that the `upload_dir` is correct. Turned *on* by default
407
+ Validates that the uploaded filename is valid. As well as validating the extension against the `extension_allowlist` it also validates that the `upload_dir` is correct. Turned *on* by default
403
408
 
404
409
  ```ruby
405
410
  validates :avatar, :remote_net_url_format => true
406
411
  ```
407
412
 
408
- Validates that the remote net url is valid. As well as validating the extension against the `extension_whitelist` it also validates that url is valid and has only the schemes specified in the `url_scheme_whitelist`. Turned *on* by default
413
+ Validates that the remote net url is valid. As well as validating the extension against the `extension_allowlist` it also validates that url is valid and has only the schemes specified in the `url_scheme_whitelist`. Turned *on* by default
409
414
 
410
415
  ## Configuration
411
416
 
@@ -426,10 +431,11 @@ CarrierWave.configure do |config|
426
431
  # on s3, but you must include an input field named
427
432
  # Content-Type on every direct upload form
428
433
 
429
- config.use_action_status = true # defaults to false; if true you must set in your uploader
430
- # 'uploader.success_action_status = 201' and set
431
- # 'f.file_field :avatar, use_action_status: true' to works
432
- # properly
434
+ config.use_action_status = true # defaults to false; if true, you must set
435
+ # success_action_status in your uploader:
436
+ # uploader.success_action_status = "201"
437
+ # and add use_action_status to the file field:
438
+ # f.file_field :avatar, use_action_status: true'
433
439
  end
434
440
  ```
435
441
 
@@ -521,7 +527,7 @@ Factory.define :user |f|
521
527
  end
522
528
  ```
523
529
 
524
- This will return a valid key based off your `upload_dir` and your `extension_whitelist`
530
+ This will return a valid key based off your `upload_dir` and your `extension_allowlist`
525
531
 
526
532
  ### Faking a background download
527
533
 
@@ -564,12 +570,16 @@ If you're Rails app was newly generated *after* version 3.2.3 and your testing t
564
570
 
565
571
  Pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested. Pull requests without tests *will not* be accepted.
566
572
 
567
- gem install bundler
568
- bundle install
573
+ ```bash
574
+ gem install bundler
575
+ bundle install
576
+ ```
569
577
 
570
578
  You should now be able to run the tests
571
579
 
572
- bundle exec rake
580
+ ```bash
581
+ bundle exec rake
582
+ ```
573
583
 
574
584
  ### Using the Sample Application
575
585
 
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "carrierwave_direct"
16
16
 
17
- s.add_dependency "carrierwave", '>= 1.0.0'
17
+ s.add_dependency "carrierwave", '>= 2.2.0'
18
18
  s.add_dependency "fog-aws"
19
19
 
20
20
  s.add_development_dependency "rspec", '~> 3.0'
21
21
  s.add_development_dependency "timecop"
22
- s.add_development_dependency "rails", ">= 3.2.12"
22
+ s.add_development_dependency "rails", ">= 5.1.0"
23
23
  s.add_development_dependency "sqlite3"
24
24
  s.add_development_dependency "capybara"
25
25
  s.add_development_dependency "byebug"
@@ -6,7 +6,7 @@ gem "fog-aws"
6
6
  group :test do
7
7
  gem "rspec", '~> 3.0'
8
8
  gem "timecop"
9
- gem "rails", "~>4.2.0"
9
+ gem "rails", "~>6.0.0"
10
10
  gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
11
11
  gem "capybara"
12
12
  # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave"
4
+ gem "fog-aws"
5
+
6
+ group :test do
7
+ gem "rspec", '~> 3.0'
8
+ gem "timecop"
9
+ gem "rails", "~>6.1.0"
10
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
11
+ gem "capybara"
12
+ # gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
13
+ end
@@ -18,7 +18,7 @@ module CarrierWaveDirect
18
18
  page.find("input[name='file']", visible: false).value
19
19
  end
20
20
 
21
- def upload_directly(uploader, button_locator, options = {})
21
+ def upload_directly(uploader, button_locator, **options)
22
22
  options[:success] = true unless options[:success] == false
23
23
  options[:success] &&= !options[:fail]
24
24
 
@@ -33,9 +33,9 @@ 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
37
  redirect_url_params = Rack::Utils.parse_nested_query(redirect_url.query)
38
-
38
+
39
39
  redirect_url.query = Rack::Utils.build_nested_query({
40
40
  :bucket => uploader.fog_directory,
41
41
  :key => options[:redirect_key],
@@ -18,7 +18,7 @@ module CarrierWaveDirect
18
18
  options[:filename] = filename_parts.join(".")
19
19
  end
20
20
  options[:filename] ||= "filename"
21
- valid_extension = uploader.extension_whitelist.first if uploader.extension_whitelist
21
+ valid_extension = uploader.extension_allowlist.first if uploader.extension_allowlist
22
22
  options[:extension] = options[:extension] ? options[:extension].gsub(".", "") : (valid_extension || "extension")
23
23
  key = options[:base].split("/")
24
24
  key.pop
@@ -101,7 +101,7 @@ module CarrierWaveDirect
101
101
  end
102
102
 
103
103
  def extension_regexp
104
- allowed_file_types = extension_whitelist
104
+ allowed_file_types = extension_allowlist
105
105
  extension_regexp = allowed_file_types.present? && allowed_file_types.any? ? "(#{allowed_file_types.join("|")})" : "\\w+"
106
106
  end
107
107
 
@@ -23,7 +23,7 @@ module CarrierWaveDirect
23
23
  class FilenameFormatValidator < ::ActiveModel::EachValidator
24
24
  def validate_each(record, attribute, value)
25
25
  if record.send("has_#{attribute}_upload?") && record.send("#{attribute}_key") !~ record.send(attribute).key_regexp
26
- extensions = record.send(attribute).extension_whitelist
26
+ extensions = record.send(attribute).extension_allowlist
27
27
  message = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
28
28
 
29
29
  if extensions.present?
@@ -43,7 +43,7 @@ module CarrierWaveDirect
43
43
  url_scheme_white_list = uploader.url_scheme_white_list
44
44
 
45
45
  if (remote_net_url !~ URI.regexp(url_scheme_white_list) || remote_net_url !~ /#{uploader.extension_regexp}\z/)
46
- extensions = uploader.extension_whitelist
46
+ extensions = uploader.extension_allowlist
47
47
 
48
48
  message = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
49
49
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CarrierwaveDirect
4
- VERSION = "2.1.0"
4
+ VERSION = "3.0.0"
5
5
  end
6
6
 
@@ -104,8 +104,8 @@ describe CarrierWaveDirect::ActiveRecord do
104
104
  messages = I18n.t("errors.messages.carrierwave_direct_filename_invalid")
105
105
 
106
106
  if i18n_options
107
- if i18n_options[:extension_whitelist]
108
- extensions = i18n_options[:extension_whitelist].to_sentence
107
+ if i18n_options[:extension_allowlist]
108
+ extensions = i18n_options[:extension_allowlist].to_sentence
109
109
  messages += I18n.t("errors.messages.carrierwave_direct_allowed_extensions", :extensions => extensions)
110
110
  end
111
111
 
@@ -244,7 +244,7 @@ describe CarrierWaveDirect::ActiveRecord do
244
244
 
245
245
  context "where the uploader has an extension white list" do
246
246
  before do
247
- subject.video.stub(:extension_whitelist).and_return(%w{avi mp4})
247
+ subject.video.stub(:extension_allowlist).and_return(%w{avi mp4})
248
248
  end
249
249
 
250
250
  context "and the uploaded file's extension is included in the list" do
@@ -302,7 +302,7 @@ describe CarrierWaveDirect::ActiveRecord do
302
302
  context "on create" do
303
303
  context "where the uploader has an extension white list" do
304
304
  before do
305
- subject.video.stub(:extension_whitelist).and_return(%w{avi mp4})
305
+ subject.video.stub(:extension_allowlist).and_return(%w{avi mp4})
306
306
  end
307
307
 
308
308
  context "and the url's extension is included in the list" do
@@ -325,7 +325,7 @@ describe CarrierWaveDirect::ActiveRecord do
325
325
  end
326
326
 
327
327
  it_should_behave_like "a remote net url i18n error message" do
328
- let(:i18n_options) { {:extension_whitelist => %w{avi mp4} } }
328
+ let(:i18n_options) { {:extension_allowlist => %w{avi mp4} } }
329
329
  end
330
330
 
331
331
  it "should include the white listed extensions in the error message" do
@@ -15,8 +15,8 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
15
15
  allow(subject).to receive(:page).and_return(page)
16
16
  end
17
17
 
18
- def find_element_value(css, value, options = nil)
19
- if options
18
+ def find_element_value(css, value, **options)
19
+ if options.keys.any?
20
20
  allow(page).to receive(:find).with(css, options).and_return(selector)
21
21
  else
22
22
  allow(page).to receive(:find).with(css).and_return(selector)
@@ -36,10 +36,10 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
36
36
  describe "#upload_directly" do
37
37
  let(:uploader) { DirectUploader.new }
38
38
 
39
- def upload_directly(options = {})
39
+ def upload_directly(**options)
40
40
  options[:button_locator] ||= ""
41
41
  button_locator = options.delete(:button_locator)
42
- subject.upload_directly(uploader, button_locator, options)
42
+ subject.upload_directly(uploader, button_locator, **options)
43
43
  end
44
44
 
45
45
  def stub_common
@@ -19,7 +19,7 @@ describe CarrierWaveDirect::Test::Helpers do
19
19
 
20
20
  context "['exe', 'bmp']" do
21
21
  before do
22
- allow(direct_uploader).to receive(:extension_whitelist).and_return(%w{exe bmp})
22
+ allow(direct_uploader).to receive(:extension_allowlist).and_return(%w{exe bmp})
23
23
  end
24
24
 
25
25
  it "should return '*/guid/filename.exe'" do
@@ -29,7 +29,7 @@ describe CarrierWaveDirect::Test::Helpers do
29
29
 
30
30
  context "[]" do
31
31
  before do
32
- allow(direct_uploader).to receive(:extension_whitelist).and_return([])
32
+ allow(direct_uploader).to receive(:extension_allowlist).and_return([])
33
33
  end
34
34
 
35
35
  it_should_behave_like "returning the default extension"
@@ -37,7 +37,7 @@ describe CarrierWaveDirect::Test::Helpers do
37
37
 
38
38
  context "nil" do
39
39
  before do
40
- allow(direct_uploader).to receive(:extension_whitelist).and_return(nil)
40
+ allow(direct_uploader).to receive(:extension_allowlist).and_return(nil)
41
41
  end
42
42
 
43
43
  it_should_behave_like "returning the default extension"
@@ -145,26 +145,26 @@ describe CarrierWaveDirect::Uploader do
145
145
  expect(subject.extension_regexp).to be_a(String)
146
146
  end
147
147
 
148
- context "where #extension_whitelist returns nil" do
148
+ context "where #extension_allowlist returns nil" do
149
149
  before do
150
- allow(subject).to receive(:extension_whitelist).and_return(nil)
150
+ allow(subject).to receive(:extension_allowlist).and_return(nil)
151
151
  end
152
152
 
153
153
  it_should_behave_like "a globally allowed file extension"
154
154
  end
155
155
 
156
- context "where #extension_whitelist returns []" do
156
+ context "where #extension_allowlist returns []" do
157
157
  before do
158
- allow(subject).to receive(:extension_whitelist).and_return([])
158
+ allow(subject).to receive(:extension_allowlist).and_return([])
159
159
  end
160
160
 
161
161
  it_should_behave_like "a globally allowed file extension"
162
162
  end
163
163
 
164
- context "where #extension_whitelist returns ['exe', 'bmp']" do
164
+ context "where #extension_allowlist returns ['exe', 'bmp']" do
165
165
 
166
166
  before do
167
- allow(subject).to receive(:extension_whitelist).and_return(%w{exe bmp})
167
+ allow(subject).to receive(:extension_allowlist).and_return(%w{exe bmp})
168
168
  end
169
169
 
170
170
  it "should return '(exe|bmp)'" do
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: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wilkie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-25 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog-aws
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.2.12
75
+ version: 5.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.12
82
+ version: 5.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -137,9 +137,10 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - carrierwave_direct.gemspec
140
- - gemfiles/4.2.gemfile
141
140
  - gemfiles/5.1.gemfile
142
141
  - gemfiles/5.2.gemfile
142
+ - gemfiles/6.0.gemfile
143
+ - gemfiles/6.1.gemfile
143
144
  - lib/carrierwave_direct.rb
144
145
  - lib/carrierwave_direct/action_view_extensions/form_helper.rb
145
146
  - lib/carrierwave_direct/form_builder.rb
@@ -197,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
198
  - !ruby/object:Gem::Version
198
199
  version: '0'
199
200
  requirements: []
200
- rubyforge_project: carrierwave_direct
201
- rubygems_version: 2.7.6
201
+ rubygems_version: 3.0.3
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: Upload direct to S3 using CarrierWave