sucker_punch 0.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +6 -0
- data/README.md +43 -7
- data/lib/sucker_punch.rb +0 -1
- data/lib/sucker_punch/exceptions.rb +1 -2
- data/lib/sucker_punch/version.rb +1 -1
- data/spec/sucker_punch_spec.rb +0 -8
- data/sucker_punch.gemspec +1 -1
- metadata +6 -6
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -110,21 +110,21 @@ SuckerPunch::Queue[:log_queue].busy_size # => 4
|
|
110
110
|
SuckerPunch::Queue[:log_queue].idle_size # => 3
|
111
111
|
```
|
112
112
|
|
113
|
-
## Testing
|
113
|
+
## Testing (Only 0.3.1+)
|
114
114
|
|
115
115
|
```Ruby
|
116
116
|
# spec/spec_helper.rb
|
117
117
|
require 'sucker_punch/testing'
|
118
118
|
```
|
119
119
|
|
120
|
-
Requiring this library completely stubs out the internals of Sucker
|
120
|
+
Requiring this library completely stubs out the internals of Sucker Punch, but will provide the necessary tools to confirm your jobs are being enqueud.
|
121
121
|
|
122
122
|
```Ruby
|
123
123
|
# spec/spec_helper.rb
|
124
124
|
require 'sucker_punch/testing'
|
125
125
|
|
126
126
|
RSpec.configure do |config|
|
127
|
-
config.after
|
127
|
+
config.after do
|
128
128
|
SuckerPunch.reset! # => Resets the queues and jobs in the queues before each test
|
129
129
|
end
|
130
130
|
end
|
@@ -134,7 +134,7 @@ SuckerPunch.config do
|
|
134
134
|
queue name: :email, worker: EmailWorker, workers: 2
|
135
135
|
end
|
136
136
|
|
137
|
-
#
|
137
|
+
# app/workers/email_worker.rb
|
138
138
|
class EmailWorker
|
139
139
|
include SuckerPunch::Worker
|
140
140
|
|
@@ -151,9 +151,6 @@ class User < ActiveRecord::Base
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
# spec/spec_helper.rb
|
155
|
-
require 'sucker_punch/testing'
|
156
|
-
|
157
154
|
# spec/models/user_spec.rb
|
158
155
|
require 'spec_helper'
|
159
156
|
|
@@ -180,6 +177,45 @@ SuckerPunch::Queue[:log_queue].async.perform("login")
|
|
180
177
|
|
181
178
|
## Troubleshooting
|
182
179
|
|
180
|
+
If you're running tests in transactions (using DatabaseCleaner or a native solution), Sucker Punch workers may have trouble finding database records that were created during test setup because the worker class is running in a separate thread and the Transaction operates on a different thread so it clears out the data before the worker can do its business. The best thing to do is cleanup data created for tests workers through a truncation strategy by tagging the rspec tests as workers and then specifying the strategy in `spec_helper` like below:
|
181
|
+
|
182
|
+
```Ruby
|
183
|
+
# spec/spec_helper.rb
|
184
|
+
RSpec.configure do |config|
|
185
|
+
config.before(:each) do
|
186
|
+
DatabaseCleaner.strategy = :transaction
|
187
|
+
end
|
188
|
+
|
189
|
+
# Clean up all worker specs with truncation
|
190
|
+
config.before(:each, :worker => true) do
|
191
|
+
DatabaseCleaner.strategy = :truncation
|
192
|
+
end
|
193
|
+
|
194
|
+
config.before(:each) do
|
195
|
+
DatabaseCleaner.start
|
196
|
+
end
|
197
|
+
|
198
|
+
config.after(:each) do
|
199
|
+
DatabaseCleaner.clean
|
200
|
+
end
|
201
|
+
|
202
|
+
# spec/workers/email_worker_spec.rb
|
203
|
+
require 'spec_helper'
|
204
|
+
|
205
|
+
# Tag the spec as a worker spec so data is persisted long enough for the test
|
206
|
+
describe EmailWorker, worker: true do
|
207
|
+
describe "#perform" do
|
208
|
+
let(:user) { FactoryGirl.create(:user) }
|
209
|
+
|
210
|
+
it "delivers an email" do
|
211
|
+
expect {
|
212
|
+
EmailWorker.new.perform(user.id)
|
213
|
+
}.to change{ ActionMailer::Base.deliveries.size }.by(1)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
```
|
218
|
+
|
183
219
|
When using Passenger or Unicorn, you should configure the queues within a block that runs after the child process is forked.
|
184
220
|
|
185
221
|
```Ruby
|
data/lib/sucker_punch.rb
CHANGED
data/lib/sucker_punch/version.rb
CHANGED
data/spec/sucker_punch_spec.rb
CHANGED
@@ -15,14 +15,6 @@ describe SuckerPunch do
|
|
15
15
|
queue name: :crazy_queue, worker: FakeWorker, workers: 3
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
it "supports size for workers count" do
|
20
|
-
SuckerPunch::Queue.any_instance.should_receive(:register).with(FakeWorker, 3)
|
21
|
-
|
22
|
-
SuckerPunch.config do
|
23
|
-
queue name: :crazy_queue, worker: FakeWorker, size: 3
|
24
|
-
end
|
25
|
-
end
|
26
18
|
end
|
27
19
|
|
28
20
|
context "with no queue name" do
|
data/sucker_punch.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sucker_punch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -48,17 +48,17 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 0.13.0
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.13.0
|
62
62
|
description: Asynchronous processing library for Ruby
|
63
63
|
email:
|
64
64
|
- brandonhilkert@gmail.com
|