Skip to content

Instantly share code, notes, and snippets.

@avk
Created February 25, 2009 21:06
Show Gist options
  • Save avk/70408 to your computer and use it in GitHub Desktop.
Save avk/70408 to your computer and use it in GitHub Desktop.
require 'test_helper'
class PatientTest < ActiveSupport::TestCase
def test_should_create_patient
assert_difference 'Patient.count' do
patient = create_patient
assert !patient.new_record?, "#{patient.errors.full_messages.to_sentence}"
end
end
def test_should_require_gender
assert_no_difference 'Patient.count' do
p = create_patient(:male => nil)
assert p.errors.on(:male)
end
end
def test_should_create_male_patients
assert_difference 'Patient.count' do
p = create_patient(:male => true)
assert !p.new_record?, "#{p.errors.full_messages.to_sentence}"
end
end
def test_should_create_female_patients
assert_difference 'Patient.count' do
p = create_patient(:male => false)
assert !p.new_record?, "#{p.errors.full_messages.to_sentence}"
end
end
def test_should_require_date_of_birth
assert_no_difference 'Patient.count' do
p = create_patient(:date_of_birth => nil)
assert p.errors.on(:date_of_birth)
end
end
def test_should_have_a_date_of_birth_within_the_last_100_years
assert_no_difference 'Patient.count' do
p = create_patient(:date_of_birth => 100.years.ago.to_date)
assert p.errors.on(:date_of_birth)
end
assert_difference 'Patient.count' do
p = create_patient(:date_of_birth => 99.years.ago.to_date)
assert !p.new_record?, "#{p.errors.full_messages.to_sentence}"
end
end
def test_should_not_allow_a_future_date_of_birth
assert_no_difference 'Patient.count' do
p = create_patient(:date_of_birth => Date.today + 1)
assert p.errors.on(:date_of_birth)
end
end
def test_should_require_date_of_diagnosis
assert_no_difference 'Patient.count' do
p = create_patient(:date_of_diagnosis => nil)
assert p.errors.on(:date_of_diagnosis)
end
end
def test_should_not_allow_a_future_date_of_diagnosis
assert_no_difference 'Patient.count' do
p = create_patient(:date_of_diagnosis => Date.today + 1)
assert p.errors.on(:date_of_diagnosis)
end
end
def test_should_not_allow_a_date_of_diagnosis_before_date_of_birth
assert_no_difference 'Patient.count' do
birth = 27.years.ago
diagnosis = birth - 1.day
p = create_patient(:date_of_birth => birth, :date_of_diagnosis => diagnosis)
assert p.errors.on(:date_of_diagnosis)
end
end
def test_should_default_to_false_for_lomitil_or_opiates
p = create_patient(:lomitil_or_opiates => nil)
assert p.lomitil_or_opiates == false
end
protected
def create_patient(options = {})
record = Patient.new(valid_options_for_patient.merge(options))
record.save
record
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment