Skip to content
Snippets Groups Projects
Commit f6b49a8a authored by Butler, Alexis (UG - Computer Science)'s avatar Butler, Alexis (UG - Computer Science)
Browse files

Wrote and passed admin order controller tests

parent 9b408177
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ Rails.application.routes.draw do
namespace :admin do
root to: 'dashboard#index'
resources :products, :sections, :users, except: %i[edit update show]
resources :orders, only: %i[index show destroy]
resources :orders, only: %i[index destroy]
end
......
require 'test_helper'
#TODO: write order admin tests
class Admin::OrdersControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
test 'should get table of orders if admin' do
sign_in_as_admin
get admin_orders_url
assert_response(:success)
assert_select 'body.orders' do
assert_select 'a.btn.btn-sm.btn-danger', Order.count
end
end
test "should get create" do
test 'should not get table of orders if not admin' do
sign_in_as_tester
get admin_orders_url
assert_response(:redirect)
assert_redirected_to(root_url)
assert_equal 'You must be admin to go there!', flash[:danger]
end
test "should get new" do
test 'should delete an order' do
sign_in_as_admin
assert_difference('Order.count',-1) do
delete admin_order_url(id: orders(:one))
end
assert_response(:redirect)
assert_redirected_to(admin_orders_url)
assert_equal 'Order deleted', flash[:success]
end
test "should get destroy" do
test 'should not delete an order if not an admin' do
sign_in_as_tester
assert_no_difference('Order.count') do
delete admin_order_url(id: orders(:one))
end
assert_response(:redirect)
assert_redirected_to(root_url)
assert_equal 'You must be admin to go there!', flash[:danger]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment