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

72 lines
1.8 KiB
Ruby
Raw Permalink 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 }
project { association(:project, :wiki_repo) }
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 = {
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|
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|
page.create(message: evaluator.message)
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) }
project { create(:project) }
trait :for_wiki_page do
transient do
2020-05-24 23:13:21 +05:30
wiki_page { create(:wiki_page, container: project) }
2020-04-22 19:07:51 +05:30
end
2020-05-24 23:13:21 +05:30
project { @overrides[:wiki_page]&.container || create(: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
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-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