chore: more transactions with filesystem actions cleanup

This commit is contained in:
2026-05-01 16:19:50 +02:00
parent 3133beffcb
commit 7f5077c6ad
8 changed files with 177 additions and 50 deletions

View File

@@ -54,6 +54,27 @@ defmodule BDS.MetadataTest do
assert loaded.blog_languages == ["de", "fr"]
end
test "update_project_metadata keeps committed database changes when filesystem flush fails", %{
project: project,
temp_dir: temp_dir
} do
meta_path = Path.join(temp_dir, "meta")
File.rm_rf!(meta_path)
File.write!(meta_path, "not a directory")
assert {:error, _reason} =
BDS.Metadata.update_project_metadata(project.id, %{
name: "Committed Metadata",
description: "Stored before flush"
})
assert BDS.Projects.get_project!(project.id).name == "Committed Metadata"
assert {:ok, loaded} = BDS.Metadata.get_project_metadata(project.id)
assert loaded.name == "Committed Metadata"
assert loaded.description == "Stored before flush"
end
test "category and publishing updates write their meta files and sync_project_metadata_from_filesystem loads them",
%{project: project, temp_dir: temp_dir} do
assert {:ok, _metadata} = BDS.Metadata.add_category(project.id, "news")

View File

@@ -72,6 +72,26 @@ defmodule BDS.ProjectsTest do
refute {"not-found", :not_found} in starter_slugs
end
test "create_project keeps committed project when template rebuild fails", %{
temp_root: temp_root
} do
temp_dir = Path.join(temp_root, "broken-template-blog")
templates_dir = Path.join(temp_dir, "templates")
File.mkdir_p!(templates_dir)
File.write!(
Path.join(templates_dir, "broken.liquid"),
"---\ntitle: Broken Template\nkind: post\n---\nBody"
)
assert_raise KeyError, fn ->
BDS.Projects.create_project(%{name: "Broken Templates", data_path: temp_dir})
end
assert %Project{name: "Broken Templates"} =
Repo.get_by(Project, data_path: temp_dir)
end
test "set_active_project clears the previous active project and activates the target", %{
temp_root: temp_root
} do

View File

@@ -94,6 +94,30 @@ defmodule BDS.TagsTest do
assert [%{"name" => "Beta"}] = Jason.decode!(File.read!(tags_path))
end
test "rename_tag keeps committed database changes when tags json flush fails", %{
project: project,
temp_dir: temp_dir
} do
assert {:ok, tag} = BDS.Tags.create_tag(%{project_id: project.id, name: "Alpha"})
assert {:ok, post} =
BDS.Posts.create_post(%{
project_id: project.id,
title: "Tagged Draft",
content: "Body",
tags: ["Alpha"]
})
meta_path = Path.join(temp_dir, "meta")
File.rm_rf!(meta_path)
File.write!(meta_path, "not a directory")
assert {:error, _reason} = BDS.Tags.rename_tag(tag.id, "Beta")
assert Repo.get!(BDS.Tags.Tag, tag.id).name == "Beta"
assert Repo.get!(Post, post.id).tags == ["Beta"]
end
test "merge_tags moves source tags onto the target, deduplicates post tags, deletes sources, and refreshes tags.json",
%{project: project, temp_dir: temp_dir} do
assert {:ok, source_a} = BDS.Tags.create_tag(%{project_id: project.id, name: "Alpha"})