Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change file size of error message to human size #2199

Merged
merged 3 commits into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/carrierwave/uploader/file_size.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support'

module CarrierWave
module Uploader
module FileSize
Expand Down Expand Up @@ -29,9 +31,9 @@ def check_size!(new_file)
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
Expand Down
4 changes: 2 additions & 2 deletions spec/uploader/file_size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
let(:range) { 2097152..4194304 }

it "raises an integrity error" do
is_expected.to raise_error(CarrierWave::IntegrityError)
is_expected.to raise_error(CarrierWave::IntegrityError, 'File size should be greater than 2 MB')
end
end

context "when above the maximum" do
let(:range) { 0..10 }

it "raises an integrity error" do
is_expected.to raise_error(CarrierWave::IntegrityError)
is_expected.to raise_error(CarrierWave::IntegrityError, 'File size should be less than 10 Bytes')
end
end

Expand Down