Starting to get the tests in and working

This commit is contained in:
Jez Caudle 2023-01-26 19:48:25 +00:00
parent dda03a1a9a
commit d73d234465
5 changed files with 28 additions and 18 deletions

View File

@ -1,3 +1,6 @@
class Caf < ApplicationRecord
belongs_to :company
validates :name, presence: true
validates :name, uniqueness: { scope: :company_id, message: "should be unique to the company"}
end

View File

@ -1,11 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
#
# one:
# company: one
# name: MyString1
# description: MyText1
#
# two:
# company: two
# name: MyString2
# description: MyText2
one:
company: one
name: HiddenAgendaCAF
description: MyText1
two:
company: two
name: CaudleMotorsportCAF
description: MyText2

View File

@ -1,7 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# one:
# name: HiddenAgendaLtd
#
# two:
# name: CaudleMotorsports
one:
name: HiddenAgendaLtd
two:
name: CaudleMotorsports

Binary file not shown.

View File

@ -1,7 +1,14 @@
require "test_helper"
class CafTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "name_unique_per_company" do
company = Company.where(name: "HiddenAgendaLtd").first
c = company.cafs.new(name: "HiddenAgendaCAF")
assert !c.save
end
test "name cant be blank" do
c = Caf.new
assert !c.save
end
end