audited-activejob 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/audited/active_job.rb +13 -5
- data/lib/audited/active_job/version.rb +1 -1
- data/spec/audited/active_job_spec.rb +77 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/support/audit_model.rb +6 -0
- data/spec/support/test_job.rb +7 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9284c4dd4face8354666d613c857578754815c
|
4
|
+
data.tar.gz: 9b3efea5550c313dcdd22f0c06ceee58741dccb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 102a7d84ee4eff3322c22e81044727817008ac165b6cfccb965dba65a5b23c6665fae4c1c94045ca0553985d5fcfec8b37a38cd48f1259c830bba2bab9b0e6ca
|
7
|
+
data.tar.gz: 50df632247b25ee57c299173af683fb05e3a08135f8933e72712974111e9cc2849a004b35fe29f0e38220828052c14c04e83615cf79485bcb7c7a22bb36e999c
|
data/lib/audited/active_job.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
module Audited
|
2
2
|
module ActiveJob
|
3
3
|
def self.included(base)
|
4
|
-
base.send :
|
4
|
+
base.send :include, ::ActiveJob::Users if defined?(::ActiveJob::Users)
|
5
5
|
|
6
6
|
base.send :around_perform do |_job, block|
|
7
|
-
|
8
|
-
|
9
|
-
arguments << options unless options.empty?
|
10
|
-
|
7
|
+
extract_audit_user!
|
8
|
+
|
11
9
|
Audited.audit_class.as_user(audit_user) do
|
12
10
|
block.call
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
14
|
+
def extract_audit_user!
|
15
|
+
options = arguments.extract_options!
|
16
|
+
@audit_user = options.delete(:audit_user)
|
17
|
+
arguments << options unless options.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def audit_user
|
21
|
+
@audit_user || try(:job_user)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Audited::ActiveJob do
|
4
|
+
subject { TestJob.new }
|
5
|
+
|
6
|
+
context 'when an audit_user argument is passed to the job' do
|
7
|
+
let(:user) { {email: 'mark@markrebec.com'} }
|
8
|
+
|
9
|
+
it 'extracts the audit_user keyword argument' do
|
10
|
+
subject.arguments << {audit_user: user}
|
11
|
+
subject.extract_audit_user!
|
12
|
+
|
13
|
+
expect(subject.audit_user).to eq(user)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'passes other keyword arguments through' do
|
17
|
+
subject.arguments << {audit_user: user, foo: 'bar'}
|
18
|
+
subject.extract_audit_user!
|
19
|
+
|
20
|
+
expect(subject.arguments.last).to eq({foo: 'bar'})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when an audit_user argument is not passed to the job' do
|
25
|
+
it 'sets the audit_user to nil' do
|
26
|
+
subject.extract_audit_user!
|
27
|
+
|
28
|
+
expect(subject.audit_user).to eq(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'passes all keyword arguments through' do
|
32
|
+
subject.arguments << {foo: 'bar'}
|
33
|
+
subject.extract_audit_user!
|
34
|
+
|
35
|
+
expect(subject.arguments.last).to eq({foo: 'bar'})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#audit_user' do
|
40
|
+
let(:audit_user) { {email: 'audit@example.com'} }
|
41
|
+
let(:job_user) { {email: 'job@example.com'} }
|
42
|
+
|
43
|
+
context 'when a job_user argument is passed to the job' do
|
44
|
+
context 'and no audit_user argument is passed to the job' do
|
45
|
+
it 'falls back to the job_user argument' do
|
46
|
+
subject.arguments << {job_user: job_user}
|
47
|
+
subject.extract_job_user!
|
48
|
+
subject.extract_audit_user!
|
49
|
+
|
50
|
+
expect(subject.audit_user).to eq(job_user)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'and an audit_user argument is passed to the job' do
|
55
|
+
it 'prefers the audit_user argument' do
|
56
|
+
subject.arguments << {job_user: job_user, audit_user: audit_user}
|
57
|
+
subject.extract_job_user!
|
58
|
+
subject.extract_audit_user!
|
59
|
+
|
60
|
+
expect(subject.audit_user).to eq(audit_user)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'around_perform' do
|
67
|
+
it 'calls extract_audit_user!' do
|
68
|
+
expect_any_instance_of(TestJob).to receive(:extract_audit_user!)
|
69
|
+
TestJob.perform_now
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'calls Audited.audit_class.as_user with the audit_user' do
|
73
|
+
expect(Audited.audit_class).to receive(:as_user).with(nil)
|
74
|
+
TestJob.perform_now
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'coveralls'
|
2
2
|
Coveralls.wear!
|
3
|
+
require 'active_job'
|
4
|
+
require 'active_job/users'
|
5
|
+
require 'audited'
|
3
6
|
require 'audited-activejob'
|
4
7
|
require 'rspec'
|
5
8
|
|
6
|
-
|
9
|
+
Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
|
7
10
|
|
8
11
|
RSpec.configure do |config|
|
9
12
|
# rspec-expectations config goes here. You can use an alternate
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audited-activejob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activejob-users
|
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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,7 +91,10 @@ files:
|
|
77
91
|
- lib/audited-activejob.rb
|
78
92
|
- lib/audited/active_job.rb
|
79
93
|
- lib/audited/active_job/version.rb
|
94
|
+
- spec/audited/active_job_spec.rb
|
80
95
|
- spec/spec_helper.rb
|
96
|
+
- spec/support/audit_model.rb
|
97
|
+
- spec/support/test_job.rb
|
81
98
|
homepage: http://github.com/markrebec/audited-activejob
|
82
99
|
licenses: []
|
83
100
|
metadata: {}
|
@@ -103,5 +120,7 @@ specification_version: 4
|
|
103
120
|
summary: Pass a user through to your active_jobs and associate it with any generated
|
104
121
|
audits
|
105
122
|
test_files:
|
123
|
+
- spec/audited/active_job_spec.rb
|
106
124
|
- spec/spec_helper.rb
|
107
|
-
|
125
|
+
- spec/support/audit_model.rb
|
126
|
+
- spec/support/test_job.rb
|