The validation of a token needs to load the token_object every time.

pull/5159/head
Wieland Lindenthal 8 years ago
parent b20da3f682
commit 1352d9f31e
  1. 10
      app/models/enterprise_token.rb
  2. 7
      spec/models/enterprise_token_spec.rb

@ -80,6 +80,13 @@ class EnterpriseToken < ActiveRecord::Base
RequestStore.delete :current_ee_token
end
def unset_current_token_object
# Clear current cache
if defined?(@token_object)
remove_instance_variable(:@token_object)
end
end
private
def load_token
@ -90,6 +97,7 @@ class EnterpriseToken < ActiveRecord::Base
end
def valid_token_object
errors.add(:encoded_token, :unreadable) unless token_object
unset_current_token_object
errors.add(:encoded_token, :unreadable) unless load_token
end
end

@ -77,6 +77,13 @@ RSpec.describe EnterpriseToken, type: :model do
expect(EnterpriseToken.show_banners).to eq(true)
end
end
context 'updating it with an invalid token' do
it 'will fail validations' do
subject.encoded_token = "bar"
expect(subject.save).to be_falsey
end
end
end
describe 'no token' do

Loading…
Cancel
Save