file_handling_consumer.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'rails_helper'
  2. shared_examples_for 'FileHandlingConsumer' do
  3. let(:event) { Event.new(user: @checker.user, payload: {'file_pointer' => {'file' => 'text.txt', 'agent_id' => @checker.id}}) }
  4. it 'returns a file pointer' do
  5. expect(@checker.get_file_pointer('testfile')).to eq(file_pointer: { file: "testfile", agent_id: @checker.id})
  6. end
  7. it 'get_io raises an exception when trying to access an agent of a different user' do
  8. @checker2 = @checker.dup
  9. @checker2.user = users(:bob)
  10. @checker2.save!
  11. event.payload['file_pointer']['agent_id'] = @checker2.id
  12. expect { @checker.get_io(event) }.to raise_error(ActiveRecord::RecordNotFound)
  13. end
  14. context '#has_file_pointer?' do
  15. it 'returns true if the event contains a file pointer' do
  16. expect(@checker.has_file_pointer?(event)).to be_truthy
  17. end
  18. it 'returns false if the event does not contain a file pointer' do
  19. expect(@checker.has_file_pointer?(Event.new)).to be_falsy
  20. end
  21. end
  22. it '#get_upload_io returns a Faraday::UploadIO instance' do
  23. io_mock = double()
  24. expect(@checker).to receive(:get_io).with(event) { StringIO.new("testdata") }
  25. upload_io = @checker.get_upload_io(event)
  26. expect(upload_io).to be_a(Faraday::UploadIO)
  27. expect(upload_io.content_type).to eq('text/plain')
  28. end
  29. end