forked from tobi/delayed_job
-
Notifications
You must be signed in to change notification settings - Fork 957
/
helper.rb
61 lines (46 loc) · 1.47 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start
require 'logger'
require 'rspec'
require 'action_mailer'
require 'active_support/dependencies'
require 'active_record'
require 'delayed_job'
require 'delayed/backend/shared_spec'
Delayed::Worker.logger = Logger.new('/tmp/dj.log')
ENV['RAILS_ENV'] = 'test'
Delayed::Worker.backend = :test
# Add this directory so the ActiveSupport autoloading works
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
# Add this to simulate Railtie initializer being executed
ActionMailer::Base.send(:extend, Delayed::DelayMail)
# Used to test interactions between DJ and an ORM
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
ActiveRecord::Base.logger = Delayed::Worker.logger
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :stories, :primary_key => :story_id, :force => true do |table|
table.string :text
table.boolean :scoped, :default => true
end
end
class Story < ActiveRecord::Base
self.primary_key = 'story_id'
def tell; text; end
def whatever(n, _); tell*n; end
default_scope { where(:scoped => true) }
handle_asynchronously :whatever
end
RSpec.configure do |config|
config.after(:each) do
Delayed::Worker.reset
end
config.expect_with :rspec do |c|
c.syntax = :expect
end
end