feat: added liquid templates
This commit is contained in:
@@ -1,31 +1,72 @@
|
||||
defmodule BDS.ProjectsTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias BDS.Projects.Project
|
||||
alias BDS.Repo
|
||||
alias BDS.Templates.Template
|
||||
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
|
||||
temp_root = Path.join(System.tmp_dir!(), "bds-projects-#{System.unique_integer([:positive])}")
|
||||
File.mkdir_p!(temp_root)
|
||||
|
||||
on_exit(fn -> File.rm_rf(temp_root) end)
|
||||
|
||||
%{temp_root: temp_root}
|
||||
end
|
||||
|
||||
test "create_project slugifies names, keeps new projects inactive, and deduplicates slugs" do
|
||||
assert {:ok, first} = BDS.Projects.create_project(%{name: "Föö Bär Blog", data_path: "/tmp/blog"})
|
||||
test "create_project slugifies names, keeps new projects inactive, and deduplicates slugs", %{temp_root: temp_root} do
|
||||
first_dir = Path.join(temp_root, "first")
|
||||
second_dir = Path.join(temp_root, "second")
|
||||
File.mkdir_p!(first_dir)
|
||||
File.mkdir_p!(second_dir)
|
||||
|
||||
assert {:ok, first} = BDS.Projects.create_project(%{name: "Föö Bär Blog", data_path: first_dir})
|
||||
|
||||
assert first.name == "Föö Bär Blog"
|
||||
assert first.slug == "foo-bar-blog"
|
||||
assert first.data_path == "/tmp/blog"
|
||||
assert first.data_path == first_dir
|
||||
assert first.is_active == false
|
||||
assert is_integer(first.created_at)
|
||||
assert is_integer(first.updated_at)
|
||||
|
||||
assert {:ok, second} = BDS.Projects.create_project(%{name: "Föö Bär Blog"})
|
||||
assert {:ok, second} = BDS.Projects.create_project(%{name: "Föö Bär Blog", data_path: second_dir})
|
||||
assert second.slug == "foo-bar-blog-2"
|
||||
assert second.is_active == false
|
||||
end
|
||||
|
||||
test "set_active_project clears the previous active project and activates the target" do
|
||||
assert {:ok, first} = BDS.Projects.create_project(%{name: "First"})
|
||||
assert {:ok, second} = BDS.Projects.create_project(%{name: "Second"})
|
||||
test "create_project installs starter templates into the project data directory", %{temp_root: temp_root} do
|
||||
temp_dir = Path.join(temp_root, "starter")
|
||||
File.mkdir_p!(temp_dir)
|
||||
|
||||
assert {:ok, project} = BDS.Projects.create_project(%{name: "Starter Blog", data_path: temp_dir})
|
||||
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "single-post.liquid"]))
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "post-list.liquid"]))
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "not-found.liquid"]))
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "partials", "head.liquid"]))
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "partials", "menu-items.liquid"]))
|
||||
assert File.exists?(Path.join([temp_dir, "templates", "macros", "gallery.liquid"]))
|
||||
|
||||
starter_slugs =
|
||||
Repo.all(from template in Template, where: template.project_id == ^project.id, select: {template.slug, template.kind})
|
||||
|
||||
assert {"single-post", :post} in starter_slugs
|
||||
assert {"post-list", :list} in starter_slugs
|
||||
assert {"not-found", :not_found} in starter_slugs
|
||||
end
|
||||
|
||||
test "set_active_project clears the previous active project and activates the target", %{temp_root: temp_root} do
|
||||
first_dir = Path.join(temp_root, "active-first")
|
||||
second_dir = Path.join(temp_root, "active-second")
|
||||
File.mkdir_p!(first_dir)
|
||||
File.mkdir_p!(second_dir)
|
||||
|
||||
assert {:ok, first} = BDS.Projects.create_project(%{name: "First", data_path: first_dir})
|
||||
assert {:ok, second} = BDS.Projects.create_project(%{name: "Second", data_path: second_dir})
|
||||
|
||||
assert {:ok, active_first} = BDS.Projects.set_active_project(first.id)
|
||||
assert active_first.is_active == true
|
||||
|
||||
Reference in New Issue
Block a user