-
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.
Requiring admin to category functionality.
- Loading branch information
Showing
4 changed files
with
29 additions
and
0 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ class CategoriesControllerTest < ActionController::TestCase | |
|
||
def setup | ||
@category = Category.create(name: "sports") | ||
@user = User.create(username: "John", email: "[email protected]", password: "password", admin: true) | ||
end | ||
|
||
test 'should get category index' do | ||
|
@@ -12,6 +13,7 @@ def setup | |
end | ||
|
||
test 'should get category new' do | ||
session[:user_id] = @user.id | ||
get :new | ||
assert_response :success | ||
end | ||
|
@@ -20,4 +22,11 @@ def setup | |
get :show, params: { id: @category.id } | ||
assert_response :success | ||
end | ||
|
||
test 'should redirect create when admin not logged in' do | ||
assert_no_difference 'Category.count' do | ||
post :create, params: { category: { name: "sports" } } | ||
end | ||
assert_redirected_to categories_path | ||
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,13 @@ | ||
require 'test_helper' | ||
|
||
class CreateCategoriesTest < ActionDispatch::IntegrationTest | ||
|
||
def setup | ||
@user = User.create(username: "John", email: "[email protected]", password: "password", admin: true) | ||
end | ||
|
||
test "get new category test and create category" do | ||
sign_in_as(@user, "password") | ||
get new_category_path | ||
assert_template 'categories/new' | ||
assert_difference 'Category.count', 1 do | ||
|
@@ -14,6 +20,7 @@ class CreateCategoriesTest < ActionDispatch::IntegrationTest | |
end | ||
|
||
test "invalid category submission results in failure" do | ||
sign_in_as(@user, "password") | ||
get new_category_path | ||
assert_template 'categories/new' | ||
assert_no_difference 'Category.count' do | ||
|
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