class Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher
@private
Attributes
Public Class Methods
Source
# 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
Public Instance Methods
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 60 def description "have :#{token_attribute} as a secure token" end
Source
# 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
Source
# 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
Source
# 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
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 78 def matches?(subject) @subject = subject @errors = run_checks @errors.empty? end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 112 def has_expected_db_column? matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string) matcher.matches?(@subject) end
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 117 def has_expected_db_index? matcher = HaveDbIndexMatcher.new(token_attribute).unique(true) matcher.matches?(@subject) end
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 105 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
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 91 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 !@options[:ignore_check_for_db_index] && !has_expected_db_index? @errors << "missing unique index for #{table_and_column}" end @errors end
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 122 def table_and_column "#{table_name}.#{token_attribute}" end
Source
# File lib/shoulda/matchers/active_record/have_secure_token_matcher.rb, line 126 def table_name @subject.class.table_name end