Allow updating currency of ticket if its the only ticket
This commit is contained in:
parent
efda31870b
commit
69f4771ec6
2 changed files with 6 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ class Ticket < ActiveRecord::Base
|
|||
private
|
||||
|
||||
def tickets_of_conference_have_same_currency
|
||||
return if self.persisted? && Ticket.where(conference_id: conference_id).count == 1
|
||||
unless Ticket.where(conference_id: conference_id).all?{|t| t.price_currency == self.price_currency }
|
||||
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ describe Ticket do
|
|||
end
|
||||
end
|
||||
|
||||
it 'allows updating currency of ticket if its the only ticket of the conference' do
|
||||
ticket.price_currency = 'INR'
|
||||
expect(ticket).to be_valid
|
||||
end
|
||||
|
||||
describe 'association' do
|
||||
it { should belong_to(:conference) }
|
||||
it { should have_many(:ticket_purchases).dependent(:destroy) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue