diff --git a/app/models/product.rb b/app/models/product.rb index 79b1ccb54ed1d361638304410064c553eae7f615..27ad6f282abdee8e3cc25a02ff6223707a0c9f98 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 5d890a35f8d3c809ff76e35b8d4e63e741f868dc..e56c99bf25ba90b3ee511610c190aa0399d4c113 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 87014d407b6851b68ec0b5354e0c00c86a941449..180355109c795352b90241c7dc82c855b697f7d6 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?