class Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher
@private
Attributes
token_attribute[R]
Public Class Methods
new(token_attribute)
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 42 def initialize(token_attribute) @token_attribute = token_attribute end
Public Instance Methods
description()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 46 def description "have :#{token_attribute} as a secure token" end
failure_message()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 50 def failure_message return if !@errors "Expected #{@subject.class} to #{description} but the following " \ "errors were found: #{@errors.join(', ')}" end
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 56 def failure_message_when_negated return if !@errors "Did not expect #{@subject.class} to have secure token " \ ":#{token_attribute}" end
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 62 def matches?(subject) @subject = subject @errors = run_checks @errors.empty? end
Private Instance Methods
has_expected_db_column?()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 91 def has_expected_db_column? matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string) matcher.matches?(@subject) end
has_expected_db_index?()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 96 def has_expected_db_index? matcher = HaveDbIndexMatcher.new(token_attribute).unique(true) matcher.matches?(@subject) end
has_expected_instance_methods?()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 84 def has_expected_instance_methods? @subject.respond_to?(token_attribute.to_s) && @subject.respond_to?("#{token_attribute}=") && @subject.respond_to?("regenerate_#{token_attribute}") && @subject.class.respond_to?(:generate_unique_secure_token) end
run_checks()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 70 def run_checks @errors = [] if !has_expected_instance_methods? @errors << 'missing expected class and instance methods' end if !has_expected_db_column? @errors << "missing correct column #{token_attribute}:string" end if !has_expected_db_index? @errors << "missing unique index for #{table_and_column}" end @errors end
table_and_column()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 101 def table_and_column "#{table_name}.#{token_attribute}" end
table_name()
click to toggle source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 105 def table_name @subject.class.table_name end