2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-15 00:47:09 -04:00
|
|
|
require 'ostruct'
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2016-04-15 00:47:09 -04:00
|
|
|
factory :wiki_page do
|
2016-12-20 08:31:21 -05:00
|
|
|
transient do
|
2020-03-19 08:09:33 -04:00
|
|
|
title { generate(:wiki_page_title) }
|
|
|
|
content { 'Content for wiki page' }
|
2020-04-27 05:09:51 -04:00
|
|
|
format { :markdown }
|
|
|
|
message { nil }
|
2020-04-22 08:09:29 -04:00
|
|
|
project { association(:project, :wiki_repo) }
|
|
|
|
container { project }
|
2020-04-27 05:09:51 -04:00
|
|
|
wiki { association(:wiki, container: container) }
|
|
|
|
page { OpenStruct.new(url_path: title) }
|
|
|
|
end
|
|
|
|
|
|
|
|
initialize_with do
|
|
|
|
new(wiki, page).tap do |page|
|
|
|
|
page.attributes = {
|
2020-03-19 08:09:33 -04:00
|
|
|
title: title,
|
|
|
|
content: content,
|
|
|
|
format: format
|
2016-12-20 08:31:21 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
# Clear our default @page, except when using build_stubbed
|
|
|
|
after(:build) do |page|
|
|
|
|
page.instance_variable_set('@page', nil)
|
2016-12-20 08:31:21 -05:00
|
|
|
end
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
to_create do |page, evaluator|
|
|
|
|
page.create(message: evaluator.message)
|
2020-03-19 08:09:33 -04:00
|
|
|
end
|
2016-04-15 00:47:09 -04:00
|
|
|
end
|
2020-03-19 08:09:33 -04:00
|
|
|
|
|
|
|
factory :wiki_page_meta, class: 'WikiPage::Meta' do
|
|
|
|
title { generate(:wiki_page_title) }
|
|
|
|
project { create(:project) }
|
|
|
|
|
|
|
|
trait :for_wiki_page do
|
|
|
|
transient do
|
2020-04-22 08:09:29 -04:00
|
|
|
wiki_page { create(:wiki_page, container: project) }
|
2020-03-19 08:09:33 -04:00
|
|
|
end
|
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
project { @overrides[:wiki_page]&.container || create(:project) }
|
2020-03-19 08:09:33 -04:00
|
|
|
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}" }
|
2020-05-11 23:09:31 -04:00
|
|
|
sequence(:wiki_filename) { |n| "Page_#{n}.md" }
|
2020-03-19 08:09:33 -04:00
|
|
|
sequence(:sluggified_title) { |n| "slug-#{n}" }
|
2016-04-15 00:47:09 -04:00
|
|
|
end
|