Class: RailsAuditLog::Matchers::HaveAuditLogEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_audit_log/matchers.rb

Overview

RSpec matcher — asserts that a record already has a matching entry.

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ HaveAuditLogEntry

Returns a new instance of HaveAuditLogEntry.



50
51
52
53
# File 'lib/rails_audit_log/matchers.rb', line 50

def initialize(event)
  @event    = event
  @touching = nil
end

Instance Method Details

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
# File 'lib/rails_audit_log/matchers.rb', line 84

def description
  "have an audit log entry#{qualifier}"
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
# File 'lib/rails_audit_log/matchers.rb', line 74

def failure_message
  "expected #{@record.class}##{@record.id} to have an audit log entry#{qualifier}"
end

#failure_message_when_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/rails_audit_log/matchers.rb', line 79

def failure_message_when_negated
  "expected #{@record.class}##{@record.id} not to have an audit log entry#{qualifier}"
end

#matches?(record) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


65
66
67
68
69
70
71
# File 'lib/rails_audit_log/matchers.rb', line 65

def matches?(record)
  @record = record
  scope = record.audit_log_entries
  scope = scope.where(event: @event.to_s) if @event
  scope = scope.touching(@touching)       if @touching
  scope.exists?
end

#touching(attribute) ⇒ self

Chains an attribute filter onto the matcher.

Parameters:

  • attribute (Symbol, String)

Returns:

  • (self)


59
60
61
62
# File 'lib/rails_audit_log/matchers.rb', line 59

def touching(attribute)
  @touching = attribute
  self
end