Class: Audited::RspecMatchers::AuditMatcher
- Inherits:
-
Object
- Object
- Audited::RspecMatchers::AuditMatcher
- Defined in:
- lib/audited/rspec_matchers.rb
Overview
:nodoc:
Instance Method Summary collapse
- #associated_with(model) ⇒ Object
- #description ⇒ Object
- #except(*fields) ⇒ Object
- #failure_message ⇒ Object
-
#initialize ⇒ AuditMatcher
constructor
A new instance of AuditMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #on(*actions) ⇒ Object
- #only(*fields) ⇒ Object
- #requires_comment ⇒ Object
Constructor Details
#initialize ⇒ AuditMatcher
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 |
#description ⇒ Object
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_message ⇒ Object
71 72 73 |
# File 'lib/audited/rspec_matchers.rb', line 71 def "Expected #{@expectation}" end |
#matches?(subject) ⇒ 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_message ⇒ Object
75 76 77 |
# File 'lib/audited/rspec_matchers.rb', line 75 def "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_comment ⇒ Object
53 54 55 56 |
# File 'lib/audited/rspec_matchers.rb', line 53 def requires_comment @options[:comment_required] = true self end |