activejob-users 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c290e729335f4a6927c156aa0c12b47938096ca
4
+ data.tar.gz: b231fb49a34daa59e345c9924406e9772af0a659
5
+ SHA512:
6
+ metadata.gz: 3b1e2b5f99b0e4a8c2189a48a1df7d741dd098f340cd1d113c930913e0bc853493ecab7deb3b0e73d578baf8bcc66f8fb62b1a64f773b33ce06bcbaf0c8750b3
7
+ data.tar.gz: f828f6551011564b38a901490a4e5ab64c77ecfc379b6defb349dc64bf9d33cc0fbe269e11564e6c0b0b7b28a7dee8c5d0838f9f20338cd8064f31403f5c1d8d
@@ -0,0 +1,19 @@
1
+ module ActiveJob
2
+ module Users
3
+ def self.included(base)
4
+ base.send :attr_reader, :job_user
5
+
6
+ base.send :around_perform do |_job, block|
7
+ extract_job_user!
8
+
9
+ block.call
10
+ end
11
+
12
+ def extract_job_user!
13
+ options = arguments.extract_options!
14
+ @job_user = options.delete(:job_user)
15
+ arguments << options unless options.empty?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveJob
2
+ module Users
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_job/users'
2
+ require 'active_job/users/version'
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveJob::Users do
4
+ subject { TestJob.new }
5
+
6
+ context 'when a job_user argument is passed to the job' do
7
+ let(:user) { {email: 'mark@markrebec.com'} }
8
+
9
+ it 'extracts the job_user keyword argument' do
10
+ subject.arguments << {job_user: user}
11
+ subject.extract_job_user!
12
+
13
+ expect(subject.job_user).to eq(user)
14
+ end
15
+
16
+ it 'passes other keyword arguments through' do
17
+ subject.arguments << {job_user: user, foo: 'bar'}
18
+ subject.extract_job_user!
19
+
20
+ expect(subject.arguments.last).to eq({foo: 'bar'})
21
+ end
22
+ end
23
+
24
+ context 'when a job_user argument is not passed to the job' do
25
+ it 'sets the job_user to nil' do
26
+ subject.extract_job_user!
27
+
28
+ expect(subject.job_user).to eq(nil)
29
+ end
30
+
31
+ it 'passes all keyword arguments through' do
32
+ subject.arguments << {foo: 'bar'}
33
+ subject.extract_job_user!
34
+
35
+ expect(subject.arguments.last).to eq({foo: 'bar'})
36
+ end
37
+ end
38
+
39
+ describe 'around_perform' do
40
+ it 'calls extract_job_user!' do
41
+ expect_any_instance_of(TestJob).to receive(:extract_job_user!)
42
+ TestJob.perform_now
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,73 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ require 'active_job'
4
+ require 'activejob-users'
5
+ require 'rspec'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ # rspec-expectations config goes here. You can use an alternate
11
+ # assertion/expectation library such as wrong or the stdlib/minitest
12
+ # assertions if you prefer.
13
+ config.expect_with :rspec do |expectations|
14
+ # This option will default to `true` in RSpec 4. It makes the `description`
15
+ # and `failure_message` of custom matchers include text for helper methods
16
+ # defined using `chain`, e.g.:
17
+ # be_bigger_than(2).and_smaller_than(4).description
18
+ # # => "be bigger than 2 and smaller than 4"
19
+ # ...rather than:
20
+ # # => "be bigger than 2"
21
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
22
+ end
23
+
24
+ # rspec-mocks config goes here. You can use an alternate test double
25
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
26
+ config.mock_with :rspec do |mocks|
27
+ # Prevents you from mocking or stubbing a method that does not exist on
28
+ # a real object. This is generally recommended, and will default to
29
+ # `true` in RSpec 4.
30
+ mocks.verify_partial_doubles = true
31
+ end
32
+
33
+ # Many RSpec users commonly either run the entire suite or an individual
34
+ # file, and it's useful to allow more verbose output when running an
35
+ # individual spec file.
36
+ if config.files_to_run.one?
37
+ # Use the documentation formatter for detailed output,
38
+ # unless a formatter has already been configured
39
+ # (e.g. via a command-line flag).
40
+ config.default_formatter = 'doc'
41
+ end
42
+
43
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
44
+ # For more details, see:
45
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
46
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
47
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
48
+ config.disable_monkey_patching!
49
+
50
+ # Run specs in random order to surface order dependencies. If you find an
51
+ # order dependency and want to debug it, you can fix the order by providing
52
+ # the seed, which is printed after each run.
53
+ # --seed 1234
54
+ config.order = :random
55
+
56
+ # Seed global randomization in this process using the `--seed` CLI option.
57
+ # Setting this allows you to use `--seed` to deterministically reproduce
58
+ # test failures related to randomization by passing the same `--seed` value
59
+ # as the one that triggered the failure.
60
+ Kernel.srand config.seed
61
+
62
+ # Print the 10 slowest examples and example groups at the
63
+ # end of the spec run, to help surface which specs are running
64
+ # particularly slow.
65
+ #config.profile_examples = 10
66
+
67
+ # These two settings work together to allow you to limit a spec run
68
+ # to individual examples or groups you care about by tagging them with
69
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
70
+ # get run.
71
+ #config.filter_run :focus
72
+ #config.run_all_when_everything_filtered = true
73
+ end
@@ -0,0 +1,7 @@
1
+ class TestJob < ActiveJob::Base
2
+ include ActiveJob::Users
3
+ queue_as :default
4
+
5
+ def perform
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activejob-users
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Rebec
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activejob
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Pass a user through to your active_jobs for context
56
+ email:
57
+ - mark@markrebec.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/active_job/users.rb
63
+ - lib/active_job/users/version.rb
64
+ - lib/activejob-users.rb
65
+ - spec/active_job/users_spec.rb
66
+ - spec/spec_helper.rb
67
+ - spec/support/test_job.rb
68
+ homepage: http://github.com/markrebec/activejob-users
69
+ licenses: []
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.8
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Pass a user through to your active_jobs for context
91
+ test_files:
92
+ - spec/active_job/users_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/support/test_job.rb