Skip to content

Commit

Permalink
Add distinct links for students and instructors
Browse files Browse the repository at this point in the history
  • Loading branch information
wicz committed Mar 24, 2012
1 parent 852bbdb commit ee5689c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
19 changes: 14 additions & 5 deletions app/decorators/person_decorator.rb
Expand Up @@ -4,9 +4,9 @@ class PersonDecorator < ApplicationDecorator
allows :name, :email, :github_nickname, :permissions

def self.from_github(github_nickname)
PersonDecorator.new(Clubhouse::Client::Person.new(github_nickname))
rescue Clubhouse::Client::PersonNotFound
return nil
PersonDecorator.new(Clubhouse::Client::Person.new(github_nickname))
rescue Clubhouse::Client::PersonNotFound
return nil
end

def membership_for(course)
Expand All @@ -18,8 +18,9 @@ def role_for(course)
end

def has_role?(role, course)
membership = membership_for(course)
membership.has_role?(role) if membership
role_for(course).to_s.capitalize == role.to_s.capitalize
# membership = membership_for(course)
# membership.has_role?(role) if membership
end

def to_param
Expand All @@ -29,4 +30,12 @@ def to_param
def ==(person)
github_nickname == person.github_nickname
end

def profile_url(course)
if has_role?(:student, course)
h.course_student_path(course, self)
else
"http://community.mendicantuniversity.org/people/#{person.github_nickname}"
end
end
end
2 changes: 1 addition & 1 deletion app/views/course_memberships/_participants.html.haml
Expand Up @@ -3,7 +3,7 @@
%ul
- @participants.each do |participant|
%li
= link_to(participant.name, course_student_path(@course, participant))
= link_to(participant.name, participant.profile_url(@course))
= "#{participant.role_for(@course)}"
\-
= link_to "Remove", course_membership_path(participant.membership_for(@course)), :method => :delete
1 change: 1 addition & 0 deletions test/functional/courses_controller_test.rb
Expand Up @@ -10,5 +10,6 @@
it "lists participants in course page" do
get(:show, id: @course.id)
assigns(:participants).size.must_equal 1
assigns(:participants).must_include @student
end
end
16 changes: 10 additions & 6 deletions test/integration/participants_test.rb
Expand Up @@ -4,13 +4,17 @@
before do
@course = FactoryGirl.create(:webdev)
@student = build_person(:student, @course)
@instructor = build_person(:instructor, @course)

sign_in(@student)
click_link "Web Development"
end

it "links student to her page in the course" do
find_link("Student")["href"].must_equal course_student_path(@course, @student)
end

describe "participant is a student" do
it "links to student page" do
sign_in(@student)
click_link "Web Development"
find_link("Student")["href"].must_equal course_student_path(@course, @student)
end
it "links instructor to his community page" do
find_link("Instructor")["href"].must_equal "http://community.mendicantuniversity.org/people/instructor"
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -6,7 +6,7 @@
require "support/spec"

Clubhouse::Client.test_mode = true
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.strategy = :transaction

def build_person(person, course = nil)
PersonDecorator.new(FactoryGirl.build(person, course: course))
Expand Down

0 comments on commit ee5689c

Please sign in to comment.