adioso_agent_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require 'rails_helper'
  2. describe Agents::AdiosoAgent do
  3. before do
  4. stub_request(:get, /parse/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/adioso_parse.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
  5. stub_request(:get, /fares/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/adioso_fare.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
  6. @valid_params = {
  7. :start_date => "June 25 2013",
  8. :end_date => "July 15 2013",
  9. :from => "Portland",
  10. :to => "Chicago",
  11. :username => "xx",
  12. :password => "xx",
  13. :expected_update_period_in_days => "2"
  14. }
  15. @checker = Agents::AdiosoAgent.new(:name => "somename", :options => @valid_params)
  16. @checker.user = users(:jane)
  17. @checker.save!
  18. end
  19. describe "#check" do
  20. it "should check that initial run creates an event" do
  21. expect { @checker.check }.to change { Event.count }.by(1)
  22. end
  23. end
  24. describe "#working?" do
  25. it "checks if its generating events as scheduled" do
  26. expect(@checker).not_to be_working
  27. @checker.check
  28. expect(@checker.reload).to be_working
  29. three_days_from_now = 3.days.from_now
  30. allow(Time).to receive(:now) { three_days_from_now }
  31. expect(@checker).not_to be_working
  32. end
  33. end
  34. end