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
FIX: correctly fetch() content for Backbone.Model Objects #62
Conversation
This lib did not correctly fetch()/ 'read'/'GET' from local storage for Backbone.Model objects. It does work in the tests however because the tests do not refresh the page and load once again from localStorage. in my personal test this worked for Backbone.Model, but I did not test Backbone.Collection Objects.
…mework test used 'length' as a property.
Can't be merged automatically. Could you rebase/merge master into your branch? |
Never mind, I'll do it later this afternoon. I'm refactoring all tests and then some. |
From my tests, this seems fine without your code. I did some logging in there and from the current test suite, the logging within your conditional never got called. Can you write a failing test case with what's currently in master to prove your point? I fail to see the case where it doesn't work. (maybe a change since you opened this pull request fixed it by magic) |
Jerome, I will try to find the time to learn your testing frame work, but I The case is this, if you have a model by it self it was not correctly if you have a model as part of a collection, it would read it just fine. For me to get back around to this will be a few days or longer if I have to On Sun, Jan 13, 2013 at 2:00 PM, Jerome Gravel-Niquet <
Justin Kruger http://jDavid.net |
I completely get that :) If you'd explain in more details what's wrong, I should be able to do it myself. Up to you. |
In your documentation you provide an example to make a Backbone.Collection I hope that makes more sense. Imagine the usage. window.SomeModel = Backbone.Model.extend({ localStorage: new Backbone.LocalStorage("SomeCollection"), // Unique // ... everything else is normal. This is the code I am using. AppSettings = Backbone.Model.extend({
Using Defaults?') https://github.com/jeromegn/Backbone.localStorage Include Backbone.localStorage after having included Backbone.js: <script type="text/javascript" src="backbone.js"></script><scripttype="text/javascript" src="backbone.localStorage.js"></script> Create your collections like so: window.SomeCollection = Backbone.Collection.extend({ localStorage: new Backbone.LocalStorage("SomeCollection"), // Unique // ... everything else is normal. On Mon, Jan 14, 2013 at 6:21 PM, Jerome Gravel-Niquet <
Justin Kruger http://jDavid.net |
That's what I thought it was. If that was the case, then the tests concerning the model would fail, no? For instance, this line would not update the model correctly: https://github.com/jeromegn/Backbone.localStorage/blob/master/spec/localStorage_spec.js#L204 I ran those tests with your code, and the code under the conditional that checked for an Array was never called. Are you sure this is still an issue? These are the models tests: https://github.com/jeromegn/Backbone.localStorage/blob/master/spec/localStorage_spec.js#L183-L238 |
those tests only do a save/fetch pattern and test. your other tests had you shouldn't be required to do a save and fetch to use the Model. the I traced through the code in my use. I also wrote a chrome.storage.sync Sent from my mobile On Jan 14, 2013, at 6:43 PM, Jerome Gravel-Niquet notifications@github.com That's what I thought it was. If that was the case, then the tests For instance, this line would not update the model correctly: I ran those tests with your code, and the code under the conditional that These are the models tests: — |
I'm not testing set and get because those are handled by Backbone. We're not testing Backbone here. My library doesn't touch that part. I do a fetch so that my plugin is being used. I'll add some more tests and see if I can replicate the issue. It does look like you're the only one who reported this though. Jerome Gravel-Niquet On Monday, 14 January, 2013 at 22:15, Justin Kruger wrote:
|
how do i set up the new test environment i have node installed, and i did the npm install for the two modules i have mac osx, could you point me to someplace to help me get this set up? On Mon, Jan 14, 2013 at 7:37 PM, Jerome Gravel-Niquet <
Justin Kruger http://jDavid.net |
The setup is a bit complicated, but you could just open the Check your path, make sure your global and local node_modules are in there. For instance: PATH="./node_modules/.bin:/usr/local/bin:/usr/local/sbin:$PATH" You'll also need to install phantomjs. If you're on OS X, Homebrew is perfect for that. |
This should now fix the scenario when Backbone.Model Objects are being used on their own and not as a model for a Backbone.Collection.
This also passes all tests now.