Module: RailsAuditLog::MinitestAssertions
- Defined in:
- lib/rails_audit_log/minitest_assertions.rb
Overview
Opt-in Minitest assertions for audit log expectations.
Setup
# test/test_helper.rb
require "rails_audit_log/minitest_assertions"
class ActiveSupport::TestCase
include RailsAuditLog::MinitestAssertions
end
Usage
assert_audit_log_entry(post, event: :update, touching: :title)
refute_audit_log_entry(post, event: :create)
Instance Method Summary collapse
-
#assert_audit_log_entry(record, event: nil, touching: nil, message: nil) ⇒ void
Asserts that
recordhas at least one AuditLogEntry matching the given filters. -
#refute_audit_log_entry(record, event: nil, touching: nil, message: nil) ⇒ void
Asserts that
recordhas no AuditLogEntry matching the given filters.
Instance Method Details
#assert_audit_log_entry(record, event: nil, touching: nil, message: nil) ⇒ void
This method returns an undefined value.
Asserts that record has at least one AuditLogEntry matching the given filters. Fails with a descriptive message when no entry is found.
29 30 31 32 33 |
# File 'lib/rails_audit_log/minitest_assertions.rb', line 29 def assert_audit_log_entry(record, event: nil, touching: nil, message: nil) scope = build_scope(record, event, touching) msg = || ("to have", record, event, touching) assert scope.exists?, msg end |
#refute_audit_log_entry(record, event: nil, touching: nil, message: nil) ⇒ void
This method returns an undefined value.
Asserts that record has no AuditLogEntry matching the given filters. Fails with a descriptive message when a matching entry is found.
45 46 47 48 49 |
# File 'lib/rails_audit_log/minitest_assertions.rb', line 45 def refute_audit_log_entry(record, event: nil, touching: nil, message: nil) scope = build_scope(record, event, touching) msg = || ("not to have", record, event, touching) refute scope.exists?, msg end |