active_batch 0.0.1 → 0.0.2

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.
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ module ActiveBatch
4
+ class BatchJobTest < ActiveJob::TestCase
5
+
6
+ setup do
7
+ @test_string = 'test'
8
+ end
9
+
10
+ test 'can be enqueued outside a batch' do
11
+ BatchJob.perform_now(@test_string)
12
+ assert_equal @test_string, IO.read('/tmp/batch_job_result')
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,6 @@ require 'test_helper'
2
2
 
3
3
  module ActiveBatch
4
4
  class BatchSchedulerJobTest < ActiveJob::TestCase
5
- include ActiveJob::TestHelper
6
5
 
7
6
  setup do
8
7
  @batch_job = 'BatchJob'
@@ -37,5 +36,11 @@ module ActiveBatch
37
36
  batch = Batch.find_by(job_id: job.job_id)
38
37
  assert_equal @test_string.length, batch.work_units.enqueued.count
39
38
  end
39
+
40
+ test 'uses same queue than the Batch Job' do
41
+ assert_enqueued_with(job: BatchSchedulerJob, queue: BatchJob.new.queue_name) do
42
+ BatchSchedulerJob.perform_later(BatchJob)
43
+ end
44
+ end
40
45
  end
41
46
  end
@@ -41,10 +41,10 @@ module ActiveBatch
41
41
  @work_unit_running.update!(status: :done)
42
42
  BatchStatusCheckJob.perform_now(@batch)
43
43
 
44
- assert File.exists?('/tmp/batch_job_result')
44
+ assert File.exists?('/tmp/batch_job_results')
45
45
  assert File.exists?('/tmp/batch_job_arguments')
46
46
  assert_equal @batch.arguments.first, IO.read('/tmp/batch_job_arguments')
47
- assert_equal [@first_result, @second_result].to_s, IO.read('/tmp/batch_job_result')
47
+ assert_equal [@first_result, @second_result].to_s, IO.read('/tmp/batch_job_results')
48
48
  end
49
49
 
50
50
  end
@@ -10,11 +10,12 @@ class BatchJob < ActiveJob::Base
10
10
  end
11
11
 
12
12
  def self.after_batch(args, results)
13
- File.open('/tmp/batch_job_arguments', 'w') { |f| f << args.first }
14
- File.open('/tmp/batch_job_result', 'w') { |f| f << results }
13
+ File.open('/tmp/batch_job_arguments', 'w') { |f| f << args }
14
+ File.open('/tmp/batch_job_results', 'w') { |f| f << results }
15
15
  end
16
16
 
17
17
  def perform(char)
18
+ File.open('/tmp/batch_job_result', 'w') { |f| f << char }
18
19
  save_result(char)
19
20
  end
20
21
 
@@ -3,19 +3,26 @@ require 'test_helper'
3
3
  module ActiveBatch
4
4
  class BatchedJobTest < ActiveSupport::TestCase
5
5
 
6
- test 'can save work result' do
6
+ test 'can save work result when in batch' do
7
7
  @batched_job = BatchJob.new
8
+ @batched_job.in_batch = true
8
9
  @work_unit = WorkUnit.create(job_id: @batched_job.job_id)
9
10
  @batched_job.save_result('blah')
10
11
  assert_equal 'blah', @work_unit.reload.work_result
11
12
  end
12
13
 
13
- test 'sets status to failed on exception' do
14
+ test 'sets status to failed on exception when in batch' do
14
15
  @rescue_job = RescueJob.new
16
+ @rescue_job.in_batch = true
15
17
  @work_unit = WorkUnit.create(job_id: @rescue_job.job_id)
16
18
  @rescue_job.perform_now rescue nil
17
19
  assert @work_unit.reload.failed?
18
20
  end
19
21
 
22
+ test 'can perform batch' do
23
+ assert_enqueued_with(job: BatchSchedulerJob, args: [BatchJob, 1, 2]) do
24
+ BatchJob.perform_batch(1, 2)
25
+ end
26
+ end
20
27
  end
21
28
  end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module ActiveBatch
4
+ class WithActiveJobArgumentsTest < ActiveSupport::TestCase
5
+
6
+ setup do
7
+ build_model :dummy do
8
+ string :arguments
9
+
10
+ include WithActiveJobArguments
11
+ end
12
+ @arguments = [1, { 'a' => 3 }, Batch.create]
13
+ end
14
+
15
+ test 'serializes active job arguments' do
16
+ dummy = Dummy.create(arguments: @arguments)
17
+ assert_equal @arguments, Dummy.find(dummy.id).arguments
18
+ end
19
+
20
+ end
21
+ end
data/test/test_helper.rb CHANGED
@@ -7,6 +7,7 @@ ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate',
7
7
  require "rails/test_help"
8
8
  require "jobs/batch_job"
9
9
  require "jobs/rescue_job"
10
+ require 'acts_as_fu'
10
11
 
11
12
  # Filter out Minitest backtrace while allowing backtrace from other libraries
12
13
  # to be shown.
@@ -18,4 +19,9 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
18
19
  # Load fixtures from the engine
19
20
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
20
21
  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
22
+ end
23
+
24
+ class ActiveSupport::TestCase
25
+ include ActiveJob::TestHelper
26
+ include ActsAsFu
21
27
  end
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - adrien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.2.0
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
26
  version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: acts_as_fu
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  description: Allows handling batch of ActiveJobs
@@ -46,7 +60,6 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - MIT-LICENSE
49
- - README.rdoc
50
63
  - Rakefile
51
64
  - app/assets/javascripts/active_batch/application.js
52
65
  - app/assets/javascripts/active_batch/batches.js
@@ -65,6 +78,7 @@ files:
65
78
  - app/jobs/active_batch/batch_status_check_job.rb
66
79
  - app/models/active_batch/batch.rb
67
80
  - app/models/active_batch/work_unit.rb
81
+ - app/models/concerns/active_batch/with_active_job_arguments.rb
68
82
  - app/views/active_batch/batches/_form.html.erb
69
83
  - app/views/active_batch/batches/index.html.erb
70
84
  - app/views/active_batch/batches/new.html.erb
@@ -136,6 +150,7 @@ files:
136
150
  - test/fixtures/active_batch/batches.yml
137
151
  - test/fixtures/active_batch/work_units.yml
138
152
  - test/integration/navigation_test.rb
153
+ - test/jobs/active_batch/batch_job_test.rb
139
154
  - test/jobs/active_batch/batch_scheduler_job_test.rb
140
155
  - test/jobs/active_batch/batch_status_check_job_test.rb
141
156
  - test/jobs/batch_job.rb
@@ -143,6 +158,7 @@ files:
143
158
  - test/lib/active_batch/batched_job_test.rb
144
159
  - test/models/active_batch/batch_test.rb
145
160
  - test/models/active_batch/work_unit_test.rb
161
+ - test/models/concerns/active_batch/with_active_job_arguments_test.rb
146
162
  - test/test_helper.rb
147
163
  homepage: https://github.com/idolweb/active_batch
148
164
  licenses:
@@ -154,17 +170,17 @@ require_paths:
154
170
  - lib
155
171
  required_ruby_version: !ruby/object:Gem::Requirement
156
172
  requirements:
157
- - - ">="
173
+ - - '>='
158
174
  - !ruby/object:Gem::Version
159
175
  version: '0'
160
176
  required_rubygems_version: !ruby/object:Gem::Requirement
161
177
  requirements:
162
- - - ">="
178
+ - - '>='
163
179
  - !ruby/object:Gem::Version
164
180
  version: '0'
165
181
  requirements: []
166
182
  rubyforge_project:
167
- rubygems_version: 2.4.5
183
+ rubygems_version: 2.4.6
168
184
  signing_key:
169
185
  specification_version: 4
170
186
  summary: Batch of ActiveJobs
@@ -226,6 +242,7 @@ test_files:
226
242
  - test/fixtures/active_batch/batches.yml
227
243
  - test/fixtures/active_batch/work_units.yml
228
244
  - test/integration/navigation_test.rb
245
+ - test/jobs/active_batch/batch_job_test.rb
229
246
  - test/jobs/active_batch/batch_scheduler_job_test.rb
230
247
  - test/jobs/active_batch/batch_status_check_job_test.rb
231
248
  - test/jobs/batch_job.rb
@@ -233,4 +250,5 @@ test_files:
233
250
  - test/lib/active_batch/batched_job_test.rb
234
251
  - test/models/active_batch/batch_test.rb
235
252
  - test/models/active_batch/work_unit_test.rb
253
+ - test/models/concerns/active_batch/with_active_job_arguments_test.rb
236
254
  - test/test_helper.rb
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = ActiveBatch
2
-
3
- This project rocks and uses MIT-LICENSE.