jobs_helper_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'rails_helper'
  2. describe JobsHelper do
  3. let(:job) { Delayed::Job.new }
  4. describe '#status' do
  5. it "works for failed jobs" do
  6. job.failed_at = Time.now
  7. expect(status(job)).to eq('<span class="label label-danger">failed</span>')
  8. end
  9. it "works for running jobs" do
  10. job.locked_at = Time.now
  11. job.locked_by = 'test'
  12. expect(status(job)).to eq('<span class="label label-info">running</span>')
  13. end
  14. it "works for queued jobs" do
  15. expect(status(job)).to eq('<span class="label label-warning">queued</span>')
  16. end
  17. end
  18. describe '#relative_distance_of_time_in_words' do
  19. it "in the past" do
  20. expect(relative_distance_of_time_in_words(Time.now-5.minutes)).to eq('5m ago')
  21. end
  22. it "in the future" do
  23. expect(relative_distance_of_time_in_words(Time.now+5.minutes)).to eq('in 5m')
  24. end
  25. end
  26. describe "#agent_from_job" do
  27. context "when handler does not contain job_data" do
  28. before do
  29. job.handler = "--- !ruby/object:AgentCheckJob\narguments:\n- 1\n"
  30. end
  31. it "finds the agent for AgentCheckJob" do
  32. expect(agent_from_job(job)).to eq(false)
  33. end
  34. end
  35. end
  36. end