Skip to content

Commit

Permalink
Merge pull request #58 from cristianbica/logging-tests
Browse files Browse the repository at this point in the history
Added tests for logging
  • Loading branch information
dhh committed May 22, 2014
2 parents 53410c9 + 3fe95c8 commit 61deda5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/active_job/enqueuing.rb
Expand Up @@ -21,7 +21,7 @@ def enqueue(*args)
#
# Returns truthy if a job was scheduled.
def enqueue_in(interval, *args)
enqueue_at(interval.from_now, *args)
enqueue_at(interval.seconds.from_now, *args)
end

# Enqueue a job to be performed at an explicit point in time.
Expand Down
4 changes: 2 additions & 2 deletions lib/active_job/logging.rb
Expand Up @@ -12,7 +12,7 @@ def enqueue(event)
def enqueue_at(event)
info "Enqueued #{event.payload[:job].name} to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event)
end

def perform(event)
info "Performed #{event.payload[:job].name} to #{queue_name(event)}" + args_info(event)
end
Expand All @@ -25,7 +25,7 @@ def queue_name(event)
def args_info(event)
event.payload[:args].any? ? ": #{event.payload[:args].inspect}" : ""
end

def enqueued_at(event)
Time.at(event.payload[:timestamp]).utc
end
Expand Down
49 changes: 49 additions & 0 deletions test/cases/logging_test.rb
@@ -0,0 +1,49 @@
require 'helper'
require "active_support/log_subscriber/test_helper"

class AdapterTest < ActiveSupport::TestCase
include ActiveSupport::LogSubscriber::TestHelper
include ActiveSupport::Logger::Severity

def setup
super
$BUFFER = []
@old_logger = ActiveJob::Base.logger
ActiveJob::Base.logger = @logger
ActiveJob::Logging::LogSubscriber.attach_to :active_job
end

def teardown
super
ActiveJob::Logging::LogSubscriber.log_subscribers.pop
ActiveJob::Base.logger = @old_logger
end

def set_logger(logger)
ActiveJob::Base.logger = logger
end

def test_enqueue_job_logging
HelloJob.enqueue "Cristian"
assert_match(/Enqueued HelloJob to .*?:.*Cristian/, @logger.logged(:info).join)
end

def test_perform_job_logging
HelloJob.enqueue "Cristian"
assert_match(/Performed HelloJob to .*?:.*Cristian/, @logger.logged(:info).join)
end

def test_enqueue_at_job_logging
HelloJob.enqueue_at 1, "Cristian"
assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.logged(:info).join)
rescue NotImplementedError
skip
end

def test_enqueue_in_job_logging
HelloJob.enqueue_in 2, "Cristian"
assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.logged(:info).join)
rescue NotImplementedError
skip
end
end

0 comments on commit 61deda5

Please sign in to comment.