Class: Audited::RspecMatchers::AuditMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/audited/rspec_matchers.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeAuditMatcher

Returns a new instance of AuditMatcher.



36
37
38
# File 'lib/audited/rspec_matchers.rb', line 36

def initialize
  @options = {}
end

Instance Method Details

#associated_with(model) ⇒ Object



40
41
42
43
# File 'lib/audited/rspec_matchers.rb', line 40

def associated_with(model)
  @options[:associated_with] = model
  self
end

#descriptionObject



80
81
82
83
84
85
86
87
88
# File 'lib/audited/rspec_matchers.rb', line 80

def description
  description = "audited"
  description += " associated with #{@options[:associated_with]}" if @options.key?(:associated_with)
  description += " only => #{@options[:only].join ", "}" if @options.key?(:only)
  description += " except => #{@options[:except].join(", ")}" if @options.key?(:except)
  description += " requires audit_comment" if @options.key?(:comment_required)

  description
end

#except(*fields) ⇒ Object



50
51
52
53
# File 'lib/audited/rspec_matchers.rb', line 50

def except(*fields)
  @options[:except] = fields.flatten.map(&:to_s)
  self
end

#failure_messageObject



70
71
72
# File 'lib/audited/rspec_matchers.rb', line 70

def failure_message
  "Expected #{@expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/audited/rspec_matchers.rb', line 65

def matches?(subject)
  @subject = subject
  auditing_enabled? && required_checks_for_options_satisfied?
end

#negative_failure_messageObject Also known as: failure_message_when_negated



74
75
76
# File 'lib/audited/rspec_matchers.rb', line 74

def negative_failure_message
  "Did not expect #{@expectation}"
end

#on(*actions) ⇒ Object



60
61
62
63
# File 'lib/audited/rspec_matchers.rb', line 60

def on(*actions)
  @options[:on] = actions.flatten.map(&:to_sym)
  self
end

#only(*fields) ⇒ Object



45
46
47
48
# File 'lib/audited/rspec_matchers.rb', line 45

def only(*fields)
  @options[:only] = fields.flatten.map(&:to_s)
  self
end

#requires_commentObject



55
56
57
58
# File 'lib/audited/rspec_matchers.rb', line 55

def requires_comment
  @options[:comment_required] = true
  self
end