From a0d95d9a49bc09a46e7170f3fe64510881a939d0 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 18 Dec 2023 20:16:55 +0000 Subject: Starts adding tests for organisation --- app/models/organisation.rb | 2 ++ spec/models/organisation_spec.rb | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 89ad982..4177c35 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,3 +1,5 @@ class Organisation < ApplicationRecord has_many :events, dependent: :destroy + + validates :name, presence: true, length: { maximum: 25 } end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 6f6cdca..090cdc2 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -1,5 +1,16 @@ require 'rails_helper' RSpec.describe Organisation, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe "validations" do + it "is invalid if no name given" do + org = Organisation.new() + expect(org).to_not be_valid + end + + it "is invalid with a name longer than 25 chars" do + name = "a" * 26 + org = Organisation.new(name: name) + expect(org).to_not be_valid + end + end end -- cgit v1.2.3