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

$.fixture templated values not being included in callback data #136

Open
webbower opened this issue Aug 28, 2012 · 0 comments
Open

$.fixture templated values not being included in callback data #136

webbower opened this issue Aug 28, 2012 · 0 comments

Comments

@webbower
Copy link

If you set up a dynamic fixture with a templated URL, the originalOptions param of the callback will not be updated with the templated URL values if the data prop was not set in options of the AJAX call.

$.fixture('GET /todo/{id}', function(orig) {
    console.log(orig.data.id); // undefined
    console.log(orig.data); // undefined
});

$.ajax({
    url: '/todo/10',
    dataType: 'json',
});

I suspect the problem is that here https://github.com/jupiterjs/jquerymx/blob/master/dom/fixture/fixture.js#L62, if you try to merge an object into undefined with jQuery.extend, it fails. So if $.extend(originalOptions.data, data) equates to $.extend(undefined, { id: '10' }), then data isn't created.

The solution I devised involves checking to make sure the data property of originalOptions exists and if it doesn't, setting it to an empty object before calling jQuery.extend.

@@ -53,6 +53,10 @@
            settings.dataTypes.splice(0,0,"fixture");

            if(data){
+               if(! ('data' in originalOptions)) {
+                   originalOptions.data = {};
+               }
+               
                $.extend(originalOptions.data, data)
            }
            // add to settings data from fixture ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant