Skip to content

Instantly share code, notes, and snippets.

@martinstreicher
Created June 15, 2010 00:51
Show Gist options
  • Save martinstreicher/438539 to your computer and use it in GitHub Desktop.
Save martinstreicher/438539 to your computer and use it in GitHub Desktop.
class Prescription < ActiveRecord::Base
belongs_to :doctor, :class_name => 'User', :foreign_key => 'doctor_id'
belongs_to :patient, :class_name => 'User', :foreign_key => 'patient_id'
belongs_to :pharmacist, :class_name => 'User', :foreign_key => 'pharmacist_id'
belongs_to :prescribable, :polymorphic => true
has_many :prescription_transactions
validates_presence_of :patient
validates_presence_of :uuid
# ...
end
class Prescription < ActiveRecord::Base
generator_for(:doctor_id) { User.generate(:role => 'doctor').id }
generator_for(:expired_at) { Date.today + 5.days }
generator_for(:filled_on) { Date.today }
generator_for(:max_refill) { (5..10).to_a.rand }
generator_for(:patient_id) { User.generate(:role => 'patient').id }
generator_for(:pharmacist_id) { User.generate(:role => 'pharmacist').id }
generator_for(:quantity) { (1..10).to_a.random_element }
generator_for(:refill_number) { (1..5).to_a.random_element }
generator_for :state, :new
generator_for :uuid, :start => Faker::Lorem.words(1).join('')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment