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-09-24 08:09:37 -04:00
|
|
|
project { association(:project) }
|
2020-04-22 08:09:29 -04:00
|
|
|
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-09-24 08:09:37 -04:00
|
|
|
slug: title&.tr(' ', '-'),
|
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|
|
2020-07-21 08:09:30 -04:00
|
|
|
# WikiPages is ActiveModel which doesn't support `create!`.
|
|
|
|
page.create(message: evaluator.message) # rubocop:disable Rails/SaveBang
|
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) }
|
2020-11-02 07:09:03 -05:00
|
|
|
project { association(:project) }
|
2020-03-19 08:09:33 -04:00
|
|
|
|
|
|
|
trait :for_wiki_page do
|
|
|
|
transient do
|
2020-11-02 07:09:03 -05:00
|
|
|
wiki_page { association(:wiki_page, container: project) }
|
2020-03-19 08:09:33 -04:00
|
|
|
end
|
|
|
|
|
2020-11-02 07:09:03 -05:00
|
|
|
project { @overrides[:wiki_page]&.container || association(: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
|
2020-11-02 07:09:03 -05:00
|
|
|
wiki_page_meta { association(:wiki_page_meta) }
|
2020-03-19 08:09:33 -04:00
|
|
|
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
|