From af33c893a402732789b8036bad93d8785dbdbd92 Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Thu, 25 Jul 2013 13:50:23 +0100 Subject: [PATCH] Adds validation of status to model and associated unit test --- app/models/organisation.rb | 1 + spec/models/organisation_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index dd2abf7..93167c6 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -13,6 +13,7 @@ class Organisation < ActiveRecord::Base has_ancestry validates_presence_of :registration_no, :census_url_no, :name, :status + validates_inclusion_of :status, in: STATES scope :open, where(status: 'O') diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 2eb8664..1ccec71 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -22,6 +22,10 @@ FactoryGirl.build(:organisation, status: nil).should_not be_valid end + it 'is invalid with a status of anything other than O or C' do + FactoryGirl.build(:organisation, status: 'P').should_not be_valid + end + it 'has many memberships' do FactoryGirl.create(:organisation).should have_many(:memberships) end