-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1629 from senid231/admin-api-audit
admin api fix audit whodunnit
- Loading branch information
Showing
5 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# @example usage: | ||
# include_examples :creates_audit_log do | ||
# let(:audit_log_attrs) do | ||
# item = Account.last | ||
# { event: 'create', item_id: item.id, item_type: item.class.name, whodunnit: admin_user.id.to_s } | ||
# end | ||
# end | ||
# # when several items are created at once | ||
# include_examples :creates_audit_log, qty: 2 do | ||
# let(:audit_log_attrs) do | ||
# [Account.last, CustomersAuth.last].map do |item| | ||
# { event: 'create', item_id: item.id, item_type: item.class.name, whodunnit: admin_user.id.to_s } | ||
# end | ||
# end | ||
# end | ||
RSpec.shared_examples :creates_audit_log do |qty: 1, ordered: false| | ||
# Note: we didn't calculate qty by audit_log_attrs, because we want it to be called only after subject, | ||
# so we could use subject result in audit_log_attrs. | ||
|
||
it 'creates audit log', :aggregate_failures do | ||
expect { subject }.to change { AuditLogItem.count }.by(qty) | ||
logs = AuditLogItem.last(qty) | ||
actual_attrs_list = logs.map { |log| log.attributes.symbolize_keys } | ||
expected_attrs_list = Array.wrap(audit_log_attrs).map { |attrs| hash_including(attrs) } | ||
|
||
if ordered | ||
expected_attrs_list.each_with_index do |expected_attrs, index| | ||
expect(actual_attrs_list[index]).to match(expected_attrs) | ||
end | ||
else | ||
expect(actual_attrs_list).to match_array(expected_attrs_list) | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
spec/support/examples/audit_logs/does_not_create_audit_log.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
# @example usage: | ||
# include_examples :does_not_create_audit_log | ||
RSpec.shared_examples :does_not_create_audit_log do | ||
it 'dos not create audit log' do | ||
expect { subject }.not_to change { AuditLogItem.count } | ||
end | ||
end |