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.
- Finished Categories controller - Finished Posts controller - Begin search controller
- Loading branch information
Showing
22 changed files
with
268 additions
and
68 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
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
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
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
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
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
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
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,19 +1,10 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | ||
# Character.create(name: 'Luke', movie: movies.first) | ||
# | ||
|
||
HOME_DEFAULT_PAGE = "# Welcome to Pearl Wiki\n"\ | ||
# Create the default pages for home and about | ||
SystemPage.create({name: "Home", contents: "# About the wiki\n"\ | ||
"Check me out on [Github](https://github.com/bthuilot/PearlWiki)!"}) | ||
SystemPage.create({name: "About", contents: "# Welcome to Pearl Wiki\n"\ | ||
"A wiki powered by rails\n"\ | ||
"\n\n"\ | ||
"To get started, create a [category](/categories/new) and [post](/page/new) or edit the [home page](/home/edit) and the [about page](/about/edit)." | ||
|
||
ABOUT_DEFAULT_PAGE = "# About the wiki\n"\ | ||
"Check me out on [Github](https://github.com/bthuilot/RailsWiki)!" | ||
# | ||
SystemPage.create({name: "Home", contents: HOME_DEFAULT_PAGE}) | ||
SystemPage.create({name: "About", contents: ABOUT_DEFAULT_PAGE}) | ||
"To get started, create a [category](/categories/new) and [post](/page/new) or edit the [home page](/home/edit) and the [about page](/about/edit)."}) |
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,44 @@ | ||
require 'test_helper' | ||
|
||
class CategoriesControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
|
||
test "should get new category page" do | ||
get new_categories_url | ||
assert_response :success | ||
test_page_title "Create Category" | ||
end | ||
|
||
test "should get show page" do | ||
get categories_url(categories(:software_dev)) | ||
assert_response :success | ||
assert @controller.instance_variable_get(:@category).name == "Software Development Category", "Should display software category" | ||
test_page_title "Software Development Category" | ||
end | ||
|
||
test "should get edit page" do | ||
get edit_categories_url(categories(:admin)) | ||
assert_response :success | ||
assert @controller.instance_variable_get(:@category).name == "Admin Category", "Admin category should be displayed" | ||
test_page_title "Edit Admin Category" | ||
end | ||
|
||
test "should update categories" do | ||
post update_categories_url(categories(:admin)), params: {category: {name: "Admin Category Changed", homepage: "This category was changed"}} | ||
assert_redirected_to %r(^#{categories_url(categories(:admin))}) | ||
admin = @controller.instance_variable_get(:@category) | ||
assert admin.name == "Admin Category Changed" and admin.homepage == "This category was changed" | ||
end | ||
|
||
test "should fail to update categories" do | ||
post update_categories_url(categories(:admin)), params: {category: {name: "", homepage: "This category was changed"}} | ||
assert_redirected_to %r(^#{edit_categories_url(categories(:admin))}\?) | ||
end | ||
|
||
test "should delete category and posts" do | ||
assert_difference(-> {Category.count} => -1, -> {Post.count} => -10) do | ||
delete destroy_categories_url(categories(:admin)) | ||
end | ||
assert_redirected_to %r(^#{root_url}\?) | ||
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,46 @@ | ||
require 'test_helper' | ||
|
||
class PostsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
test "should get new post page" do | ||
get new_post_url | ||
assert_response :success | ||
test_page_title "New Post" | ||
end | ||
|
||
test "should get show page" do | ||
get post_url(posts(:software_dev_1)) | ||
assert_response :success | ||
post = @controller.instance_variable_get(:@post) | ||
assert post.title == "Software Dev Post", "Should display software post" | ||
assert post.category.name == "Software Development Category", "Should display software post category" | ||
test_page_title "Software Dev Post" | ||
end | ||
|
||
test "should get edit page" do | ||
get edit_post_url(posts(:finance_1)) | ||
assert_response :success | ||
assert @controller.instance_variable_get(:@post).title == "Finance Post", "Finance post should be displayed" | ||
test_page_title "Edit Finance Post" | ||
end | ||
|
||
test "should update posts" do | ||
post update_post_url(posts(:finance_1)), params: {post: {title: "Finance Post Changed", contents: "This post was changed"}} | ||
assert_redirected_to %r(^#{post_url(posts(:finance_1))}) | ||
finance_post = @controller.instance_variable_get(:@post) | ||
assert finance_post.title == "Finance Post Changed" and finance_post.contents == "This post was changed" | ||
end | ||
|
||
test "should fail to update posts" do | ||
post update_post_url(posts(:finance_1)), params: {post: {title: "", contents: "This post was changed"}} | ||
url = @response.get_header("location") | ||
assert_match(/errors.*Title\+can.*t\+be\+blank/, url) | ||
assert_redirected_to %r(^#{edit_post_url(posts(:finance_1))}\?) | ||
end | ||
|
||
test "should delete post and posts" do | ||
assert_difference('Post.count', -1) do | ||
delete destroy_post_url(posts(:finance_1)) | ||
end | ||
assert_redirected_to %r(^#{categories_url(posts(:finance_1).category)}\?) | ||
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,25 @@ | ||
require 'test_helper' | ||
|
||
class StaticPagesControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def setup | ||
# 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 | ||
end | ||
|
||
test "should get home page" do | ||
get root_url | ||
test_page_title "Home" | ||
all_categories = @controller.instance_variable_get(:@categories) | ||
assert_equal all_categories.length, categories.length | ||
end | ||
|
||
test "should get about page" do | ||
get about_url | ||
test_page_title "About" | ||
all_categories = @controller.instance_variable_get(:@categories) | ||
assert_equal all_categories.length, categories.length | ||
end | ||
|
||
end |
Oops, something went wrong.