From 76614c7aefae3b7f0622eb56ac40887fd771d26b Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Thu, 21 Feb 2019 09:22:37 -0500 Subject: [PATCH] added rspec covering User#check_reference invoked from :before_destroy callback --- spec/models/user_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 24eb6c6fc022..178a4ca46ac5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -622,4 +622,18 @@ expect(user.regional_users).to match_array([user, regional_user]) end end + + describe "#check_reference" do + let(:user) { FactoryBot.create(:user) } + + it "invoked from 'before_destroy' callback" do + expect(user).to receive(:check_reference) + user.destroy + end + + it "throws 'abort' if reference to this user present in miq_requests table" do + FactoryBot.create(:vm_migrate_request, :requester => user) + expect { user.check_reference }.to throw_symbol(:abort) + end + end end