That one test just took forever to pass and now that it's done, no more screen time, please. We'll update this later.
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
schoolswithterms(both directions). - Associate
termswithcourses(both directions). If a term has any courses associated with it, the term should not be deletable. - Associate
courseswithcourse_students(both directions). If the course has any students associated with it, the course should not be deletable. - Associate
assignmentswithcourses(both directions). When a course is destroyed, its assignments should be automatically destroyed. - Associate
lessonswith theirpre_class_assignments(both directions). - Set up a School to have many
coursesthrough the school'sterms. - Validate that Lessons have
names. - Validate that Readings must have an
order_number, alesson_id, and aurl. - Validate that the Readings
urlmust start withhttp://orhttps://. Use a regular expression. - Validate that Courses have a
course_codeand aname. - Validate that the
course_codeis unique within a giventerm_id. - Validate that the
course_codestarts with three letters and ends with three numbers. Use a regular expression.
Person B:
- Associate
lessonswithreadings(both directions). When a lesson is destroyed, its readings should be automatically destroyed. - Associate
lessonswithcourses(both directions). When a course is destroyed, its lessons should be automatically destroyed. - Associate
courseswithcourse_instructors(both directions). If the course has any students associated with it, the course should not be deletable. - Associate
lessonswith theirin_class_assignments(both directions). - Set up a Course to have many
readingsthrough 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
emailis unique. - Validate that the User's
emailhas the appropriate form for an e-mail address. Use a regular expression. - Validate that the User's
photo_urlmust start withhttp://orhttps://. Use a regular expression. - Validate that Assignments have a
course_id,name, andpercent_of_grade. - Validate that the Assignment
nameis 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_instructorswithinstructors(who happen to be users) - Associate
assignmentswithassignment_grades(both directions) - Set up a Course to have many
instructorsthrough the Course'scourse_instructors. - Validate that an Assignment's
due_atfield 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
studentsthrough 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 itsprimaryflag 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
assignmentsshould be ordered bydue_at, thenactive_at.
Person B:
- A Course's
studentsshould be ordered bylast_name, thenfirst_name.
Then, together:
- Associate Lessons with their
child_lessons(and vice-versa). Sort thechild_lessonsbyid.
(And, of course, tests tests tests).