Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to mongoose v3, build out test suite #6

Merged
merged 1 commit into from
Aug 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions jbha.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ CourseSchema = new mongoose.Schema
unique: false
sparse: true
assignments: [{ type: mongoose.Schema.ObjectId, ref: 'assignment' }]
{strict: true}

Course = mongoose.model 'course', CourseSchema

Expand All @@ -83,14 +82,12 @@ AssignmentSchema = new mongoose.Schema
done:
type: Boolean
default: false
{strict: true}

Assignment = mongoose.model 'assignment', AssignmentSchema

FeedbackSchema = new mongoose.Schema
_id: String
message: String
{strict: true}

FeedbackSchema.path('message').validate (v) ->
return v.length < 5000
Expand Down Expand Up @@ -136,7 +133,7 @@ Jbha.Client =
Account
.findOne()
.where('_id', username)
.run (err, account_from_db) =>
.exec (err, account_from_db) =>
return if @_call_if_truthy err, cb
cookie = res.headers['set-cookie'][1].split(';')[0]
account = account_from_db or new Account()
Expand Down Expand Up @@ -179,8 +176,8 @@ Jbha.Client =
Account
.findOne()
.where('_id', token.username)
.select(['nickname', 'details', 'is_new', 'firstrun', 'updated', 'feedback_given'])
.run cb
.select('nickname details is_new firstrun updated feedback_given')
.exec cb

update_settings: (token, settings, cb) ->
Account.update _id: token.username,
Expand Down Expand Up @@ -209,19 +206,19 @@ Jbha.Client =
by_course: (token, cb) ->
Course
.where('owner', token.username)
.populate('assignments', ['title', 'archived', 'details', 'date', 'done', 'jbha_id'])
.exclude(['owner', 'jbha_id'])
.run (err, courses) =>
.populate('assignments', 'title archived details date done jbha_id')
.select('-owner -jbha_id')
.exec (err, courses) =>
@_call_if_truthy(err, cb)
cb courses
cb err, courses

create_assignment: (token, data, cb) ->
async.waterfall [

(wf_callback) ->
Course
.findById(data.course)
.run wf_callback
.exec wf_callback

(course, wf_callback) ->
assignment = new Assignment()
Expand Down Expand Up @@ -251,7 +248,7 @@ Jbha.Client =
assignments: assignment._id
},
{
$pull: {assignments: assignment._id}
pull: {assignments: assignment._id}
},
{},
(err) ->
Expand All @@ -261,7 +258,7 @@ Jbha.Client =
.findOne()
.where('owner', token.username)
.where('_id', assignment.course)
.run wf_callback
.exec wf_callback
(course, wf_callback) ->
course.assignments.push assignment._id
course.save wf_callback
Expand Down Expand Up @@ -302,7 +299,8 @@ Jbha.Client =
title: course.title
teacher: course.teacher
},
cb
(err, numAffected, raw) ->
cb err

delete_course: (token, course, cb) ->
Course
Expand All @@ -325,7 +323,7 @@ Jbha.Client =
read_feedbacks: (cb) ->
Feedback
.find()
.run (err, feedbacks) ->
.exec (err, feedbacks) ->
if err
cb err.err
else
Expand Down Expand Up @@ -355,7 +353,7 @@ Jbha.Client =
.where('owner', token.username)
.where('jbha_id', course_data.id)
.populate('assignments')
.run wf_callback
.exec wf_callback

# Pass the course along, or create a new
# one if it didn't exist in the database.
Expand Down Expand Up @@ -520,8 +518,8 @@ Jbha.Client =
Account
.find()
.sort('updated', -1)
.select('_id', 'updated', 'nickname')
.run (err, docs) ->
.select('_id updated nickname')
.exec (err, docs) ->
if docs.length < num_shown
showing = docs.length
else
Expand Down
30 changes: 13 additions & 17 deletions jbha.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Homework, simplified.",
"author": "Avi Romanoff <aviromanoff@gmail.com>",
"main": "server.js",
"version": "3.1.3-6",
"version": "3.2.0",
"scripts": {
"start": "server.js"
},
Expand All @@ -23,7 +23,7 @@
"handlebars-precompiler": "1.0.0beta",
"jade": "0.26.1",
"markdown": "0.3.1",
"mongoose": "2.6.5",
"mongoose": "3.0.2",
"moment": "1.7.0",
"optimist": "0.3.4",
"socket.io": "0.9.10",
Expand Down
4 changes: 2 additions & 2 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ app.post "/setup", ensureSession, (req, res) ->
res.redirect "/"

app.get "/app*", ensureSession, hydrateSettings, (req, res) ->
jbha.Client.by_course req.token, (courses) ->
jbha.Client.by_course req.token, (err, courses) ->
if !req.settings || req.settings.is_new
res.redirect "/setup"
else
Expand Down Expand Up @@ -313,7 +313,7 @@ io.sockets.on "connection", (socket) ->

socket.on "courses:read", (data, cb) ->
return unless _.isFunction cb
jbha.Client.by_course token, (courses) ->
jbha.Client.by_course token, (err, courses) ->
cb null, courses

socket.on "course:update", (data, cb) ->
Expand Down
4 changes: 2 additions & 2 deletions server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading