Skip to content

Commit

Permalink
Add paper_trail to reporters and bump version to 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
amkisko committed Feb 2, 2024
1 parent 3d74056 commit deec423
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.4.1

* Add paper_trail support

# 1.4.0

* Set minimum ruby version requirement to 2.5.0
Expand Down
14 changes: 9 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
PATH
remote: .
specs:
action_reporter (1.4.0)
audited (~> 5)
honeybadger (~> 5)
action_reporter (1.4.1)
rails (> 5)
scout_apm (~> 5)
sentry-ruby (~> 5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -129,6 +125,9 @@ GEM
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
paper_trail (15.1.0)
activerecord (>= 6.1)
request_store (~> 1.4)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
Expand Down Expand Up @@ -228,8 +227,13 @@ PLATFORMS

DEPENDENCIES
action_reporter!
audited (~> 5)
honeybadger (~> 5)
paper_trail (~> 15)
pry (~> 0.14)
rspec (~> 3)
scout_apm (~> 5)
sentry-ruby (~> 5)
simplecov (~> 0.21)
simplecov-cobertura (~> 2)
webmock (~> 3)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ruby wrapper for multiple reporting services.
Supported services:
- Rails logger
- Audited
- PaperTrail
- Sentry
- Honeybadger
- scoutapm
Expand Down Expand Up @@ -39,6 +40,7 @@ Put this in your `config/initializers/action_reporter.rb` file:
ActionReporter.enabled_reporters = [
ActionReporter::RailsReporter.new,
# ActionReporter::AuditedReporter.new,
# ActionReporter::PaperTrailReporter.new,
# ActionReporter::SentryReporter.new,
# ActionReporter::HoneybadgerReporter.new,
# ActionReporter::ScoutApmReporter.new
Expand Down
10 changes: 6 additions & 4 deletions action_reporter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ Gem::Specification.new do |gem|
gem.require_path = "lib"

gem.add_runtime_dependency 'rails', '> 5'
gem.add_runtime_dependency 'audited', '~> 5'
gem.add_runtime_dependency 'honeybadger', '~> 5'
gem.add_runtime_dependency 'sentry-ruby', '~> 5'
gem.add_runtime_dependency 'scout_apm', '~> 5'

gem.add_development_dependency 'audited', '~> 5'
gem.add_development_dependency 'honeybadger', '~> 5'
gem.add_development_dependency 'sentry-ruby', '~> 5'
gem.add_development_dependency 'scout_apm', '~> 5'
gem.add_development_dependency 'paper_trail', '~> 15'

gem.add_development_dependency 'rspec', '~> 3'
gem.add_development_dependency 'webmock', '~> 3'
Expand Down
6 changes: 4 additions & 2 deletions lib/action_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
require 'action_reporter/sentry_reporter'
require 'action_reporter/scout_apm_reporter'
require 'action_reporter/audited_reporter'
require 'action_reporter/paper_trail_reporter'

module ActionReporter
module_function

VERSION = '1.4.0'.freeze
VERSION = '1.4.1'.freeze

AVAILABLE_REPORTERS = [
ActionReporter::RailsReporter,
ActionReporter::HoneybadgerReporter,
ActionReporter::SentryReporter,
ActionReporter::ScoutApmReporter,
ActionReporter::AuditedReporter
ActionReporter::AuditedReporter,
ActionReporter::PaperTrailReporter
].freeze

@enabled_reporters = []
Expand Down
23 changes: 23 additions & 0 deletions lib/action_reporter/paper_trail_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ActionReporter
class PaperTrailReporter < Base
class_accessor "PaperTrail", gem_spec: "paper_trail (~> 15)"

def notify(*)
end

def context(args)
end

def reset_context
PaperTrail.request.whodunnit = nil
end

def audited_user
PaperTrail.request.whodunnit
end

def audited_user=(user)
PaperTrail.request.whodunnit = user
end
end
end
12 changes: 12 additions & 0 deletions spec/action_reporter/audited_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@

end

describe '#audited_user=' do
subject(:audited_user=) { instance.audited_user = user }

let(:user) { double('User', to_global_id: 'gid://user/1') }

it 'sets audited_user' do
expect(Audited.store[:audited_user]).to eq(nil)
subject
expect(Audited.store[:audited_user]).to eq(user)
end
end

describe '#reset_context' do
subject(:reset_context) { instance.reset_context }

Expand Down
36 changes: 36 additions & 0 deletions spec/action_reporter/paper_trail_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'
require 'rails'
require 'paper_trail'

RSpec.describe ActionReporter::PaperTrailReporter do
subject(:instance) { described_class.new }

describe '#notify' do

end

describe '#context' do

end

describe '#audited_user=' do
subject(:audited_user=) { instance.audited_user = user }

let(:user) { double('User', to_global_id: 'gid://user/1') }

it 'sets audited_user' do
expect(PaperTrail.request.whodunnit).to eq(nil)
subject
expect(PaperTrail.request.whodunnit).to eq(user)
end
end

describe '#reset_context' do
subject(:reset_context) { instance.reset_context }

it 'resets context' do
expect(PaperTrail.request).to receive(:whodunnit=).with(nil)
subject
end
end
end

0 comments on commit deec423

Please sign in to comment.