Class: Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/have_secure_token_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_attribute) ⇒ HaveSecureTokenMatcher

Returns a new instance of HaveSecureTokenMatcher.



55
56
57
58
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 55

def initialize(token_attribute)
  @token_attribute = token_attribute
  @options = { ignore_check_for_db_index: false }
end

Instance Attribute Details

#token_attributeObject (readonly)

Returns the value of attribute token_attribute.



53
54
55
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 53

def token_attribute
  @token_attribute
end

Instance Method Details

#descriptionObject



60
61
62
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 60

def description
  "have :#{token_attribute} as a secure token"
end

#failure_messageObject



64
65
66
67
68
69
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 64

def failure_message
  return if !@errors

  "Expected #{@subject.class} to #{description} but the following " \
  "errors were found: #{@errors.join(', ')}"
end

#failure_message_when_negatedObject



71
72
73
74
75
76
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 71

def failure_message_when_negated
  return if !@errors

  "Did not expect #{@subject.class} to have secure token " \
  ":#{token_attribute}"
end

#ignoring_check_for_db_indexObject



84
85
86
87
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 84

def ignoring_check_for_db_index
  @options[:ignore_check_for_db_index] = true
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
# File 'lib/shoulda/matchers/active_record/have_secure_token_matcher.rb', line 78

def matches?(subject)
  @subject = subject
  @errors = run_checks
  @errors.empty?
end