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

Implement Collections and fixtures #13

Open
zvictor opened this issue Jun 12, 2013 · 8 comments
Open

Implement Collections and fixtures #13

zvictor opened this issue Jun 12, 2013 · 8 comments

Comments

@zvictor
Copy link
Contributor

zvictor commented Jun 12, 2013

As seen on extendind Laika example, we can extend Laika to use Collections in the same way we would use Meteor API, but extendind we have to declare Collection inside of each test.

Can we make Collection natively available inside test?
Can we also support fixtures?

@arunoda
Copy link
Owner

arunoda commented Jun 12, 2013

This is a really good idea!

I prefer to have an API like server.Collection and client.Collection

var Posts = new server.Collection('posts');

What you think?

I think for the fixtures we can add it our actions API (not documented yet)
See: http://goo.gl/JPuRF

If we added it to actions we can simply use it like this.

server.evalSync(laika.actions.fixtures('coll-name', [{}, {}]));

What you think about it?

@zvictor
Copy link
Contributor Author

zvictor commented Jun 12, 2013

great idea! server.Collection and client.Collection are even better.

About the fixtures I thought we could attach a copy of the fixtures in a key of the respective collection, been able to use this way:

var Posts = server.Collection('posts');

someUpdateFn();

var before = Posts.fixtures.findOne({title: "Laika is cool"});
var after = Posts.findOne({title: "Laika is cool"});

I think I haven't got the idea of actions, but it is important to keep the simplicity of the "extendind Laika" example when defining the fixtures data.

I like the idea of having files .js or .json with fixture data, and then just a command to insert all of them at the same time. If your idea of action require to pass the fixtures through evalSync, then I dislike it.

@arunoda
Copy link
Owner

arunoda commented Jun 12, 2013

okay. forget about actions. Let's think about some API for fixtures.
How about this.

  • We can place fixture data in .json file inside fixtures/<Coll Name>.json
  • Then we can automatically load these
  • And also we can have a laika.addFixtures() api too

for running we can simply use your functions, with laika prefixed.

var fixtures = laika.runAllFixtures()
var singleFixture = laika.runFixture('Posts');

for the querying it. I think following makes sense too

var Posts = server.Collection('posts');

//fixtures variable is defined in the above code section
var before = fixtures['Posts'].findOne({title: "Laika is cool"});
var after = Posts.findOne({title: "Laika is cool"});

@zvictor
Copy link
Contributor Author

zvictor commented Jun 13, 2013

I agree with almost everything, but I prefer Posts.fixtures rather than fixtures['Posts'].
The latter one leads to a misleading: should I write fixtures['Posts'] or fixtures['posts']?

Note: I reviewed my implementation of Collections and replaced the eval(collName) by Meteor._RemoteCollectionDriver.open(collName). Before that, the user was supposed to type Collection('Posts') instead of Collection('posts'). I have not updated the repo code yet.

@arunoda
Copy link
Owner

arunoda commented Jun 13, 2013

Okay. That's nice.
Now it is possible this. Thats nice. We'll use collName as the actual collection name.

PS. I didn't knew about Meteor._RemoteCollectionDriver.open()

@arunoda
Copy link
Owner

arunoda commented Jun 13, 2013

Are you working on this, or shall I start?

@zvictor
Copy link
Contributor Author

zvictor commented Jun 13, 2013

I cannot work on this now, so would be nice if you could.

this Meteor._RemoteCollectionDriver.open() I found digging Meteor at packages/mongo-livedata/collection.js.
As you want to implement Collections for the client also, I would suggest you to take a better look from line 57 to 65:

 if (!options._driver) {
    if (name && self._connection === Meteor.default_server &&
        Meteor._RemoteCollectionDriver)
      options._driver = Meteor._RemoteCollectionDriver;
    else
      options._driver = Meteor._LocalCollectionDriver;
  }

  self._collection = options._driver.open(name);

It seems to me that _LocalCollectionDriver should be used in the client side.

@arunoda
Copy link
Owner

arunoda commented Jun 13, 2013

Awesome. I'll work on this.

On Fri, Jun 14, 2013 at 12:27 AM, zVictor notifications@github.com wrote:

I cannot work on this now, so would be nice if you could.

this Meteor._RemoteCollectionDriver.open() I found digging Meteor at *
packages/mongo-livedata/collection.js*.
As you want to implement Collections for the client also, I would suggest
you to take a better look from line 57 to 65:

if (!options._driver) {
if (name && self._connection === Meteor.default_server &&
Meteor._RemoteCollectionDriver)
options._driver = Meteor._RemoteCollectionDriver;
else
options._driver = Meteor._LocalCollectionDriver;
}

self._collection = options._driver.open(name);

It seems to me that _LocalCollectionDriver should be used in the client
side.


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-19416133
.

Arunoda Susiripala

@arunoda http://twitter.com/arunoda
http://gplus.to/arunodahttps://github.com/arunoda
http://www.linkedin.com/in/arunoda

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

2 participants