Class: RailsAuditLog::Matchers::HaveAuditLogEntry

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

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ HaveAuditLogEntry

Returns a new instance of HaveAuditLogEntry.



12
13
14
15
# File 'lib/rails_audit_log/matchers.rb', line 12

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

Instance Method Details

#descriptionObject



38
39
40
# File 'lib/rails_audit_log/matchers.rb', line 38

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

#failure_messageObject



30
31
32
# File 'lib/rails_audit_log/matchers.rb', line 30

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

#failure_message_when_negatedObject



34
35
36
# File 'lib/rails_audit_log/matchers.rb', line 34

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

#matches?(record) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/rails_audit_log/matchers.rb', line 22

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) ⇒ Object



17
18
19
20
# File 'lib/rails_audit_log/matchers.rb', line 17

def touching(attribute)
  @touching = attribute
  self
end