Skip to content

Commit

Permalink
Tests, WIP
Browse files Browse the repository at this point in the history
Add schema for tests
Rework initialization sequence
  • Loading branch information
Bill Kayser committed Feb 4, 2010
1 parent 5b7a4c0 commit 5fe0d26
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require "#{File.dirname(__FILE__)}/../helper.rb"

begin
require 'delayed_job'
rescue LoadError => e
# framework not available
end

module DelayedJobInstrumentation
require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))

class LongRunningJob
def perform
Expand All @@ -16,7 +23,7 @@ def perform
end
end

class DelayedJobTest < Test::Unit::TestCase
class TestDelayedJob < Test::Unit::TestCase
def local_env
NewRelic::Control.instance.local_env
end
Expand Down Expand Up @@ -105,4 +112,4 @@ def test_lock_sampler
end

end
end if defined? Delayed::Job
end if defined? Delayed::Job and defined? SQLite3
3 changes: 3 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'newrelic_rpm'
require 'rpm_contrib'

class Test::Unit::TestCase
end

require 'schema.rb'
31 changes: 31 additions & 0 deletions test/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use this file to add tables you need to do testing
# These are created in a sqllite memory DB

begin
require 'sqlite3'
require 'active_record'

ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
ActiveRecord::Migration.verbose = false

ActiveRecord::Schema.define do

create_table :delayed_jobs, :force => true do |table|
table.integer :priority, :default => 0
table.integer :attempts, :default => 0
table.text :handler
table.string :last_error
table.datetime :run_at
table.datetime :locked_at
table.string :locked_by
table.datetime :failed_at
table.timestamps
end

create_table :stories, :force => true do |table|
table.string :text
end
end
rescue LoadError
# Skip AR tests
end
2 changes: 1 addition & 1 deletion test/test_rpm_contrib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'helper'
require "#{File.dirname(__FILE__)}/helper"

class TestRpmContrib < Test::Unit::TestCase
def test_something_for_real
Expand Down

0 comments on commit 5fe0d26

Please sign in to comment.