audited-activejob 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 120aff781d352f12152137ba7f7757f1ae0ba782
4
- data.tar.gz: b9f29b3ad623bf2c1c51148f68c4949a48a1cf82
3
+ metadata.gz: 9d9284c4dd4face8354666d613c857578754815c
4
+ data.tar.gz: 9b3efea5550c313dcdd22f0c06ceee58741dccb6
5
5
  SHA512:
6
- metadata.gz: fa489ed1cee3592546cc7ee80414243234eba36f939a56d26e59fb986a6ae86012ce8f7fc2ef2ae682510aaaae99262b5d8542c4b38fa7f994f86683f5dda8c9
7
- data.tar.gz: d07b7f67b621e807827421959abc4cf238fcdcb92073dbcd253d5a9cdca7c2a8d12bb48248fe8c42e228a11138ba6a338c4869ed6f24355b038b1aadc4af319e
6
+ metadata.gz: 102a7d84ee4eff3322c22e81044727817008ac165b6cfccb965dba65a5b23c6665fae4c1c94045ca0553985d5fcfec8b37a38cd48f1259c830bba2bab9b0e6ca
7
+ data.tar.gz: 50df632247b25ee57c299173af683fb05e3a08135f8933e72712974111e9cc2849a004b35fe29f0e38220828052c14c04e83615cf79485bcb7c7a22bb36e999c
@@ -1,17 +1,25 @@
1
1
  module Audited
2
2
  module ActiveJob
3
3
  def self.included(base)
4
- base.send :attr_reader, :audit_user
4
+ base.send :include, ::ActiveJob::Users if defined?(::ActiveJob::Users)
5
5
 
6
6
  base.send :around_perform do |_job, block|
7
- options = arguments.extract_options!
8
- @audit_user = options.delete(:audit_user)
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
@@ -1,5 +1,5 @@
1
1
  module Audited
2
2
  module ActiveJob
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  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
@@ -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
- #Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
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
@@ -0,0 +1,6 @@
1
+ class AuditModel
2
+ def self.as_user(user)
3
+ # noop
4
+ end
5
+ end
6
+ Audited.audit_class = AuditModel
@@ -0,0 +1,7 @@
1
+ class TestJob < ActiveJob::Base
2
+ include Audited::ActiveJob
3
+ queue_as :default
4
+
5
+ def perform
6
+ end
7
+ end
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
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
- has_rdoc:
125
+ - spec/support/audit_model.rb
126
+ - spec/support/test_job.rb