Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure user_attributes returns a Hash #1361

Merged
merged 3 commits into from Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/airbrake_api/v3/notice_parser.rb
Expand Up @@ -69,7 +69,8 @@ def request
end

def user_attributes
return context['user'] if context['user']
user = context['user']
return user.is_a?(Hash) ? user : { user: user } if user

{
'id' => context['userId'],
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/airbrake_api/v3/notice_parser_spec.rb
Expand Up @@ -105,6 +105,20 @@
expect(parser.attributes[:server_environment]['hostname']).to eq('app01.infra.example.com')
end

describe '#user_attributes' do
it 'returns a user context hash' do
user_hash = { id: 1, name: 'John Doe' }
parser = described_class.new('context' => { 'user' => user_hash })
expect(parser.send(:user_attributes)).to eq(user_hash)
end

it 'returns a hash for a user context string' do
user_string = '[Filtered]'
parser = described_class.new('context' => { 'user' => user_string })
expect(parser.send(:user_attributes)).to eq(user: user_string)
end
end

def build_params_for(fixture, options = {})
json = Rails.root.join('spec', 'fixtures', fixture).read
data = JSON.parse(json)
Expand Down