'use strict';

var assert = require('assert');

module.exports = function(App, options, runner) {
  var app;

  describe('app.onLoad', function() {
    beforeEach(function() {
      app = new App();
    });

    describe('app.collection', function() {
      it('should emit an onLoad when view is created', function(cb) {
        var collection = app.collection();

        app.on('onLoad', function(view) {
          assert.equal(view.path, 'blog/foo.js');
          cb();
        });

        app.onLoad('blog/:title', function(view, next) {
          assert.equal(view.path, 'blog/foo.js');
          next();
        });

        collection.addView('whatever', {path: 'blog/foo.js', content: 'bar baz'});
      });
    });

    describe('view collections', function() {
      it('should emit an onLoad when view is created', function(cb) {
        app.create('posts');

        app.on('onLoad', function(view) {
          assert.equal(view.path, 'blog/foo.js');
          cb();
        });

        app.onLoad('blog/:title', function(view, next) {
          assert.equal(view.path, 'blog/foo.js');
          next();
        });

        app.post('whatever', {path: 'blog/foo.js', content: 'bar baz'});
      });
    });
  });
};

@@ -702,32 +702,1817 @@
 az'%7D);%0A      %7D);
+%0A%0A      it('should support async loading', function(cb) %7B%0A        var collection = app.collection();%0A%0A        app.onLoad('blog/:title', function(view, next) %7B%0A          assert.equal(view.path, 'blog/foo.js');%0A          next();%0A        %7D);%0A%0A        var obj = %7Bpath: 'blog/foo.js', content: 'bar baz'%7D;%0A        collection.addView('whatever', obj, function(err, view) %7B%0A          if (err) return cb(err);%0A          cb();%0A        %7D);%0A      %7D);%0A%0A      it('should expose the view in the callback', function(cb) %7B%0A        var collection = app.collection();%0A%0A        var obj = %7Bpath: 'blog/foo.js', content: 'bar baz'%7D;%0A        collection.addView('whatever', obj, function(err, view) %7B%0A          if (err) return cb(err);%0A          assert(view);%0A          assert(view.path);%0A          cb();%0A        %7D);%0A      %7D);%0A%0A      it('should run %60.onLoad%60 middleware before calling the callback', function(cb) %7B%0A        var collection = app.collection();%0A%0A        app.onLoad(/blog/, function(view, next) %7B%0A          view.title = 'foo';%0A          next();%0A        %7D);%0A%0A        var obj = %7Bpath: 'blog/foo.js', content: 'bar baz'%7D;%0A        collection.addView('whatever', obj, function(err, view) %7B%0A          if (err) return cb(err);%0A          assert.equal(view.title, 'foo');%0A          cb();%0A        %7D);%0A      %7D);%0A%0A      it('should be async', function(cb) %7B%0A        var collection = app.collection();%0A%0A        app.onLoad(/blog/, function(view, next) %7B%0A          view.title = 'foo';%0A          setTimeout(function() %7B%0A            next();%0A          %7D, 20);%0A        %7D);%0A%0A        var obj = %7Bpath: 'blog/foo.js', content: 'bar baz'%7D;%0A        collection.addView('whatever', obj, function(err, view) %7B%0A          if (err) return cb(err);%0A          assert.equal(view.title, 'foo');%0A          cb();%0A        %7D);%0A      %7D);
 %0A    %7D);%0A%0A    de

add async loading tests