2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-16 08:56:30 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ChatName do
|
2020-02-12 10:09:37 -05:00
|
|
|
let_it_be(:chat_name) { create(:chat_name) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2017-09-05 03:37:06 -04:00
|
|
|
subject { chat_name }
|
2016-11-16 08:56:30 -05:00
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
it { is_expected.to belong_to(:integration) }
|
2016-11-16 08:56:30 -05:00
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
2021-05-12 08:10:24 -04:00
|
|
|
it { is_expected.to validate_presence_of(:integration) }
|
2016-11-16 08:56:30 -05:00
|
|
|
it { is_expected.to validate_presence_of(:team_id) }
|
|
|
|
it { is_expected.to validate_presence_of(:chat_id) }
|
|
|
|
|
2022-08-12 23:09:28 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:integration_id) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:integration_id, :team_id) }
|
2018-02-22 12:34:04 -05:00
|
|
|
|
2020-04-01 23:08:01 -04:00
|
|
|
it 'is removed when the project is deleted' do
|
2021-05-12 08:10:24 -04:00
|
|
|
expect { subject.reload.integration.project.delete }.to change { ChatName.count }.by(-1)
|
2020-04-01 23:08:01 -04:00
|
|
|
|
|
|
|
expect(ChatName.where(id: subject.id)).not_to exist
|
|
|
|
end
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
describe '#update_last_used_at', :clean_gitlab_redis_shared_state do
|
|
|
|
it 'updates the last_used_at timestamp' do
|
|
|
|
expect(subject.last_used_at).to be_nil
|
|
|
|
|
|
|
|
subject.update_last_used_at
|
|
|
|
|
|
|
|
expect(subject.last_used_at).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update last_used_at if it was recently updated' do
|
|
|
|
subject.update_last_used_at
|
|
|
|
|
|
|
|
time = subject.last_used_at
|
|
|
|
|
|
|
|
subject.update_last_used_at
|
|
|
|
|
|
|
|
expect(subject.last_used_at).to eq(time)
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 11:13:41 -04:00
|
|
|
|
|
|
|
it_behaves_like 'it has loose foreign keys' do
|
|
|
|
let(:factory_name) { :chat_name }
|
|
|
|
end
|
2016-11-16 08:56:30 -05:00
|
|
|
end
|