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

Passed controller tests for product. Rationalised image nullabillity and made...

Passed controller tests for product. Rationalised image nullabillity and made relevant mods to model test
parent 383a554b
No related branches found
No related tags found
No related merge requests found
......@@ -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
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
......
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?
......
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