From 71d9774d5822d82a003fc671048902a37b80899a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 20 Jul 2020 17:05:04 +0200 Subject: [PATCH] models: require belong_to associations on trusted_device_token --- app/models/trusted_device_token.rb | 2 +- spec/factories/trusted_device_token.rb | 5 +++++ spec/models/trusted_device_token_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 spec/factories/trusted_device_token.rb diff --git a/app/models/trusted_device_token.rb b/app/models/trusted_device_token.rb index 65f37ffcc..06d84a4a9 100644 --- a/app/models/trusted_device_token.rb +++ b/app/models/trusted_device_token.rb @@ -12,7 +12,7 @@ class TrustedDeviceToken < ApplicationRecord LOGIN_TOKEN_VALIDITY = 1.week LOGIN_TOKEN_YOUTH = 15.minutes - belongs_to :instructeur + belongs_to :instructeur, optional: false has_secure_token def token_valid? diff --git a/spec/factories/trusted_device_token.rb b/spec/factories/trusted_device_token.rb new file mode 100644 index 000000000..cee78e328 --- /dev/null +++ b/spec/factories/trusted_device_token.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :trusted_device_token do + association :instructeur + end +end diff --git a/spec/models/trusted_device_token_spec.rb b/spec/models/trusted_device_token_spec.rb index ed5ae1e51..d3aa8b89b 100644 --- a/spec/models/trusted_device_token_spec.rb +++ b/spec/models/trusted_device_token_spec.rb @@ -1,6 +1,6 @@ RSpec.describe TrustedDeviceToken, type: :model do describe '#token_valid?' do - let(:token) { TrustedDeviceToken.create } + let(:token) { create(:trusted_device_token) } context 'when the token is create after login_token_validity' do it { expect(token.token_valid?).to be true } @@ -14,7 +14,7 @@ RSpec.describe TrustedDeviceToken, type: :model do end describe '#token_young?' do - let(:token) { TrustedDeviceToken.create } + let(:token) { create(:trusted_device_token) } context 'when the token is create after login_token_youth' do it { expect(token.token_young?).to be true }