activejob 4.2.0 → 4.2.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activejob might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3925ce1b459be37d50b6ca6abfb3f64998ddc9a5
4
- data.tar.gz: 4f770e914535bfd505164c4c906ec5b86a982488
3
+ metadata.gz: 3d4b1917882888a451df55d600965755a46b26a5
4
+ data.tar.gz: 501326baaf11dd12a503e7ba68a20ea82d05f65f
5
5
  SHA512:
6
- metadata.gz: 3035f8ace873f16092a49af5efb3643761a57f1a6eb9925be754538e5b1f42f09c5458a19e9be2641c81074faf4d342ca861cf78da703fc5a608ef2cacb01221
7
- data.tar.gz: 73150f5ffcee5caab778da0ddd73dcb35d9dd10225d3b0e5798e6e01553a92bb13b7f38865184efd5cd15fd0b190e41f25cfec75c28c46e6d091e6a43437537f
6
+ metadata.gz: 92f1f60a13299069e5acb2a0f660c5a3b4117d5932b2d026134f881974675e932caa99200640d409906cd9f225f1b0683aa2a9bcf43423494ca302e2d26ff3c9
7
+ data.tar.gz: 568d2685bacd7d1e1c415dc5319921461022641f1d97fa1cc49a95bc0b3cb6ddc2999136cc31578c58b61a07589002f6023af9bb07280471db879da40ad49a93
@@ -1 +1,10 @@
1
- * Started project.
1
+ * Allow keyword arguments to be used with Active Job.
2
+
3
+ Fixes #18741.
4
+
5
+ *Sean Griffin*
6
+
7
+
8
+ ## Rails 4.2.0 (December 20, 2014) ##
9
+
10
+ * Started project.
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/hash'
2
+
1
3
  module ActiveJob
2
4
  # Raised when an exception is raised during job arguments deserialization.
3
5
  #
@@ -42,7 +44,9 @@ module ActiveJob
42
44
 
43
45
  private
44
46
  GLOBALID_KEY = '_aj_globalid'.freeze
45
- private_constant :GLOBALID_KEY
47
+ SYMBOL_KEYS_KEY = '_aj_symbol_keys'.freeze
48
+ WITH_INDIFFERENT_ACCESS_KEY = '_aj_hash_with_indifferent_access'.freeze
49
+ private_constant :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
46
50
 
47
51
  def serialize_argument(argument)
48
52
  case argument
@@ -52,10 +56,15 @@ module ActiveJob
52
56
  { GLOBALID_KEY => argument.to_global_id.to_s }
53
57
  when Array
54
58
  argument.map { |arg| serialize_argument(arg) }
59
+ when ActiveSupport::HashWithIndifferentAccess
60
+ result = serialize_hash(argument)
61
+ result[WITH_INDIFFERENT_ACCESS_KEY] = serialize_argument(true)
62
+ result
55
63
  when Hash
56
- argument.each_with_object({}) do |(key, value), hash|
57
- hash[serialize_hash_key(key)] = serialize_argument(value)
58
- end
64
+ symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
65
+ result = serialize_hash(argument)
66
+ result[SYMBOL_KEYS_KEY] = symbol_keys
67
+ result
59
68
  else
60
69
  raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
61
70
  end
@@ -73,7 +82,7 @@ module ActiveJob
73
82
  if serialized_global_id?(argument)
74
83
  deserialize_global_id argument
75
84
  else
76
- deserialize_hash argument
85
+ deserialize_hash(argument)
77
86
  end
78
87
  else
79
88
  raise ArgumentError, "Can only deserialize primitive arguments: #{argument.inspect}"
@@ -88,13 +97,27 @@ module ActiveJob
88
97
  GlobalID::Locator.locate hash[GLOBALID_KEY]
89
98
  end
90
99
 
100
+ def serialize_hash(argument)
101
+ argument.each_with_object({}) do |(key, value), hash|
102
+ hash[serialize_hash_key(key)] = serialize_argument(value)
103
+ end
104
+ end
105
+
91
106
  def deserialize_hash(serialized_hash)
92
- serialized_hash.each_with_object({}.with_indifferent_access) do |(key, value), hash|
93
- hash[key] = deserialize_argument(value)
107
+ result = serialized_hash.transform_values { |v| deserialize_argument(v) }
108
+ if result.delete(WITH_INDIFFERENT_ACCESS_KEY)
109
+ result = result.with_indifferent_access
110
+ elsif symbol_keys = result.delete(SYMBOL_KEYS_KEY)
111
+ result = transform_symbol_keys(result, symbol_keys)
94
112
  end
113
+ result
95
114
  end
96
115
 
97
- RESERVED_KEYS = [GLOBALID_KEY, GLOBALID_KEY.to_sym]
116
+ RESERVED_KEYS = [
117
+ GLOBALID_KEY, GLOBALID_KEY.to_sym,
118
+ SYMBOL_KEYS_KEY, SYMBOL_KEYS_KEY.to_sym,
119
+ WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
120
+ ]
98
121
  private_constant :RESERVED_KEYS
99
122
 
100
123
  def serialize_hash_key(key)
@@ -107,5 +130,15 @@ module ActiveJob
107
130
  raise SerializationError.new("Only string and symbol hash keys may be serialized as job arguments, but #{key.inspect} is a #{key.class}")
108
131
  end
109
132
  end
133
+
134
+ def transform_symbol_keys(hash, symbol_keys)
135
+ hash.transform_keys do |key|
136
+ if symbol_keys.include?(key)
137
+ key.to_sym
138
+ else
139
+ key
140
+ end
141
+ end
142
+ end
110
143
  end
111
144
  end
@@ -7,8 +7,8 @@ module ActiveJob
7
7
  module VERSION
8
8
  MAJOR = 4
9
9
  MINOR = 2
10
- TINY = 0
11
- PRE = nil
10
+ TINY = 1
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -2,7 +2,7 @@ require 'active_job/queue_adapters/inline_adapter'
2
2
  require 'active_support/core_ext/string/inflections'
3
3
 
4
4
  module ActiveJob
5
- # The <tt>ActionJob::QueueAdapter</tt> module is used to load the
5
+ # The <tt>ActionJob::QueueAdapter</tt> module is used to load the
6
6
  # correct adapter. The default queue adapter is the :inline queue.
7
7
  module QueueAdapter #:nodoc:
8
8
  extend ActiveSupport::Concern
@@ -21,8 +21,8 @@ module ActiveJob
21
21
  ActiveJob::QueueAdapters::TestAdapter.new
22
22
  when Symbol, String
23
23
  load_adapter(name_or_adapter)
24
- when Class
25
- name_or_adapter
24
+ else
25
+ name_or_adapter if name_or_adapter.respond_to?(:enqueue)
26
26
  end
27
27
  end
28
28
 
@@ -15,7 +15,7 @@ module ActiveJob
15
15
  end
16
16
 
17
17
  def enqueue_at(*) #:nodoc:
18
- raise NotImplementedError.new("Use a queueing backend to enqueue jobs in the future. Read more at http://guides.rubyonrails.org/v4.2.0/active_job_basics.html")
18
+ raise NotImplementedError.new("Use a queueing backend to enqueue jobs in the future. Read more at http://guides.rubyonrails.org/active_job_basics.html")
19
19
  end
20
20
  end
21
21
  end
@@ -14,6 +14,11 @@ module ActiveJob
14
14
  attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs)
15
15
  attr_writer(:enqueued_jobs, :performed_jobs)
16
16
 
17
+ def initialize
18
+ self.perform_enqueued_jobs = false
19
+ self.perform_enqueued_at_jobs = false
20
+ end
21
+
17
22
  # Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
18
23
  def enqueued_jobs
19
24
  @enqueued_jobs ||= []
@@ -26,19 +31,19 @@ module ActiveJob
26
31
 
27
32
  def enqueue(job) #:nodoc:
28
33
  if perform_enqueued_jobs
29
- performed_jobs << {job: job.class, args: job.arguments, queue: job.queue_name}
30
- job.perform_now
34
+ performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name}
35
+ Base.execute job.serialize
31
36
  else
32
- enqueued_jobs << {job: job.class, args: job.arguments, queue: job.queue_name}
37
+ enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name}
33
38
  end
34
39
  end
35
40
 
36
41
  def enqueue_at(job, timestamp) #:nodoc:
37
42
  if perform_enqueued_at_jobs
38
- performed_jobs << {job: job.class, args: job.arguments, queue: job.queue_name, at: timestamp}
39
- job.perform_now
43
+ performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp}
44
+ Base.execute job.serialize
40
45
  else
41
- enqueued_jobs << {job: job.class, args: job.arguments, queue: job.queue_name, at: timestamp}
46
+ enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp}
42
47
  end
43
48
  end
44
49
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/hash/keys'
2
+
1
3
  module ActiveJob
2
4
  # Provides helper methods for testing Active Job
3
5
  module TestHelper
@@ -157,9 +159,10 @@ module ActiveJob
157
159
  original_enqueued_jobs = enqueued_jobs.dup
158
160
  clear_enqueued_jobs
159
161
  args.assert_valid_keys(:job, :args, :at, :queue)
162
+ serialized_args = serialize_args_for_assertion(args)
160
163
  yield
161
164
  matching_job = enqueued_jobs.any? do |job|
162
- args.all? { |key, value| value == job[key] }
165
+ serialized_args.all? { |key, value| value == job[key] }
163
166
  end
164
167
  assert matching_job, "No enqueued job found with #{args}"
165
168
  ensure
@@ -177,9 +180,10 @@ module ActiveJob
177
180
  original_performed_jobs = performed_jobs.dup
178
181
  clear_performed_jobs
179
182
  args.assert_valid_keys(:job, :args, :at, :queue)
183
+ serialized_args = serialize_args_for_assertion(args)
180
184
  perform_enqueued_jobs { yield }
181
185
  matching_job = performed_jobs.any? do |job|
182
- args.all? { |key, value| value == job[key] }
186
+ serialized_args.all? { |key, value| value == job[key] }
183
187
  end
184
188
  assert matching_job, "No performed job found with #{args}"
185
189
  ensure
@@ -213,6 +217,14 @@ module ActiveJob
213
217
  def clear_performed_jobs
214
218
  performed_jobs.clear
215
219
  end
220
+
221
+ def serialize_args_for_assertion(args)
222
+ serialized_args = args.dup
223
+ if job_args = serialized_args.delete(:args)
224
+ serialized_args[:args] = ActiveJob::Arguments.serialize(job_args)
225
+ end
226
+ serialized_args
227
+ end
216
228
  end
217
229
  end
218
230
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-20 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 4.2.1.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: 4.2.1.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: globalid
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,12 +92,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: 1.9.3
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - ">"
96
96
  - !ruby/object:Gem::Version
97
- version: '0'
97
+ version: 1.3.1
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.2.2
100
+ rubygems_version: 2.4.5
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: Job framework with pluggable queues.