Skip to content

Instantly share code, notes, and snippets.

@Gowiem
Created November 28, 2013 02:15
Show Gist options
  • Save Gowiem/7686304 to your computer and use it in GitHub Desktop.
Save Gowiem/7686304 to your computer and use it in GitHub Desktop.
Ember Runloop and AJAX Callbacks Issue
// Testing Helper which I use to log a user in.
// This blows up before 'student logged in' is logged
var loginStudent = function(username, password) {
visit('/').click('.studentsLogin .btn span')
.fillIn('#email-field', username)
.fillIn('#password-field', password)
.click('#login-button').then(function() {
console.log("Student logged in");
});
}
// The click(#login-button) above ends up calling the following method in my
// auth_controller.js
login: function(route) {
var self = this,
userType = route.routeName === "studentLogin" ? "student" : "teacher",
loginUrl = Sis.urls[userType + 'Login'],
postData = {};
postData[userType + "[email]"] = route.currentModel.get('email');
postData[userType + "[password]"] = route.currentModel.get('password');
$.ajax({
url: loginUrl,
type: "POST",
data: postData,
success: function(data) {
self.store.push(userType, data[userType]);
self.store.find(userType, data[userType].id).then(function(user) {
self.set('currentUser', user);
if (user.get('isTeacher')) {
route.transitionTo('teachers');
} else {
route.get('store').find('project').then(function(projects) {
route.transitionTo('project', projects.get('firstObject'));
});
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status==401) {
route.controllerFor('login').set("errorMsg", "That email/password combo didn't work. Please try again");
} else if (jqXHR.status==406) {
route.controllerFor('login').set("errorMsg", "Request not acceptable (406): make sure Devise responds to JSON.")
} else {
console.log("Login Error: ", jqXHR.status, "error: ", errorThrown);
}
}
});
},
// This is the error that I'm getting in the console:
// Assertion failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment