Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Last active December 25, 2015 06:58
Show Gist options
  • Save cadwallion/6935525 to your computer and use it in GitHub Desktop.
Save cadwallion/6935525 to your computer and use it in GitHub Desktop.
Coursify examples
class Course < ActiveRecord::Base
include Coursify::Publishable
include Coursify::Enrollable
enrollable_by :user
has_many :lessons
end
course = Course.create(title: "Something Cool")
user1 = User.create(login: "me")
user2 = User.create(login: "someoneelse")
course.publish!
course.enroll! user1, due_date: Time.now + 2.weeks
course.enroll! user2, due_date: Time.now + 2.weeks
course.enrolled_users == [user1, user2]
course.complete! user2
enrollments = Course.incomplete_enrollments
all_enrollments = Course.enrollments
courses = Course.completed_by user2
user1.enrolled_courses == [course]
user1.incomplete_courses == [course]
user1.completed_courses == []
user2.incomplete_courses == []
user2.completed_course == [course]
course.unenroll! user1
lesson = course.lessons.create(title: "something boring")
lesson.completions == []
lesson.completed_by(user1) == false
lesson.complete_for user1
lesson.completed_by(user1) == true
lesson.completed_users == [user1]
user1.completed_lessons == [lesson]
class Lesson < ActiveRecord::Base
include Coursify::Completable
belongs_to :course
completable_by :user, for: :course
end
class User < ActiveRecord::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment