From 3cc500690182f2139d38b22fe6adc5a3eb67b5b4 Mon Sep 17 00:00:00 2001 From: "Butler, Alexis (UG - Computer Science)" <ab02259@surrey.ac.uk> Date: Sun, 29 Nov 2020 14:41:36 +0000 Subject: [PATCH] Passed controller tests for product. Rationalised image nullabillity and made relevant mods to model test --- app/models/product.rb | 2 +- test/controllers/admin/products_controller_test.rb | 1 - test/models/product_test.rb | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 79b1ccb..27ad6f2 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -10,5 +10,5 @@ class Product < ApplicationRecord has_many :reviews, -> {order(created_at: :desc)}, dependent: :destroy monetize :pricePence, as: "price", numericality: true mount_uploader :image, ProductImgUploader - validates_presence_of :name, :price, :stockCount, :section, :description + validates_presence_of :name, :price, :stockCount, :section_id, :description, :image end diff --git a/test/controllers/admin/products_controller_test.rb b/test/controllers/admin/products_controller_test.rb index 5d890a3..e56c99b 100644 --- a/test/controllers/admin/products_controller_test.rb +++ b/test/controllers/admin/products_controller_test.rb @@ -1,5 +1,4 @@ require 'test_helper' -#TODO: finish product admin tests class Admin::ProductsControllerTest < ActionDispatch::IntegrationTest test 'should get table of all products' do sign_in_as_admin diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 87014d4..1803551 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,6 +1,9 @@ require 'test_helper' class ProductTest < ActiveSupport::TestCase + def openAsset(filename) + File.open(Rails.root.join('db', 'seedAssets', filename)) + end test 'should not save product without name' do prod = Product.new(name: '', description: 'Desc', stockCount: 2, pricePence: 52, image: 'TooLazyForRealImg', section: sections(:one)) assert !prod.valid? @@ -24,12 +27,13 @@ class ProductTest < ActiveSupport::TestCase assert !prod.valid? end test 'should save a valid product' do + imgFile = openAsset("Clothes1.png") prod = Product.new({ name: "prodname", description: "proddesc", stockCount: 67, pricePence: 7082, - image: "ImageFIle", + image: imgFile, section_id: sections(:one).id }) assert prod.valid? -- GitLab