Take an existing legacy codebase with no associations or validations and add them.
After completing this assignment, you should...
- Become more comfortable working with code which you did not write
- Become more comfortable adding functionality to an existing codebase
- Understand how two developers can work on the same codebase
- Be able to branch your code
- Be able to handle merge conflicts
- Be able to write associations
- Be able to write validations
- Be able to add tests to verify associations and validations
- A GitHub organization. Your team should create a new organization in GitHub for this assignment.
- A pull request to this repository. Fork this repository to your organization, do the work, then create a pull request.
- A modified README.
- A test suite. This test suite must be written using TDD.
This means that BEFORE adding any of these validations or associations you must:
- Write a new test.
- Run your tests and see that ONLY the new one fails (but make sure that it DOES fail).
- Write code to make the test pass.
- Run your tests and see that all tests pass.
- (Repeat those last two as necessary.)
Use the homework submission form on the course website to state when you are done.
Your assignment is to take the existing code in this folder and add associations and validations to it. You will be working with a partner, but you will be branching your code, splitting the tasks amongst the two of you, and working on them separately. Once you have finished your separate tasks, then you will merge your branches together and deal with any merge conflicts that arise.
If you would like, you can merge your branches more than once.
The tasks will be divided as follows. "Associate" means to place has_many
, belongs_to
, has_and_belongs_to_many
, etc in the appropriate classes. "Validate" means to use validates
in the appropriate classes with the appropriate parameters.
Person A:
- Associate
schools
withterms
(both directions). - Associate
terms
withcourses
(both directions). If a term has any courses associated with it, the term should not be deletable. - Associate
courses
withcourse_students
(both directions). If the course has any students associated with it, the course should not be deletable. - Associate
assignments
withcourses
(both directions). When a course is destroyed, its assignments should be automatically destroyed. - Associate
lessons
with theirpre_class_assignments
(both directions). - Set up a School to have many
courses
through the school'sterms
. - Validate that Lessons have
names
. - Validate that Readings must have an
order_number
, alesson_id
, and aurl
. - Validate that the Readings
url
must start withhttp://
orhttps://
. Use a regular expression. - Validate that Courses have a
course_code
and aname
. - Validate that the
course_code
is unique within a giventerm_id
. - Validate that the
course_code
starts with three letters and ends with three numbers. Use a regular expression.
Person B:
- Associate
lessons
withreadings
(both directions). When a lesson is destroyed, its readings should be automatically destroyed. - Associate
lessons
withcourses
(both directions). When a course is destroyed, its lessons should be automatically destroyed. - Associate
courses
withcourse_instructors
(both directions). If the course has any instructors associated with it, the course should not be deletable. - Associate
lessons
with theirin_class_assignments
(both directions). - Set up a Course to have many
readings
through the Course'slessons
. - Validate that Schools must have
name
. - Validate that Terms must have
name
,starts_on
,ends_on
, andschool_id
. - Validate that the User has a
first_name
, alast_name
, and anemail
. - Validate that the User's
email
is unique. - Validate that the User's
email
has the appropriate form for an e-mail address. Use a regular expression. - Validate that the User's
photo_url
must start withhttp://
orhttps://
. Use a regular expression. - Validate that Assignments have a
course_id
,name
, andpercent_of_grade
. - Validate that the Assignment
name
is unique within a givencourse_id
.
Don't forget to write tests for each of these before coding them!
After merging, add the following validations and associations, then merge again:
Person A:
- Associate
course_instructors
withinstructors
(who happen to be users) - Associate
assignments
withassignment_grades
(both directions) - Set up a Course to have many
instructors
through the Course'scourse_instructors
. - Validate that an Assignment's
due_at
field is not before the Assignment'sactive_at
.
Person B:
- Associate CourseStudents with
students
(who happen to be users) - Associate CourseStudents with
assignment_grades
(both directions) - Set up a Course to have many
students
through the course'scourse_students
. - Associate a Course with its ONE
primary_instructor
. This primary instructor is the one who is referenced by a course_instructor which has itsprimary
flag set totrue
.
Again, don't forget to write tests!
Although you've set up associations between these records, there's no telling what order the associated records will come back in. For instance, when you call course.assignments
, they may or may not be sorted by the due date.
After merging hard mode, modify the associations to do the following, then merge again:
Person A:
- A Course's
assignments
should be ordered bydue_at
, thenactive_at
.
Person B:
- A Course's
students
should be ordered bylast_name
, thenfirst_name
.
Then, together:
- Associate Lessons with their
child_lessons
(and vice-versa). Sort thechild_lessons
byid
.
(And, of course, tests tests tests).