diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/slash_commands/command_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/deploy_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/issue_new_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/issue_search_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/issue_show_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/chat_name_spec.rb | 20 | ||||
-rw-r--r-- | spec/services/chat_names/find_user_service_spec.rb | 25 |
7 files changed, 48 insertions, 14 deletions
diff --git a/spec/lib/gitlab/slash_commands/command_spec.rb b/spec/lib/gitlab/slash_commands/command_spec.rb index 0173a45d480..e3447d974aa 100644 --- a/spec/lib/gitlab/slash_commands/command_spec.rb +++ b/spec/lib/gitlab/slash_commands/command_spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' describe Gitlab::SlashCommands::Command do let(:project) { create(:project) } let(:user) { create(:user) } + let(:chat_name) { double(:chat_name, user: user) } describe '#execute' do subject do - described_class.new(project, user, params).execute + described_class.new(project, chat_name, params).execute end context 'when no command is available' do @@ -88,7 +89,7 @@ describe Gitlab::SlashCommands::Command do end describe '#match_command' do - subject { described_class.new(project, user, params).match_command.first } + subject { described_class.new(project, chat_name, params).match_command.first } context 'IssueShow is triggered' do let(:params) { { text: 'issue show 123' } } diff --git a/spec/lib/gitlab/slash_commands/deploy_spec.rb b/spec/lib/gitlab/slash_commands/deploy_spec.rb index 74b5ef4bb26..0d57334aa4c 100644 --- a/spec/lib/gitlab/slash_commands/deploy_spec.rb +++ b/spec/lib/gitlab/slash_commands/deploy_spec.rb @@ -4,6 +4,7 @@ describe Gitlab::SlashCommands::Deploy do describe '#execute' do let(:project) { create(:project) } let(:user) { create(:user) } + let(:chat_name) { double(:chat_name, user: user) } let(:regex_match) { described_class.match('deploy staging to production') } before do @@ -16,7 +17,7 @@ describe Gitlab::SlashCommands::Deploy do end subject do - described_class.new(project, user).execute(regex_match) + described_class.new(project, chat_name).execute(regex_match) end context 'if no environment is defined' do diff --git a/spec/lib/gitlab/slash_commands/issue_new_spec.rb b/spec/lib/gitlab/slash_commands/issue_new_spec.rb index 3b077c58c50..8e7df946529 100644 --- a/spec/lib/gitlab/slash_commands/issue_new_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_new_spec.rb @@ -4,6 +4,7 @@ describe Gitlab::SlashCommands::IssueNew do describe '#execute' do let(:project) { create(:project) } let(:user) { create(:user) } + let(:chat_name) { double(:chat_name, user: user) } let(:regex_match) { described_class.match("issue create bird is the word") } before do @@ -11,7 +12,7 @@ describe Gitlab::SlashCommands::IssueNew do end subject do - described_class.new(project, user).execute(regex_match) + described_class.new(project, chat_name).execute(regex_match) end context 'without description' do diff --git a/spec/lib/gitlab/slash_commands/issue_search_spec.rb b/spec/lib/gitlab/slash_commands/issue_search_spec.rb index 35d01efc1bd..189e9592f1b 100644 --- a/spec/lib/gitlab/slash_commands/issue_search_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_search_spec.rb @@ -6,10 +6,11 @@ describe Gitlab::SlashCommands::IssueSearch do let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') } let(:project) { create(:project) } let(:user) { create(:user) } + let(:chat_name) { double(:chat_name, user: user) } let(:regex_match) { described_class.match("issue search find") } subject do - described_class.new(project, user).execute(regex_match) + described_class.new(project, chat_name).execute(regex_match) end context 'when the user has no access' do diff --git a/spec/lib/gitlab/slash_commands/issue_show_spec.rb b/spec/lib/gitlab/slash_commands/issue_show_spec.rb index e5834d5a2ee..b1db1638237 100644 --- a/spec/lib/gitlab/slash_commands/issue_show_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_show_spec.rb @@ -5,6 +5,7 @@ describe Gitlab::SlashCommands::IssueShow do let(:issue) { create(:issue, project: project) } let(:project) { create(:project) } let(:user) { issue.author } + let(:chat_name) { double(:chat_name, user: user) } let(:regex_match) { described_class.match("issue show #{issue.iid}") } before do @@ -12,7 +13,7 @@ describe Gitlab::SlashCommands::IssueShow do end subject do - described_class.new(project, user).execute(regex_match) + described_class.new(project, chat_name).execute(regex_match) end context 'the issue exists' do diff --git a/spec/models/chat_name_spec.rb b/spec/models/chat_name_spec.rb index e89e534d914..504bc710b25 100644 --- a/spec/models/chat_name_spec.rb +++ b/spec/models/chat_name_spec.rb @@ -14,4 +14,24 @@ describe ChatName do it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:service_id) } it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:service_id, :team_id) } + + 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 end diff --git a/spec/services/chat_names/find_user_service_spec.rb b/spec/services/chat_names/find_user_service_spec.rb index 79aaac3aeb6..5734b10109a 100644 --- a/spec/services/chat_names/find_user_service_spec.rb +++ b/spec/services/chat_names/find_user_service_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ChatNames::FindUserService do +describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state do describe '#execute' do let(:service) { create(:service) } @@ -13,21 +13,30 @@ describe ChatNames::FindUserService do context 'when existing user is requested' do let(:params) { { team_id: chat_name.team_id, user_id: chat_name.chat_id } } - it 'returns the existing user' do - is_expected.to eq(user) + it 'returns the existing chat_name' do + is_expected.to eq(chat_name) end - it 'updates when last time chat name was used' do + it 'updates the last used timestamp if one is not already set' do expect(chat_name.last_used_at).to be_nil subject - initial_last_used = chat_name.reload.last_used_at - expect(initial_last_used).to be_present + expect(chat_name.reload.last_used_at).to be_present + end + + it 'only updates an existing timestamp once within a certain time frame' do + service = described_class.new(service, params) + + expect(chat_name.last_used_at).to be_nil + + service.execute + + time = chat_name.reload.last_used_at - Timecop.travel(2.days.from_now) { described_class.new(service, params).execute } + service.execute - expect(chat_name.reload.last_used_at).to be > initial_last_used + expect(chat_name.reload.last_used_at).to eq(time) end end |