sidekiq-symbols 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Appraisals +19 -0
- data/README.md +101 -13
- data/gemfiles/sidekiq_2_x.gemfile +5 -0
- data/gemfiles/sidekiq_3_x.gemfile +5 -0
- data/gemfiles/sidekiq_4_x.gemfile +5 -0
- data/gemfiles/sidekiq_5_x.gemfile +5 -0
- data/gemfiles/sidekiq_edge.gemfile +5 -0
- data/lib/sidekiq/symbols.rb +17 -6
- data/sidekiq-symbols.gemspec +6 -5
- data/spec/examples.txt +12 -0
- data/spec/re_run_friendly_formatter.rb +10 -10
- data/spec/spec_helper.rb +76 -5
- data/spec/symbols_spec.rb +83 -7
- metadata +30 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1954164e938224ab274441208d5036c6976bd1f
|
4
|
+
data.tar.gz: 11d6e29155f5ced734b6928da6054f4c66355e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c7be9b66e74d61e0d754fa6d901c3ba3d9a494d6abcb95c59d620aa04421e104e077a35929036dadc476346e2698f044702e6b629c80d8bbca1c34fa7c659d
|
7
|
+
data.tar.gz: e88beb69b21bbee8a0cc41c8fbbbbd9be023a68ad3efc7eb9407215f086dda7887ea605904dfdb4846c8e831db4c1081228c0b92e4a1d984e776d0fb73804c65
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise "sidekiq-2-x" do
|
2
|
+
gem "sidekiq", "~> 2.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "sidekiq-3-x" do
|
6
|
+
gem "sidekiq", "~> 3.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "sidekiq-4-x" do
|
10
|
+
gem "sidekiq", "~> 4.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "sidekiq-5-x" do
|
14
|
+
gem "sidekiq", "~> 4.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "sidekiq-edge" do
|
18
|
+
gem "sidekiq", github: "mperham/sidekiq"
|
19
|
+
end
|
data/README.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
|
+
# sidekiq-symbols
|
2
|
+
|
1
3
|
[](https://travis-ci.org/aprescott/sidekiq-symbols)
|
2
4
|
|
3
|
-
sidekiq-symbols gives you symbol keys for your
|
5
|
+
sidekiq-symbols gives you symbol keys and Ruby keyword arguments for your Sidekiq jobs.
|
6
|
+
|
7
|
+
### License
|
8
|
+
|
9
|
+
Copyright (c) 2014 Adam Prescott, licensed under the MIT license. See LICENSE.
|
4
10
|
|
5
11
|
### Caveats
|
6
12
|
|
7
|
-
I have not tested this in a production environment! The 0.x version is there for a reason!
|
13
|
+
While there is an automated test suite, and I have smoke-tested manually, I have not thoroughly tested this in a production environment! The 0.x version is there for a reason!
|
8
14
|
|
9
|
-
###
|
15
|
+
### Installing
|
10
16
|
|
11
|
-
|
17
|
+
With Bundler:
|
12
18
|
|
13
19
|
```ruby
|
14
|
-
|
20
|
+
# in Gemfile
|
21
|
+
gem "sidekiq-symbols"
|
15
22
|
```
|
16
23
|
|
17
|
-
|
24
|
+
Either `require "sidekiq-symbols"` or `require "sidekiq/symbols"`.
|
25
|
+
|
26
|
+
### To use
|
27
|
+
|
28
|
+
Include the `Sidekiq::Symbols` module in your job class:
|
18
29
|
|
19
30
|
```ruby
|
20
31
|
class SomeJob
|
@@ -27,19 +38,41 @@ end
|
|
27
38
|
|
28
39
|
### What it does
|
29
40
|
|
30
|
-
|
41
|
+
Consider this Sidekiq job:
|
31
42
|
|
32
43
|
```ruby
|
33
|
-
|
44
|
+
class SomeJob
|
45
|
+
include Sidekiq::Worker
|
46
|
+
|
47
|
+
def perform(opts = {})
|
48
|
+
raise unless opts.has_key?(:x)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# used as:
|
53
|
+
|
54
|
+
SomeJob.perform_async(x: 1)
|
34
55
|
```
|
35
56
|
|
36
|
-
|
57
|
+
Because Sidekiq round-trips job arguments through JSON serialization-deserialization, this job will raise as the arguments are converted from
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
{ x: 1 }
|
61
|
+
```
|
62
|
+
|
63
|
+
to
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
{ "x" => 1 }
|
67
|
+
```
|
68
|
+
|
69
|
+
and then passes it to `perform`. So it will end up being called as:
|
37
70
|
|
38
71
|
```ruby
|
39
72
|
perform("x" => 1)
|
40
73
|
```
|
41
74
|
|
42
|
-
sidekiq-symbols forces `perform` to
|
75
|
+
sidekiq-symbols forces `perform` to work with symbols, not strings:
|
43
76
|
|
44
77
|
```ruby
|
45
78
|
class SomeJob
|
@@ -47,14 +80,14 @@ class SomeJob
|
|
47
80
|
include Sidekiq::Symbols
|
48
81
|
|
49
82
|
def perform(arg, opts = {})
|
50
|
-
opts[:x] # this
|
83
|
+
opts[:x] == 1 # this is true now!
|
51
84
|
end
|
52
85
|
end
|
53
86
|
|
54
87
|
SomeJob.perform_async("foo", x: 1)
|
55
88
|
```
|
56
89
|
|
57
|
-
Note that `perform_async("foo", "x" => 1)` here
|
90
|
+
Note that this means you **cannot** use strings for this job! `perform_async("foo", "x" => 1)` here is converted to `perform("foo", x: 1)` because `Sidekiq::Symbols` is included.
|
58
91
|
|
59
92
|
### Keyword arguments
|
60
93
|
|
@@ -66,7 +99,62 @@ class SomeJob
|
|
66
99
|
include Sidekiq::Symbols
|
67
100
|
|
68
101
|
def perform(x: 1, y: 2)
|
69
|
-
# x and y are
|
102
|
+
# x and y are available
|
70
103
|
end
|
71
104
|
end
|
72
105
|
```
|
106
|
+
|
107
|
+
### Beware subclasses!
|
108
|
+
|
109
|
+
You may be tempted to add `include Sidekiq::Symbols` to a base class and inherit from that base class to get symbol support. **This will not work how you expect.**
|
110
|
+
|
111
|
+
Specifically, this situation won't correctly symbolize keys:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
# does NOT work
|
115
|
+
|
116
|
+
class BaseJob
|
117
|
+
include Sidekiq::Worker
|
118
|
+
include Sidekiq::Symbols
|
119
|
+
end
|
120
|
+
|
121
|
+
class FooJob < BaseJob
|
122
|
+
def perform
|
123
|
+
# ...
|
124
|
+
end
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
As long as you stick to keeping `include Sidekiq::Symbols` on "leaf" classes (at the bottom of the inheritance chain), it should work.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
# does work
|
132
|
+
|
133
|
+
class BaseJob
|
134
|
+
include Sidekiq::Worker
|
135
|
+
end
|
136
|
+
|
137
|
+
class FooJob < BaseJob
|
138
|
+
include Sidekiq::Symbols
|
139
|
+
|
140
|
+
def perform
|
141
|
+
# ...
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
It is recommended that you test any job classes that use `Sidekiq::Symbols` and that also rely on subclassing.
|
147
|
+
|
148
|
+
### Development
|
149
|
+
|
150
|
+
Issues (bugs, questions, etc.) should be opened with [the GitHub project](https://github.com/aprescott/sidekiq-symbols).
|
151
|
+
|
152
|
+
To contribute changes:
|
153
|
+
|
154
|
+
1. Visit the [GitHub repository for `sidekiq-symbols`](https://github.com/aprescott/sidekiq-symbols).
|
155
|
+
2. [Fork the repository](https://help.github.com/articles/fork-a-repo).
|
156
|
+
3. Make new feature branch: `git checkout -b master new-feature` (do not add on top of `master`!)
|
157
|
+
4. Implement the feature, along with tests.
|
158
|
+
5. [Send a pull request](https://help.github.com/articles/fork-a-repo).
|
159
|
+
|
160
|
+
Tests live in `spec/`. Run them with `rspec`. To run tests against various Sidekiq versions, use `appraisal rspec`. (See the [Appraisal](https://github.com/thoughtbot/appraisal) project and the `Appraisals` file for more details.)
|
data/lib/sidekiq/symbols.rb
CHANGED
@@ -9,7 +9,7 @@ module Symbols
|
|
9
9
|
module Symbolizer
|
10
10
|
def perform(*args)
|
11
11
|
symbolized_args = args.map do |arg|
|
12
|
-
if
|
12
|
+
if __sidekiq_symbols_should_process?(arg)
|
13
13
|
__sidekiq_symbols_symbolize_keys(arg)
|
14
14
|
else
|
15
15
|
arg
|
@@ -21,12 +21,23 @@ module Symbols
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def __sidekiq_symbols_symbolize_keys(arg)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
case arg
|
25
|
+
when Hash
|
26
|
+
h = {}
|
27
|
+
arg.each do |k, v|
|
28
|
+
k = k.to_sym if k.respond_to?(:to_sym)
|
29
|
+
h[k] = __sidekiq_symbols_should_process?(v) ? __sidekiq_symbols_symbolize_keys(v) : v
|
30
|
+
end
|
31
|
+
h
|
32
|
+
when Array
|
33
|
+
arg.map { |v| __sidekiq_symbols_should_process?(v) ? __sidekiq_symbols_symbolize_keys(v) : v }
|
34
|
+
else
|
35
|
+
arg
|
28
36
|
end
|
29
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
def __sidekiq_symbols_should_process?(arg)
|
40
|
+
arg.is_a?(Hash) || arg.is_a?(Array)
|
30
41
|
end
|
31
42
|
end
|
32
43
|
end
|
data/sidekiq-symbols.gemspec
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "sidekiq-symbols"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.2.0"
|
4
4
|
s.authors = ["Adam Prescott"]
|
5
5
|
s.email = ["adam@aprescott.com"]
|
6
6
|
s.homepage = "https://github.com/aprescott/sidekiq-symbols"
|
7
|
-
s.summary = "
|
8
|
-
s.description = "
|
9
|
-
s.files = Dir["{lib/**/*,spec
|
7
|
+
s.summary = "Give Sidekiq symbols and keyword arguments."
|
8
|
+
s.description = "Forces Sidekiq jobs to use symbolized keys and enables keyword arguments."
|
9
|
+
s.files = Dir["{lib/**/*,spec/**/*,gemfiles/*.gemfile}"] + %w[sidekiq-symbols.gemspec LICENSE Gemfile Appraisals README.md]
|
10
10
|
s.require_path = "lib"
|
11
11
|
s.test_files = Dir["spec/*"]
|
12
12
|
s.required_ruby_version = ">= 2.0.0"
|
13
13
|
s.licenses = ["MIT"]
|
14
14
|
|
15
15
|
s.add_dependency("sidekiq")
|
16
|
-
s.add_development_dependency("rspec", ">= 3.
|
16
|
+
s.add_development_dependency("rspec", ">= 3.3")
|
17
17
|
s.add_development_dependency("pry-byebug")
|
18
|
+
s.add_development_dependency("appraisal")
|
18
19
|
end
|
data/spec/examples.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------- | ------ | --------------- |
|
3
|
+
./spec/symbols_spec.rb[1:1] | passed | 0.00018 seconds |
|
4
|
+
./spec/symbols_spec.rb[1:2] | passed | 0.00028 seconds |
|
5
|
+
./spec/symbols_spec.rb[1:3] | passed | 0.00019 seconds |
|
6
|
+
./spec/symbols_spec.rb[1:4] | passed | 0.00019 seconds |
|
7
|
+
./spec/symbols_spec.rb[1:5] | passed | 0.00177 seconds |
|
8
|
+
./spec/symbols_spec.rb[1:6] | passed | 0.00019 seconds |
|
9
|
+
./spec/symbols_spec.rb[1:7] | passed | 0.0002 seconds |
|
10
|
+
./spec/symbols_spec.rb[1:8] | passed | 0.0002 seconds |
|
11
|
+
./spec/symbols_spec.rb[1:9:1] | passed | 0.00024 seconds |
|
12
|
+
./spec/symbols_spec.rb[1:10] | passed | 0.00119 seconds |
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require "rspec/core/formatters/progress_formatter"
|
2
|
-
|
2
|
+
|
3
3
|
class ReRunFriendlyFormatter < RSpec::Core::Formatters::ProgressFormatter
|
4
4
|
RSpec::Core::Formatters.register self, :dump_summary
|
5
|
-
|
5
|
+
|
6
6
|
def dump_summary(summary)
|
7
7
|
super
|
8
|
-
|
8
|
+
|
9
9
|
failed_files = summary.failed_examples.map { |e| RSpec::Core::Metadata::relative_path(e.file_path) }.uniq
|
10
|
-
|
10
|
+
|
11
11
|
return if summary.failed_examples.empty? || failed_files.length > 10
|
12
|
-
|
12
|
+
|
13
13
|
output.puts
|
14
14
|
output.puts "Rerun all failed examples:"
|
15
15
|
output.puts
|
16
|
-
|
16
|
+
|
17
17
|
output.puts failure_colored("rspec #{summary.failed_examples.map { |e| RSpec::Core::Metadata::relative_path(e.location) }.join(" ")}")
|
18
|
-
|
18
|
+
|
19
19
|
output.puts
|
20
20
|
output.puts "Rerun all files containing failures:"
|
21
21
|
output.puts
|
22
|
-
|
22
|
+
|
23
23
|
output.puts failure_colored("rspec #{failed_files.join(" ")}")
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
private
|
27
|
-
|
27
|
+
|
28
28
|
def failure_colored(str)
|
29
29
|
RSpec::Core::Formatters::ConsoleCodes.wrap(str, :failure)
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,18 +4,89 @@ require "sidekiq/testing"
|
|
4
4
|
require "pry-byebug"
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
|
-
config.
|
8
|
-
|
7
|
+
# rspec-expectations config goes here. You can use an alternate
|
8
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
9
|
+
# assertions if you prefer.
|
10
|
+
config.expect_with :rspec do |expectations|
|
11
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
12
|
+
# and `failure_message` of custom matchers include text for helper methods
|
13
|
+
# defined using `chain`, e.g.:
|
14
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
15
|
+
# # => "be bigger than 2 and smaller than 4"
|
16
|
+
# ...rather than:
|
17
|
+
# # => "be bigger than 2"
|
18
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
9
19
|
end
|
10
20
|
|
21
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
22
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
25
|
+
# a real object. This is generally recommended, and will default to
|
26
|
+
# `true` in RSpec 4.
|
27
|
+
mocks.verify_partial_doubles = true
|
28
|
+
end
|
29
|
+
|
30
|
+
# These two settings work together to allow you to limit a spec run
|
31
|
+
# to individual examples or groups you care about by tagging them with
|
32
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
33
|
+
# get run.
|
11
34
|
config.filter_run :focus
|
12
35
|
config.run_all_when_everything_filtered = true
|
13
36
|
|
14
|
-
|
15
|
-
|
37
|
+
# Allows RSpec to persist some state between runs in order to support
|
38
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
39
|
+
# you configure your source control system to ignore this file.
|
40
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
41
|
+
|
42
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
43
|
+
# recommended. For more details, see:
|
44
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
45
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
46
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
47
|
+
config.disable_monkey_patching!
|
48
|
+
|
49
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
50
|
+
# be too noisy due to issues in dependencies.
|
51
|
+
config.warnings = false
|
52
|
+
|
53
|
+
# Run specs in random order to surface order dependencies. If you find an
|
54
|
+
# order dependency and want to debug it, you can fix the order by providing
|
55
|
+
# the seed, which is printed after each run.
|
56
|
+
# --seed 1234
|
57
|
+
config.order = :random
|
58
|
+
|
59
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
60
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
61
|
+
# test failures related to randomization by passing the same `--seed` value
|
62
|
+
# as the one that triggered the failure.
|
63
|
+
Kernel.srand config.seed
|
64
|
+
end
|
65
|
+
|
66
|
+
# sidekiq test configuration
|
67
|
+
RSpec.configure do |config|
|
68
|
+
config.before(:each) do |example_method|
|
69
|
+
# Clears out the jobs for tests using the fake testing
|
70
|
+
Sidekiq::Worker.clear_all
|
71
|
+
end
|
72
|
+
|
73
|
+
# use an around to allow each test to specify
|
74
|
+
# its own around block and override the testing
|
75
|
+
# context.
|
76
|
+
config.before(:each) do |example_method|
|
77
|
+
# Clears out the jobs for tests using the fake testing
|
78
|
+
Sidekiq::Worker.clear_all
|
16
79
|
end
|
17
80
|
|
81
|
+
# use an around to allow each test to specify
|
82
|
+
# its own around block and override the testing
|
83
|
+
# context.
|
18
84
|
config.around(:each) do |example|
|
19
|
-
|
85
|
+
# acceptance tests run the jobs immediately.
|
86
|
+
if example.metadata[:type] == :feature || example.metadata[:sidekiq] == :inline
|
87
|
+
Sidekiq::Testing.inline!(&example)
|
88
|
+
else
|
89
|
+
Sidekiq::Testing.fake!(&example)
|
90
|
+
end
|
20
91
|
end
|
21
92
|
end
|
data/spec/symbols_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Sidekiq::Symbols do
|
1
|
+
RSpec.describe Sidekiq::Symbols, sidekiq: :inline do
|
4
2
|
class SampleJob
|
5
3
|
include Sidekiq::Worker
|
6
4
|
include Sidekiq::Symbols
|
7
5
|
|
8
6
|
def perform(*args, **kwargs)
|
9
|
-
$
|
7
|
+
$perform_arg_signature = [args, kwargs]
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -15,14 +13,17 @@ describe Sidekiq::Symbols do
|
|
15
13
|
include Sidekiq::Symbols
|
16
14
|
|
17
15
|
def perform(x, opts = {})
|
18
|
-
$
|
16
|
+
$perform_arg_signature = [x, opts]
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
def expect_transformation(klass, *input, arg_signature)
|
23
|
-
expect(klass.new.perform(*input)).to eq(arg_signature)
|
24
21
|
klass.perform_async(*input)
|
25
|
-
expect($
|
22
|
+
expect($perform_arg_signature).to eq(arg_signature)
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
$perform_arg_signature = nil
|
26
27
|
end
|
27
28
|
|
28
29
|
it "allows regular arguments" do
|
@@ -37,10 +38,85 @@ describe Sidekiq::Symbols do
|
|
37
38
|
expect_transformation(SampleHashArgJob, 1, { "x" => 1 }, [1, x: 1])
|
38
39
|
end
|
39
40
|
|
41
|
+
it "symbolizes hashes inside arrays" do
|
42
|
+
expect_transformation(SampleHashArgJob, 1, { "x" => [ { "y" => 2 } ] }, [1, x: [{y:2}]])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "handles arrays containing a mix of types" do
|
46
|
+
expect_transformation(SampleHashArgJob, 1, { "x" => [{ "y" => 2 }, "not-a-hash", 123] }, [1, { x: [{ y: 2 }, "not-a-hash", 123] }])
|
47
|
+
end
|
48
|
+
|
49
|
+
it "symbolizes hashes inside arrays inside hashes inside arrays" do
|
50
|
+
input = [1, {"x" => [ { "y" => [ { "z" => 3 } ] } ] }]
|
51
|
+
arg_signature = [1, { x: [ { y: [ { z: 3 } ] } ] }]
|
52
|
+
expect_transformation(SampleHashArgJob, *input, arg_signature)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "symbolizes hashes inside arrays inside arrays" do
|
56
|
+
input = [1, {"x" => [ [ { "y" => 2 }, { "z" => 3 } ] ] }]
|
57
|
+
arg_signature = [1, { x: [ [ { y: 2 }, { z: 3 } ] ] }]
|
58
|
+
expect_transformation(SampleHashArgJob, *input, arg_signature)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
40
62
|
it "symbolizes all arguments to Sidekiq's perform" do
|
41
63
|
input = [1, "x" => { "y" => 2, z: { "foo bar" => 0 } }]
|
42
64
|
arg_signature = [[1], { x: { y: 2, z: { :"foo bar" => 0 } } }]
|
43
65
|
|
44
66
|
expect_transformation(SampleJob, *input, arg_signature)
|
45
67
|
end
|
68
|
+
|
69
|
+
describe "subclassing" do
|
70
|
+
class BaseJob
|
71
|
+
include Sidekiq::Worker
|
72
|
+
end
|
73
|
+
|
74
|
+
class SubclassFooJob < BaseJob
|
75
|
+
include Sidekiq::Symbols
|
76
|
+
|
77
|
+
def perform(x: -1)
|
78
|
+
$subclass_x = x
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class SubclassBarJob < BaseJob
|
83
|
+
include Sidekiq::Symbols
|
84
|
+
|
85
|
+
def perform(y: -1)
|
86
|
+
$subclass_y = y
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "works on subclasses that do their own include" do
|
91
|
+
SubclassFooJob.perform_async(x: 1)
|
92
|
+
SubclassBarJob.perform_async(y: 2)
|
93
|
+
|
94
|
+
expect($subclass_x).to eq(1)
|
95
|
+
expect($subclass_y).to eq(2)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# 2.1+ introduced required keyword arguments, so this must be done with
|
100
|
+
# eval to sidestep syntax errors at parse time.
|
101
|
+
if RUBY_VERSION >= "2.1.0"
|
102
|
+
# Note that this test is asserting that perform_async raises, but in
|
103
|
+
# reality it will actually raise at the Sidekiq server level when the worker
|
104
|
+
# tries to perform the job.
|
105
|
+
#
|
106
|
+
# perform_async itself won't raise because of missing required keyword args
|
107
|
+
# in actual code.
|
108
|
+
eval <<-DEFEAT_THE_PARSER
|
109
|
+
class SampleRequiredKeywordArgsJob
|
110
|
+
include Sidekiq::Worker
|
111
|
+
include Sidekiq::Symbols
|
112
|
+
|
113
|
+
def perform(x:)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "raises on missing required keyword args" do
|
118
|
+
expect { SampleRequiredKeywordArgsJob.perform_async }.to raise_error(ArgumentError)
|
119
|
+
end
|
120
|
+
DEFEAT_THE_PARSER
|
121
|
+
end
|
46
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-symbols
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Prescott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry-byebug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,19 +52,40 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: appraisal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Forces Sidekiq jobs to use symbolized keys and enables keyword arguments.
|
56
70
|
email:
|
57
71
|
- adam@aprescott.com
|
58
72
|
executables: []
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- Appraisals
|
62
77
|
- Gemfile
|
63
78
|
- LICENSE
|
64
79
|
- README.md
|
80
|
+
- gemfiles/sidekiq_2_x.gemfile
|
81
|
+
- gemfiles/sidekiq_3_x.gemfile
|
82
|
+
- gemfiles/sidekiq_4_x.gemfile
|
83
|
+
- gemfiles/sidekiq_5_x.gemfile
|
84
|
+
- gemfiles/sidekiq_edge.gemfile
|
65
85
|
- lib/sidekiq-symbols.rb
|
66
86
|
- lib/sidekiq/symbols.rb
|
67
87
|
- sidekiq-symbols.gemspec
|
88
|
+
- spec/examples.txt
|
68
89
|
- spec/re_run_friendly_formatter.rb
|
69
90
|
- spec/spec_helper.rb
|
70
91
|
- spec/symbols_spec.rb
|
@@ -88,11 +109,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
109
|
version: '0'
|
89
110
|
requirements: []
|
90
111
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.6.14
|
92
113
|
signing_key:
|
93
114
|
specification_version: 4
|
94
|
-
summary:
|
115
|
+
summary: Give Sidekiq symbols and keyword arguments.
|
95
116
|
test_files:
|
96
|
-
- spec/re_run_friendly_formatter.rb
|
97
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/examples.txt
|
119
|
+
- spec/re_run_friendly_formatter.rb
|
98
120
|
- spec/symbols_spec.rb
|