Permalink
Browse files

using new has_role method

  • Loading branch information...
1 parent 91d7415 commit 725a6c12f3da2f73d708488b2ae1a1eab23c5f78 @seejee seejee committed Mar 18, 2012
@@ -1,7 +1,6 @@
class CoursesController < ApplicationController
def show
@course = CourseDecorator.find(params[:id])
- @is_instructor = @course.instructor?(current_person)
@members = @course.course_memberships
@tasks = @course.tasks
end
@@ -1,39 +1,8 @@
class CourseDecorator < ApplicationDecorator
decorates :course
- # Accessing Helpers
- # You can access any helper via a proxy
- #
- # Normal Usage: helpers.number_to_currency(2)
- # Abbreviated : h.number_to_currency(2)
- #
- # Or, optionally enable "lazy helpers" by including this module:
- # include Draper::LazyHelpers
- # Then use the helpers with no proxy:
- # number_to_currency(2)
-
- # Defining an Interface
- # Control access to the wrapped subject's methods using one of the following:
- #
- # To allow only the listed methods (whitelist):
- # allows :method1, :method2
- #
- # To allow everything except the listed methods (blacklist):
- # denies :method1, :method2
-
- # Presentation Methods
- # Define your own instance methods, even overriding accessors
- # generated by ActiveRecord:
- #
- # def created_at
- # h.content_tag :span, time.strftime("%a %m/%d/%y"),
- # :class => 'timestamp'
- # end
- #
- #
-
- def instructor?(current_person)
- course.instructor?(current_person)
+ def has_role?(role, person)
+ course.has_role?(role, person)
end
def description
View
@@ -6,9 +6,9 @@ def people
@people ||= course_memberships.map {|cm| cm.person }
end
- def instructor?(person)
+ def has_role?(role, person)
membership = course_memberships.for_person(person).first
- membership.instructor? if membership
+ membership.has_role?(role) if membership
end
end
@@ -15,8 +15,17 @@ def person
return nil
end
- def instructor?
- role == "Instructor"
+ def has_role?(has_role)
+ #TODO: turn ROLES into a hash
+
+ case has_role
+ when :instructor
+ role == "Instructor"
+ when :student
+ role == "Student"
+ when :mentor
+ role == "Mentor"
+ end
end
private
@@ -1,5 +1,5 @@
= render 'tasks/list'
-- if @is_instructor
+- if @course.has_role?(:instructor, current_person)
= link_to("Add Task", new_course_task_path(@course))
@@ -9,7 +9,15 @@
end
it "should not identify the student as an instructor" do
- @membership.instructor?.must_equal false
+ @membership.has_role?(:instructor).must_equal false
+ end
+
+ it "should not identify the student as an mentor" do
+ @membership.has_role?(:mentor).must_equal false
+ end
+
+ it "should identify the student as a student" do
+ @membership.has_role?(:student).must_equal true
end
end
@@ -18,8 +26,16 @@
@membership = CourseMembership.new(role: 'Instructor')
end
- it "should not identify the student as an instructor" do
- @membership.instructor?.must_equal true
+ it "should identify the instructor as an instructor" do
+ @membership.has_role?(:instructor).must_equal true
+ end
+
+ it "should not identify the instructor as an mentor" do
+ @membership.has_role?(:mentor).must_equal false
+ end
+
+ it "should not identify the instructor as a student" do
+ @membership.has_role?(:student).must_equal false
end
end
end

0 comments on commit 725a6c1

Please sign in to comment.