forked from mendicant-original/liskov
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mendicant-original#6 from wicz/student_task_decorator
Student task decorator
- Loading branch information
Showing
9 changed files
with
116 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class StudentTaskDecorator < ApplicationDecorator | ||
decorates :student_task | ||
|
||
def status | ||
status = student_task.status | ||
status == StudentTask::NOT_COMPLETE ? "Not complete" : status | ||
end | ||
|
||
def complete_task_link(current_person) | ||
if(current_person.has_role?(:instructor, student_task.course)) | ||
h.link_to "Mark as complete", "/" | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
class CompletedTask < ActiveRecord::Base | ||
NOT_COMPLETE = -1 | ||
|
||
belongs_to :course_membership | ||
belongs_to :task | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class StudentTask | ||
NOT_COMPLETE = -1 | ||
|
||
def self.build_for(course_membership) | ||
course_membership.course.tasks.map {|t| new(course_membership, t) } | ||
end | ||
|
||
def initialize(course_membership, task) | ||
@course_membership = course_membership | ||
@task = task | ||
end | ||
|
||
def course | ||
@course_membership.course | ||
end | ||
|
||
def task_id | ||
@task.id | ||
end | ||
|
||
def description | ||
@task.description | ||
end | ||
|
||
def status | ||
completed = get_completed_task | ||
completed ? completed.description : NOT_COMPLETE | ||
end | ||
|
||
def complete_task(description) | ||
#TODO: is there a better way to do an upsert? - cg | ||
completed = get_completed_task || completed_tasks.build(task_id: task_id) | ||
completed.description = description | ||
completed.save | ||
end | ||
|
||
private | ||
|
||
def completed_tasks | ||
@course_membership.completed_tasks | ||
end | ||
|
||
def get_completed_task | ||
completed_tasks.where(task_id: task_id).first | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "test_helper" | ||
require "minitest/spec" | ||
|
||
describe StudentTask do | ||
|
||
before do | ||
course = FactoryGirl.create(:webdev) | ||
student = FactoryGirl.create(:student, course: course) | ||
task = course.tasks.first | ||
@course_membership = course.membership_for(student) | ||
@student_task = StudentTask.new(@course_membership, task) | ||
end | ||
|
||
describe "when the task is not completed" do | ||
it "should have an incomplete status" do | ||
@student_task.status.must_equal StudentTask::NOT_COMPLETE | ||
end | ||
end | ||
|
||
describe "when the task is completed" do | ||
before do | ||
@student_task.complete_task("Puzzlenode") | ||
end | ||
|
||
it "should have a completed status" do | ||
@student_task.status.must_equal "Puzzlenode" | ||
end | ||
|
||
describe "when it is updated after completing" do | ||
before do | ||
@student_task.complete_task("Community") | ||
end | ||
|
||
it "should not create another completed task" do | ||
@course_membership.completed_tasks.count.must_equal 1 | ||
end | ||
|
||
it "should have the updated status" do | ||
@student_task.status.must_equal "Community" | ||
end | ||
end | ||
|
||
end | ||
end |