diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
commit | 3cd17c9430c7575b0c1f1041947f3cd0d991f00c (patch) | |
tree | 12638383d600ae6d5c8cbf6c27da7bdb2199f5e7 /spec/factories | |
parent | 8faabdf7d33b575de11b043cfe6698021d33a973 (diff) | |
parent | 8c0e358a972ca9cb2176ff9289a5a89b0c909a93 (diff) | |
download | gitlab-ce-3cd17c9430c7575b0c1f1041947f3cd0d991f00c.tar.gz |
Merge remote-tracking branch 'origin/master' into 24147-delete-env-button
Diffstat (limited to 'spec/factories')
-rw-r--r-- | spec/factories/chat_names.rb | 16 | ||||
-rw-r--r-- | spec/factories/ci/builds.rb | 19 | ||||
-rw-r--r-- | spec/factories/ci/pipelines.rb | 34 | ||||
-rw-r--r-- | spec/factories/ci/runners.rb | 4 | ||||
-rw-r--r-- | spec/factories/ci/stages.rb | 14 | ||||
-rw-r--r-- | spec/factories/commit_statuses.rb | 4 | ||||
-rw-r--r-- | spec/factories/deployments.rb | 3 | ||||
-rw-r--r-- | spec/factories/environments.rb | 28 | ||||
-rw-r--r-- | spec/factories/groups.rb | 8 | ||||
-rw-r--r-- | spec/factories/lfs_objects.rb | 2 | ||||
-rw-r--r-- | spec/factories/notes.rb | 2 | ||||
-rw-r--r-- | spec/factories/personal_access_tokens.rb | 1 | ||||
-rw-r--r-- | spec/factories/project_statistics.rb | 6 | ||||
-rw-r--r-- | spec/factories/projects.rb | 35 | ||||
-rw-r--r-- | spec/factories/subscriptions.rb | 7 | ||||
-rw-r--r-- | spec/factories/timelogs.rb | 9 | ||||
-rw-r--r-- | spec/factories/todos.rb | 5 |
17 files changed, 179 insertions, 18 deletions
diff --git a/spec/factories/chat_names.rb b/spec/factories/chat_names.rb new file mode 100644 index 00000000000..24225468d55 --- /dev/null +++ b/spec/factories/chat_names.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do + factory :chat_name, class: ChatName do + user factory: :user + service factory: :service + + team_id 'T0001' + team_domain 'Awesome Team' + + sequence :chat_id do |n| + "U#{n}" + end + sequence :chat_name do |n| + "user#{n}" + end + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 0c93bbdfe26..0397d5d4001 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -12,15 +12,17 @@ FactoryGirl.define do started_at 'Di 29. Okt 09:51:28 CET 2013' finished_at 'Di 29. Okt 09:53:28 CET 2013' commands 'ls -a' + options do { image: "ruby:2.1", services: ["postgres"] } end + yaml_variables do [ - { key: :DB_NAME, value: 'postgres', public: true } + { key: 'DB_NAME', value: 'postgres', public: true } ] end @@ -38,6 +40,10 @@ FactoryGirl.define do status 'canceled' end + trait :skipped do + status 'skipped' + end + trait :running do status 'running' end @@ -55,10 +61,21 @@ FactoryGirl.define do self.when 'manual' end + trait :teardown_environment do + environment 'staging' + options environment: { name: 'staging', + action: 'stop' } + end + trait :allowed_to_fail do allow_failure true end + trait :playable do + skipped + manual + end + after(:build) do |build, evaluator| build.project = build.pipeline.project end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index ac2a1ba5dff..77404f46c92 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -7,26 +7,38 @@ FactoryGirl.define do project factory: :empty_project factory :ci_pipeline_without_jobs do - after(:build) do |commit| - allow(commit).to receive(:ci_yaml_file) { YAML.dump({}) } + after(:build) do |pipeline| + allow(pipeline).to receive(:ci_yaml_file) { YAML.dump({}) } end end factory :ci_pipeline_with_one_job do - after(:build) do |commit| - allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" } }) } + after(:build) do |pipeline| + allow(pipeline).to receive(:ci_yaml_file) do + YAML.dump({ rspec: { script: "ls" } }) + end end end - factory :ci_pipeline_with_two_job do - after(:build) do |commit| - allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } }) } + factory :ci_pipeline do + transient { config nil } + + after(:build) do |pipeline, evaluator| + allow(pipeline).to receive(:ci_yaml_file) do + if evaluator.config + YAML.dump(evaluator.config) + else + File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + end + end + + # Populates pipeline with errors + # + pipeline.config_processor if evaluator.config end - end - factory :ci_pipeline do - after(:build) do |commit| - allow(commit).to receive(:ci_yaml_file) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) } + trait :invalid do + config(rspec: nil) end end end diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index e3b73e29987..ed4acca23f1 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -8,6 +8,10 @@ FactoryGirl.define do is_shared false active true + trait :online do + contacted_at Time.now + end + trait :shared do is_shared true end diff --git a/spec/factories/ci/stages.rb b/spec/factories/ci/stages.rb new file mode 100644 index 00000000000..7f557b25ccb --- /dev/null +++ b/spec/factories/ci/stages.rb @@ -0,0 +1,14 @@ +FactoryGirl.define do + factory :ci_stage, class: Ci::Stage do + transient do + name 'test' + status nil + warnings nil + pipeline factory: :ci_empty_pipeline + end + + initialize_with do + Ci::Stage.new(pipeline, name: name, status: status, warnings: warnings) + end + end +end diff --git a/spec/factories/commit_statuses.rb b/spec/factories/commit_statuses.rb index 995f2080f10..756b341ecba 100644 --- a/spec/factories/commit_statuses.rb +++ b/spec/factories/commit_statuses.rb @@ -19,6 +19,10 @@ FactoryGirl.define do status 'canceled' end + trait :skipped do + status 'skipped' + end + trait :running do status 'running' end diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb index 6f24bf58d14..29ad1af9fd9 100644 --- a/spec/factories/deployments.rb +++ b/spec/factories/deployments.rb @@ -3,8 +3,9 @@ FactoryGirl.define do sha '97de212e80737a608d939f648d959671fb0a0142' ref 'master' tag false + user project nil - + deployable factory: :ci_build environment factory: :environment after(:build) do |deployment, evaluator| diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index 846cccfc7fa..0852dda6b29 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -4,5 +4,33 @@ FactoryGirl.define do project factory: :empty_project sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" } + + trait :with_review_app do |environment| + project + + transient do + ref 'master' + end + + # At this point `review app` is an ephemeral concept related to + # deployments being deployed for given environment. There is no + # first-class `review app` available so we need to create set of + # interconnected objects to simulate a review app. + # + after(:create) do |environment, evaluator| + deployment = create(:deployment, + environment: environment, + project: environment.project, + ref: evaluator.ref, + sha: environment.project.commit(evaluator.ref).id) + + teardown_build = create(:ci_build, :manual, + name: "#{deployment.environment.name}:teardown", + pipeline: deployment.deployable.pipeline) + + deployment.update_column(:on_stop, teardown_build.name) + environment.update_attribute(:deployments, [deployment]) + end + end end end diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index 2d47a6f6c4c..ece6beb9fa9 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -15,5 +15,13 @@ FactoryGirl.define do trait :private do visibility_level Gitlab::VisibilityLevel::PRIVATE end + + trait :access_requestable do + request_access_enabled true + end + + trait :nested do + parent factory: :group + end end end diff --git a/spec/factories/lfs_objects.rb b/spec/factories/lfs_objects.rb index a81645acd2b..477fab9e964 100644 --- a/spec/factories/lfs_objects.rb +++ b/spec/factories/lfs_objects.rb @@ -2,7 +2,7 @@ include ActionDispatch::TestProcess FactoryGirl.define do factory :lfs_object do - oid "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a17f80" + sequence(:oid) { |n| "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a%05x" % n } size 499013 end diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 6919002dedc..a10ba629760 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -67,7 +67,7 @@ FactoryGirl.define do end trait :on_project_snippet do - noteable { create(:snippet, project: project) } + noteable { create(:project_snippet, project: project) } end trait :system do diff --git a/spec/factories/personal_access_tokens.rb b/spec/factories/personal_access_tokens.rb index da4c72bcb5b..811eab7e15b 100644 --- a/spec/factories/personal_access_tokens.rb +++ b/spec/factories/personal_access_tokens.rb @@ -5,5 +5,6 @@ FactoryGirl.define do name { FFaker::Product.brand } revoked false expires_at { 5.days.from_now } + scopes ['api'] end end diff --git a/spec/factories/project_statistics.rb b/spec/factories/project_statistics.rb new file mode 100644 index 00000000000..72d43096216 --- /dev/null +++ b/spec/factories/project_statistics.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :project_statistics do + project { create :project } + namespace { project.namespace } + end +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index bfd88a254f1..992580a6b34 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -24,6 +24,18 @@ FactoryGirl.define do visibility_level Gitlab::VisibilityLevel::PRIVATE end + trait :archived do + archived true + end + + trait :access_requestable do + request_access_enabled true + end + + trait :repository do + # no-op... for now! + end + trait :empty_repo do after(:create) do |project| project.create_repository @@ -38,6 +50,12 @@ FactoryGirl.define do end end + trait :test_repo do + after :create do |project| + TestEnv.copy_repo(project) + end + end + # Nest Project Feature attributes transient do wiki_access_level ProjectFeature::ENABLED @@ -87,9 +105,7 @@ FactoryGirl.define do factory :project, parent: :empty_project do path { 'gitlabhq' } - after :create do |project| - TestEnv.copy_repo(project) - end + test_repo end factory :forked_project_with_submodules, parent: :empty_project do @@ -129,4 +145,17 @@ FactoryGirl.define do ) end end + + factory :kubernetes_project, parent: :empty_project do + after :create do |project| + project.create_kubernetes_service( + active: true, + properties: { + namespace: project.path, + api_url: 'https://kubernetes.example.com', + token: 'a' * 40, + } + ) + end + end end diff --git a/spec/factories/subscriptions.rb b/spec/factories/subscriptions.rb new file mode 100644 index 00000000000..b11b0a0a17b --- /dev/null +++ b/spec/factories/subscriptions.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :subscription do + user + project factory: :empty_project + subscribable factory: :issue + end +end diff --git a/spec/factories/timelogs.rb b/spec/factories/timelogs.rb new file mode 100644 index 00000000000..12fc4ec4486 --- /dev/null +++ b/spec/factories/timelogs.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :timelog do + time_spent 3600 + user + association :trackable, factory: :issue + end +end diff --git a/spec/factories/todos.rb b/spec/factories/todos.rb index 866e663f026..85a8c263643 100644 --- a/spec/factories/todos.rb +++ b/spec/factories/todos.rb @@ -21,12 +21,17 @@ FactoryGirl.define do trait :build_failed do action { Todo::BUILD_FAILED } + target factory: :merge_request end trait :approval_required do action { Todo::APPROVAL_REQUIRED } end + trait :unmergeable do + action { Todo::UNMERGEABLE } + end + trait :done do state :done end |