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.



34
35
36
# File 'lib/audited/rspec_matchers.rb', line 34

def initialize
  @options = {}
end

Instance Method Details

#associated_with(model) ⇒ Object



38
39
40
41
# File 'lib/audited/rspec_matchers.rb', line 38

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

#descriptionObject



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

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



48
49
50
51
# File 'lib/audited/rspec_matchers.rb', line 48

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

#failure_messageObject



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

def failure_message
  "Expected #{@expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  @subject = subject
  auditing_enabled? &&
    associated_with_model? &&
    records_changes_to_specified_fields? &&
    comment_required_valid?
end

#negative_failure_messageObject



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

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

#on(*actions) ⇒ Object



58
59
60
61
# File 'lib/audited/rspec_matchers.rb', line 58

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

#only(*fields) ⇒ Object



43
44
45
46
# File 'lib/audited/rspec_matchers.rb', line 43

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

#requires_commentObject



53
54
55
56
# File 'lib/audited/rspec_matchers.rb', line 53

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