summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb')
-rw-r--r--spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb
index 26c83ed6793..226fdb9c948 100644
--- a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb
+++ b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb
@@ -21,6 +21,55 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do
end
end
+ describe '.find' do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:other_project) { create(:project) }
+
+ described_class::TEMPLATES_WITH_LATEST_VERSION.keys.each do |key|
+ it "finds the latest template for #{key}" do
+ result = described_class.find(key, project)
+ expect(result.full_name).to eq("#{key}.latest.gitlab-ci.yml")
+ expect(result.content).to be_present
+ end
+
+ context 'when `redirect_to_latest_template` feature flag is disabled' do
+ before do
+ stub_feature_flags("redirect_to_latest_template_#{key.underscore.tr('/', '_')}".to_sym => false)
+ end
+
+ it "finds the stable template for #{key}" do
+ result = described_class.find(key, project)
+ expect(result.full_name).to eq("#{key}.gitlab-ci.yml")
+ expect(result.content).to be_present
+ end
+ end
+
+ context 'when `redirect_to_latest_template` feature flag is enabled on the project' do
+ before do
+ stub_feature_flags("redirect_to_latest_template_#{key.underscore.tr('/', '_')}".to_sym => project)
+ end
+
+ it "finds the latest template for #{key}" do
+ result = described_class.find(key, project)
+ expect(result.full_name).to eq("#{key}.latest.gitlab-ci.yml")
+ expect(result.content).to be_present
+ end
+ end
+
+ context 'when `redirect_to_latest_template` feature flag is enabled on the other project' do
+ before do
+ stub_feature_flags("redirect_to_latest_template_#{key.underscore.tr('/', '_')}".to_sym => other_project)
+ end
+
+ it "finds the stable template for #{key}" do
+ result = described_class.find(key, project)
+ expect(result.full_name).to eq("#{key}.gitlab-ci.yml")
+ expect(result.content).to be_present
+ end
+ end
+ end
+ end
+
describe '#content' do
it 'loads the full file' do
gitignore = subject.new(Rails.root.join('lib/gitlab/ci/templates/Ruby.gitlab-ci.yml'))