diff --git a/HISTORY.md b/HISTORY.md
index 2e3b03a..95cce0a 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -2,10 +2,13 @@
## 0.6.10
- Fixed bug where changing a property type from "number" to "string" made existing properties uneditable.
+- Fixed bug where `changed()` was returning true for values that had not changed.
+- Fixed certain error's returned as HTML rather than JSON.
## 0.6.9
-- Fixed bug where `internal-client` was not accessible from modules
+ - Fixed bug where `internal-client` was not accessible from modules
+ - Fixed restarts caused by 404s of unexpected http verbs
## 0.6.8
diff --git a/clib/ajax.js b/clib/ajax.js
index 6e0ef8d..6bd47c5 100644
--- a/clib/ajax.js
+++ b/clib/ajax.js
@@ -31,8 +31,11 @@ function sendRequest(url,options) {
req.open(method,url,true);
req.withCredentials = true;
// req.setRequestHeader('User-Agent','XMLHTTP/1.0');
- if (data)
- req.setRequestHeader('Content-type', options.contentType || 'application/json');
+ if (data) {
+ req.setRequestHeader('Content-Type', options.contentType || 'application/json');
+ }
+ req.setRequestHeader('Accept', 'application/json');
+
if (typeof sendRequest.headers === 'object') {
for (var k in sendRequest.headers) {
if (sendRequest.headers.hasOwnProperty(k)) {
diff --git a/lib/resources/collection/index.js b/lib/resources/collection/index.js
index 7c20a73..3887009 100644
--- a/lib/resources/collection/index.js
+++ b/lib/resources/collection/index.js
@@ -440,7 +440,13 @@ Collection.prototype.save = function (ctx, fn) {
};
domain.changed = function (property) {
- if(domain.data.hasOwnProperty(property)) return true;
+ if(domain.data.hasOwnProperty(property)) {
+ if(domain.previous && domain.previous[property] === domain.data[property]) {
+ return false;
+ }
+
+ return true;
+ }
return false;
};
@@ -466,7 +472,8 @@ Collection.prototype.save = function (ctx, fn) {
prev[key] = obj[key];
obj[key] = item[key];
});
-
+
+ prev.id = id;
item = obj;
domain['this'] = item;
domain.data = item;
diff --git a/lib/router.js b/lib/router.js
index f81100c..9be4a53 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -3,6 +3,7 @@ var db = require('./db')
, escapeRegExp = /[\-\[\]{}()+?.,\\\^$|#\s]/g
, debug = require('debug')('router')
, doh = require('doh')
+ , error404 = doh.createResponder()
, async = require('async');
/**
@@ -83,7 +84,7 @@ Router.prototype.route = function (req, res) {
} else {
debug('404 %s', req.url);
res.statusCode = 404;
- res.domain.emit('error', new Error('Resource not found'));
+ error404({message: 'resource not found'}, req, res);
}
});
});
diff --git a/test-app/public/index.html b/test-app/public/index.html
index 5e9dfb2..8073119 100644
--- a/test-app/public/index.html
+++ b/test-app/public/index.html
@@ -12,6 +12,7 @@
+
diff --git a/test-app/public/test/collection.test.js b/test-app/public/test/collection.test.js
index 6783ff8..911ec74 100644
--- a/test-app/public/test/collection.test.js
+++ b/test-app/public/test/collection.test.js
@@ -871,6 +871,17 @@ describe('Collection', function() {
});
});
+ it('should not return true when a value has not changed', function(done) {
+ dpd.changed.post({name: '$NO_CHANGE'}, function (c) {
+ dpd.changed.put(c.id, {name: '$NO_CHANGE'}, function (c) {
+ if(c.name != '$NO_CHANGE') {
+ throw new Error('incorrect name change');
+ }
+ done();
+ });
+ });
+ });
+
afterEach(function (done) {
this.timeout(10000);
cleanCollection(dpd.changed, done);
diff --git a/test-app/public/test/misc.test.js b/test-app/public/test/misc.test.js
new file mode 100644
index 0000000..d2aacdc
--- /dev/null
+++ b/test-app/public/test/misc.test.js
@@ -0,0 +1,17 @@
+describe('404s', function(){
+ it('should not prevent a server from responding', function(done) {
+ this.timeout(5000);
+
+ var tests = 50;
+ var remaining = tests;
+
+ while(tests--) {
+ dpd('/').post({foo: 'bar'}, function (res, err) {
+ remaining--;
+ if(!remaining) {
+ done();
+ }
+ });
+ }
+ });
+});
\ No newline at end of file
diff --git a/test-app/resources/changed/put.js b/test-app/resources/changed/put.js
new file mode 100644
index 0000000..dfedcb6
--- /dev/null
+++ b/test-app/resources/changed/put.js
@@ -0,0 +1,5 @@
+if(this.name === '$NO_CHANGE') {
+ if(changed('name')) {
+ this.name = 'saw name change';
+ }
+}
\ No newline at end of file