Commit 82a0cc88 authored by Alex Kalderimis's avatar Alex Kalderimis

Remove WikiPage#meta method

this was only ever needed in tests, and having it on the actual
wiki-page model is just incurring technical debt and installing a
permanent footgun. It is removed and replaced with factories.

This also refactors the event spec to be much more declarative for
visibility tests.
parent c4fbaa06
......@@ -29,12 +29,6 @@ class WikiPage
alias_method :==, :eql?
def meta
raise 'Metadata only available for valid pages' unless valid?
@meta ||= WikiPage::Meta.find_or_create(slug, self)
end
# Sorts and groups pages by directory.
#
# pages - an array of WikiPage objects.
......@@ -242,7 +236,6 @@ class WikiPage
end
save do
@meta = nil if title_changed?
wiki.update_page(
@page,
content: content,
......
......@@ -27,10 +27,10 @@ FactoryBot.define do
action { Event::CREATED }
transient do
wiki_page { create(:wiki_page, wiki: create(:project_wiki, project: project)) }
wiki_page { create(:wiki_page, project: project) }
end
target { wiki_page.meta }
target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) }
end
end
......
......@@ -51,7 +51,14 @@ FactoryBot.define do
wiki_page { create(:wiki_page, project: project) }
end
initialize_with { wiki_page.meta }
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
......
This diff is collapsed.
......@@ -664,30 +664,6 @@ describe WikiPage do
end
end
describe '#meta' do
it 'returns an appropriate metadata object' do
wiki_page = create(:wiki_page)
expect(wiki_page.meta).to have_attributes(
valid?: true,
canonical_slug: wiki_page.slug,
title: wiki_page.title,
project: wiki_page.project,
slugs: include(have_attributes(slug: wiki_page.slug))
)
end
it 'is up-to-date after updates' do
wiki_page = create(:wiki_page)
old_title = wiki_page.title
new_title = FFaker::Lorem.sentence
expect do
wiki_page.update(title: new_title)
end.to change { wiki_page.meta.title }.from(old_title).to(new_title)
end
end
private
def remove_temp_repo(path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment