From df3b2e3c333ecc218b46cc19cbea5c3e747c66e9 Mon Sep 17 00:00:00 2001 From: Max Woolf Date: Tue, 18 Jan 2022 13:17:19 +0000 Subject: [PATCH] Add support for text columns for secure matchers --- .../active_record/have_secure_token_matcher.rb | 2 +- .../active_record/have_secure_token_matcher_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb b/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb index ba76d31e5..ad23d244b 100644 --- a/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +++ b/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb @@ -110,7 +110,7 @@ def has_expected_instance_methods? end def has_expected_db_column? - matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string) + matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string) || HaveDbColumnMatcher.new(token_attribute).of_type(:text) matcher.matches?(@subject) end diff --git a/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb index 574ee7bea..4b4ba0333 100644 --- a/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb @@ -27,6 +27,17 @@ expect(valid_model.new).to have_secure_token end + it 'matches when the subject configures has_secure_token with the db using a text datatype' do + create_table(:users) do |t| + t.string :token + t.index :text, unique: true + end + + valid_model = define_model_class(:User) { has_secure_token } + + expect(valid_model.new).to have_secure_token + end + it 'matches when the subject configures has_secure_token with the db for ' \ 'a custom attribute' do create_table(:users) do |t|