Tests for ticket model

Change in error message of validation cause previously it was:
"Price currency Currency is different.."
`paid?` method returned true even when `ticket_purchases` is empty for
a given user.
This commit is contained in:
Aditya Prakash 2016-03-05 15:49:10 +05:30
parent c5c392d4c7
commit ebd01f064a
2 changed files with 70 additions and 16 deletions

View file

@ -18,7 +18,7 @@ class Ticket < ActiveRecord::Base
end
def paid?(user)
ticket_purchases.where(user_id: user.id, paid: false).count == 0
ticket_purchases.find_by(user: user, paid: true).present?
end
def quantity_bought_by(user)
@ -52,7 +52,7 @@ class Ticket < ActiveRecord::Base
def tickets_of_conference_have_same_currency
unless Ticket.where(conference_id: conference_id).all?{|t| t.price_currency == self.price_currency }
errors.add(:price_currency, 'Currency is different from the exist ticktes of this conference.')
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
end
end
end