Skip to content

Commit

Permalink
Implement reporter check_in
Browse files Browse the repository at this point in the history
  • Loading branch information
amkisko committed Apr 18, 2023
1 parent a7a7fec commit 0af9095
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0

* Add reporter check-in method

# 1.0.7

* Moving Sentry context under `context` key
Expand Down
2 changes: 1 addition & 1 deletion action_reporter.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "action_reporter"
s.version = "1.0.7"
s.version = "1.1.0"

s.license = "MIT"

Expand Down
8 changes: 8 additions & 0 deletions lib/action_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ def audited_user=(user)
reporter.audited_user = user
end
end

def check_in(identifier)
enabled_reporters.each do |reporter|
next unless reporter.respond_to?(:check_in)

reporter.check_in(identifier)
end
end
end
10 changes: 10 additions & 0 deletions lib/action_reporter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def transform_context(context)
end
end

def resolve_check_in_id(identifier)
if identifier.is_a?(String)
identifier
elsif identifier.respond_to?(:reporter_check_in)
identifier.reporter_check_in
else
raise ArgumentError, "Unknown check-in identifier: #{identifier.inspect}"
end
end

def notify(*)
end

Expand Down
5 changes: 5 additions & 0 deletions lib/action_reporter/honeybadger_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ def context(args)
def reset_context
Honeybadger.context.clear!
end

def check_in(identifier)
check_in_id = resolve_check_in_id(identifier)
Honeybadger.check_in(check_in_id)
end
end
end
5 changes: 5 additions & 0 deletions lib/action_reporter/rails_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ def context(args)
new_context = transform_context(args)
Rails.logger.info("Reporter context: #{new_context.inspect}")
end

def check_in(identifier)
check_in_id = resolve_check_in_id(identifier)
Rails.logger.info("Reporter check-in: #{check_in_id}")
end
end
end
2 changes: 1 addition & 1 deletion lib/action_reporter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActionReporter
VERSION = '1.0.7'
VERSION = '1.1.0'
end
35 changes: 33 additions & 2 deletions spec/action_reporter/honeybadger_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@
RSpec.describe ActionReporter::HoneybadgerReporter do
subject { described_class.new }

let(:honeybadger_stub) { double('Honeybadger') }
before do
stub_const('Honeybadger', honeybadger_stub)
Honeybadger.configure do |config|

end
end

describe '#notify' do

end

describe '#context' do

end

describe '#check_in' do
subject(:check_in) { described_class.new.check_in(identifier) }

context "when identifier is a string" do

end

context "when identifier is a class" do
let(:reporter_check_in) { "reporter_check_in_test" }
let(:identifier) { double("User", reporter_check_in: reporter_check_in) }

before do
stub_request(:get, "https://api.honeybadger.io/v1/check_in/#{reporter_check_in}").to_return(status: 200, body: "", headers: {})
end

it 'returns identifier' do
expect(Honeybadger).to receive(:check_in).with(reporter_check_in).and_call_original
subject
end
end
end
end

0 comments on commit 0af9095

Please sign in to comment.