For this homework, you will create simple model classes in Rails, write tests to run them, and practice using the basic version control features of Git.
You will do this homework as a team; however, each member of your team will be responsible for the completion of a particular task.
Each team member will choose one task from the list below to complete. All team members must do a different task. If your team has only three members, then ignore Task 4.
IMPORTANT: Be sure to add your university username (e.g., mine is “sdflming”) in a comment near the top of each of your model class file. (Otherwise, how will we know which work is yours?)
The tasks are given on the following pages. For each of the following tasks:
rails generate model ...
Model classes to create:
Add these validations to class Owner
:
length
name
must be 100 characters or less.format
ssn
must follow the general format of a 9-digit social security number (e.g., "123-45-6789"
).inclusion
gender
must be "male"
, "female"
, or "other"
.uniqueness
ssn
must be unique.presence
name
and ssn
must have values.allow_blank
gender
and yob
may be blank.numericality
yob
(year of birth) less than the year 17 years prior to the current year.Model classes to create:
Add these validations to class Appraiser
:
length
name
must be 50 characters or less.format
email
must follow the general format of an email address.inclusion
classification
must be "trainee"
, "registered"
, "licensed"
, "certified residential"
, or "certified general"
.uniqueness
email
must be unique.presence
name
and email
must have values.allow_blank
classification
and lic_exp_year
may be blank.numericality
lic_exp_year
must be one of the years in the five years following the current year.Model classes to create:
Add these validations to class Lender
:
length
firm
must be 60 characters or less.format
url
must follow the general format of a URL.inclusion
lender_type
must be "bank"
, "broker"
, "FHA"
, "VA"
, or "USDA"
.uniqueness
firm
and url
must be unique.presence
firm
and lender_type
must have values.allow_blank
url
and year_founded
may be blank.numericality
year_founded
must not be greater than the current year.Model classes to create:
Add these validations to class Inspector
:
length
name
must be no more than 36 characters.format
phone
must follow the general format of a 10-digit telephone number (e.g., "123-456-7890"
).inclusion
organization
must be "InterNACHI"
, "ASHI"
, "NAHI"
, "CAHPI"
, or "PHPIC"
.uniqueness
phone
must be unique.presence
name
and phone
must have values.allow_blank
organization
and rating
may be blank.numericality
rating
must be between 1 and 5.Before you can submit, all team members must have merged their code into the master branch and pushed the updates to GitHub. If a team member does not complete his/her work on time, you may submit without his/her contribution.
To submit your team’s work, you must “tag” the current commit in the master branch:
git tag -a hw5v1 -m 'Tagged Homework 5 submission (version 1)'
git push origin --tags
To grade your work, I will check out the appropriate tag, and run it on my machine.
Note that if for some reason you need to update your submission, simply repeat the tagging process, but increment the version number (e.g., hw5v2
, hw5v3
, hw5v4
, etc.).
Total marks: 100
Below, the top-level number is the items total point value. If an item is not submitted at all, 0 points will be awarded for that item. The sub-bullets indicate standard deductions for errors in a submitted item. The deduction list below may not be complete because there may be mistakes that we did not expect. The deduction for an unexpected mistake will be assessed at the time it’s discovered and will reflect how severe the instructor thinks the mistake is.
Other deductions: