diff options
Diffstat (limited to 'spec/factories')
-rw-r--r-- | spec/factories/events.rb | 10 | ||||
-rw-r--r-- | spec/factories/lists.rb | 1 | ||||
-rw-r--r-- | spec/factories/wiki_pages.rb | 56 |
3 files changed, 63 insertions, 4 deletions
diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 81d57a25058..b4285627de3 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -22,6 +22,16 @@ FactoryBot.define do action { Event::CLOSED } target factory: :closed_issue end + + factory :wiki_page_event do + action { Event::CREATED } + + transient do + wiki_page { create(:wiki_page, project: project) } + end + + target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } + end end factory :push_event, class: 'PushEvent' do diff --git a/spec/factories/lists.rb b/spec/factories/lists.rb index cf00351b231..623b080c073 100644 --- a/spec/factories/lists.rb +++ b/spec/factories/lists.rb @@ -7,6 +7,7 @@ FactoryBot.define do list_type { :label } max_issue_count { 0 } max_issue_weight { 0 } + limit_metric { nil } sequence(:position) end diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb index 86571f062ba..8eb7a12a928 100644 --- a/spec/factories/wiki_pages.rb +++ b/spec/factories/wiki_pages.rb @@ -5,17 +5,22 @@ require 'ostruct' FactoryBot.define do factory :wiki_page do transient do + title { generate(:wiki_page_title) } + content { 'Content for wiki page' } + format { 'markdown' } + project { create(:project) } attrs do { - title: 'Title.with.dot', - content: 'Content for wiki page', - format: 'markdown' + title: title, + content: content, + format: format } end end page { OpenStruct.new(url_path: 'some-name') } - association :wiki, factory: :project_wiki, strategy: :build + wiki { build(:project_wiki, project: project) } + initialize_with { new(wiki, page) } before(:create) do |page, evaluator| @@ -25,5 +30,48 @@ FactoryBot.define do to_create do |page| page.create end + + trait :with_real_page do + project { create(:project, :repository) } + + 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 + end end + + factory :wiki_page_meta, class: 'WikiPage::Meta' do + title { generate(:wiki_page_title) } + project { create(:project) } + + trait :for_wiki_page do + transient do + wiki_page { create(:wiki_page, project: project) } + end + + project { @overrides[:wiki_page]&.project || create(:project) } + title { wiki_page.title } + + initialize_with do + raise 'Metadata only available for valid pages' unless wiki_page.valid? + + WikiPage::Meta.find_or_create(wiki_page.slug, wiki_page) + end + end + end + + factory :wiki_page_slug, class: 'WikiPage::Slug' do + wiki_page_meta { create(:wiki_page_meta) } + slug { generate(:sluggified_title) } + canonical { false } + + trait :canonical do + canonical { true } + end + end + + sequence(:wiki_page_title) { |n| "Page #{n}" } + sequence(:sluggified_title) { |n| "slug-#{n}" } end |