Created
April 3, 2019 05:42
-
-
Save dangalipo/622ae89c6f17db4780041cf65f2164f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe FileIntegrityValidator do | |
class TestClass | |
include ActiveModel::Model | |
attr_accessor :file_path, :content_type | |
validates_with FileIntegrityValidator | |
end | |
subject(:validated_object) do | |
TestClass.new(content_type: 'application/pdf', file_path: file_path) | |
end | |
describe 'validating a clean file' do | |
let(:file_path) { Rails.root.join('spec/fixtures/pdfs/clean.pdf') } | |
it { is_expected.to be_valid } | |
specify do | |
expect(ExceptionHandler).not_to receive(:notify) | |
validated_object.valid? | |
end | |
end | |
describe 'validating a corrupt file' do | |
let(:file_path) { Rails.root.join('spec/fixtures/pdfs/corrupt.pdf') } | |
let(:errors) { ['File path File is corrupt'] } | |
let(:message) { 'This means we have rejected a corrupt file. No further action is needed' } | |
it { is_expected.to be_invalid } | |
specify do | |
expect { validated_object.valid? } | |
.to change { validated_object.errors.full_messages } | |
.to eq(errors) | |
end | |
specify do | |
expect(ExceptionHandler).not_to receive(:notify) | |
.with(instance_of(MiniMagick::Invalid), message) | |
validated_object.valid? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment