From 3162c76bbf14e8b6fd7c32204417d57221fafc66 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 00:26:32 +0300 Subject: [PATCH] Require account registrar to be present #475 --- app/models/account.rb | 3 ++- spec/models/account_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index bee11833b..b7c43eab3 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,6 +1,7 @@ class Account < ActiveRecord::Base include Versions - belongs_to :registrar + + belongs_to :registrar, required: true has_many :account_activities validates :account_type, presence: true diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 292ccfa6a..f3ba1fdb5 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe Account do +RSpec.describe Account do context 'with invalid attribute' do before :all do @account = Account.new @@ -45,4 +45,14 @@ describe Account do end end end + + describe 'registrar validation', db: false do + subject(:account) { described_class.new } + + it 'rejects absent' do + account.registrar = nil + account.validate + expect(account.errors).to have_key(:registrar) + end + end end