DEV: Fix failing spec.

DEV: Fix failing spec.

diff --git a/app/models/user_badge.rb b/app/models/user_badge.rb
index 1e46287..bbac402 100644
--- a/app/models/user_badge.rb
+++ b/app/models/user_badge.rb
@@ -27,7 +27,7 @@ class UserBadge < ActiveRecord::Base
   private
 
   def single_grant_badge?
-    self.badge.single_grant?
+    self.badge ? self.badge.single_grant? : true
   end
 end
 
diff --git a/spec/jobs/auto_expire_user_api_keys_spec.rb b/spec/jobs/auto_expire_user_api_keys_spec.rb
index 8460fbc..a25ecfe 100644
--- a/spec/jobs/auto_expire_user_api_keys_spec.rb
+++ b/spec/jobs/auto_expire_user_api_keys_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Jobs::AutoExpireUserApiKeys do
   context 'when user api key is unused in last 1 days' do
 
     before do
-      SiteSetting.expire_user_api_keys_days = true
+      SiteSetting.expire_user_api_keys_days = 1
     end
 
     it 'should revoke the key' do
@@ -17,7 +17,7 @@ RSpec.describe Jobs::AutoExpireUserApiKeys do
 
       described_class.new.execute({})
 
-      expect(key1.reload.revoked_at).to eq(Time.zone.now)
+      expect(key1.reload.revoked_at).to be_within(1.second).of(Time.zone.now)
       expect(key2.reload.revoked_at).to eq(nil)
     end
   end
diff --git a/spec/models/user_badge_spec.rb b/spec/models/user_badge_spec.rb
index 5161b41..cd36201 100644
--- a/spec/models/user_badge_spec.rb
+++ b/spec/models/user_badge_spec.rb
@@ -4,7 +4,9 @@ require_dependency 'user_badge'
 describe UserBadge do
 
   context 'validations' do
-    before(:each) { BadgeGranter.grant(Fabricate(:badge), Fabricate(:user)) }
+    let(:badge) { Fabricate(:badge) }
+    let(:user) { Fabricate(:user) }
+    let(:subject) { BadgeGranter.grant(badge, user) }
 
     it { is_expected.to validate_presence_of(:badge_id) }
     it { is_expected.to validate_presence_of(:user_id) }

GitHub sha: d07605d8