Last active
December 25, 2015 06:58
-
-
Save cadwallion/6935525 to your computer and use it in GitHub Desktop.
Coursify examples
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
class Course < ActiveRecord::Base | |
include Coursify::Publishable | |
include Coursify::Enrollable | |
enrollable_by :user | |
has_many :lessons | |
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
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] |
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
class Lesson < ActiveRecord::Base | |
include Coursify::Completable | |
belongs_to :course | |
completable_by :user, for: :course | |
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
class User < ActiveRecord::Base | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment