Sha256: 6b241d4463e9b52404ab97cd71996e0da3617f9fed8b49f248e81d9232bccf00

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'
require 'support/delayed_job_fake'
require 'delayed_job_web/application/app'

class TestDelayedJobWeb < MiniTest::Unit::TestCase

  include Rack::Test::Methods

  def app
    DelayedJobWeb
  end

  def test_requeue_failed

    dataset = Minitest::Mock.new
    where = lambda { | criteria |
      criteria.must_equal 'last_error IS NOT NULL'
      dataset
    }

    dataset.expect(:update_all, nil, [:run_at => time, :failed_at => nil])

    Time.stub(:now, time) do
      Delayed::Job.stub(:where, where) do
        post "/requeue/failed", request_data, rack_env
        last_response.status.must_equal 302
      end
    end

    dataset.verify

  end

  def test_requeue_pending

    dataset = Minitest::Mock.new
    where = lambda { | criteria |
      criteria.must_equal 'last_error IS NOT NULL'
      dataset
    }

    dataset.expect(:update_all, nil, [:run_at => time, :failed_at => nil])

    Time.stub(:now, time) do
      Delayed::Job.stub(:where, where) do
        post "/requeue/failed", request_data, rack_env
        last_response.status.must_equal 302
      end
    end

    dataset.verify

  end

  def test_requeue_id
    job = Minitest::Mock.new
    job.expect(:update_attributes, nil, [:run_at => time, :failed_at => nil])

    find = lambda { | id |
      id.must_equal "1"
      job
    }

    Time.stub(:now, time) do
      Delayed::Job.stub(:find, find) do
        post "/requeue/1", request_data, rack_env
        last_response.status.must_equal 302
      end
    end

    job.verify
  end

  private

  def time
    @time ||= Time.now
  end

  def rack_env
    {'rack.session' => {:csrf => "123"}}
  end

  def request_data
    {"authenticity_token" => "123"}
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
delayed_job_web-1.2.10 test/lib/delayed_job_web/application/test_app.rb