New upstream version 1.2.2

parent 8778c226
......@@ -19,7 +19,7 @@ gemfile:
sudo: false
before_install:
- gem update bundler
#- gem update bundler
before_script:
- psql -c 'create database carrierwave_test;' -U postgres
......@@ -68,3 +68,6 @@ notifications:
addons:
postgresql: "9.3"
apt:
packages:
- ghostscript
......@@ -5,6 +5,32 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## 1.2.2 - 2018-01-02
### Fixed
* Reset Content-Type on converting file format(@kyoshidajp [#2237](https://github.com/carrierwaveuploader/carrierwave/pull/2237))
## 1.2.1 - 2017-10-04
### Fixed
* Locale check breaks when a Symbol is given to available_locales(@mshibuya [#2234](https://github.com/carrierwaveuploader/carrierwave/issues/2234))
## 1.2.0 - 2017-09-30
### Added
* Added Proc Support for Width and Height(@tomprats [#2169](https://github.com/carrierwaveuploader/carrierwave/pull/2169))
### Changed
* Decode unicode filenames from URL(@fedorkk [#2131](https://github.com/carrierwaveuploader/carrierwave/pull/2131))
* Change file size of error message to human size(@aki77 [#2199](https://github.com/carrierwaveuploader/carrierwave/pull/2199))
### Fixed
* Bundled en translation was not loaded by default, causing translation missing(@mshibuya [95ce39d3](https://github.com/carrierwaveuploader/carrierwave/commit/95ce39d3ec98bee9b2846b32fdcf093c78fa44fb))
* Remove potentially redundant HEAD request on checking fog file existence(@eritiro [#2140](https://github.com/carrierwaveuploader/carrierwave/pull/2140))
* Failing with uninitialized constant if uri is not loaded(@jasdeepsingh [#2223](https://github.com/carrierwaveuploader/carrierwave/pull/2223))
* RMagick cloud not process remotely stored files(@zog [#2185](https://github.com/carrierwaveuploader/carrierwave/pull/2185))
* Check if files are identical via FS rather than name before move(@riffraff [#2191](https://github.com/carrierwaveuploader/carrierwave/pull/2191))
* Regexp `extension_whitelist` is also case-insensitive now(@vmdhoke [#2201](https://github.com/carrierwaveuploader/carrierwave/pull/2201))
* Use `__send__` instead of `send` (@dminuoso [#2178](https://github.com/carrierwaveuploader/carrierwave/pull/2178))
## 1.1.0 - 2017-04-30
### Added
......
......@@ -301,14 +301,22 @@ end
```
When this uploader is used, an uploaded image would be scaled to be no larger
than 800 by 800 pixels. A version called thumb is then created, which is scaled
and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
than 800 by 800 pixels. The original aspect ratio will be kept.
A version called thumb is then created, which is scaled
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 copping
if the aspect ratio requires it.
The uploader could be used like this:
```ruby
uploader = AvatarUploader.new
uploader.store!(my_file) # size: 1024x768
uploader.url # => '/url/to/my_file.png' # size: 800x600
uploader.url # => '/url/to/my_file.png' # size: 800x800
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
```
......@@ -665,9 +673,9 @@ 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_public = false # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
config.fog_directory = 'name_of_directory' # 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
```
......@@ -901,19 +909,28 @@ mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
## I18n
The Active Record validations use the Rails i18n framework. Add these keys to
The Active Record validations use the Rails `i18n` framework. Add these keys to
your translations file:
```yaml
errors:
messages:
carrierwave_processing_error: "Cannot resize image."
carrierwave_integrity_error: "Not an image."
carrierwave_download_error: "Couldn't download image."
carrierwave_processing_error: failed to be processed
carrierwave_integrity_error: is not of an allowed file type
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_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}"
min_size_error: "File size should be greater than %{min_size}"
max_size_error: "File size should be less than %{max_size}"
```
The [`carrierwave-i18n`](https://github.com/carrierwaveuploader/carrierwave-i18n)
library adds support for additional locales.
## Large files
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then
......
......@@ -30,16 +30,15 @@ Gem::Specification.new do |s|
s.add_development_dependency "pg"
end
s.add_development_dependency "rails", ">= 4.0.0"
s.add_development_dependency "cucumber", "~> 2.3.2"
s.add_development_dependency "rspec", "~> 3.4.0"
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 "mini_magick", ">= 3.6.0"
if RUBY_ENGINE != 'jruby'
s.add_development_dependency "rmagick"
end
s.add_development_dependency "nokogiri", "~> 1.6.3"
s.add_development_dependency "timecop", "0.7.1"
s.add_development_dependency "timecop"
s.add_development_dependency "generator_spec", ">= 0.9.1"
s.add_development_dependency "pry"
end
......@@ -2,5 +2,6 @@ source "https://rubygems.org"
gem "rails", "~> 4.0.0"
gem "railties", "~> 4.0.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 4.1.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 4.2.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
......@@ -2,6 +2,6 @@ source "https://rubygems.org"
gem "rails", "~> 5.0.0"
gem "activemodel-serializers-xml"
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", branch: "rails-5", platforms: :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0", platforms: :jruby
gemspec :path => "../"
......@@ -2,6 +2,6 @@ source "https://rubygems.org"
gem "rails", "~> 5.1.0"
gem "activemodel-serializers-xml"
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", branch: "rails-5", platforms: :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby
gemspec :path => "../"
......@@ -41,6 +41,10 @@ elsif defined?(Rails)
initializer "carrierwave.setup_paths" do |app|
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
available_locales = Array(app.config.i18n.available_locales || [])
if available_locales.blank? || available_locales.include?(:en)
I18n.load_path.prepend(File.join(File.dirname(__FILE__), 'carrierwave', 'locale', "en.yml"))
end
end
initializer "carrierwave.active_record" do
......
......@@ -15,7 +15,7 @@ module CarrierWave
class_eval <<-RUBY, __FILE__, __LINE__+1
def remote_#{column}_url=(url)
column = _mounter(:#{column}).serialization_column
send(:"\#{column}_will_change!")
__send__(:"\#{column}_will_change!")
super
end
RUBY
......@@ -30,7 +30,7 @@ module CarrierWave
class_eval <<-RUBY, __FILE__, __LINE__+1
def remote_#{column}_urls=(url)
column = _mounter(:#{column}).serialization_column
send(:"\#{column}_will_change!")
__send__(:"\#{column}_will_change!")
super
end
RUBY
......@@ -63,8 +63,8 @@ module CarrierWave
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{column}=(new_file)
column = _mounter(:#{column}).serialization_column
if !(new_file.blank? && send(:#{column}).blank?)
send(:"\#{column}_will_change!")
if !(new_file.blank? && __send__(:#{column}).blank?)
__send__(:"\#{column}_will_change!")
end
super
......@@ -72,7 +72,7 @@ module CarrierWave
def remove_#{column}=(value)
column = _mounter(:#{column}).serialization_column
send(:"\#{column}_will_change!")
__send__(:"\#{column}_will_change!")
super
end
......
......@@ -127,6 +127,8 @@ module CarrierWave
# [MiniMagick::Image] additional manipulations to perform
#
def resize_to_limit(width, height, combine_options: {})
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.combine_options do |cmd|
cmd.resize "#{width}x#{height}>"
......@@ -152,6 +154,8 @@ module CarrierWave
# [MiniMagick::Image] additional manipulations to perform
#
def resize_to_fit(width, height, combine_options: {})
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.combine_options do |cmd|
cmd.resize "#{width}x#{height}"
......@@ -178,6 +182,8 @@ module CarrierWave
# [MiniMagick::Image] additional manipulations to perform
#
def resize_to_fill(width, height, gravity = 'Center', combine_options: {})
width = dimension_from width
height = dimension_from height
manipulate! do |img|
cols, rows = img[:dimensions]
img.combine_options do |cmd|
......@@ -225,6 +231,8 @@ module CarrierWave
# [MiniMagick::Image] additional manipulations to perform
#
def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {})
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.combine_options do |cmd|
cmd.thumbnail "#{width}x#{height}>"
......@@ -295,6 +303,7 @@ module CarrierWave
if @format
move_to = current_path.chomp(File.extname(current_path)) + ".#{@format}"
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.move_to(move_to, permissions, directory_permissions)
end
......@@ -319,6 +328,11 @@ module CarrierWave
end
end
def dimension_from(value)
return value unless value.instance_of?(Proc)
value.arity >= 1 ? value.call(self) : value.call
end
def mini_magick_image
if url
::MiniMagick::Image.open(url)
......
......@@ -133,6 +133,8 @@ module CarrierWave
# [Magick::Image] additional manipulations to perform
#
def resize_to_limit(width, height)
width = dimension_from width
height = dimension_from height
manipulate! do |img|
geometry = Magick::Geometry.new(width, height, 0, 0, Magick::GreaterGeometry)
new_img = img.change_geometry(geometry) do |new_width, new_height|
......@@ -162,6 +164,8 @@ module CarrierWave
# [Magick::Image] additional manipulations to perform
#
def resize_to_fit(width, height)
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.resize_to_fit!(width, height)
img = yield(img) if block_given?
......@@ -186,6 +190,8 @@ module CarrierWave
# [Magick::Image] additional manipulations to perform
#
def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.crop_resized!(width, height, gravity)
img = yield(img) if block_given?
......@@ -211,6 +217,8 @@ module CarrierWave
# [Magick::Image] additional manipulations to perform
#
def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
width = dimension_from width
height = dimension_from height
manipulate! do |img|
img.resize_to_fit!(width, height)
new_img = ::Magick::Image.new(width, height) { self.background_color = background == :transparent ? 'rgba(255,255,255,0)' : background.to_s }
......@@ -348,6 +356,7 @@ module CarrierWave
if options[:format] || @format
frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.move_to(move_to, permissions, directory_permissions)
else
frames.write(current_path, &write_block)
......@@ -371,8 +380,13 @@ module CarrierWave
image.try(:destroy!)
end
def dimension_from(value)
return value unless value.instance_of?(Proc)
value.arity >= 1 ? value.call(self) : value.call
end
def rmagick_image
::Magick::Image.read(current_path).first
::Magick::Image.from_blob(self.read).first
end
end # RMagick
......
......@@ -197,7 +197,7 @@ module CarrierWave
#
def move!(new_path)
if exists?
FileUtils.mv(path, new_path) unless new_path == path
FileUtils.mv(path, new_path) unless File.identical?(new_path, path)
else
File.open(new_path, "wb") { |f| f.write(read) }
end
......
......@@ -297,7 +297,7 @@ module CarrierWave
#
# [Boolean] true if file exists or false
def exists?
!!directory.files.head(path)
!!file
end
##
......
......@@ -129,7 +129,7 @@ module CarrierWave
eager_load_fog(value) if value && '#{name}' == 'fog_credentials'
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
name = superclass.#{name}
return nil if name.nil? && !instance_variable_defined?("@#{name}")
return nil if name.nil? && !instance_variable_defined?(:@#{name})
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
end
......
......@@ -16,7 +16,7 @@ module CarrierWave
end
def original_filename
filename = filename_from_header || File.basename(file.base_uri.path)
filename = filename_from_header || filename_from_uri
mime_type = MIME::Types[file.content_type].first
unless File.extname(filename).present? || mime_type.blank?
filename = "#{filename}.#{mime_type.extensions.first}"
......@@ -55,6 +55,10 @@ module CarrierWave
end
end
def filename_from_uri
URI.decode(File.basename(file.base_uri.path))
end
def method_missing(*args, &block)
file.send(*args, &block)
end
......
......@@ -43,7 +43,8 @@ module CarrierWave
end
def whitelisted_extension?(extension)
Array(extension_whitelist).any? { |item| extension =~ /\A#{item}\z/i }
downcase_extension = extension.downcase
Array(extension_whitelist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
end
end # ExtensionWhitelist
......
require 'active_support'
module CarrierWave
module Uploader
module FileSize
......@@ -29,9 +31,9 @@ module CarrierWave
expected_size_range = size_range
if expected_size_range.is_a?(::Range)
if size < expected_size_range.min
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => expected_size_range.min)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.min))
elsif size > expected_size_range.max
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => expected_size_range.max)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.max))
end
end
end
......
require 'uri'
module CarrierWave
module Utilities
module Uri
......
......@@ -11,7 +11,7 @@ module CarrierWave
class ProcessingValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
if e = record.send("#{attribute}_processing_error")
if e = record.__send__("#{attribute}_processing_error")
message = (e.message == e.class.to_s) ? :carrierwave_processing_error : e.message
record.errors.add(attribute, message)
end
......@@ -21,7 +21,7 @@ module CarrierWave
class IntegrityValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
if e = record.send("#{attribute}_integrity_error")
if e = record.__send__("#{attribute}_integrity_error")
message = (e.message == e.class.to_s) ? :carrierwave_integrity_error : e.message
record.errors.add(attribute, message)
end
......@@ -31,7 +31,7 @@ module CarrierWave
class DownloadValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
if e = record.send("#{attribute}_download_error")
if e = record.__send__("#{attribute}_download_error")
message = (e.message == e.class.to_s) ? :carrierwave_download_error : e.message
record.errors.add(attribute, message)
end
......
module CarrierWave
VERSION = "1.1.0"
VERSION = "1.2.2"
end
class <%= class_name %>Uploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
......@@ -45,5 +44,4 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
# def filename
# "something.jpg" if original_filename
# end
end
......@@ -304,6 +304,25 @@ describe CarrierWave::Mount do
expect(@instance.remote_image_url).to eq("http://www.example.com/test.jpg")
end
describe "URI with unicode symbols" do
before do
stub_request(
:get,
"http://www.example.com/%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.jpg"
).to_return(body: File.read(file_path("юникод.jpg")))
end
it "works correctly" do
@instance.remote_image_url = "http://www.example.com/%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.jpg"
expect(@instance.remote_image_url).to eq("http://www.example.com/%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.jpg")
end
it "decodes it correctly" do
@instance.remote_image_url = "http://www.example.com/%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.jpg"
expect(@instance.image.current_path).to match(/юникод.jpg$/)
end
end
end
describe "#remote_image_url=" do
......
......@@ -21,6 +21,7 @@ describe CarrierWave::MiniMagick do
instance.convert('png')
expect(instance.file.extension).to eq('png')
expect(instance).to be_format('png')
expect(instance.file.content_type).to eq('image/png')
end
it "converts all pages when no page number is specified" do
......@@ -191,6 +192,32 @@ describe CarrierWave::MiniMagick do
end
end
describe '#dimension_from' do
it 'evaluates procs' do
instance.resize_to_fill(Proc.new { 200 }, Proc.new { 200 })
expect(instance).to have_dimensions(200, 200)
end
it 'evaluates procs with uploader instance' do
width_argument = nil
width = Proc.new do |uploader|
width_argument = uploader
200
end
height_argument = nil
height = Proc.new do |uploader|
height_argument = uploader
200
end
instance.resize_to_fill(width, height)
expect(instance).to have_dimensions(200, 200)
expect(instance).to eq(width_argument)
expect(instance).to eq(height_argument)
end
end
describe "test errors" do
context "invalid image file" do
before { File.open(instance.current_path, 'w') { |f| f.puts "bogus" } }
......
......@@ -23,6 +23,7 @@ describe CarrierWave::RMagick, :rmagick => true do
instance.convert(:png)
expect(instance.file.extension).to eq('png')
expect(instance).to be_format('png')
expect(instance.file.content_type).to eq('image/png')
end
end
......@@ -220,6 +221,64 @@ describe CarrierWave::RMagick, :rmagick => true do
end
end
describe '#dimension_from' do
it 'evaluates procs' do
instance.resize_to_fill(Proc.new { 200 }, Proc.new { 200 })
expect(instance).to have_dimensions(200, 200)
end
it 'evaluates procs with uploader instance' do
width_argument = nil
width = Proc.new do |uploader|
width_argument = uploader
200
end
height_argument = nil
height = Proc.new do |uploader|
height_argument = uploader
200
end
instance.resize_to_fill(width, height)
expect(instance).to have_dimensions(200, 200)
expect(instance).to eq(width_argument)
expect(instance).to eq(height_argument)
end
end
describe "#rmagick_image" do
it "returns a ::Magick::Image" do
expect{instance.send(:rmagick_image)}.to_not raise_exception
expect(instance.send(:rmagick_image).class).to eq(::Magick::Image)
end
context "with a remotely stored file" do
class RemoteFile < CarrierWave::SanitizedFile
def initialize local_path
@local_path = local_path
end
def current_path
"foo/bar.jpg"
end
def read
File.read @local_path
end
end
before do
allow(instance).to receive(:file).and_return(RemoteFile.new(landscape_file_copy_path))
end
it "returns a ::Magick::Image" do
expect{instance.send(:rmagick_image)}.to_not raise_exception
expect(instance.send(:rmagick_image).class).to eq(::Magick::Image)
end
end
end
describe "test errors" do
context "invalid image file" do
before do
......
......@@ -308,11 +308,29 @@ describe CarrierWave::SanitizedFile do
expect(sanitized_file.move_to(file_path("gurr.png"))).to eq(sanitized_file)
end
it "should preserve the file's content type" do
content_type = sanitized_file.content_type
it "should convert the file's content type" do
sanitized_file.move_to(file_path("new_dir","gurr.png"))
expect(sanitized_file.content_type).to eq(content_type)
expect(sanitized_file.content_type).to eq("image/jpeg")
end
context 'target path only differs by case' do
let(:upcased_sanitized_file) { CarrierWave::SanitizedFile.new(stub_file("upcase.JPG", "image/jpeg")) }
before do
FileUtils.cp(file_path("test.jpg"), file_path("upcase.JPG"))
expect(upcased_sanitized_file).not_to be_empty
end
after(:all) do
FileUtils.rm_f(file_path("upcase.JPG"))
FileUtils.rm_f(file_path("upcase.jpg"))
end
it "should not raise an error when moved" do
expect(running { upcased_sanitized_file.move_to(upcased_sanitized_file.path.downcase) }).not_to raise_error
end
end
end
......
......@@ -103,7 +103,7 @@ module CarrierWave
module ManipulationHelpers
def color_of_pixel(path, x, y)
image = ::MiniMagick::Image.open(path)
color = image.run_command("convert", "#{image.path}[1x1+#{x}+#{y}]", "-depth", "8", "txt:").split("\n")[1]
image.run_command("convert", "#{image.path}[1x1+#{x}+#{y}]", "-depth", "8", "txt:").split("\n")[1]
end
end
end
......
......@@ -8,6 +8,9 @@ describe CarrierWave::Uploader::Download do
let(:url) { base_url + "/test.jpg" }
let(:test_file) { File.read(file_path(test_file_name)) }
let(:test_file_name) { "test.jpg" }
let(:unicode_named_file) { File.read(file_path(unicode_filename)) }
let(:unicode_URL) { URI.encode(base_url + "/#{unicode_filename}") }
let(:unicode_filename) { "юникод.jpg" }
let(:authentication_headers) do
{
'Accept'=>'*/*',
......@@ -44,6 +47,8 @@ describe CarrierWave::Uploader::Download do
stub_request(:get, "www.example.com/authorization_required.jpg").
with(:headers => authentication_headers).
to_return(body: test_file)
stub_request(:get, unicode_URL).to_return(body: unicode_named_file)
end
context "when a file was downloaded" do
......@@ -77,6 +82,25 @@ describe CarrierWave::Uploader::Download do
end
end
context "with unicode sybmols in URL" do
before do
uploader.download!(unicode_URL)
end
it "caches a file" do
expect(uploader.file).to be_an_instance_of(CarrierWave::SanitizedFile)
end
it "sets the filename to the file's decoded sanitized filename" do
expect(uploader.filename).to eq("#{unicode_filename}")
end
it "moves it to the tmp dir" do
expect(uploader.file.path).to eq(public_path("uploads/tmp/#{cache_id}/#{unicode_filename}"))
expect(uploader.file.exists?).to be_truthy
end
end
context "with directory permissions set" do
let(:permissions) { 0777 }
......
......@@ -82,6 +82,14 @@ describe CarrierWave::Uploader do
@uploader.cache!(File.open(file_path('test.jpeg')))
}).not_to raise_error
end
it "accepts extensions as regular expressions in a case insensitive manner" do
allow(@uploader).to receive(:extension_whitelist).and_return([/jpe?g/, 'gif', 'png'])
expect(running {
@uploader.cache!(File.open(file_path('case.JPG')))
}).not_to raise_error
end
end
context "when the whitelist is a single value" do
......
......@@ -28,7 +28,7 @@ describe CarrierWave::Uploader do
let(:range) { 2097152..4194304 }
it "raises an integrity error" do
is_expected.to raise_error(CarrierWave::IntegrityError)