[Pkg-javascript-commits] [node-mocks-http] 07/296: Sometimes the prototype code would run and bubble all the way up. Now it is more reliable.
Thorsten Alteholz
alteholz at moszumanska.debian.org
Mon Feb 8 18:13:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-mocks-http.
commit f80b10d868a3f7882730af7469c2e4953015960e
Author: Howard Abrams <howard at cloud-eco.com>
Date: Sun Feb 19 10:07:38 2012 -0800
Sometimes the prototype code would run and bubble all the way up. Now it is more reliable.
---
lib/mockRequest.js | 213 ++++++++++++++++++++++++++---------------------------
1 file changed, 104 insertions(+), 109 deletions(-)
diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index bc343f5..9ab4945 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -8,113 +8,6 @@
* @author Howard Abrams <howard.abrams at gmail.com>
*/
-Provider = function(options){
- if (!options) {
- options = {};
- }
-
- this.method = (options.method) ? options.method : 'GET';
- this.url = (options.url ) ? options.url : '';
- this.params = (options.params) ? options.params : {};
- this.body = (options.body ) ? options.body : {};
-
- console.log(this);
-};
-
-
-/**
- * Function: _setParameter
- *
- * Set parameters that the client can then get using the 'params'
- * key.
- *
- * Parameters:
- *
- * key - The key. For instance, 'bob' would be accessed: request.params.bob
- * value - The value to return when accessed.
- */
-
-Provider.prototype._setParameter = function( key, value ) {
- this.params[key] = value;
-};
-
-/**
- * Function: _setMethod
- *
- * Sets the HTTP method that the client gets when the called the 'method'
- * property. This defaults to 'GET' if it is not set.
- *
- * Parameters:
- *
- * method - The HTTP method, e.g. GET, POST, PUT, DELETE, etc.
- *
- * Note: We don't validate the string. We just return it.
- */
-
-Provider.prototype._setMethod = function( method ) {
- this.method = method;
-};
-
-/**
- * Function: _setURL
- *
- * Sets the URL value that the client gets when the called the 'url'
- * property.
- *
- * Parameters:
- *
- * url - The request path, e.g. /my-route/452
- *
- * Note: We don't validate the string. We just return it. Typically, these
- * do not include hostname, port or that part of the URL.
- */
-
-Provider.prototype._setURL = function( url ) {
- this.url = url;
-};
-
-/**
- * Function: _setBody
- *
- * Sets the body that the client gets when the called the 'body'
- * parameter. This defaults to 'GET' if it is not set.
- *
- * Parameters:
- *
- * body - An object representing the body.
- *
- * If you expect the 'body' to come from a form, this typically means that
- * it would be a flat object of properties and values, as in:
- *
- * > { name: 'Howard Abrams',
- * > age: 522
- * > }
- *
- * If the client is expecting a JSON object through a REST interface, then
- * this object could be anything.
- */
-
-Provider.prototype._setBody = function( body ) {
- this.body = body;
-};
-
-/**
- * Function: _addBody
- *
- * Adds another body parameter the client gets when calling the 'body'
- * parameter with another property value, e.g. the name of a form element
- * that was passed in.
- *
- * Parameters:
- *
- * key - The key. For instance, 'bob' would be accessed: request.params.bob
- * value - The value to return when accessed.
- */
-
-Provider.prototype._addBody = function( key, value ) {
- this.body[key] = value;
-};
-
/**
* Function: createRequest
*
@@ -133,6 +26,108 @@ Provider.prototype._addBody = function( key, value ) {
* body - The body values, , see <mockRequest._setBody>
*/
-exports.createRequest = function(options){
- return new Provider(options);
+exports.createRequest = function(options) {
+ if (!options) {
+ options = {};
+ }
+
+ return {
+ method: (options.method) ? options.method : 'GET',
+ url : (options.url ) ? options.url : '',
+ params: (options.params) ? options.params : {},
+ body : (options.body ) ? options.body : {},
+
+ /**
+ * Function: _setParameter
+ *
+ * Set parameters that the client can then get using the 'params'
+ * key.
+ *
+ * Parameters:
+ *
+ * key - The key. For instance, 'bob' would be accessed: request.params.bob
+ * value - The value to return when accessed.
+ */
+
+ _setParameter: function( key, value ) {
+ this.params[key] = value;
+ },
+
+ /**
+ * Function: _setMethod
+ *
+ * Sets the HTTP method that the client gets when the called the 'method'
+ * property. This defaults to 'GET' if it is not set.
+ *
+ * Parameters:
+ *
+ * method - The HTTP method, e.g. GET, POST, PUT, DELETE, etc.
+ *
+ * Note: We don't validate the string. We just return it.
+ */
+
+ _setMethod: function( method ) {
+ this.method = method;
+ },
+
+ /**
+ * Function: _setURL
+ *
+ * Sets the URL value that the client gets when the called the 'url'
+ * property.
+ *
+ * Parameters:
+ *
+ * url - The request path, e.g. /my-route/452
+ *
+ * Note: We don't validate the string. We just return it. Typically, these
+ * do not include hostname, port or that part of the URL.
+ */
+
+ _setURL: function( url ) {
+ this.url = url;
+ },
+
+ /**
+ * Function: _setBody
+ *
+ * Sets the body that the client gets when the called the 'body'
+ * parameter. This defaults to 'GET' if it is not set.
+ *
+ * Parameters:
+ *
+ * body - An object representing the body.
+ *
+ * If you expect the 'body' to come from a form, this typically means that
+ * it would be a flat object of properties and values, as in:
+ *
+ * > { name: 'Howard Abrams',
+ * > age: 522
+ * > }
+ *
+ * If the client is expecting a JSON object through a REST interface, then
+ * this object could be anything.
+ */
+
+ _setBody: function( body ) {
+ this.body = body;
+ },
+
+ /**
+ * Function: _addBody
+ *
+ * Adds another body parameter the client gets when calling the 'body'
+ * parameter with another property value, e.g. the name of a form element
+ * that was passed in.
+ *
+ * Parameters:
+ *
+ * key - The key. For instance, 'bob' would be accessed: request.params.bob
+ * value - The value to return when accessed.
+ */
+
+ _addBody: function( key, value ) {
+ this.body[key] = value;
+ }
+ };
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git
More information about the Pkg-javascript-commits
mailing list