mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
Validate uniquness of api_key
.
This commit is contained in:
parent
57d6a5dc9c
commit
6b17178533
@ -2,6 +2,7 @@ class ApiKey < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :created_by, class_name: User
|
||||
|
||||
validates :user_id, uniqueness: true
|
||||
validates_presence_of :key
|
||||
|
||||
def regenerate!(updated_by)
|
||||
|
@ -3,14 +3,18 @@ require 'rails_helper'
|
||||
require_dependency 'api_key'
|
||||
|
||||
describe ApiKey do
|
||||
let(: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 }
|
||||
|
||||
skip 'validates uniqueness of user_id' do
|
||||
Fabricate(:api_key)
|
||||
is_expected.to validate_uniqueness_of(:user_id)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user