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|