Permalink
Browse files

adding ability to edit exams

  • Loading branch information...
1 parent d2d8275 commit e12fdfb9ad1e345866bb0865a99a55c1987bcfc3 @jasondew committed Oct 13, 2011
Showing with 10 additions and 10 deletions.
  1. +6 −6 app/models/exam.rb
  2. +1 −1 app/views/exams/_form.html.haml
  3. +1 −1 features/exams.feature
  4. +2 −2 spec/models/exam_spec.rb
View
@@ -2,16 +2,16 @@ class Exam < ActiveRecord::Base
belongs_to :course
- has_many :grades
+ has_many :grades do
+ def for user
+ detect {|grade| grade.user == user }
+ end
+ end
accepts_nested_attributes_for :grades
def grade_for user
- if (grade = grades.find_by_user_id(user.id))
- grade.value
- else
- '**'
- end
+ grades.find_by_user_id(user.to_param).try(:value)
end
def mean
@@ -8,7 +8,7 @@
%th Grade
- @exam.course.students.each do |student|
- = form.fields_for :grades, @exam.grades.build(:user => student) do |grade_form|
+ = form.fields_for :grades, (@exam.grades.for(student) || @exam.grades.build(:user => student)) do |grade_form|
%tr
%td= student
%td
View
@@ -11,7 +11,7 @@ Feature: exams
| Jane | Dane |
And I am logged in as an instructor
- Scenario:
+ Scenario: Adding/updating exam grades
When I go to the gradebook page
And I follow "Add an exam"
And I fill in the following:
View
@@ -15,11 +15,11 @@
exam.grade_for(user).should == 0.92
end
- it "should return ** when no grade exists" do
+ it "should return nil when no grade exists" do
user = mock!.id { :user_id }.subject
mock(exam).grades { mock!.find_by_user_id(:user_id) { nil }.subject }
- exam.grade_for(user).should == "**"
+ exam.grade_for(user).should be_nil
end
end

0 comments on commit e12fdfb

Please sign in to comment.