Use object instead of id for validation

This commit is contained in:
Kaustubh Nair 2019-04-06 18:55:35 +05:30
parent 9fdd372f18
commit 6a9c205567
2 changed files with 1 additions and 5 deletions

View file

@ -6,7 +6,7 @@ class Vote < ApplicationRecord
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
validates :user_id, uniqueness: { scope: :event_id } validates :user, uniqueness: { scope: :event }
delegate :name, to: :user delegate :name, to: :user

View file

@ -9,9 +9,5 @@ describe Vote do
describe 'validation' do describe 'validation' do
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:event_id) } 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
end end
end end