2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ChatName do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:chat_name) { create(:chat_name) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
subject { chat_name }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it { is_expected.to belong_to(:integration) }
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
2021-06-08 01:23:25 +05:30
|
|
|
it { is_expected.to validate_presence_of(:integration) }
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to validate_presence_of(:team_id) }
|
|
|
|
it { is_expected.to validate_presence_of(:chat_id) }
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
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-03-27 19:54:05 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'is removed when the project is deleted' do
|
2021-06-08 01:23:25 +05:30
|
|
|
expect { subject.reload.integration.project.delete }.to change { ChatName.count }.by(-1)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
expect(ChatName.where(id: subject.id)).not_to exist
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
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-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
it_behaves_like 'it has loose foreign keys' do
|
|
|
|
let(:factory_name) { :chat_name }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|