Permalink
Browse files

1.8.7 support

  • Loading branch information...
1 parent 657380a commit c355433529e1c5a729134dcf6c9743deea5cd06f @akshayrawat committed Sep 25, 2012
View
@@ -25,7 +25,11 @@ Or install it yourself as:
## Note
-Supports `activerecord` and `mongoid`.
+* Supports `activerecord` and `mongoid`.
+* Supports `ruby 1.8.7` or higher for `activerecord`. `delayed_job_mongoid` depends
+ on `mongoid 3.0` which needs ruby 1.9, so there is no support for `ruby
+ 1.8.7` for that.
+
## Usage
@@ -65,4 +69,4 @@ root:
rake test:prepare
rake
-![Screenshot](https://github.com/akshayrawat/dj_mon_demo/raw/master/docs/screenshot.jpg)
+![Screenshot](https://github.com/akshayrawat/dj_mon_demo/raw/master/docs/screenshot.jpg)
View
@@ -19,14 +19,22 @@ namespace :test do
t.libs = [ "test/dummy_active_record" ]
end
- desc "Run all tests for the Mongoid backend"
- Rake::TestTask.new(:mongoid) do |t|
- t.pattern = 'test/**/*_test.rb'
- t.libs = [ "test/dummy_mongoid" ]
- end
+ if RUBY_VERSION =~ /^1\.9/
+
+ desc "Run all tests for the Mongoid backend"
+ Rake::TestTask.new(:mongoid) do |t|
+ t.pattern = 'test/**/*_test.rb'
+ t.libs = [ "test/dummy_mongoid" ]
+ end
+ desc "Runs all tests"
+ task "all"=> [ :active_record, :mongoid ]
+
+ else
+ # delayed_job_mongoid needs ~> mongoid 3.0 which needs ruby 1.9.
+ desc "Runs active_record tests"
+ task "all"=> [ :active_record ]
- desc "Runs all tests"
- task "all"=> [ :active_record, :mongoid ]
+ end
desc "Prepare environment for tests"
task :prepare do
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
-Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
+Dummy::Application.config.session_store :cookie_store, :key=> '_dummy_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json]
+ wrap_parameters :format=> [:json]
end
# Disable root element in JSON by default.
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
-Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
+Dummy::Application.config.session_store :cookie_store, :key=> '_dummy_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json]
+ wrap_parameters :format=> [:json]
end
# Disable root element in JSON by default.
@@ -1,4 +1,4 @@
-require_relative 'test_helper.rb'
+require File.expand_path('../test_helper.rb', __FILE__)
Delayed::Worker.max_attempts = 1
Delayed::Worker.destroy_failed_jobs = false
@@ -18,41 +18,41 @@ class ApiTest < ActionDispatch::IntegrationTest
context "authorization" do
%w(all failed active queued dj_counts settings).each do |protected_get|
should "not allow unauthorized GET to /dj_reports/#{protected_get}" do
- unauthorized_get "/dj_mon/dj_reports/#{protected_get}", format: 'json'
+ unauthorized_get "/dj_mon/dj_reports/#{protected_get}", :format=> 'json'
assert_equal 401, status
end
end
should "not allow unauthorized POST access to /dj_reports/retry" do
- unauthorized_post "/dj_mon/dj_reports/100/retry/", format: 'json'
+ unauthorized_post "/dj_mon/dj_reports/100/retry/", :format=> 'json'
assert_equal 401, status
end
should "not allow unauthorized DELETE access to /dj_reports/delete" do
- unauthorized_delete "/dj_mon/dj_reports/100/", format: 'json'
+ unauthorized_delete "/dj_mon/dj_reports/100/", :format=> 'json'
assert_equal 401, status
end
end
context "GET /dj_counts" do
setup do
- build_active_jobs(count: 1)
- build_failed_jobs(count: 2)
- build_queued_jobs(count: 3)
+ build_active_jobs(:count=> 1)
+ build_failed_jobs(:count=> 2)
+ build_queued_jobs(:count=> 3)
end
should "have counts for all, active, queued, failed jobs" do
- authorized_get '/dj_mon/dj_reports/dj_counts', format: 'json'
+ authorized_get '/dj_mon/dj_reports/dj_counts', :format=> 'json'
assert_equal 200, status
- assert_equal({ all: 6, active: 1, failed: 2, queued: 3 }, json_response.symbolize_keys)
+ assert_equal({ :all=> 6, :active=> 1, :failed=> 2, :queued=> 3 }, json_response.symbolize_keys)
end
end
context "GET /settings" do
should "return delayed job settings" do
- authorized_get '/dj_mon/dj_reports/settings', format: 'json'
+ authorized_get '/dj_mon/dj_reports/settings', :format=> 'json'
assert_equal 200, status
@@ -70,74 +70,74 @@ class ApiTest < ActionDispatch::IntegrationTest
context "GET /failed" do
setup do
- build_failed_jobs({ count: 2, queue: "queue_mailer_1", priority: 3 })
+ build_failed_jobs({ :count=> 2, :queue=> "queue_mailer_1", :priority=> 3 })
end
should "return details of failed jobs" do
- authorized_get '/dj_mon/dj_reports/failed', format: 'json'
+ authorized_get '/dj_mon/dj_reports/failed', :format=> 'json'
assert_equal 2, json_response.size
- assert_job({failed: true, priority: 3, attempts: 1, queue: 'queue_mailer_1'}, json_response.first)
+ assert_job({:failed=> true, :priority=> 3, :attempts=> 1, :queue=> 'queue_mailer_1'}, json_response.first)
end
end
context "GET /queued" do
setup do
- build_queued_jobs(count: 3, priority: 2, queue: "queue_mailer_2")
+ build_queued_jobs(:count=> 3, :priority=> 2, :queue=> "queue_mailer_2")
end
should "return details of queued jobs" do
- authorized_get '/dj_mon/dj_reports/queued', format: 'json'
+ authorized_get '/dj_mon/dj_reports/queued', :format=> 'json'
assert_equal 3, json_response.size
- assert_job({failed: false, priority: 2, attempts: 0, queue: 'queue_mailer_2'}, json_response.first)
+ assert_job({:failed=> false, :priority=> 2, :attempts=> 0, :queue=> 'queue_mailer_2'}, json_response.first)
end
end
context "GET /active" do
setup do
- build_active_jobs(count: 2, priority: 2, queue: "queue_mailer_3")
+ build_active_jobs(:count=> 2, :priority=> 2, :queue=> "queue_mailer_3")
end
should "return details of active jobs" do
- authorized_get '/dj_mon/dj_reports/active', format: 'json'
+ authorized_get '/dj_mon/dj_reports/active', :format=> 'json'
assert_equal 2, json_response.size
- assert_job({failed: false, priority: 2, attempts: 0, queue: 'queue_mailer_3'}, json_response.first)
+ assert_job({:failed=> false, :priority=> 2, :attempts=> 0, :queue=> 'queue_mailer_3'}, json_response.first)
end
end
context "GET /all" do
setup do
- build_failed_jobs({ count: 1, priority: 1, queue: "queue_mailer_1" })
- build_queued_jobs(count: 1, priority: 2, queue: "queue_mailer_2")
- build_active_jobs({ count: 1, priority: 3, queue: 'queue_mailer_3' })
+ build_failed_jobs({ :count=> 1, :priority=> 1, :queue=> "queue_mailer_1" })
+ build_queued_jobs(:count=> 1, :priority=> 2, :queue=> "queue_mailer_2")
+ build_active_jobs({ :count=> 1, :priority=> 3, :queue=> 'queue_mailer_3' })
end
should "return details of queued, failed and active jobs" do
- authorized_get '/dj_mon/dj_reports/all', format: 'json'
+ authorized_get '/dj_mon/dj_reports/all', :format=> 'json'
assert_equal 3, json_response.size
- assert_job_in_queue('queue_mailer_1', { failed: true, priority: 1, attempts: 1, queue: 'queue_mailer_1' })
- assert_job_in_queue('queue_mailer_2', { failed: false, priority: 2, attempts: 0, queue: 'queue_mailer_2' })
- assert_job_in_queue('queue_mailer_3', { failed: false, priority: 3, attempts: 0, queue: 'queue_mailer_3' })
+ assert_job_in_queue('queue_mailer_1', { :failed=> true, :priority=> 1, :attempts=> 1, :queue=> 'queue_mailer_1' })
+ assert_job_in_queue('queue_mailer_2', { :failed=> false, :priority=> 2, :attempts=> 0, :queue=> 'queue_mailer_2' })
+ assert_job_in_queue('queue_mailer_3', { :failed=> false, :priority=> 3, :attempts=> 0, :queue=> 'queue_mailer_3' })
end
end
context "DELETE /:id" do
should "delete the job specified by the :id" do
job = build_failed_jobs.first
- authorized_delete "/dj_mon/dj_reports/#{job.id}", format: 'json'
+ authorized_delete "/dj_mon/dj_reports/#{job.id}", :format=> 'json'
- assert Delayed::Job.where(id: job.id).empty?
+ assert Delayed::Job.where(:id=> job.id).empty?
assert response.body.strip.empty?
end
end
context "POST /retry/:id" do
should "reset failed_at column so that delayed job retries it" do
job = build_failed_jobs.first
- authorized_post "/dj_mon/dj_reports/#{job.id}/retry", format: 'json'
+ authorized_post "/dj_mon/dj_reports/#{job.id}/retry", :format=> 'json'
assert_nil job.reload.failed_at
assert response.body.strip.empty?
@@ -147,25 +147,25 @@ class ApiTest < ActionDispatch::IntegrationTest
private
def build_queued_jobs(options = {})
- options = { count: 1, priority: 1, queue: 'queue_mailer' }.merge(options)
+ options = { :count=> 1, :priority=> 1, :queue=> 'queue_mailer' }.merge(options)
options[:count].times.map do
- Delayed::Job.enqueue(TestJob.new, priority: options[:priority], queue: options[:queue])
+ Delayed::Job.enqueue(TestJob.new, :priority=> options[:priority], :queue=> options[:queue])
end
end
def build_active_jobs(options = {})
- options = { count: 1, priority: 1, queue: 'queue_mailer' }.merge(options)
+ options = { :count=> 1, :priority=> 1, :queue=> 'queue_mailer' }.merge(options)
options[:count].times.map do
- job = Delayed::Job.enqueue(TestJob.new, priority: options[:priority], queue: options[:queue])
- job.update_attributes({locked_at: Time.current, locked_by: 'some-worker'})
+ job = Delayed::Job.enqueue(TestJob.new, :priority=> options[:priority], :queue=> options[:queue])
+ job.update_attributes({:locked_at=> Time.current, :locked_by=> 'some-worker'})
job
end
end
def build_failed_jobs(options = {})
- options = { count: 1, priority: 1, queue: 'queue_mailer' }.merge(options)
+ options = { :count=> 1, :priority=> 1, :queue=> 'queue_mailer' }.merge(options)
options[:count].times.map do
- job = Delayed::Job.enqueue(FailingTestJob.new, priority: options[:priority], queue: options[:queue])
+ job = Delayed::Job.enqueue(FailingTestJob.new, :priority=> options[:priority], :queue=> options[:queue])
worker.run(job)
job
end
@@ -182,12 +182,12 @@ def assert_job(expected, actual)
assert_equal expected[:attempts], actual['attempts']
assert_equal expected[:queue], actual['queue']
if expected[:failed]
- assert_equal "--- !ruby/object:FailingTestJob {}\n", actual['payload']
- assert_include actual['last_error'], "this one fails"
- assert_include actual['last_error_summary'], "this one fails"
+ assert_equal "--- !ruby/object:FailingTestJob {}", actual['payload'].strip
+ assert actual['last_error'].include?("this one fails")
+ assert actual['last_error_summary'].include?("this one fails")
assert_not_nil DateTime.strptime(actual['failed_at'], DjMon::DjReport::TIME_FORMAT)
else
- assert_equal "--- !ruby/object:TestJob {}\n", actual['payload']
+ assert_equal "--- !ruby/object:TestJob {}", actual['payload'].strip
assert actual['failed_at'].empty?
assert_nil actual['last_error']
assert actual['last_error_summary'].empty?
@@ -6,8 +6,8 @@
puts "Running tests for #{Delayed::Worker.backend}"
require "rails/test_help"
-require_relative '../support/test_job'
-require_relative '../support/failing_test_job'
+require File.expand_path('../../support/test_job', __FILE__)
+require File.expand_path('../../support/failing_test_job', __FILE__)
Rails.backtrace_cleaner.remove_silencers!

0 comments on commit c355433

Please sign in to comment.