From bf72032f03d276567bf5fae9298b9013d5f6d117 Mon Sep 17 00:00:00 2001 From: "Butler, Alexis (UG - Computer Science)" <ab02259@surrey.ac.uk> Date: Thu, 26 Nov 2020 20:14:11 +0000 Subject: [PATCH] Finished product controller test --- test/controllers/products_controller_test.rb | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index ed2b52f..a14503d 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -1,19 +1,36 @@ require 'test_helper' -#TODO: Finish writing product controller tests class ProductsControllerTest < ActionDispatch::IntegrationTest test 'should show all products' do - + get root_url + assert_response(:success) + assert_select 'div.productTable' do + assert_select 'article.product', 2 + end end test 'should show specific product' do - + get product_url(products(:one)) + assert_response(:success) end test 'should show product reviews' do - + get product_url(products(:one)) + assert_response(:success) + assert_select 'article.productDetails' do + assert_select 'strong', 3 # The only thing on the product detail view page that is strong is the review rating + end end test 'should show review creation form if logged in' do - + sign_in_as_tester + get product_url(products(:one)) + assert_response(:success) + assert_select 'article.productDetails' do + assert_select 'input' + end end test 'should not have review form if not logged in' do - + get product_url(products(:one)) + assert_response(:success) + assert_select 'article.productDetails' do + assert_select 'input', 0 + end end end -- GitLab