Change validation scope and Fix tests
This commit is contained in:
parent
b9cb0804ef
commit
9fdd372f18
2 changed files with 3 additions and 5 deletions
|
|
@ -6,7 +6,7 @@ class Vote < ApplicationRecord
|
|||
|
||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
||||
validates :event, uniqueness: { scope: :user }
|
||||
validates :user_id, uniqueness: { scope: :event_id }
|
||||
|
||||
delegate :name, to: :user
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@ describe Vote do
|
|||
let(:vote) { create(:vote, event: event, user: user) }
|
||||
|
||||
describe 'validation' do
|
||||
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:event_id) }
|
||||
|
||||
it 'has a valid factory' do
|
||||
expect(build(:vote)).to be_valid
|
||||
end
|
||||
|
||||
it 'validates uniqueness of event in scope of user' do
|
||||
expect(build(:vote, event: vote.event, user: vote.user)).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue