pdf_agent_spec.rb 729 B

123456789101112131415161718192021222324252627
  1. require 'rails_helper'
  2. describe Agents::PdfInfoAgent do
  3. let(:agent) do
  4. _agent = Agents::PdfInfoAgent.new(name: "PDF Info Agent")
  5. _agent.user = users(:bob)
  6. _agent.sources << agents(:bob_website_agent)
  7. _agent.save!
  8. _agent
  9. end
  10. describe "#receive" do
  11. before do
  12. @event = Event.new(payload: {'url' => 'http://mypdf.com'})
  13. end
  14. it "should call HyPDF" do
  15. expect {
  16. expect(agent).to receive(:open).with('http://mypdf.com') { "data" }
  17. expect(HyPDF).to receive(:pdfinfo).with('data') { {title: "Huginn"} }
  18. agent.receive([@event])
  19. }.to change { Event.count }.by(1)
  20. event = Event.last
  21. expect(event.payload[:title]).to eq('Huginn')
  22. end
  23. end
  24. end