diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 12:09:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 12:09:51 +0300 |
commit | 39fa1b598749be0aad699032bbf31450b3ff0098 (patch) | |
tree | 15a4c28989d58f9315e58458a3a494ff8cfc1525 /spec/factories | |
parent | a59d305223365cb31bb670f134383d6ff316a13e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/factories')
-rw-r--r-- | spec/factories/sprints.rb | 48 | ||||
-rw-r--r-- | spec/factories/wiki_pages.rb | 34 |
2 files changed, 62 insertions, 20 deletions
diff --git a/spec/factories/sprints.rb b/spec/factories/sprints.rb new file mode 100644 index 00000000000..da0c3c82467 --- /dev/null +++ b/spec/factories/sprints.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :sprint do + title + + transient do + project { nil } + group { nil } + project_id { nil } + group_id { nil } + resource_parent { nil } + end + + trait :active do + state { Sprint::STATE_ID_MAP[:active] } + end + + trait :closed do + state { Sprint::STATE_ID_MAP[:closed] } + end + + trait :with_dates do + start_date { Date.new(2000, 1, 1) } + due_date { Date.new(2000, 1, 30) } + end + + after(:build, :stub) do |sprint, evaluator| + if evaluator.group + sprint.group = evaluator.group + elsif evaluator.group_id + sprint.group_id = evaluator.group_id + elsif evaluator.project + sprint.project = evaluator.project + elsif evaluator.project_id + sprint.project_id = evaluator.project_id + elsif evaluator.resource_parent + id = evaluator.resource_parent.id + evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id + else + sprint.project = create(:project) + end + end + + factory :active_sprint, traits: [:active] + factory :closed_sprint, traits: [:closed] + end +end diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb index 8eafad07268..e5df970dc9c 100644 --- a/spec/factories/wiki_pages.rb +++ b/spec/factories/wiki_pages.rb @@ -7,11 +7,17 @@ FactoryBot.define do transient do title { generate(:wiki_page_title) } content { 'Content for wiki page' } - format { 'markdown' } + format { :markdown } + message { nil } project { association(:project, :wiki_repo) } container { project } - attrs do - { + wiki { association(:wiki, container: container) } + page { OpenStruct.new(url_path: title) } + end + + initialize_with do + new(wiki, page).tap do |page| + page.attributes = { title: title, content: content, format: format @@ -19,25 +25,13 @@ FactoryBot.define do end end - page { OpenStruct.new(url_path: 'some-name') } - wiki { association(:wiki, container: container) } - - initialize_with { new(wiki, page) } - - before(:create) do |page, evaluator| - page.attributes = evaluator.attrs + # Clear our default @page, except when using build_stubbed + after(:build) do |page| + page.instance_variable_set('@page', nil) end - to_create do |page| - page.create - end - - trait :with_real_page do - page do - wiki.create_page(title, content) - page_title, page_dir = wiki.page_title_and_dir(title) - wiki.wiki.page(title: page_title, dir: page_dir, version: nil) - end + to_create do |page, evaluator| + page.create(message: evaluator.message) end end |