Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-11-21 21:07:57 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-21 21:07:57 +0300
commitc0b718a0dbd99e6c0d30e5bc55bdcf4a12946375 (patch)
tree8ad3691912d91d8cf7b3931f68a4284ae7b5995c /spec/models/projects
parent5dc70663c4ff1feb215428ce50673b5b646f9809 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/projects')
-rw-r--r--spec/models/projects/forks/divergence_counts_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/models/projects/forks/divergence_counts_spec.rb b/spec/models/projects/forks/divergence_counts_spec.rb
new file mode 100644
index 00000000000..1f03e37e231
--- /dev/null
+++ b/spec/models/projects/forks/divergence_counts_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Projects::Forks::DivergenceCounts do
+ include ProjectForksHelper
+
+ let_it_be(:user) { create(:user) }
+
+ describe '#counts' do
+ let(:source_repo) { create(:project, :repository, :public).repository }
+ let(:fork_repo) { fork_project(source_repo.project, user, { repository: true }).repository }
+ let(:fork_branch) { 'fork-branch' }
+ let(:cache_key) { ['project_forks', fork_repo.project.id, fork_branch, 'divergence_counts'] }
+
+ def expect_cached_counts(value)
+ counts = described_class.new(fork_repo.project, fork_branch).counts
+
+ ahead, behind = value
+ expect(counts).to eq({ ahead: ahead, behind: behind })
+
+ cached_value = [source_repo.commit.sha, fork_repo.commit(fork_branch).sha, value]
+ expect(Rails.cache.read(cache_key)).to eq(cached_value)
+ end
+
+ it 'shows how far behind/ahead a fork is from the upstream', :use_clean_rails_redis_caching do
+ fork_repo.create_branch(fork_branch)
+
+ expect_cached_counts([0, 0])
+
+ fork_repo.commit_files(
+ user,
+ branch_name: fork_branch, message: 'Committing something',
+ actions: [{ action: :create, file_path: 'encoding/CHANGELOG', content: 'New file' }]
+ )
+
+ expect_cached_counts([1, 0])
+
+ source_repo.commit_files(
+ user,
+ branch_name: source_repo.root_ref, message: 'Commit to root ref',
+ actions: [{ action: :create, file_path: 'encoding/CHANGELOG', content: 'One more' }]
+ )
+
+ source_repo.commit_files(
+ user,
+ branch_name: source_repo.root_ref, message: 'Another commit to root ref',
+ actions: [{ action: :create, file_path: 'encoding/NEW-CHANGELOG', content: 'One more time' }]
+ )
+
+ expect_cached_counts([1, 2])
+ end
+ end
+end