class Shoulda::Matchers::ActiveRecord::EncryptMatcher
@private
Attributes
Public Class Methods
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 79 def initialize(attribute) @attribute = attribute.to_sym @options = {} end
Public Instance Methods
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 125 def description "encrypt :#{@attribute}" end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 86 def deterministic(deterministic) with_option(:deterministic, deterministic) end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 90 def downcase(downcase) with_option(:downcase, downcase) end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 94 def ignore_case(ignore_case) with_option(:ignore_case, ignore_case) end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 98 def matches?(subject) @subject = subject result = encrypted_attributes_included? && options_correct?( :deterministic, :downcase, :ignore_case, ) if result @failure_message_when_negated = "Did not expect to #{description} of #{class_name}" if @options.present? @failure_message_when_negated += " using " @failure_message_when_negated += @options.map { |opt, expected| ":#{opt} option as ‹#{expected}›" }.join(' and ') end @failure_message_when_negated += ", but it did" end result end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 168 def class_name @subject.class.name end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 164 def encrypted_attribute_scheme @subject.class.type_for_attribute(@attribute).scheme end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 160 def encrypted_attributes @_encrypted_attributes ||= @subject.class.encrypted_attributes || [] end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 131 def encrypted_attributes_included? if encrypted_attributes.include?(@attribute) true else @failure_message = "Expected to #{description} of #{class_name}, but it did not" false end end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 145 def options_correct?(*opts) opts.all? do |opt| next true unless @options.key?(opt) expected = @options[opt] actual = encrypted_attribute_scheme.send("#{opt}?") next true if expected == actual @failure_message = "Expected to #{description} of #{class_name} using :#{opt} option as ‹#{expected}›, but got ‹#{actual}›" false end end
Source
# File lib/shoulda/matchers/active_record/encrypt_matcher.rb, line 140 def with_option(option_name, value) @options[option_name] = value self end