mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 02:20:41 +08:00
e219588142
* 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
23 lines
522 B
Ruby
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
|