var assert = require('assert')
  , barrels = require('../')
  , Sails = require('sails');

describe('Barrels', function() {
  var fixtures = barrels.load().objects;

  // Load fixtures into memory
  describe('#load()', function() {
    it ("should load all the json files from default folder", function() {
      assert((Object.keys(fixtures).length >= 2), 'At least two fixture files should be loaded!');
    });

    it ("should set generate lowercase property names for models", function() {
      var oneWord = Object.keys(fixtures).join();
      assert.equal(oneWord, oneWord.toLowerCase(), 'Property names should be in lowercase!');
    });
  });

  // Populate DB with fixtures
  describe('#populate()', function() {
    before(function(done) {
      Sails.lift({
        log: {
          level: 'error'
        },
        paths: {
          models: require('path').join(process.cwd(), 'test/fixtures/models')
        },
        adapters: {
          default: 'sails-memory',
        },
        session: {
          secret: 'santaClausDoesntExist'
        }
      }, function(err, sails) {
        done(err);
      });
    });

    after(function(done) {
      sails.lower(done);
    });

    it ('should populate the DB with apples and oranges', function(done) {
      barrels.populate(function(err) {
        if (err)
          return done(err);
        Apples.find(function(err, apples) {
          if (err)
            return done(err);
          var gotApples = (fixtures['apples'].length > 0);
          var applesAreInTheDb = (apples.length === fixtures['apples'].length);
          assert(gotApples&&applesAreInTheDb, 'There must be something!');

          Oranges.find(function(err, oranges) {
            if (err)
              return done(err);
            assert.equal(apples.length, oranges.length,
              'Apples and oranges should have equal amount of varieties!');
            done();
          });
        });
      });
    });
  }); 
});

@@ -933,16 +933,37 @@
     
-adapters
+connections: %7B%0A          test
 : %7B%0A
@@ -972,23 +972,25 @@
         
-default
+  adapter
 : 'sails
@@ -997,17 +997,28 @@
 -memory'
-,
+%0A          %7D
 %0A       
@@ -1033,15 +1033,14 @@
     
-session
+models
 : %7B%0A
@@ -1053,39 +1053,106 @@
     
-secret: 'santaClausDoesntExist'
+connection: 'test',%0A          migrate: 'drop'%0A        %7D,%0A        hooks: %7B%0A          %22grunt%22: false
 %0A   

update tests