diff --git a/app/decorators/student_decorator.rb b/app/decorators/student_decorator.rb index 2e15f00..f4e7679 100644 --- a/app/decorators/student_decorator.rb +++ b/app/decorators/student_decorator.rb @@ -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 diff --git a/app/decorators/task_decorator.rb b/app/decorators/task_decorator.rb new file mode 100644 index 0000000..fe725df --- /dev/null +++ b/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 diff --git a/app/views/students/show.html.haml b/app/views/students/show.html.haml index cf64c47..82f7c86 100644 --- a/app/views/students/show.html.haml +++ b/app/views/students/show.html.haml @@ -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 diff --git a/test/integration/student_page_test.rb b/test/integration/student_page_test.rb index ef28967..aeb3e86 100644 --- a/test/integration/student_page_test.rb +++ b/test/integration/student_page_test.rb @@ -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