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 at the top of your model class file. (Otherwise, how will we know which work is yours?)
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 hw4v1 -m 'Tagged Homework 4 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., hw4v2
, hw4v3
, hw4v4
, etc.).
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 30 characters or less.format
email
must follow the general format of an email address.inclusion
gender
must be "male"
, "female"
, or "other"
.uniqueness
name
must be unique.presence
name
and email
must have values.allow_blank
gender
and age
may be blank.numericality
age
must be in the range 18 to 122 (the age of the oldest known person ever).Model classes to create:
Add these validations to class Bartender
:
length
name
must be 50 characters or less.format
phone
must follow the general format of a 10-digit telephone number (e.g., "123-456-7890"
).inclusion
level
must be "beginner"
, "intermediate"
, or "master"
.uniqueness
name
must be unique.presence
name
and phone
must have values.allow_blank
level
and years_experience
may be blank.numericality
year_experience
must be between 0 and 60.Model classes to create:
Add these validations to class Alcohol
:
length
name
must be 60 characters or less.format
url
must follow the general format of a URL.inclusion
category
must be "top shelf"
, "midgrade"
, or "bottom shelf"
.uniqueness
name
and url
must be unique.presence
name
and proof
must have values.allow_blank
url
and category
may be blank.numericality
proof
must be greater than 0 and less than 200.Model classes to create:
Add these validations to class Country:
length
name
must be no more than 36 characters.format
date_founded
must follow this date format: YYYY-MM-DD (e.g., "2017-02-25"
).inclusion
continent
must be "North America"
, "South America"
, "Europe"
, "Asia"
, "Africa"
, "Australia"
, or "Antarctica"
.uniqueness
name
must be unique.presence
name
and continent
must have values.allow_blank
date_founded
and gdp
may be blank.numericality
gdp
must be between 0 and 100,000 (in billions of dollars).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: