|
3 | 3 | class Perron::Site::ResourceTest < ActiveSupport::TestCase |
4 | 4 | setup do |
5 | 5 | @page_path = "test/dummy/app/content/pages/about.md" |
| 6 | + @invalid_page = "test/dummy/app/content/pages/invalid.md" |
6 | 7 | @post_path = "test/dummy/app/content/posts/2023-05-15-sample-post.md" |
7 | 8 | @inline_erb_post_path = "test/dummy/app/content/posts/2025-10-01-inline-erb-post.md" |
8 | 9 | @page = Content::Page.new(@page_path) |
| 10 | + @invalid_page = Content::Page.new(@invalid_page) |
9 | 11 | @post = Content::Post.new(@post_path) |
10 | | - @inline_erb_post = Content::Post.new(@inline_erb_post_path) # <-- Addition |
| 12 | + @inline_erb_post = Content::Post.new(@inline_erb_post_path) |
11 | 13 | end |
12 | 14 |
|
13 | 15 | test "initialization sets file_path" do |
@@ -70,4 +72,30 @@ class Perron::Site::ResourceTest < ActiveSupport::TestCase |
70 | 72 | test "#to_partial_path returns the conventional path from a nested logical name" do |
71 | 73 | assert_equal "content/posts/post", @post.to_partial_path |
72 | 74 | end |
| 75 | + |
| 76 | + test "#valid? returns true for valid page" do |
| 77 | + assert_equal @page.valid?, true |
| 78 | + end |
| 79 | + |
| 80 | + test "#valid? returns false for invalid page" do |
| 81 | + assert_equal @invalid_page.valid?, false |
| 82 | + end |
| 83 | + |
| 84 | + test "#validate returns true for valid page" do |
| 85 | + assert_equal @page.validate, true |
| 86 | + end |
| 87 | + |
| 88 | + test "#validate returns false for invalid page" do |
| 89 | + assert_equal @invalid_page.validate, false |
| 90 | + end |
| 91 | + |
| 92 | + test "#validate! returns true for valid page" do |
| 93 | + assert_equal @page.validate!, true |
| 94 | + end |
| 95 | + |
| 96 | + test "#validate! returns false for invalid page" do |
| 97 | + assert_raises(ActiveModel::ValidationError) { @invalid_page.validate! } |
| 98 | + assert @invalid_page.errors.any? |
| 99 | + assert_includes @invalid_page.errors.full_messages, "Description can't be blank" |
| 100 | + end |
73 | 101 | end |
0 commit comments