debian-mirror-gitlab/spec/factories/wiki_pages.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.9 KiB
Ruby
Raw Normal View History

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' }
2020-05-24 23:13:21 +05:30
format { :markdown }
message { nil }
2021-01-03 14:25:43 +05:30
project { association(:project) }
2020-05-24 23:13:21 +05:30
container { project }
wiki { association(:wiki, container: container) }
page { OpenStruct.new(url_path: title) }
end
initialize_with do
new(wiki, page).tap do |page|
page.attributes = {
2021-01-03 14:25:43 +05:30
slug: title&.tr(' ', '-'),
2020-04-22 19:07:51 +05:30
title: title,
content: content,
format: format
2017-08-17 22:00:37 +05:30
}
end
end
2020-05-24 23:13:21 +05:30
# Clear our default @page, except when using build_stubbed
after(:build) do |page|
2023-03-17 16:20:25 +05:30
page.instance_variable_set(:@page, nil)
2017-08-17 22:00:37 +05:30
end
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
to_create do |page, evaluator|
2020-10-24 23:57:45 +05:30
# WikiPages is ActiveModel which doesn't support `create!`.
page.create(message: evaluator.message) # rubocop:disable Rails/SaveBang
2020-04-22 19:07:51 +05:30
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) }
2021-01-29 00:20:46 +05:30
project { association(:project) }
2020-04-22 19:07:51 +05:30
trait :for_wiki_page do
transient do
2021-01-29 00:20:46 +05:30
wiki_page { association(:wiki_page, container: project) }
2020-04-22 19:07:51 +05:30
end
2021-01-29 00:20:46 +05:30
project { @overrides[:wiki_page]&.container || association(:project) }
2020-04-22 19:07:51 +05:30
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
2021-01-29 00:20:46 +05:30
wiki_page_meta { association(:wiki_page_meta) }
2020-04-22 19:07:51 +05:30
slug { generate(:sluggified_title) }
canonical { false }
trait :canonical do
canonical { true }
end
end
sequence(:wiki_page_title) { |n| "Page #{n}" }
2020-05-24 23:13:21 +05:30
sequence(:wiki_filename) { |n| "Page_#{n}.md" }
2020-04-22 19:07:51 +05:30
sequence(:sluggified_title) { |n| "slug-#{n}" }
2016-06-02 11:05:42 +05:30
end