Skip to content

Commit

Permalink
showing course task statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
seejee committed Mar 25, 2012
1 parent 2a45108 commit b0a8abc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/decorators/student_decorator.rb
Expand Up @@ -2,7 +2,7 @@ class StudentDecorator < ApplicationDecorator
decorates :course_membership

def tasks
course_membership.course.tasks
course_membership.course.tasks.map {|t| TaskDecorator.new(course_membership, t)}
end

end
26 changes: 26 additions & 0 deletions app/decorators/task_decorator.rb
@@ -0,0 +1,26 @@
class TaskDecorator

def initialize(participant, task)
@participant = participant
@task = task
end

def id
task.id
end

def description
task.description
end

def status
"Not complete"
end

private

def task
@task
end

end
3 changes: 2 additions & 1 deletion app/views/students/show.html.haml
Expand Up @@ -4,5 +4,6 @@
%table#tasks
- @student.tasks.each do |t|
%tr{:data => {:taskid => t.id}}
%td=t.description
%td.task=t.description
%td.status=t.status

36 changes: 29 additions & 7 deletions test/integration/student_page_test.rb
Expand Up @@ -5,27 +5,49 @@
before do
@course = FactoryGirl.create(:webdev)
@student = build_person(:student, @course)
end

it "should display all of the course tasks on the student page" do
sign_in @student

click_link "Web Development"
click_link "Student"
end

it "should display all of the course tasks on the student page" do
@course.tasks.each do |t|
assert_task_is_on_page page, t
within_task(t) do
assert_task_is_on_page(t)
assert_task_is_incomplete(t)
end
end
end


end

private

def assert_task_is_on_page(page, task)
includes_task_row?(page, task).must_equal true, "Could not find task '#{task.description}' on the page"
def within_task(task)
within(:xpath, task_xpath(task)) do
yield
end
end

def assert_task_is_incomplete(task)
task_incomplete?.must_equal true, "Task '#{task.description}' is not marked as incomplete"
end

def assert_task_is_on_page(task)
task_on_page?(task).must_equal true, "Could not find task '#{task.description}' on the page"
end

def task_on_page?(task)
has_content?(task.description)
end

def task_incomplete?
has_content?("Not complete")
end

def includes_task_row?(page, task)
page.has_xpath?("//tr[@data-taskid='#{task.id}']")
def task_xpath(task)
"//tr[@data-taskid='#{task.id}']"
end

0 comments on commit b0a8abc

Please sign in to comment.