debian-mirror-gitlab/spec/factories/snippets.rb

60 lines
1.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2016-06-02 11:05:42 +05:30
factory :snippet do
author
2017-08-17 22:00:37 +05:30
title { generate(:title) }
content { generate(:title) }
2017-09-10 17:25:29 +05:30
description { generate(:title) }
2017-08-17 22:00:37 +05:30
file_name { generate(:filename) }
2020-01-01 13:55:28 +05:30
secret { false }
2016-06-02 11:05:42 +05:30
2022-08-13 15:12:31 +05:30
transient do
repository_storage { 'default' }
end
2016-06-02 11:05:42 +05:30
trait :public do
2019-12-21 20:55:43 +05:30
visibility_level { Snippet::PUBLIC }
2016-06-02 11:05:42 +05:30
end
trait :internal do
2019-12-21 20:55:43 +05:30
visibility_level { Snippet::INTERNAL }
2016-06-02 11:05:42 +05:30
end
trait :private do
2019-12-21 20:55:43 +05:30
visibility_level { Snippet::PRIVATE }
2016-06-02 11:05:42 +05:30
end
2020-03-13 15:44:24 +05:30
# Test repository - https://gitlab.com/gitlab-org/gitlab-test
trait :repository do
2022-08-13 15:12:31 +05:30
after :create do |snippet, evaluator|
snippet.track_snippet_repository(evaluator.repository_storage)
2020-04-08 14:13:33 +05:30
2022-08-13 15:12:31 +05:30
# There are various tests that rely on there being no repository cache.
# Using raw avoids caching.
repo = Gitlab::GlRepository::SNIPPET.repository_for(snippet).raw
repo.create_from_bundle(TestEnv.factory_repo_bundle_path)
2020-03-13 15:44:24 +05:30
end
end
trait :empty_repo do
after(:create) do |snippet|
2020-04-08 14:13:33 +05:30
raise "Failed to create repository!" unless snippet.create_repository
2020-03-13 15:44:24 +05:30
end
end
2016-06-02 11:05:42 +05:30
end
2017-09-10 17:25:29 +05:30
factory :project_snippet, parent: :snippet, class: :ProjectSnippet do
project
2018-03-17 18:26:18 +05:30
author { project.creator }
2017-09-10 17:25:29 +05:30
end
factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do
2020-01-01 13:55:28 +05:30
trait :secret do
visibility_level { Snippet::PUBLIC }
secret { true }
2020-04-08 14:13:33 +05:30
project { nil }
2020-01-01 13:55:28 +05:30
end
2017-09-10 17:25:29 +05:30
end
2016-06-02 11:05:42 +05:30
end