2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
require 'ostruct'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
FactoryBot.define do
|
2016-06-02 11:05:42 +05:30
|
|
|
factory :wiki_page do
|
2017-08-17 22:00:37 +05:30
|
|
|
transient do
|
2020-04-22 19:07:51 +05:30
|
|
|
title { generate(:wiki_page_title) }
|
|
|
|
content { 'Content for wiki page' }
|
|
|
|
format { 'markdown' }
|
|
|
|
project { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
attrs do
|
|
|
|
{
|
2020-04-22 19:07:51 +05:30
|
|
|
title: title,
|
|
|
|
content: content,
|
|
|
|
format: format
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
page { OpenStruct.new(url_path: 'some-name') }
|
2020-04-22 19:07:51 +05:30
|
|
|
wiki { build(:project_wiki, project: project) }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
initialize_with { new(wiki, page) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before(:create) do |page, evaluator|
|
|
|
|
page.attributes = evaluator.attrs
|
|
|
|
end
|
|
|
|
|
|
|
|
to_create do |page|
|
|
|
|
page.create
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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}" }
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|