diff options
author | Stan Hu <stanhu@gmail.com> | 2015-03-20 05:11:12 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-04-02 00:04:08 -0700 |
commit | dfd256f29ee817b5ffc563bb554a02d26ae44502 (patch) | |
tree | c28e943c541df30a2a0ab03905bf5d7bbe61b3ba /spec/lib | |
parent | 16a6ea2d1769f68157976b83bf6da468dd38853d (diff) | |
download | gitlab-ce-dfd256f29ee817b5ffc563bb554a02d26ae44502.tar.gz |
Support configurable attachment size via Application Settings
Fix bug where error messages from Dropzone would not be displayed on the issues page
Closes #1258
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/file_size_validator_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/lib/file_size_validator_spec.rb b/spec/lib/file_size_validator_spec.rb new file mode 100644 index 00000000000..5c89c854714 --- /dev/null +++ b/spec/lib/file_size_validator_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe 'Gitlab::FileSizeValidatorSpec' do + let(:validator) { FileSizeValidator.new(options) } + let(:attachment) { AttachmentUploader.new } + let(:note) { create(:note) } + + describe 'options uses an integer' do + let(:options) { { maximum: 10, attributes: { attachment: attachment } } } + + it 'attachment exceeds maximum limit' do + allow(attachment).to receive(:size) { 100 } + validator.validate_each(note, :attachment, attachment) + expect(note.errors).to have_key(:attachment) + end + + it 'attachment under maximum limit' do + allow(attachment).to receive(:size) { 1 } + validator.validate_each(note, :attachment, attachment) + expect(note.errors).not_to have_key(:attachment) + end + end + + describe 'options uses a symbol' do + let(:options) { { maximum: :test, + attributes: { attachment: attachment } } } + before do + allow(note).to receive(:test) { 10 } + end + + it 'attachment exceeds maximum limit' do + allow(attachment).to receive(:size) { 100 } + validator.validate_each(note, :attachment, attachment) + expect(note.errors).to have_key(:attachment) + end + + it 'attachment under maximum limit' do + allow(attachment).to receive(:size) { 1 } + validator.validate_each(note, :attachment, attachment) + expect(note.errors).not_to have_key(:attachment) + end + end +end |