discourse/spec/models/api_key_spec.rb
Daniel Waterworth e219588142 DEV: Prefabrication (test optimization) (#7414)
* Introduced fab!, a helper that creates database state for a group

It's almost identical to let_it_be, except:

 1. It creates a new object for each test by default,
 2. You can disable it using PREFABRICATION=0
2019-05-07 13:12:20 +10:00

23 lines
522 B
Ruby

# encoding: utf-8
# frozen_string_literal: true
require 'rails_helper'
require_dependency 'api_key'
describe ApiKey do
fab!(:user) { Fabricate(:user) }
it { is_expected.to belong_to :user }
it { is_expected.to belong_to :created_by }
it { is_expected.to validate_presence_of :key }
it 'validates uniqueness of user_id' do
Fabricate(:api_key, user: user)
api_key = Fabricate.build(:api_key, user: user)
expect(api_key.save).to eq(false)
expect(api_key.errors).to include(:user_id)
end
end