class Audited::RspecMatchers::AuditMatcher
:nodoc:
def associated_with(model)
def associated_with(model) @options[:associated_with] = model self end
def associated_with_model?
def associated_with_model? expects "#{model_class} to record audits to associated model #{@options[:associated_with]}" model_class.audit_associated_with == @options[:associated_with] end
def auditing_enabled?
def auditing_enabled? expects "#{model_class} to be audited" model_class.respond_to?(:auditing_enabled) && model_class.auditing_enabled end
def comment_required_valid?
def comment_required_valid? if @options[:comment_required] @subject.audit_comment = nil expects "to be invalid when audit_comment is not specified" @subject.valid? == false && @subject.errors.key?(:audit_comment) else true end end
def description
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
def except(*fields)
def except(*fields) @options[:except] = fields.flatten self end
def expects(message)
def expects(message) @expectation = message end
def failure_message
def failure_message "Expected #{@expectation}" end
def initialize
def initialize @options = {} end
def matches?(subject)
def matches?(subject) @subject = subject auditing_enabled? && associated_with_model? && records_changes_to_specified_fields? && comment_required_valid? end
def model_class
def model_class @subject.class end
def negative_failure_message
def negative_failure_message "Did not expect #{@expectation}" end
def on(*actions)
def on(*actions) @options[:on] = actions.flatten self end
def only(*fields)
def only(*fields) @options[:only] = fields.flatten self end
def records_changes_to_specified_fields?
def records_changes_to_specified_fields? if @options[:only] || @options[:except] if @options[:only] except = model_class.column_names - @options[:only].map(&:to_s) else except = model_class.default_ignored_attributes + Audited.ignored_attributes except |= @options[:except].collect(&:to_s) if @options[:except] end expects "non audited columns (#{model_class.non_audited_columns.inspect}) to match (#{expect})" model_class.non_audited_columns =~ except else true end end
def requires_comment
def requires_comment @options[:comment_required] = true self end