diff --git a/app/models/caf.rb b/app/models/caf.rb index a860c13..c44d340 100644 --- a/app/models/caf.rb +++ b/app/models/caf.rb @@ -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 diff --git a/test/fixtures/cafs.yml b/test/fixtures/cafs.yml index 1b865e5..f272928 100644 --- a/test/fixtures/cafs.yml +++ b/test/fixtures/cafs.yml @@ -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 diff --git a/test/fixtures/companies.yml b/test/fixtures/companies.yml index a7ee960..def1a54 100644 --- a/test/fixtures/companies.yml +++ b/test/fixtures/companies.yml @@ -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 diff --git a/test/models/.caf_test.rb.kate-swp b/test/models/.caf_test.rb.kate-swp deleted file mode 100644 index 2989df1..0000000 Binary files a/test/models/.caf_test.rb.kate-swp and /dev/null differ diff --git a/test/models/caf_test.rb b/test/models/caf_test.rb index 01ff933..ba00211 100644 --- a/test/models/caf_test.rb +++ b/test/models/caf_test.rb @@ -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