-
Notifications
You must be signed in to change notification settings - Fork 9
/
resque_spec.rb
48 lines (40 loc) · 1.26 KB
/
resque_spec.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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'resque'
require 'log_weasel/resque'
describe LogWeasel::Resque do
before do
LogWeasel::Resque.initialize! 'FOO'
end
after do
LogWeasel::Transaction.destroy
end
it "pushes with log_weasel_id in context" do
Resque.stubs(:redis).returns(stub(:sadd => nil, :rpush => nil))
Resque.expects(:encode).with do |item|
item['context'].should_not be_nil
item['context'].should have_key('log_weasel_id')
item['context']['log_weasel_id'].should =~ /^FOO-RESQUE/
end
Resque.push('queue', {'args' => [1]})
end
describe ".after_fork" do
context "with log_weasel_id" do
before do
@job = Resque::Job.new 'queue', {'args' =>[{}], 'context' => {'log_weasel_id' => "123"}}
end
it "sets transaction id from args" do
LogWeasel::Transaction.expects(:id=).with('123')
LogWeasel::Resque::Callbacks.after_fork @job, nil
end
end
context "without log_weasel_id" do
before do
@job = Resque::Job.new 'queue', {'args' =>[1]}
end
it "creates a new log_weasel_id" do
LogWeasel::Transaction.expects(:create)
LogWeasel::Resque::Callbacks.after_fork @job, nil
end
end
end
end