提交 bc00b814 编写于 作者: G Grzegorz Bizon

Do not raise if encrypted tokens field does not exist

This is mostly important in specs for migration, where we are still
using factories, despite that we have a Rubocop cop that should prevent
doing that.
上级 fa33a2ee
......@@ -15,6 +15,17 @@ module TokenAuthenticatableStrategies
end
token_authenticatable
rescue ActiveRecord::StatementInvalid
nil
end
def ensure_token(instance)
# TODO, tech debt, because some specs are testing migrations, but are still
# using factory bot to create resources, it might happen that a database
# schema does not have "#{token_name}_encrypted" field yet, however a bunch
# of models call `ensure_#{token_name}` in `before_save`.
#
super if instance.has_attribute?(encrypted_field)
end
def get_token(instance)
......@@ -40,7 +51,7 @@ module TokenAuthenticatableStrategies
def token_set?(instance)
raw_token = instance.read_attribute(encrypted_field)
raw_token ||= instance.read_attribute(token_field) if fallback?
raw_token ||= (instance.read_attribute(token_field) if fallback?)
raw_token.present?
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册