From 665f2254a2c70385b67942b13a4710dc6826c42d Mon Sep 17 00:00:00 2001 From: Alexander Koshelapov Date: Wed, 26 Jul 2017 20:07:15 +0300 Subject: [PATCH 01/51] Manage transaction rollback When we try to create new active record object into transaction and meet rollback: database row will not be created but uploader has created file in folder and doen't remove it. I changed behavior: now we store file only after commit action. This true and for update action in transaction. Changes in spec/orm/activerecord_spec.rb: - add tests which covers this flows - replace cleaning path from 'file path' to 'public_path' folder. Cause folder 'spec/fixtures/uploads ' is not used. --- lib/carrierwave/orm/activerecord.rb | 5 ++- spec/orm/activerecord_spec.rb | 56 ++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/lib/carrierwave/orm/activerecord.rb b/lib/carrierwave/orm/activerecord.rb index b23df2ce2..675cb6bf4 100644 --- a/lib/carrierwave/orm/activerecord.rb +++ b/lib/carrierwave/orm/activerecord.rb @@ -52,13 +52,12 @@ def mount_base(column, uploader=nil, options={}, &block) validates_processing_of column if uploader_option(column.to_sym, :validate_processing) validates_download_of column if uploader_option(column.to_sym, :validate_download) - after_save :"store_#{column}!" before_save :"write_#{column}_identifier" + after_save :"store_previous_changes_for_#{column}" after_commit :"remove_#{column}!", :on => :destroy after_commit :"mark_remove_#{column}_false", :on => :update - - after_save :"store_previous_changes_for_#{column}" after_commit :"remove_previously_stored_#{column}", :on => :update + after_commit :"store_#{column}!", :on => [:create, :update] class_eval <<-RUBY, __FILE__, __LINE__+1 def #{column}=(new_file) diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 965122cd8..d5ba42fa2 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -648,7 +648,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end describe 'normally' do @@ -735,7 +735,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file if old file had a different path" do @@ -758,7 +758,6 @@ def filename Event.transaction do @event.image = stub_file('new.jpeg') @event.save - expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy raise ActiveRecord::Rollback end @@ -766,6 +765,45 @@ def filename end end + describe "#mount_uploader into transaction" do + before do + @uploader.version :thumb + reset_class("Event") + Event.mount_uploader(:image, @uploader) + @event = Event.new + end + + after do + FileUtils.rm_rf(public_path("uploads")) + end + + it "should not store file during rollback" do + Event.transaction do + @event.image = stub_file('new.jpeg') + @event.save + + raise ActiveRecord::Rollback + end + + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_falsey + end + + it "should not change file during rollback" do + @event.image = stub_file('old.jpeg') + @event.save + + Event.transaction do + @event.image = stub_file('new.jpeg') + @event.save + + raise ActiveRecord::Rollback + end + + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_falsey + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy + end + end + describe '#mount_uploader removing old files with multiple uploaders' do before do @uploader = Class.new(CarrierWave::Uploader::Base) @@ -783,7 +821,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file1 and file2 if old file1 and file2 had a different paths" do @@ -826,7 +864,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file if old file had a different path" do @@ -1367,7 +1405,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end describe 'normally' do @@ -1444,7 +1482,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file if old file had a different path" do @@ -1481,7 +1519,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file1 and file2 if old file1 and file2 had a different paths" do @@ -1523,7 +1561,7 @@ def filename end after do - FileUtils.rm_rf(file_path("uploads")) + FileUtils.rm_rf(public_path("uploads")) end it "should remove old file if old file had a different path" do From 5f302821fb7aee0752987e01cec239cd940402dd Mon Sep 17 00:00:00 2001 From: Maros Hluska Date: Tue, 16 Jan 2018 11:40:18 -0800 Subject: [PATCH 02/51] Add allowed_types to content_type_whitelist_error We already do this in extension_whitelist.rb so this just matches the functionality. --- lib/carrierwave/uploader/content_type_whitelist.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/uploader/content_type_whitelist.rb b/lib/carrierwave/uploader/content_type_whitelist.rb index 22544fc6e..379bf342c 100644 --- a/lib/carrierwave/uploader/content_type_whitelist.rb +++ b/lib/carrierwave/uploader/content_type_whitelist.rb @@ -35,7 +35,7 @@ def content_type_whitelist; end def check_content_type_whitelist!(new_file) content_type = new_file.content_type if content_type_whitelist && !whitelisted_content_type?(content_type) - raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type) + raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type, allowed_types: Array(content_type_whitelist).join(", ")) end end From a610da9edd91b7af4e7dbe941c7d06a6f1a62ae6 Mon Sep 17 00:00:00 2001 From: poho Date: Mon, 29 Jan 2018 19:59:37 +1100 Subject: [PATCH 03/51] Add `use_iam_profile` aws config parameter --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d83db31e..9d3317113 100644 --- a/README.md +++ b/README.md @@ -667,8 +667,9 @@ CarrierWave.configure do |config| config.fog_provider = 'fog/aws' # required config.fog_credentials = { provider: 'AWS', # required - aws_access_key_id: 'xxx', # required - aws_secret_access_key: 'yyy', # required + aws_access_key_id: 'xxx', # required unless using use_iam_profile + aws_secret_access_key: 'yyy', # required unless using use_iam_profile + use_iam_profile: true, # optional, defaults to false region: 'eu-west-1', # optional, defaults to 'us-east-1' host: 's3.example.com', # optional, defaults to nil endpoint: 'https://s3.example.com:8080' # optional, defaults to nil From efff66dc13e3da25422cf504ec566f8b75c88774 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 21 Apr 2018 13:14:43 +0900 Subject: [PATCH 04/51] Drop support for Ruby 2.0.0 Because `class_attribute` stops working properly when used with Module#prepend, due to `singleton_class?` returning wrong result: https://github.com/rails/rails/blob/v4.2.10/activesupport/lib/active_support/core_ext/class/attribute.rb Refs. d34e1210ac6af153024f61c1f5bf92ec9be66de5 --- .travis.yml | 6 ------ carrierwave.gemspec | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea230eb3b..1f9309219 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,12 +26,6 @@ before_script: matrix: include: - - rvm: 2.0 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.0 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.0 - gemfile: gemfiles/rails-4-2.gemfile - rvm: 2.1.10 gemfile: gemfiles/rails-4-0.gemfile - rvm: 2.1.10 diff --git a/carrierwave.gemspec b/carrierwave.gemspec index 09e3c6dc3..cac2b8658 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.licenses = ["MIT"] - s.required_ruby_version = ">= 2.0.0" + s.required_ruby_version = ">= 2.1.0" s.add_dependency "activesupport", ">= 4.0.0" s.add_dependency "activemodel", ">= 4.0.0" From b313166832034467a206505cd5594f587e97f1ea Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 21 Apr 2018 14:48:38 +0900 Subject: [PATCH 05/51] Use minimal parts of fog --- carrierwave.gemspec | 5 ++++- spec/storage/fog_helper.rb | 1 + spec/storage/fog_spec.rb | 5 ++++- spec/uploader/overrides_spec.rb | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/carrierwave.gemspec b/carrierwave.gemspec index cac2b8658..179ad9179 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -33,7 +33,10 @@ Gem::Specification.new do |s| s.add_development_dependency "cucumber", "~> 2.3" s.add_development_dependency "rspec", "~> 3.4" s.add_development_dependency "webmock" - s.add_development_dependency "fog", ">= 1.28.0" + s.add_development_dependency "fog-aws" + s.add_development_dependency "fog-google", "<= 0.1.0" + s.add_development_dependency "fog-local" + s.add_development_dependency "fog-rackspace" s.add_development_dependency "mini_magick", ">= 3.6.0" if RUBY_ENGINE != 'jruby' s.add_development_dependency "rmagick" diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index d30a3535f..8aab7c926 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -5,6 +5,7 @@ def fog_tests(fog_credentials) before do CarrierWave.configure do |config| config.reset_config + config.fog_provider = "fog/#{fog_credentials[:provider].downcase}" config.fog_attributes = {} config.fog_credentials = fog_credentials config.fog_directory = CARRIERWAVE_DIRECTORY diff --git a/spec/storage/fog_spec.rb b/spec/storage/fog_spec.rb index 118911725..204006a44 100644 --- a/spec/storage/fog_spec.rb +++ b/spec/storage/fog_spec.rb @@ -1,5 +1,8 @@ require 'spec_helper' -require 'fog' +require 'fog/aws' +require 'fog/google' +require 'fog/local' +require 'fog/rackspace' require 'carrierwave/storage/fog' unless ENV['REMOTE'] == 'true' diff --git a/spec/uploader/overrides_spec.rb b/spec/uploader/overrides_spec.rb index 91229a4dd..43c0b3113 100644 --- a/spec/uploader/overrides_spec.rb +++ b/spec/uploader/overrides_spec.rb @@ -5,6 +5,7 @@ Class.new(CarrierWave::Uploader::Base).tap do |uc| uc.configure do |config| + config.fog_provider = 'fog/aws' config.fog_credentials = { :provider => 'AWS', # required :aws_access_key_id => 'XXXX', # required From c0b7fab3a14ddde0c80bdc540565fd6b4a7a7075 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 21 Apr 2018 13:39:24 +0900 Subject: [PATCH 06/51] Test against Rails 5.2 --- .travis.yml | 38 +++++++++++++++++++++-------------- gemfiles/rails-5-1.gemfile | 2 +- gemfiles/rails-5-2.gemfile | 8 ++++++++ gemfiles/rails-master.gemfile | 2 +- 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 gemfiles/rails-5-2.gemfile diff --git a/.travis.yml b/.travis.yml index 1f9309219..69a02d734 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,11 @@ language: ruby cache: bundler rvm: - - 2.2.9 - - 2.3.6 - - 2.4.3 - - jruby-9.1.15.0 + - 2.2.10 + - 2.3.7 + - 2.4.4 + - 2.5.1 + - jruby-9.1.15.0 gemfile: - gemfiles/rails-4-0.gemfile @@ -14,12 +15,12 @@ gemfile: - gemfiles/rails-4-2.gemfile - gemfiles/rails-5-0.gemfile - gemfiles/rails-5-1.gemfile - - gemfiles/rails-master.gemfile + - gemfiles/rails-5-2.gemfile sudo: false before_install: - #- gem update bundler + - gem install bundler before_script: - psql -c 'create database carrierwave_test;' -U postgres @@ -32,28 +33,35 @@ matrix: gemfile: gemfiles/rails-4-1.gemfile - rvm: 2.1.10 gemfile: gemfiles/rails-4-2.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/rails-master.gemfile - rvm: ruby-head - gemfile: gemfiles/rails-5-1.gemfile + gemfile: gemfiles/rails-5-2.gemfile - rvm: ruby-head gemfile: gemfiles/rails-master.gemfile - rvm: jruby-head - gemfile: gemfiles/rails-5-1.gemfile + gemfile: gemfiles/rails-5-0.gemfile - rvm: jruby-head - gemfile: gemfiles/rails-master.gemfile + gemfile: gemfiles/rails-5-1.gemfile exclude: - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.4.3 - gemfile: gemfiles/rails-4-2.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/rails-4-0.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/rails-4-1.gemfile + - rvm: jruby-9.1.15.0 + gemfile: gemfiles/rails-5-2.gemfile allow_failures: - rvm: ruby-head - rvm: jruby-head - rvm: jruby-9.1.15.0 - gemfile: gemfiles/rails-5-1.gemfile + gemfile: gemfiles/rails-5-0.gemfile - rvm: jruby-9.1.15.0 - gemfile: gemfiles/rails-master.gemfile + gemfile: gemfiles/rails-5-1.gemfile + - gemfile: gemfiles/rails-master.gemfile fast_finish: true notifications: diff --git a/gemfiles/rails-5-1.gemfile b/gemfiles/rails-5-1.gemfile index 3886c7b12..f47472bf2 100644 --- a/gemfiles/rails-5-1.gemfile +++ b/gemfiles/rails-5-1.gemfile @@ -3,6 +3,6 @@ source "https://rubygems.org" gem "rails", "~> 5.1.0" gem "activemodel-serializers-xml" gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby +gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby gemspec :path => "../" diff --git a/gemfiles/rails-5-2.gemfile b/gemfiles/rails-5-2.gemfile new file mode 100644 index 000000000..754bdea44 --- /dev/null +++ b/gemfiles/rails-5-2.gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem "rails", "~> 5.2.0" +gem "activemodel-serializers-xml" +gem 'pg', '~> 0.21.0', platforms: :ruby +gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby + +gemspec :path => "../" diff --git a/gemfiles/rails-master.gemfile b/gemfiles/rails-master.gemfile index 1240c5be1..d6abf9c9b 100644 --- a/gemfiles/rails-master.gemfile +++ b/gemfiles/rails-master.gemfile @@ -7,6 +7,6 @@ gem "sprockets", github: "rails/sprockets", branch: "master" gem "sprockets-rails", github: "rails/sprockets-rails", branch: "master" gem "sass-rails", github: "rails/sass-rails" gem "activemodel-serializers-xml" -gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby +gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby gemspec :path => "../" From 3c5ddd1ac0df092bbdc5a8a752f3b00305f9a94d Mon Sep 17 00:00:00 2001 From: jamie Date: Fri, 27 Apr 2018 14:54:12 +0900 Subject: [PATCH 07/51] change a comment about fog AWS S3 configuration change explicitly a comment 'name_of_directory' to 'name_of_bucket' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 078c55762..7a57aa48d 100644 --- a/README.md +++ b/README.md @@ -673,7 +673,7 @@ CarrierWave.configure do |config| host: 's3.example.com', # optional, defaults to nil endpoint: 'https://s3.example.com:8080' # optional, defaults to nil } - config.fog_directory = 'name_of_directory' # required + config.fog_directory = 'name_of_bucket' # required config.fog_public = false # optional, defaults to true config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {} end From cc9bb6679a5b9a87991e03971ca3bcf85ad0cefe Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 17 May 2018 12:55:54 +0900 Subject: [PATCH 08/51] Fix CarrierWave reads large files into memory --- lib/carrierwave/storage/fog.rb | 13 +- spec/storage/fog_helper.rb | 245 ++++++++++++++++++--------------- 2 files changed, 145 insertions(+), 113 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index ceb33aa46..16415293a 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -276,7 +276,16 @@ def initialize(uploader, base, path) # # [String] contents of file def read - file.body + file_body = file.body + + if file_body&.is_a?(::File) + file_body = ::File.open(file_body.path, 'rb') if file_body.closed? # Reopen if it's closed + file_body.read.tap do + file_body.close + end + elsif file_body&.is_a?(::String) + file_body + end end ## @@ -313,7 +322,7 @@ def store(new_file) fog_file = new_file.to_file @content_type ||= new_file.content_type @file = directory.files.create({ - :body => (fog_file ? fog_file : new_file).read, + :body => fog_file ? fog_file : new_file.read, :content_type => @content_type, :key => path, :public => @uploader.fog_public diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index 8aab7c926..1e89bbbf7 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -45,174 +45,197 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end describe '#store!' do - let(:store_path) { 'uploads/test+.jpg' } - before do - allow(@uploader).to receive(:store_path).and_return(store_path) - @fog_file = @storage.store!(file) - end + context 'when file is ::File' do + before do + allow(@uploader).to receive(:store_path).and_return(store_path) + @fog_file = @storage.store!(file) + end - it "should upload the file" do - # reading the file after upload should return the body, not a closed tempfile - expect(@fog_file.read).to eq('this is stuff') - # make sure it actually uploaded to the service, too - expect(@directory.files.get(store_path).body).to eq('this is stuff') - end + it "should upload the file" do + # reading the file after upload should return the body, not a closed tempfile + expect(@fog_file.read).to eq('this is stuff') + # make sure it actually uploaded to the service, too + expect(@directory.files.get(store_path).body).to eq('this is stuff') + end - it "should have a path" do - expect(@fog_file.path).to eq(store_path) - end + it "should have a path" do + expect(@fog_file.path).to eq(store_path) + end - it "should have a content_type" do - expect(@fog_file.content_type).to eq(file.content_type) - expect(@directory.files.get(store_path).content_type).to eq(file.content_type) - end + it "should have a content_type" do + expect(@fog_file.content_type).to eq(file.content_type) + expect(@directory.files.get(store_path).content_type).to eq(file.content_type) + end - it "should have an extension" do - expect(@fog_file.extension).to eq("jpg") - end + it "should have an extension" do + expect(@fog_file.extension).to eq("jpg") + end - context "without asset_host" do - it "should have a public_url" do - unless fog_credentials[:provider] == 'Local' - expect(@fog_file.public_url).not_to be_nil + context "without asset_host" do + it "should have a public_url" do + unless fog_credentials[:provider] == 'Local' + expect(@fog_file.public_url).not_to be_nil + end end - end - it "should have a url" do - unless fog_credentials[:provider] == 'Local' - expect(@fog_file.url).not_to be_nil + it "should have a url" do + unless fog_credentials[:provider] == 'Local' + expect(@fog_file.url).not_to be_nil + end end - end - context "directory is a valid subdomain" do - before do - allow(@uploader).to receive(:fog_directory).and_return('assets.site.com') + context "directory is a valid subdomain" do + before do + allow(@uploader).to receive(:fog_directory).and_return('assets.site.com') + end + + it "should use a subdomain URL for AWS" do + if @provider == 'AWS' + expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com') + end + end + + it "should use accelerate domain if fog_aws_accelerate is true" do + if @provider == 'AWS' + allow(@uploader).to receive(:fog_aws_accelerate).and_return(true) + expect(@fog_file.public_url).to include('https://assets.site.com.s3-accelerate.amazonaws.com') + end + end end - it "should use a subdomain URL for AWS" do + it "should not use a subdomain URL for AWS if the directory is not a valid subdomain" do if @provider == 'AWS' - expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com') + allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') + expect(@fog_file.public_url).to include('https://s3.amazonaws.com/SiteAssets') end end - it "should use accelerate domain if fog_aws_accelerate is true" do + it "should use https as a default protocol" do if @provider == 'AWS' - allow(@uploader).to receive(:fog_aws_accelerate).and_return(true) - expect(@fog_file.public_url).to include('https://assets.site.com.s3-accelerate.amazonaws.com') + expect(@fog_file.public_url).to start_with 'https://' end end - end - it "should not use a subdomain URL for AWS if the directory is not a valid subdomain" do - if @provider == 'AWS' - allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') - expect(@fog_file.public_url).to include('https://s3.amazonaws.com/SiteAssets') + it "should use https as a default protocol" do + if @provider == 'AWS' + allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(false) + expect(@fog_file.public_url).to start_with 'http://' + end end - end - it "should use https as a default protocol" do - if @provider == 'AWS' - expect(@fog_file.public_url).to start_with 'https://' + it "should use the google public url if available" do + if @provider == 'Google' + allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') + expect(@fog_file.public_url).to include('https://storage.googleapis.com/SiteAssets') + end end end - it "should use https as a default protocol" do - if @provider == 'AWS' - allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(false) - expect(@fog_file.public_url).to start_with 'http://' - end - end + context "with asset_host" do + before { allow(@uploader).to receive(:asset_host).and_return(asset_host) } - it "should use the google public url if available" do - if @provider == 'Google' - allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') - expect(@fog_file.public_url).to include('https://storage.googleapis.com/SiteAssets') - end - end - end + context "when a asset_host is a proc" do - context "with asset_host" do - before { allow(@uploader).to receive(:asset_host).and_return(asset_host) } + let(:asset_host) { proc { "http://foo.bar" } } - context "when a asset_host is a proc" do + describe "args passed to proc" do + let(:asset_host) { proc { |storage| expect(storage).to be_instance_of ::CarrierWave::Storage::Fog::File } } - let(:asset_host) { proc { "http://foo.bar" } } + it "should be the uploader" do + @fog_file.public_url + end + end - describe "args passed to proc" do - let(:asset_host) { proc { |storage| expect(storage).to be_instance_of ::CarrierWave::Storage::Fog::File } } + it "should have a asset_host rooted public_url" do + expect(@fog_file.public_url).to eq('http://foo.bar/uploads/test%2B.jpg') + end - it "should be the uploader" do - @fog_file.public_url + it "should have a asset_host rooted url" do + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') end - end - it "should have a asset_host rooted public_url" do - expect(@fog_file.public_url).to eq('http://foo.bar/uploads/test%2B.jpg') - end + it "should always have the same asset_host rooted url" do + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + end - it "should have a asset_host rooted url" do - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + it 'should retrieve file name' do + expect(@fog_file.filename).to eq('test+.jpg') + end end - it "should always have the same asset_host rooted url" do - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') - end + context "when a string" do + let(:asset_host) { "http://foo.bar" } + + it "should have a asset_host rooted public_url" do + expect(@fog_file.public_url).to eq('http://foo.bar/uploads/test%2B.jpg') + end + + it "should have a asset_host rooted url" do + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + end - it 'should retrieve file name' do - expect(@fog_file.filename).to eq('test+.jpg') + it "should always have the same asset_host rooted url" do + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + end end + end - context "when a string" do - let(:asset_host) { "http://foo.bar" } + context "without extension" do - it "should have a asset_host rooted public_url" do - expect(@fog_file.public_url).to eq('http://foo.bar/uploads/test%2B.jpg') - end + let(:store_path) { 'uploads/test' } - it "should have a asset_host rooted url" do - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') + it "should have no extension" do + expect(@fog_file.extension).to be_nil end - it "should always have the same asset_host rooted url" do - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') - expect(@fog_file.url).to eq('http://foo.bar/uploads/test%2B.jpg') - end end - end - - context "without extension" do - - let(:store_path) { 'uploads/test' } + it "should return filesize" do + expect(@fog_file.size).to eq(13) + end - it "should have no extension" do - expect(@fog_file.extension).to be_nil + it "should be deletable" do + @fog_file.delete + expect(@directory.files.head(store_path)).to eq(nil) end - end + context "when the file has been deleted" do + before { @fog_file.delete } - it "should return filesize" do - expect(@fog_file.size).to eq(13) - end + it "should not error getting the file size" do + expect { @fog_file.size }.not_to raise_error + end - it "should be deletable" do - @fog_file.delete - expect(@directory.files.head(store_path)).to eq(nil) + it "should not error getting the content type" do + expect { @fog_file.content_type }.not_to raise_error + end + end end - context "when the file has been deleted" do - before { @fog_file.delete } + context 'when file is ::StringIO' do + let(:file) do + CarrierWave::SanitizedFile.new( + :tempfile => StringIO.new('Test StringIO texts'), + :filename => 'test.jpg', + :content_type => 'image/jpeg' + ) + end - it "should not error getting the file size" do - expect { @fog_file.size }.not_to raise_error + before do + allow(@uploader).to receive(:store_path).and_return(store_path) + @fog_file = @storage.store!(file) end - it "should not error getting the content type" do - expect { @fog_file.content_type }.not_to raise_error + it "should upload the file" do + # reading the file after upload should return the body, not a closed tempfile + expect(@fog_file.read).to eq('Test StringIO texts') + # make sure it actually uploaded to the service, too + expect(@directory.files.get(store_path).body).to eq('Test StringIO texts') end end end From b8ed945a39083ff6be9a10518ae6c4286e8a53bc Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 18 May 2018 11:24:53 +0900 Subject: [PATCH 09/51] Fix test failure for old ruby versions --- lib/carrierwave/storage/fog.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 16415293a..7760975ec 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -278,13 +278,14 @@ def initialize(uploader, base, path) def read file_body = file.body - if file_body&.is_a?(::File) - file_body = ::File.open(file_body.path, 'rb') if file_body.closed? # Reopen if it's closed - file_body.read.tap do - file_body.close - end - elsif file_body&.is_a?(::String) - file_body + return if file_body.nil? + return file_body unless file_body.is_a?(::File) + + begin + file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed + file_body.read + ensure + file_body.close end end From 800e0db2554a06993f6026abcec00e7b46b47ceb Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Sun, 27 May 2018 20:45:58 +0900 Subject: [PATCH 10/51] Fix remote file is ignored when source file is removed --- lib/carrierwave/storage/fog.rb | 23 +++++++++++++++++------ spec/fixtures/new_dir/gurr.png | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/new_dir/gurr.png diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 7760975ec..074409a8e 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -281,12 +281,12 @@ def read return if file_body.nil? return file_body unless file_body.is_a?(::File) - begin - file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed - file_body.read - ensure - file_body.close - end + # Fog::Storage::XXX::File#body could return the source file which was upoloaded to the remote server. + read_source_file(file_body) if ::File.exist?(file_body.path) + + # If the source file doesn't exist, the remote content is read + @file = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables + file.body end ## @@ -468,6 +468,17 @@ def file def acl_header {'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'} end + + def read_source_file(file_body) + return unless ::File.exist?(file_body.path) + + begin + file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's already closed + file_body.read + ensure + file_body.close + end + end end end # Fog diff --git a/spec/fixtures/new_dir/gurr.png b/spec/fixtures/new_dir/gurr.png new file mode 100644 index 000000000..550ac1b13 --- /dev/null +++ b/spec/fixtures/new_dir/gurr.png @@ -0,0 +1 @@ +this is stuff \ No newline at end of file From 4dd46c723dfadcd92763654e56995e6947253d3e Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 28 May 2018 14:37:02 +0900 Subject: [PATCH 11/51] Remove unnecessary file --- spec/fixtures/new_dir/gurr.png | 1 - 1 file changed, 1 deletion(-) delete mode 100644 spec/fixtures/new_dir/gurr.png diff --git a/spec/fixtures/new_dir/gurr.png b/spec/fixtures/new_dir/gurr.png deleted file mode 100644 index 550ac1b13..000000000 --- a/spec/fixtures/new_dir/gurr.png +++ /dev/null @@ -1 +0,0 @@ -this is stuff \ No newline at end of file From adaad136b6807abb165929f2a61966fb71df6347 Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Sun, 24 Jun 2018 19:25:02 -0400 Subject: [PATCH 12/51] Add SemVer stability badge to README, and fix code climate badge --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a57aa48d..0ded13b17 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ This gem provides a simple and extremely flexible way to upload files from Ruby It works well with Rack based web applications, such as Ruby on Rails. [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave) -[![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave) +[![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave) [![git.legal](https://git.legal/projects/1363/badge.svg "Number of libraries approved")](https://git.legal/projects/1363) +[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver) ## Information @@ -307,7 +308,7 @@ to exactly 200 by 200 pixels. If you would like to crop images to a specific height and width you can use the alternative option of '''resize_to_fill'''. It will make sure -that the width and height specified are filled, only cropping +that the width and height specified are filled, only cropping if the aspect ratio requires it. The uploader could be used like this: From d463b7e34a9232c736620f7576ec72bd18c053b6 Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Mon, 25 Jun 2018 12:13:41 -0400 Subject: [PATCH 13/51] Remove defunct git.legal badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0ded13b17..99d793c3e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ It works well with Rack based web applications, such as Ruby on Rails. [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave) [![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave) -[![git.legal](https://git.legal/projects/1363/badge.svg "Number of libraries approved")](https://git.legal/projects/1363) [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver) From bed4f17c5e0455007020a41978fcce24c87003ff Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Jun 2018 14:39:45 +0900 Subject: [PATCH 14/51] Restore back Ruby 2.0 support Postponing until next major release. Refs. efff66dc13e3da25422cf504ec566f8b75c88774 --- .travis.yml | 6 ++++++ carrierwave.gemspec | 2 +- lib/carrierwave/uploader.rb | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 69a02d734..0d6eb43bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,12 @@ before_script: matrix: include: + - rvm: 2.0 + gemfile: gemfiles/rails-4-0.gemfile + - rvm: 2.0 + gemfile: gemfiles/rails-4-1.gemfile + - rvm: 2.0 + gemfile: gemfiles/rails-4-2.gemfile - rvm: 2.1.10 gemfile: gemfiles/rails-4-0.gemfile - rvm: 2.1.10 diff --git a/carrierwave.gemspec b/carrierwave.gemspec index 179ad9179..c43139e0c 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.licenses = ["MIT"] - s.required_ruby_version = ">= 2.1.0" + s.required_ruby_version = ">= 2.0.0" s.add_dependency "activesupport", ">= 4.0.0" s.add_dependency "activemodel", ">= 4.0.0" diff --git a/lib/carrierwave/uploader.rb b/lib/carrierwave/uploader.rb index 80f226ce3..d86a4dccc 100644 --- a/lib/carrierwave/uploader.rb +++ b/lib/carrierwave/uploader.rb @@ -43,6 +43,15 @@ module Uploader class Base attr_reader :file + ## + # Workaround for class_attribute malfunction when used with Module#prepend + # + if RUBY_VERSION < '2.1.0' + def self.singleton_class? + !ancestors.include? self + end + end + include CarrierWave::Uploader::Configuration include CarrierWave::Uploader::Callbacks include CarrierWave::Uploader::Proxy From 1975aac2ed17a044195aac25714536d113f4d4ac Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Jun 2018 15:27:36 +0900 Subject: [PATCH 15/51] Remove unused codes which were unintentionally left in e910beef8023070d4ffe5c525ee21d93e05e7baa. Refs. #2304 --- .../uploader/magic_mime_blacklist.rb | 94 ------------------- .../uploader/magic_mime_whitelist.rb | 94 ------------------- 2 files changed, 188 deletions(-) delete mode 100644 lib/carrierwave/uploader/magic_mime_blacklist.rb delete mode 100644 lib/carrierwave/uploader/magic_mime_whitelist.rb diff --git a/lib/carrierwave/uploader/magic_mime_blacklist.rb b/lib/carrierwave/uploader/magic_mime_blacklist.rb deleted file mode 100644 index 1a2c13b48..000000000 --- a/lib/carrierwave/uploader/magic_mime_blacklist.rb +++ /dev/null @@ -1,94 +0,0 @@ -module CarrierWave - module Uploader - - ## - # This modules validates the content type of a file with the use of - # ruby-filemagic gem and a blacklist regular expression. If you want - # to use this, you'll need to require this file: - # - # require 'carrierwave/uploader/magic_mime_blacklist' - # - # And then include it in your uploader: - # - # class MyUploader < CarrierWave::Uploader::Base - # include CarrierWave::Uploader::MagicMimeBlacklist - # - # def blacklist_mime_type_pattern - # /image\// - # end - # end - # - module MagicMimeBlacklist - extend ActiveSupport::Concern - - included do - begin - require "filemagic" - rescue LoadError => e - e.message << " (You may need to install the ruby-filemagic gem)" - raise e - end - - before :cache, :check_blacklist_pattern! - end - - ## - # Override this method in your uploader to provide a black list pattern (regexp) - # of content-types which are prohibited to be uploaded. - # Compares the file's content-type. - # - # === Returns - # - # [Regexp] a black list regexp to match the content_type - # - # === Examples - # - # def blacklist_mime_type_pattern - # /(text|application)\/json/ - # end - # - def blacklist_mime_type_pattern; end - - private - - def check_blacklist_pattern!(new_file) - return if blacklist_mime_type_pattern.nil? - - content_type = extract_content_type(new_file) - - if content_type.match(blacklist_mime_type_pattern) - raise CarrierWave::IntegrityError, - I18n.translate(:"errors.messages.mime_type_pattern_black_list_error", - :content_type => content_type) - end - end - - ## - # Extracts the content type of the given file - # - # === Returns - # - # [String] the extracted content type - # - def extract_content_type(new_file) - content_type = nil - - File.open(new_file.path) do |fd| - data = fd.read(1024) || "" - content_type = filemagic.buffer(data) - end - - content_type - end - - ## - # FileMagic object with the MAGIC_MIME_TYPE flag set - # - # @return [FileMagic] a filemagic object - def filemagic - @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE) - end - - end # MagicMimeblackList - end # Uploader -end # CarrierWave diff --git a/lib/carrierwave/uploader/magic_mime_whitelist.rb b/lib/carrierwave/uploader/magic_mime_whitelist.rb deleted file mode 100644 index de053e63b..000000000 --- a/lib/carrierwave/uploader/magic_mime_whitelist.rb +++ /dev/null @@ -1,94 +0,0 @@ -module CarrierWave - module Uploader - - ## - # This modules validates the content type of a file with the use of - # ruby-filemagic gem and a whitelist regular expression. If you want - # to use this, you'll need to require this file: - # - # require 'carrierwave/uploader/magic_mime_whitelist' - # - # And then include it in your uploader: - # - # class MyUploader < CarrierWave::Uploader::Base - # include CarrierWave::Uploader::MagicMimeWhitelist - # - # def whitelist_mime_type_pattern - # /image\// - # end - # end - # - module MagicMimeWhitelist - extend ActiveSupport::Concern - - included do - begin - require "filemagic" - rescue LoadError => e - e.message << " (You may need to install the ruby-filemagic gem)" - raise e - end - - before :cache, :check_whitelist_pattern! - end - - ## - # Override this method in your uploader to provide a white list pattern (regexp) - # of content-types which are allowed to be uploaded. - # Compares the file's content-type. - # - # === Returns - # - # [Regexp] a white list regexp to match the content_type - # - # === Examples - # - # def whitelist_mime_type_pattern - # /(text|application)\/json/ - # end - # - def whitelist_mime_type_pattern; end - - private - - def check_whitelist_pattern!(new_file) - return if whitelist_mime_type_pattern.nil? - - content_type = extract_content_type(new_file) - - if !content_type.match(whitelist_mime_type_pattern) - raise CarrierWave::IntegrityError, - I18n.translate(:"errors.messages.mime_type_pattern_white_list_error", - :content_type => content_type) - end - end - - ## - # Extracts the content type of the given file - # - # === Returns - # - # [String] the extracted content type - # - def extract_content_type(new_file) - content_type = nil - - File.open(new_file.path) do |fd| - data = fd.read(1024) || "" - content_type = filemagic.buffer(data) - end - - content_type - end - - ## - # FileMagic object with the MAGIC_MIME_TYPE flag set - # - # @return [FileMagic] a filemagic object - def filemagic - @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE) - end - - end # MagicMimeWhiteList - end # Uploader -end # CarrierWave From 6ac3b5cd7ef1f0a2163c31e21f119b877c8e2be7 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Jun 2018 15:37:58 +0900 Subject: [PATCH 16/51] Add link to carrierwave_asserts Closes #2307 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6643c0a8b..b91c5ace4 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,8 @@ describe MyUploader do end ``` +If you're looking for minitest asserts, checkout [carrierwave_asserts](https://github.com/hcfairbanks/carrierwave_asserts). + Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well. Processing can be enabled for a single version by setting the processing flag on the version like so: From 61c3ba833e7d0f06da40c7672d9de1694d5f2cbc Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Jun 2018 16:28:16 +0900 Subject: [PATCH 17/51] Version 1.2.3 --- CHANGELOG.md | 4 ++++ lib/carrierwave/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd833a41..2b1ce1159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## 1.2.3 - 2018-06-30 +### Fixed +* Fix reading whole content of large files into memory on storing(@dosuken123 [#2314](https://github.com/carrierwaveuploader/carrierwave/pull/2314)) + ## 1.2.2 - 2018-01-02 ### Fixed * Reset Content-Type on converting file format(@kyoshidajp [#2237](https://github.com/carrierwaveuploader/carrierwave/pull/2237)) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index 58d791d77..773f02eb2 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "1.2.2" + VERSION = "1.2.3" end From ac5dd2ec44319a49ce40db727e759952341aa41e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 21 Aug 2018 09:27:45 -0700 Subject: [PATCH 18/51] Fix pending spec not working in rspec 3.8.0 --- spec/orm/activerecord_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 965122cd8..94c074d11 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -681,12 +681,10 @@ def filename expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy end - pending do - it "should only delete the file once when the file is removed" do - @event.remove_image = true - expect_any_instance_of(CarrierWave::SanitizedFile).to receive(:delete).exactly(1).times - expect(@event.save).to be_truthy - end + pending("should only delete the file once when the file is removed") do + @event.remove_image = true + expect_any_instance_of(CarrierWave::SanitizedFile).to receive(:delete).exactly(1).times + expect(@event.save).to be_truthy end end From 096f7b21325216b3bf2aa88bcd56d50630bc15e2 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 15 Oct 2018 09:25:26 +0900 Subject: [PATCH 19/51] If no space left then remove old cache --- lib/carrierwave/storage/file.rb | 2 +- spec/storage/file_spec.rb | 9 ++++++++- spec/support/file_utils_helper.rb | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/carrierwave/storage/file.rb b/lib/carrierwave/storage/file.rb index b1206ddae..1cb27dcee 100644 --- a/lib/carrierwave/storage/file.rb +++ b/lib/carrierwave/storage/file.rb @@ -66,7 +66,7 @@ def retrieve!(identifier) # def cache!(new_file) new_file.move_to(::File.expand_path(uploader.cache_path, uploader.root), uploader.permissions, uploader.directory_permissions, true) - rescue Errno::EMLINK => e + rescue Errno::EMLINK, Errno::ENOSPC => e raise(e) if @cache_called @cache_called = true diff --git a/spec/storage/file_spec.rb b/spec/storage/file_spec.rb index 1fd4fd7be..ca782f011 100644 --- a/spec/storage/file_spec.rb +++ b/spec/storage/file_spec.rb @@ -40,7 +40,14 @@ describe '#cache!' do context "when FileUtils.mkdir_p raises Errno::EMLINK" do - before { fake_failed_mkdir_p } + before { fake_failed_mkdir_p(Errno::EMLINK) } + after { storage.cache!(sanitized_temp_file) } + + it { is_expected.to receive(:clean_cache!).with(600) } + end + + context "when FileUtils.mkdir_p raises Errno::ENOSPC" do + before { fake_failed_mkdir_p(Errno::ENOSPC) } after { storage.cache!(sanitized_temp_file) } it { is_expected.to receive(:clean_cache!).with(600) } diff --git a/spec/support/file_utils_helper.rb b/spec/support/file_utils_helper.rb index 4215de693..63d6954c6 100644 --- a/spec/support/file_utils_helper.rb +++ b/spec/support/file_utils_helper.rb @@ -1,6 +1,6 @@ module FileUtilsHelper - # NOTE: Make FileUtils.mkdir_p to raise `Errno::EMLINK` only once - def fake_failed_mkdir_p + # NOTE: Make FileUtils.mkdir_p to raise error only once + def fake_failed_mkdir_p(error) original_mkdir_p = FileUtils.method(:mkdir_p) mkdir_p_called = false allow(FileUtils).to receive(:mkdir_p) do |args| @@ -8,7 +8,7 @@ def fake_failed_mkdir_p original_mkdir_p.call(*args) else mkdir_p_called = true - raise Errno::EMLINK + raise error end end end From 6545b6bb7e01a53dba465931020ffeb1a46bc885 Mon Sep 17 00:00:00 2001 From: Maros Hluska Date: Mon, 15 Oct 2018 11:59:52 +0700 Subject: [PATCH 20/51] Add test --- README.md | 2 +- lib/carrierwave/locale/en.yml | 2 +- spec/uploader/content_type_whitelist_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bae60e840..cab2aef28 100644 --- a/README.md +++ b/README.md @@ -923,7 +923,7 @@ errors: carrierwave_download_error: could not be downloaded extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}" extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}" - content_type_whitelist_error: "You are not allowed to upload %{content_type} files" + content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}" content_type_blacklist_error: "You are not allowed to upload %{content_type} files" rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?" mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}" diff --git a/lib/carrierwave/locale/en.yml b/lib/carrierwave/locale/en.yml index 126192264..e10643e61 100644 --- a/lib/carrierwave/locale/en.yml +++ b/lib/carrierwave/locale/en.yml @@ -6,7 +6,7 @@ en: carrierwave_download_error: could not be downloaded extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}" extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}" - content_type_whitelist_error: "You are not allowed to upload %{content_type} files" + content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}" content_type_blacklist_error: "You are not allowed to upload %{content_type} files" rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?" mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}" diff --git a/spec/uploader/content_type_whitelist_spec.rb b/spec/uploader/content_type_whitelist_spec.rb index b1abe6cf2..ec451a7ff 100644 --- a/spec/uploader/content_type_whitelist_spec.rb +++ b/spec/uploader/content_type_whitelist_spec.rb @@ -41,6 +41,12 @@ expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError) end + + it "raises an integrity error which lists the allowed content types" do + allow(uploader).to receive(:content_type_whitelist).and_return(['image/gif', 'image/jpg']) + + expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError, %r{(?:image/gif|image/jpg)}) + end end context "when the whitelist is a single value" do From c8ca218ea737024a26e3c5aa2f0917d36e1f92c3 Mon Sep 17 00:00:00 2001 From: xenleme Date: Tue, 23 Oct 2018 18:55:27 +0300 Subject: [PATCH 21/51] Update rake reference to rails --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cab2aef28..9ee821120 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ a migration: rails g migration add_avatar_to_users avatar:string - rake db:migrate + rails db:migrate Open your model file and mount the uploader: @@ -144,12 +144,12 @@ example, create a migration like this: #### For databases with ActiveRecord json data type support (e.g. PostgreSQL, MySQL) rails g migration add_avatars_to_users avatars:json - rake db:migrate + rails db:migrate #### For database without ActiveRecord json data type support (e.g. SQLite) rails g migration add_avatars_to_users avatars:string - rake db:migrate + rails db:migrate __Note__: JSON datatype doesn't exists in SQLite adapter, that's why you can use a string datatype which will be serialized in model. From b149dcfd3dca5ed5cc4ed05c4d3ee796a422cbab Mon Sep 17 00:00:00 2001 From: artygus Date: Tue, 30 Oct 2018 23:50:08 +0300 Subject: [PATCH 22/51] MiniMagick: use read method to get file data --- lib/carrierwave/processing/mini_magick.rb | 6 +----- spec/processing/mini_magick_spec.rb | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/carrierwave/processing/mini_magick.rb b/lib/carrierwave/processing/mini_magick.rb index 8c51cb4e5..f9741aa99 100644 --- a/lib/carrierwave/processing/mini_magick.rb +++ b/lib/carrierwave/processing/mini_magick.rb @@ -341,11 +341,7 @@ def dimension_from(value) end def mini_magick_image - if url - ::MiniMagick::Image.open(url) - else - ::MiniMagick::Image.open(current_path) - end + ::MiniMagick::Image.read(self.read) end end # MiniMagick diff --git a/spec/processing/mini_magick_spec.rb b/spec/processing/mini_magick_spec.rb index 87486bbea..f1020a298 100644 --- a/spec/processing/mini_magick_spec.rb +++ b/spec/processing/mini_magick_spec.rb @@ -10,7 +10,6 @@ before do FileUtils.cp(landscape_file_path, landscape_copy_file_path) allow(instance).to receive(:cached?).and_return true - allow(instance).to receive(:url).and_return nil allow(instance).to receive(:file).and_return(CarrierWave::SanitizedFile.new(landscape_copy_file_path)) end From 091e462c30fdd443c92fe37a7e0dc1fe765d3ef6 Mon Sep 17 00:00:00 2001 From: artygus Date: Wed, 31 Oct 2018 00:30:13 +0300 Subject: [PATCH 23/51] ActiveRecord specs for dimensions with ImageProcessors included --- spec/orm/activerecord_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 94c074d11..167b66901 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -164,6 +164,30 @@ def reset_class(class_name) expect(@event.reload.image).to be_blank end + + context "with CarrierWave::MiniMagick" do + before(:each) do + @uploader.send(:include, CarrierWave::MiniMagick) + end + + it "has width and height" do + @event.image = stub_file('landscape.jpg') + expect(@event.image.width).to eq 640 + expect(@event.image.height).to eq 480 + end + end + + context "with CarrierWave::MiniMagick", :rmagick => true do + before(:each) do + @uploader.send(:include, CarrierWave::RMagick) + end + + it "has width and height" do + @event.image = stub_file('landscape.jpg') + expect(@event.image.width).to eq 640 + expect(@event.image.height).to eq 480 + end + end end describe '#image=' do From 90833250a04a8ce176fa477f9223854a6c0d4589 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Wed, 28 Nov 2018 20:49:45 +0000 Subject: [PATCH 24/51] add jets turbine support --- lib/carrierwave.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/carrierwave.rb b/lib/carrierwave.rb index 7e00510f5..7ed58163d 100644 --- a/lib/carrierwave.rb +++ b/lib/carrierwave.rb @@ -34,6 +34,26 @@ def tmp_path Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f } end +elsif defined?(Jets) + + module CarrierWave + class Turbine < Jets::Turbine + initializer "carrierwave.setup_paths" do |app| + CarrierWave.root = Jets.root.to_s + CarrierWave.tmp_path = "/tmp/carrierwave" + CarrierWave.configure do |config| + config.cache_dir = "/tmp/carrierwave/uploads/tmp" + end + end + + initializer "carrierwave.active_record" do + ActiveSupport.on_load :active_record do + require 'carrierwave/orm/activerecord' + end + end + end + end + elsif defined?(Rails) module CarrierWave From 0b15883a18deaf79568a8b315ecafdb5c5b9b37a Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 16 Dec 2018 06:55:55 -0800 Subject: [PATCH 25/51] Only include `x-amz-acl` header for AWS Even in AWS S3 compatibility mode, Google now appears to reject requests that includes this header with this error: ``` Requests cannot specify both x-amz and x-goog headers ``` --- lib/carrierwave/storage/fog.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 074409a8e..462a9deaf 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -352,7 +352,7 @@ def public_url end else # AWS/Google optimized for speed over correctness - case @uploader.fog_credentials[:provider].to_s + case fog_provider when 'AWS' # check if some endpoint is set in fog_credentials if @uploader.fog_credentials.has_key?(:endpoint) @@ -466,7 +466,15 @@ def file end def acl_header - {'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'} + if fog_provider == 'AWS' + {'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'} + else + {} + end + end + + def fog_provider + @uploader.fog_credentials[:provider].to_s end def read_source_file(file_body) From f8bcd470a2615f9b8db76d9884b1915a2752b4d3 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 16 Dec 2018 21:09:51 -0800 Subject: [PATCH 26/51] Add spec for Fog#acl_header --- lib/carrierwave/storage/fog.rb | 2 +- spec/storage/fog_helper.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 462a9deaf..49e702924 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -467,7 +467,7 @@ def file def acl_header if fog_provider == 'AWS' - {'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'} + { 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' } else {} end diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index 1e89bbbf7..e1e22db56 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -44,6 +44,28 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end end + context '#acl_header' do + let(:store_path) { 'uploads/test+.jpg' } + + before do + allow(@uploader).to receive(:store_path).and_return(store_path) + end + + it 'includes acl_header when necessary' do + if file.is_a?(CarrierWave::Storage::Fog::File) + if @provider == 'AWS' + expect(@storage.connection).to receive(:copy_object) + .with(anything, anything, anything, anything, { "x-amz-acl"=>"public-read" }).and_call_original + else + expect(@storage.connection).to receive(:copy_object) + .with(anything, anything, anything, anything, {}).and_call_original + end + end + + @storage.store!(file) + end + end + describe '#store!' do let(:store_path) { 'uploads/test+.jpg' } From ddce60273917d04b6fab30e52d0bb724b1f88e2e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 17 Dec 2018 02:11:49 -0800 Subject: [PATCH 27/51] Fix failing master builds Leftover `new_dir` directories with the wrong permissions were causing false positives when multiple examples were running. --- spec/sanitized_file_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/sanitized_file_spec.rb b/spec/sanitized_file_spec.rb index 5d8273d9c..f1e7375b9 100644 --- a/spec/sanitized_file_spec.rb +++ b/spec/sanitized_file_spec.rb @@ -9,6 +9,7 @@ describe CarrierWave::SanitizedFile do before do + FileUtils.rm_rf(file_path("new_dir")) FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg')) end @@ -301,7 +302,6 @@ sanitized_file.move_to(file_path("new_dir","gurr.png"), nil, 0775) expect(sanitized_file).to have_directory_permissions(0775) - FileUtils.rm_rf(file_path("new_dir")) end it "should return itself" do @@ -395,7 +395,6 @@ new_file = sanitized_file.copy_to(file_path("new_dir", "gurr.png"), nil, 0755) expect(new_file).to have_directory_permissions(0755) - FileUtils.rm_rf(file_path("new_dir")) end it "should preserve the file's content type" do From c952bae52c0e43ea8f33a6d0f59eb5ea1d0036e9 Mon Sep 17 00:00:00 2001 From: Ransom Briggs Date: Thu, 20 Dec 2018 15:49:23 -0600 Subject: [PATCH 28/51] Fix issue with subdomains and buckets with periods --- lib/carrierwave/storage/fog.rb | 6 +++++- spec/storage/fog_helper.rb | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 074409a8e..92a3c8b8b 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -359,8 +359,12 @@ def public_url "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{encoded_path}" else protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http" + + subdomain_regex = /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/ + valid_subdomain = @uploader.fog_directory.to_s =~ subdomain_regex && !(protocol == 'https' && @uploader.fog_directory =~ /\./) + # if directory is a valid subdomain, use that style for access - if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/ + if valid_subdomain s3_subdomain = @uploader.fog_aws_accelerate ? "s3-accelerate" : "s3" "#{protocol}://#{@uploader.fog_directory}.#{s3_subdomain}.amazonaws.com/#{encoded_path}" else diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index 1e89bbbf7..68a6dd826 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -88,19 +88,19 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base context "directory is a valid subdomain" do before do - allow(@uploader).to receive(:fog_directory).and_return('assets.site.com') + allow(@uploader).to receive(:fog_directory).and_return('assets-site-com') end it "should use a subdomain URL for AWS" do if @provider == 'AWS' - expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com') + expect(@fog_file.public_url).to include('https://assets-site-com.s3.amazonaws.com') end end it "should use accelerate domain if fog_aws_accelerate is true" do if @provider == 'AWS' allow(@uploader).to receive(:fog_aws_accelerate).and_return(true) - expect(@fog_file.public_url).to include('https://assets.site.com.s3-accelerate.amazonaws.com') + expect(@fog_file.public_url).to include('https://assets-site-com.s3-accelerate.amazonaws.com') end end end @@ -112,6 +112,22 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end end + it "should not use a subdomain URL for AWS if https && the directory is not accessible over https as a virtual hosted bucket" do + if @provider == 'AWS' + allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(true) + allow(@uploader).to receive(:fog_directory).and_return('foo.bar') + expect(@fog_file.public_url).to include('https://s3.amazonaws.com/foo.bar') + end + end + + it "should use a subdomain URL for AWS if http && the directory is not accessible over https as a virtual hosted bucket" do + if @provider == 'AWS' + allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(false) + allow(@uploader).to receive(:fog_directory).and_return('foo.bar') + expect(@fog_file.public_url).to include('http://foo.bar.s3.amazonaws.com/') + end + end + it "should use https as a default protocol" do if @provider == 'AWS' expect(@fog_file.public_url).to start_with 'https://' From b71fb05620fb3956f3eee3d5ed025cafe29dd23a Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 22 Dec 2018 09:53:46 -0800 Subject: [PATCH 29/51] Move cleanup to after block --- spec/sanitized_file_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/sanitized_file_spec.rb b/spec/sanitized_file_spec.rb index f1e7375b9..e8dde0a72 100644 --- a/spec/sanitized_file_spec.rb +++ b/spec/sanitized_file_spec.rb @@ -9,10 +9,13 @@ describe CarrierWave::SanitizedFile do before do - FileUtils.rm_rf(file_path("new_dir")) FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg')) end + after do + FileUtils.rm_rf(file_path("new_dir")) + end + after(:all) do if File.exist?(file_path('llama.jpg')) FileUtils.rm(file_path('llama.jpg')) From 0f7eb8818bc42dae3fff180325db1d8cac788945 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 16 Aug 2018 13:35:06 -0700 Subject: [PATCH 30/51] Add query parameter support for fog-google This requires https://github.com/fog/fog-google/pull/409/files --- carrierwave.gemspec | 2 +- lib/carrierwave/storage/fog.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/carrierwave.gemspec b/carrierwave.gemspec index c43139e0c..03a555ab2 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 3.4" s.add_development_dependency "webmock" s.add_development_dependency "fog-aws" - s.add_development_dependency "fog-google", "<= 0.1.0" + s.add_development_dependency "fog-google", "~> 1.7.1" s.add_development_dependency "fog-local" s.add_development_dependency "fog-rackspace" s.add_development_dependency "mini_magick", ">= 3.6.0" diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 49e702924..f739c3cd0 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -192,7 +192,7 @@ def authenticated_url(options = {}) local_file = local_directory.files.new(:key => path) expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration case @uploader.fog_credentials[:provider] - when 'AWS' + when 'AWS', 'Google' local_file.url(expire_at, options) when 'Rackspace' connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options) From d3d11516fad3d0d48b4b97bf12081af7e6ea7674 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 16 Dec 2018 07:21:31 -0800 Subject: [PATCH 31/51] Check if options parameter is available in :url method This is to ensure older versions of fog-google don't break. --- lib/carrierwave/storage/fog.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index f739c3cd0..71f94e428 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -193,7 +193,13 @@ def authenticated_url(options = {}) expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration case @uploader.fog_credentials[:provider] when 'AWS', 'Google' - local_file.url(expire_at, options) + # Older versions of fog-google do not support options as a parameter + if url_options_supported?(local_file) + local_file.url(expire_at, options) + else + warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider." + local_file.url(expire_at) + end when 'Rackspace' connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options) when 'OpenStack' @@ -487,6 +493,11 @@ def read_source_file(file_body) file_body.close end end + + def url_options_supported?(local_file) + parameters = file.method(:url).parameters + parameters.count == 2 && parameters[1].include?(:options) + end end end # Fog From cf21b93db05f887404abd823f4c912127c95f381 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 23 Dec 2018 06:55:22 -0800 Subject: [PATCH 32/51] Add test to ensure Google handles query parameters --- spec/storage/fog_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index e1e22db56..593ce0702 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -430,7 +430,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end it "should handle query params" do - if @provider == 'AWS' && !Fog.mocking? + if ['AWS', 'Google'].include?(@provider) && !Fog.mocking? headers = Excon.get(@fog_file.url(:query => {"response-content-disposition" => "attachment"})).headers expect(headers["Content-Disposition"]).to eq("attachment") end From a0e0330ac18b5cf3dbf8977b7a5637b0ac2a6d29 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Mon, 24 Dec 2018 16:59:55 +0900 Subject: [PATCH 33/51] Minor fixes of #2349 --- lib/carrierwave/processing/mini_magick.rb | 2 +- spec/orm/activerecord_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/carrierwave/processing/mini_magick.rb b/lib/carrierwave/processing/mini_magick.rb index f9741aa99..f4970c17f 100644 --- a/lib/carrierwave/processing/mini_magick.rb +++ b/lib/carrierwave/processing/mini_magick.rb @@ -341,7 +341,7 @@ def dimension_from(value) end def mini_magick_image - ::MiniMagick::Image.read(self.read) + ::MiniMagick::Image.read(read) end end # MiniMagick diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 167b66901..5cae3bf6f 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -177,7 +177,7 @@ def reset_class(class_name) end end - context "with CarrierWave::MiniMagick", :rmagick => true do + context "with CarrierWave::RMagick", :rmagick => true do before(:each) do @uploader.send(:include, CarrierWave::RMagick) end From 930abb7b2043999b1648ba1c2274585ccaf014e4 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Mon, 24 Dec 2018 19:23:14 +0900 Subject: [PATCH 34/51] Version 1.3.0 :gift: --- CHANGELOG.md | 12 ++++++++++++ lib/carrierwave/version.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1ce1159..c47433452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## 1.3.0 - 2018-12-24 +### Added +* Query parameter support for fog-google(@stanhu [#2332](https://github.com/carrierwaveuploader/carrierwave/pull/2332)) +* Jets Turbine Support(@tongueroo [#2355](https://github.com/carrierwaveuploader/carrierwave/pull/2355)) +* Add `allowed_types` to `content_type_whitelist_error`(@mhluska [#2270](https://github.com/carrierwaveuploader/carrierwave/pull/2270)) + +### Fixed +* S3 HTTPS url causes certificate issue when bucket name contains period(@ransombriggs [#2359](https://github.com/carrierwaveuploader/carrierwave/pull/2359)) +* Failed to get image dimensions when image is cached but not stored yet(@artygus [#2349](https://github.com/carrierwaveuploader/carrierwave/pull/2349)) +* Only include `x-amz-acl` header for AWS(@stanhu [#2356](https://github.com/carrierwaveuploader/carrierwave/pull/2356)) +* Remove old caches when no space is left on disk(@dosuken123 [#2342](https://github.com/carrierwaveuploader/carrierwave/pull/2342)) + ## 1.2.3 - 2018-06-30 ### Fixed * Fix reading whole content of large files into memory on storing(@dosuken123 [#2314](https://github.com/carrierwaveuploader/carrierwave/pull/2314)) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index 773f02eb2..6559ba296 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "1.2.3" + VERSION = "1.3.0" end From 0b9a64a1bb9f20d1de154dc3bf2e2dd988210220 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Tue, 25 Dec 2018 20:29:49 +0900 Subject: [PATCH 35/51] #url_options_supported? breaks when #file is nil Closes #2361, Refs. #2332 --- lib/carrierwave/storage/fog.rb | 2 +- spec/storage/fog_helper.rb | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 14c416aad..863e6a130 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -499,7 +499,7 @@ def read_source_file(file_body) end def url_options_supported?(local_file) - parameters = file.method(:url).parameters + parameters = local_file.method(:url).parameters parameters.count == 2 && parameters[1].include?(:options) end end diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index fb898cbb0..f1d6da7cf 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -3,6 +3,7 @@ def fog_tests(fog_credentials) shared_examples_for "#{fog_credentials[:provider]} storage" do before do + WebMock.disable! unless Fog.mocking? CarrierWave.configure do |config| config.reset_config config.fog_provider = "fog/#{fog_credentials[:provider].downcase}" @@ -34,6 +35,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base CarrierWave.configure do |config| config.reset_config end + WebMock.enable! unless Fog.mocking? end describe '#cache_stored_file!' do @@ -343,7 +345,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end describe '#clean_cache!' do - let(:today) { '2016/10/09 10:00:00'.to_time } + let(:today) { Time.now.round } let(:five_days_ago) { today.ago(5.days) } let(:three_days_ago) { today.ago(3.days) } let(:yesterday) { today.yesterday } @@ -431,7 +433,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base it "should not be available at public URL" do unless Fog.mocking? || fog_credentials[:provider] == 'Local' - expect(running{ open(@fog_file.public_url) }).to raise_error + expect(running{ open(@fog_file.public_url) }).to raise_error OpenURI::HTTPError end end @@ -446,9 +448,24 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end it "should handle query params" do - if ['AWS', 'Google'].include?(@provider) && !Fog.mocking? - headers = Excon.get(@fog_file.url(:query => {"response-content-disposition" => "attachment"})).headers - expect(headers["Content-Disposition"]).to eq("attachment") + if ['AWS', 'Google'].include?(@provider) + url = @fog_file.url(:query => {"response-content-disposition" => "attachment"}) + expect(url).to match(/response-content-disposition=attachment/) + unless Fog.mocking? + # Workaround for S3 SignatureDoesNotMatch issue + # https://github.com/excon/excon/issues/475 + Excon.defaults[:omit_default_port] = true + response = Excon.get(url) + expect(response.status).to be 200 + expect(response.headers["Content-Disposition"]).to eq("attachment") + end + end + end + + it "should not use #file to get signed url" do + if ['AWS', 'Google'].include?(@provider) + allow(@fog_file).to receive(:file).and_return(nil) + expect { @fog_file.url }.not_to raise_error end end end From 9d17a443d39ddf0c44bac985f69bf4c94d923a16 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 29 Dec 2018 18:55:13 +0900 Subject: [PATCH 36/51] Version 1.3.1 --- CHANGELOG.md | 4 ++++ lib/carrierwave/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c47433452..f8a2d0ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## 1.3.1 - 2018-12-29 +### Fixed +* Fix `#url_options_supported?` causing nil error(@mshibuya [0b9a64a1](https://github.com/carrierwaveuploader/carrierwave/commit/0b9a64a1bb9f20d1de154dc3bf2e2dd988210220), [#2361](https://github.com/carrierwaveuploader/carrierwave/issues/2361)) + ## 1.3.0 - 2018-12-24 ### Added * Query parameter support for fog-google(@stanhu [#2332](https://github.com/carrierwaveuploader/carrierwave/pull/2332)) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index 6559ba296..4a95400d7 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "1.3.0" + VERSION = "1.3.1" end From d7069240b8d9980d114120d3c98fd34f15eebb74 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 06:38:21 +0900 Subject: [PATCH 37/51] CI against newer rubies or Travis would cause weird bundler failures --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d6eb43bb..1e4f9a691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ cache: bundler rvm: - 2.2.10 - - 2.3.7 - - 2.4.4 - - 2.5.1 + - 2.3.8 + - 2.4.5 + - 2.5.3 - jruby-9.1.15.0 gemfile: @@ -39,7 +39,7 @@ matrix: gemfile: gemfiles/rails-4-1.gemfile - rvm: 2.1.10 gemfile: gemfiles/rails-4-2.gemfile - - rvm: 2.5.1 + - rvm: 2.5.3 gemfile: gemfiles/rails-master.gemfile - rvm: ruby-head gemfile: gemfiles/rails-5-2.gemfile @@ -50,13 +50,13 @@ matrix: - rvm: jruby-head gemfile: gemfiles/rails-5-1.gemfile exclude: - - rvm: 2.4.4 + - rvm: 2.4.5 gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.4.4 + - rvm: 2.4.5 gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.5.1 + - rvm: 2.5.3 gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.5.1 + - rvm: 2.5.3 gemfile: gemfiles/rails-4-1.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails-5-2.gemfile From e2b1ce04a39a744a7299306bc1ec8b428405ef84 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 06:39:16 +0900 Subject: [PATCH 38/51] We're still testing against old rubies that aren't supported by bundler 2.x --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1e4f9a691..287086314 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ gemfile: sudo: false before_install: - - gem install bundler + - gem install bundler -v '<2' before_script: - psql -c 'create database carrierwave_test;' -U postgres From 993bb98daf25473c851526c83df30c7d3b1c54a6 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 07:12:01 +0900 Subject: [PATCH 39/51] CI against newer jruby 9.1.x --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 287086314..432fb7e64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ rvm: - 2.3.8 - 2.4.5 - 2.5.3 - - jruby-9.1.15.0 + - jruby-9.1.17.0 gemfile: - gemfiles/rails-4-0.gemfile @@ -58,14 +58,14 @@ matrix: gemfile: gemfiles/rails-4-0.gemfile - rvm: 2.5.3 gemfile: gemfiles/rails-4-1.gemfile - - rvm: jruby-9.1.15.0 + - rvm: jruby-9.1.17.0 gemfile: gemfiles/rails-5-2.gemfile allow_failures: - rvm: ruby-head - rvm: jruby-head - - rvm: jruby-9.1.15.0 + - rvm: jruby-9.1.17.0 gemfile: gemfiles/rails-5-0.gemfile - - rvm: jruby-9.1.15.0 + - rvm: jruby-9.1.17.0 gemfile: gemfiles/rails-5-1.gemfile - gemfile: gemfiles/rails-master.gemfile fast_finish: true From da472ccb138a11aed993b55ea6622ff88ba9c10b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 07:15:53 +0900 Subject: [PATCH 40/51] CI against ruby 2.6 --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 432fb7e64..793a3aed2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ rvm: - 2.3.8 - 2.4.5 - 2.5.3 + - 2.6.0 - jruby-9.1.17.0 gemfile: @@ -39,7 +40,7 @@ matrix: gemfile: gemfiles/rails-4-1.gemfile - rvm: 2.1.10 gemfile: gemfiles/rails-4-2.gemfile - - rvm: 2.5.3 + - rvm: 2.6.0 gemfile: gemfiles/rails-master.gemfile - rvm: ruby-head gemfile: gemfiles/rails-5-2.gemfile @@ -58,6 +59,12 @@ matrix: gemfile: gemfiles/rails-4-0.gemfile - rvm: 2.5.3 gemfile: gemfiles/rails-4-1.gemfile + - rvm: 2.6.0 + gemfile: gemfiles/rails-4-0.gemfile + - rvm: 2.6.0 + gemfile: gemfiles/rails-4-1.gemfile + - rvm: 2.6.0 + gemfile: gemfiles/rails-4-2.gemfile - rvm: jruby-9.1.17.0 gemfile: gemfiles/rails-5-2.gemfile allow_failures: From b27c41cbaf9059b66961184e16eaf063fc8477ff Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 08:31:30 +0900 Subject: [PATCH 41/51] CI against jruby 9.2 --- .travis.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 793a3aed2..81fdf1d65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ rvm: - 2.4.5 - 2.5.3 - 2.6.0 - - jruby-9.1.17.0 + - jruby-9.2.5.0 gemfile: - gemfiles/rails-4-0.gemfile @@ -65,15 +65,13 @@ matrix: gemfile: gemfiles/rails-4-1.gemfile - rvm: 2.6.0 gemfile: gemfiles/rails-4-2.gemfile - - rvm: jruby-9.1.17.0 - gemfile: gemfiles/rails-5-2.gemfile + - rvm: jruby-9.2.5.0 + gemfile: gemfiles/rails-4-0.gemfile + - rvm: jruby-9.2.5.0 + gemfile: gemfiles/rails-4-1.gemfile allow_failures: - rvm: ruby-head - rvm: jruby-head - - rvm: jruby-9.1.17.0 - gemfile: gemfiles/rails-5-0.gemfile - - rvm: jruby-9.1.17.0 - gemfile: gemfiles/rails-5-1.gemfile - gemfile: gemfiles/rails-master.gemfile fast_finish: true From ff0ffc06f902aa92b30ad6a40d3624511e4f666f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 11 Jan 2019 13:43:10 +0900 Subject: [PATCH 42/51] Use gemified version of activerecord-jdbcpostgresql-adapter --- gemfiles/rails-5-1.gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/rails-5-1.gemfile b/gemfiles/rails-5-1.gemfile index f47472bf2..64e6932cf 100644 --- a/gemfiles/rails-5-1.gemfile +++ b/gemfiles/rails-5-1.gemfile @@ -3,6 +3,6 @@ source "https://rubygems.org" gem "rails", "~> 5.1.0" gem "activemodel-serializers-xml" gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby +gem "activerecord-jdbcpostgresql-adapter", '~> 51.0', platforms: :jruby gemspec :path => "../" From be47c82f82a9774c19645dbf2fc8976a5fd143c3 Mon Sep 17 00:00:00 2001 From: nagatech Date: Sat, 26 Jan 2019 13:49:54 +0900 Subject: [PATCH 43/51] Refactor SanitizedFile#path --- lib/carrierwave/sanitized_file.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index 0c889941e..b5ba07840 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -114,12 +114,11 @@ def size # [String, nil] the path where the file is located. # def path - unless @file.blank? - if is_path? - File.expand_path(@file) - elsif @file.respond_to?(:path) and not @file.path.blank? - File.expand_path(@file.path) - end + return if @file.blank? + if is_path? + File.expand_path(@file) + elsif @file.respond_to?(:path) && !@file.path.blank? + File.expand_path(@file.path) end end From 677e1d6ace8576551fb2aa070d20489752dc1b5d Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 26 Jan 2019 17:52:19 +0900 Subject: [PATCH 44/51] Fix JRuby builds --- .travis.yml | 2 ++ gemfiles/rails-5-2.gemfile | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 81fdf1d65..7bacb44c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,8 @@ gemfile: sudo: false before_install: + # https://github.com/danmayer/coverband/issues/162#issuecomment-452173268 + - rm /home/travis/.rvm/gems/*/specifications/bundler-2.*.gemspec || true - gem install bundler -v '<2' before_script: diff --git a/gemfiles/rails-5-2.gemfile b/gemfiles/rails-5-2.gemfile index 754bdea44..e8c0aa564 100644 --- a/gemfiles/rails-5-2.gemfile +++ b/gemfiles/rails-5-2.gemfile @@ -3,6 +3,5 @@ source "https://rubygems.org" gem "rails", "~> 5.2.0" gem "activemodel-serializers-xml" gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby gemspec :path => "../" From 98565f28b80d19934920eb69657419c96102bd69 Mon Sep 17 00:00:00 2001 From: Hagar Abdlwahab Date: Mon, 18 Feb 2019 11:01:11 +0200 Subject: [PATCH 45/51] Update README.md to upload multiple files you need to mount the uploader in your model with (mount_uploaders) with `s` not (mount_uploader) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9ee821120..a322c374d 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,9 @@ class User < ActiveRecord::Base end ``` +Make sure that you mount the uploader with write (mount_uploaders) with `s` not (mount_uploader) +in order to avoid errors when uploading multiple files + Make sure your file input fields are set up as multiple file fields. For example in Rails you'll want to do something like this: From 73dc05df9de6cf37e4574265e57103ab940f67a6 Mon Sep 17 00:00:00 2001 From: Petr Stepchenko Date: Mon, 18 Feb 2019 21:46:28 +0700 Subject: [PATCH 46/51] Add AzureRM to support authenticated_url --- lib/carrierwave/storage/fog.rb | 4 ++-- spec/storage/fog_helper.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 863e6a130..5ec5c5266 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -177,7 +177,7 @@ def attributes ## # Return a temporary authenticated url to a private file, if available - # Only supported for AWS, Rackspace and Google providers + # Only supported for AWS, Rackspace, Google and AzureRM providers # # === Returns # @@ -186,7 +186,7 @@ def attributes # [NilClass] no authenticated url available # def authenticated_url(options = {}) - if ['AWS', 'Google', 'Rackspace', 'OpenStack'].include?(@uploader.fog_credentials[:provider]) + if ['AWS', 'Google', 'Rackspace', 'OpenStack', 'AzureRM'].include?(@uploader.fog_credentials[:provider]) # avoid a get by using local references local_directory = connection.directories.new(:key => @uploader.fog_directory) local_file = local_directory.files.new(:key => path) diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index f1d6da7cf..455698a6b 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -438,7 +438,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base end it "should have an authenticated_url" do - if ['AWS', 'Rackspace', 'Google', 'OpenStack'].include?(@provider) + if ['AWS', 'Rackspace', 'Google', 'OpenStack', 'AzureRM'].include?(@provider) expect(@fog_file.authenticated_url).not_to be_nil end end From 629dba59c5d625c6874ddf45e3886a6a95bef74c Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 26 Feb 2019 01:33:38 -0800 Subject: [PATCH 47/51] Pass OpenStack options in get_object_https_url The options parameter has been supported all along in OpenStack. This may be needed to talk to servers that are configured on non-standard ports. --- lib/carrierwave/storage/fog.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 863e6a130..85d830dbf 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -200,10 +200,8 @@ def authenticated_url(options = {}) warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider." local_file.url(expire_at) end - when 'Rackspace' + when 'Rackspace', 'OpenStack' connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options) - when 'OpenStack' - connection.get_object_https_url(@uploader.fog_directory, path, expire_at) else local_file.url(expire_at) end From 93650ab2f748f091b3d677a8c5df39305f60bc66 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Tue, 19 Mar 2019 13:13:11 +0900 Subject: [PATCH 48/51] Travis's ImageMagick is pretty old, lock RMagick to 2.x --- carrierwave.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carrierwave.gemspec b/carrierwave.gemspec index 03a555ab2..e250721fc 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |s| s.add_development_dependency "fog-rackspace" s.add_development_dependency "mini_magick", ">= 3.6.0" if RUBY_ENGINE != 'jruby' - s.add_development_dependency "rmagick" + s.add_development_dependency "rmagick", "~> 2.16" end s.add_development_dependency "timecop" s.add_development_dependency "generator_spec", ">= 0.9.1" From aa85ea7324743edc51ef223020d24b87243312f1 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Mar 2019 17:47:03 +0900 Subject: [PATCH 49/51] Start development for 2.0.0 --- lib/carrierwave/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index 4a95400d7..0642bbc69 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "1.3.1" + VERSION = "2.0.0.alpha" end From bada043f39801625d748b9a89ef475eff5c8bdd5 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Mar 2019 17:53:43 +0900 Subject: [PATCH 50/51] Drop support for Ruby < 2.2 and Rails 4.x --- .travis.yml | 34 ---------------------------------- carrierwave.gemspec | 8 ++++---- gemfiles/rails-4-0.gemfile | 8 -------- gemfiles/rails-4-1.gemfile | 7 ------- gemfiles/rails-4-2.gemfile | 7 ------- lib/carrierwave/uploader.rb | 9 --------- 6 files changed, 4 insertions(+), 69 deletions(-) delete mode 100644 gemfiles/rails-4-0.gemfile delete mode 100644 gemfiles/rails-4-1.gemfile delete mode 100644 gemfiles/rails-4-2.gemfile diff --git a/.travis.yml b/.travis.yml index 7bacb44c1..4d53c0097 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,6 @@ rvm: - jruby-9.2.5.0 gemfile: - - gemfiles/rails-4-0.gemfile - - gemfiles/rails-4-1.gemfile - - gemfiles/rails-4-2.gemfile - gemfiles/rails-5-0.gemfile - gemfiles/rails-5-1.gemfile - gemfiles/rails-5-2.gemfile @@ -30,18 +27,6 @@ before_script: matrix: include: - - rvm: 2.0 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.0 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.0 - gemfile: gemfiles/rails-4-2.gemfile - - rvm: 2.1.10 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.1.10 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.1.10 - gemfile: gemfiles/rails-4-2.gemfile - rvm: 2.6.0 gemfile: gemfiles/rails-master.gemfile - rvm: ruby-head @@ -52,25 +37,6 @@ matrix: gemfile: gemfiles/rails-5-0.gemfile - rvm: jruby-head gemfile: gemfiles/rails-5-1.gemfile - exclude: - - rvm: 2.4.5 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.4.5 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.5.3 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.5.3 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.6.0 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: 2.6.0 - gemfile: gemfiles/rails-4-1.gemfile - - rvm: 2.6.0 - gemfile: gemfiles/rails-4-2.gemfile - - rvm: jruby-9.2.5.0 - gemfile: gemfiles/rails-4-0.gemfile - - rvm: jruby-9.2.5.0 - gemfile: gemfiles/rails-4-1.gemfile allow_failures: - rvm: ruby-head - rvm: jruby-head diff --git a/carrierwave.gemspec b/carrierwave.gemspec index e250721fc..1153dc15e 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -19,17 +19,17 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.licenses = ["MIT"] - s.required_ruby_version = ">= 2.0.0" + s.required_ruby_version = ">= 2.2.2" - s.add_dependency "activesupport", ">= 4.0.0" - s.add_dependency "activemodel", ">= 4.0.0" + s.add_dependency "activesupport", ">= 5.0.0" + s.add_dependency "activemodel", ">= 5.0.0" s.add_dependency "mime-types", ">= 1.16" if RUBY_ENGINE == 'jruby' s.add_development_dependency 'activerecord-jdbcpostgresql-adapter' else s.add_development_dependency "pg" end - s.add_development_dependency "rails", ">= 4.0.0" + s.add_development_dependency "rails", ">= 5.0.0" s.add_development_dependency "cucumber", "~> 2.3" s.add_development_dependency "rspec", "~> 3.4" s.add_development_dependency "webmock" diff --git a/gemfiles/rails-4-0.gemfile b/gemfiles/rails-4-0.gemfile deleted file mode 100644 index fec1290e2..000000000 --- a/gemfiles/rails-4-0.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -source "https://rubygems.org" - -gem "rails", "~> 4.0.0" -gem "railties", "~> 4.0.0" -gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby - -gemspec :path => "../" diff --git a/gemfiles/rails-4-1.gemfile b/gemfiles/rails-4-1.gemfile deleted file mode 100644 index 2bec01cea..000000000 --- a/gemfiles/rails-4-1.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source "https://rubygems.org" - -gem "rails", "~> 4.1.0" -gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby - -gemspec :path => "../" diff --git a/gemfiles/rails-4-2.gemfile b/gemfiles/rails-4-2.gemfile deleted file mode 100644 index 476335f54..000000000 --- a/gemfiles/rails-4-2.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source "https://rubygems.org" - -gem "rails", "~> 4.2.0" -gem 'pg', '~> 0.21.0', platforms: :ruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby - -gemspec :path => "../" diff --git a/lib/carrierwave/uploader.rb b/lib/carrierwave/uploader.rb index d86a4dccc..80f226ce3 100644 --- a/lib/carrierwave/uploader.rb +++ b/lib/carrierwave/uploader.rb @@ -43,15 +43,6 @@ module Uploader class Base attr_reader :file - ## - # Workaround for class_attribute malfunction when used with Module#prepend - # - if RUBY_VERSION < '2.1.0' - def self.singleton_class? - !ancestors.include? self - end - end - include CarrierWave::Uploader::Configuration include CarrierWave::Uploader::Callbacks include CarrierWave::Uploader::Proxy From a69a9c228d89a9d4d2f4f9e693af2d7ee128c525 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 30 Mar 2019 18:10:04 +0900 Subject: [PATCH 51/51] Test against Rails 6 --- .travis.yml | 33 +++++++++++++++++++-------------- carrierwave.gemspec | 2 +- gemfiles/rails-6-0.gemfile | 7 +++++++ 3 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 gemfiles/rails-6-0.gemfile diff --git a/.travis.yml b/.travis.yml index 4d53c0097..8254ee742 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,17 +3,13 @@ language: ruby cache: bundler rvm: - - 2.2.10 - - 2.3.8 - - 2.4.5 - - 2.5.3 - - 2.6.0 + - 2.5.5 + - 2.6.2 - jruby-9.2.5.0 gemfile: - - gemfiles/rails-5-0.gemfile - - gemfiles/rails-5-1.gemfile - gemfiles/rails-5-2.gemfile + - gemfiles/rails-6-0.gemfile sudo: false @@ -27,16 +23,25 @@ before_script: matrix: include: - - rvm: 2.6.0 - gemfile: gemfiles/rails-master.gemfile - - rvm: ruby-head + - rvm: 2.2.10 gemfile: gemfiles/rails-5-2.gemfile - - rvm: ruby-head - gemfile: gemfiles/rails-master.gemfile - - rvm: jruby-head + - rvm: 2.3.8 + gemfile: gemfiles/rails-5-2.gemfile + - rvm: 2.4.5 + gemfile: gemfiles/rails-5-2.gemfile + - rvm: 2.5.5 gemfile: gemfiles/rails-5-0.gemfile - - rvm: jruby-head + - rvm: 2.5.5 gemfile: gemfiles/rails-5-1.gemfile + - rvm: 2.6.2 + gemfile: gemfiles/rails-master.gemfile + - rvm: ruby-head + gemfile: gemfiles/rails-6-0.gemfile + - rvm: jruby-head + gemfile: gemfiles/rails-5-2.gemfile + exclude: + - rvm: jruby-9.2.5.0 + gemfile: gemfiles/rails-6-0.gemfile allow_failures: - rvm: ruby-head - rvm: jruby-head diff --git a/carrierwave.gemspec b/carrierwave.gemspec index 1153dc15e..7159c5d8b 100644 --- a/carrierwave.gemspec +++ b/carrierwave.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 3.4" s.add_development_dependency "webmock" s.add_development_dependency "fog-aws" - s.add_development_dependency "fog-google", "~> 1.7.1" + s.add_development_dependency "fog-google", "~> 1.7" s.add_development_dependency "fog-local" s.add_development_dependency "fog-rackspace" s.add_development_dependency "mini_magick", ">= 3.6.0" diff --git a/gemfiles/rails-6-0.gemfile b/gemfiles/rails-6-0.gemfile new file mode 100644 index 000000000..1b761b019 --- /dev/null +++ b/gemfiles/rails-6-0.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +gem "rails", "~> 6.0.0.beta3" +gem "activemodel-serializers-xml" +gem 'pg', '~> 0.21.0', platforms: :ruby + +gemspec :path => "../"