This repository has been archived by the owner on Nov 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class SystemPage < ApplicationRecord | ||
validates :name, uniqueness: true, presence: true, length: {maximum: 50} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
require 'test_helper' | ||
|
||
class CategoryTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
|
||
setup do | ||
@category = Category.new({name: "Test Category", homepage: "# Hello World!!"}) | ||
end | ||
|
||
test "Valid category" do | ||
assert @category.valid?, "Category with unique name and a homepage" | ||
end | ||
|
||
test "Category missing name" do | ||
@category.name = nil | ||
refute @category.valid?, "Category with missing name" | ||
assert_not_nil @category.errors[:name] | ||
end | ||
|
||
test "Category non unique name" do | ||
@category.name = "Finance Category" | ||
refute @category.valid?, "Category with duplicate name" | ||
assert_not_nil @category.errors[:name] | ||
end | ||
|
||
test "Category name longer than 50 characters" do | ||
@category.name = "-" * 51 | ||
refute @category.valid?, "Category with name longer than 50" | ||
assert_not_nil @category.errors[:name] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
require 'test_helper' | ||
|
||
class PostTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
setup do | ||
@post = Post.new({title: "Test Post", contents: "# Hello World!!", category: categories(:dev_ops)}) | ||
end | ||
|
||
test "Valid post" do | ||
assert @post.valid?, "Post with title, category, and a contents" | ||
end | ||
|
||
test "Post is missing category" do | ||
@post.category = nil | ||
refute @post.valid? | ||
end | ||
|
||
test "Post missing title" do | ||
@post.title = nil | ||
refute @post.valid?, "Post with missing title" | ||
assert_not_nil @post.errors[:title] | ||
end | ||
|
||
test "Post title longer than 50 characters" do | ||
@post.title = "-" * 51 | ||
refute @post.valid?, "Post with title longer than 50" | ||
assert_not_nil @post.errors[:title] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
require 'test_helper' | ||
|
||
class SystemPageTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
setup do | ||
# Need to load in default system pages | ||
# These are created in `seeds.rb` so | ||
# This command loads it in before the tests run | ||
Rails.application.load_seed | ||
@system_page = SystemPage.new({name: "Test SystemPage", contents: "# Hello World!!"}) | ||
end | ||
|
||
test "Valid system_page" do | ||
assert @system_page.valid?, "SystemPage with unique name and a contents" | ||
end | ||
|
||
test "SystemPage missing name" do | ||
@system_page.name = nil | ||
refute @system_page.valid?, "SystemPage with missing name" | ||
assert_not_nil @system_page.errors[:name] | ||
end | ||
|
||
test "SystemPage non unique name" do | ||
@system_page.name = "Home" | ||
refute @system_page.valid?, "SystemPage with duplicate name" | ||
assert_not_nil @system_page.errors[:name] | ||
end | ||
|
||
end |