diff --git a/config/routes.rb b/config/routes.rb index f2d5f508cff0247ebd949bcfae44118e527599e3..c54e83d5612e5fa65d171b03d0e06ae5514b61b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/admin/orders_controller_test.rb b/test/controllers/admin/orders_controller_test.rb index 227a6e14fc1e9490b2a16ee829e315a7d174b0ba..21fe0df7d2e8ead238f3fe878999f35bdf1d1a88 100644 --- a/test/controllers/admin/orders_controller_test.rb +++ b/test/controllers/admin/orders_controller_test.rb @@ -1,16 +1,36 @@ 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