Skip to content

Commit

Permalink
reindent thing...
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierlacot committed Jul 22, 2011
1 parent bb7ffe6 commit f5ed2de
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 321 deletions.
5 changes: 3 additions & 2 deletions README.markdown
Expand Up @@ -7,7 +7,8 @@ This repository contains a simple example which demonstrates how to use joli.js.

## How to start the project

* download the source code,
* go to the project root and type:
First, download the source code. Take care that joli.js itself is a submodule of this repository, so you may have to get it separately.

Go to the project root and type the command:

$ make
32 changes: 16 additions & 16 deletions Resources/app.js
Expand Up @@ -4,25 +4,25 @@
Ti.include('/lib/model/models.js');

// load jasmine library and adapter
Ti.include('/lib/vendor/jasmine/jasmine-1.0.2.js');
Ti.include('/lib/vendor/jasmine/jasmine-titanium.js');
Ti.include('/lib/vendor/jasmine/jasmine-1.0.2.js');
Ti.include('/lib/vendor/jasmine/jasmine-titanium.js');

// initialize the model
joli.models.initialize();
// initialize the model
joli.models.initialize();

// load test facility functions
Ti.include('/test/main.js');
// load test facility functions
Ti.include('/test/main.js');

// load all the tests
Ti.include('/test/joli.js');
Ti.include('/test/connection.js');
Ti.include('/test/migration.js');
Ti.include('/test/model.js');
Ti.include('/test/models.js');
Ti.include('/test/query.js');
Ti.include('/test/record.js');
// load all the tests
Ti.include('/test/joli.js');
Ti.include('/test/connection.js');
Ti.include('/test/migration.js');
Ti.include('/test/model.js');
Ti.include('/test/models.js');
Ti.include('/test/query.js');
Ti.include('/test/record.js');

// execute the tests
jasmine.getEnv().addReporter(new jasmine.TitaniumReporter());
jasmine.getEnv().execute();
jasmine.getEnv().addReporter(new jasmine.TitaniumReporter());
jasmine.getEnv().execute();
})();
38 changes: 19 additions & 19 deletions Resources/test/connection.js
@@ -1,26 +1,26 @@
(function() {
describe('joli.connexion', function() {
var test = new joliTest();
describe('joli.connexion', function() {
var test = new joliTest();

/**
* Set up the test conditions
*/
var setUp = function() {
test.clearTables();
test.insertCity();
};
/**
* Set up the test conditions
*/
var setUp = function() {
test.clearTables();
test.insertCity();
};

it('joli.Connection.lastInsertRowId()', function() {
setUp();
it('joli.Connection.lastInsertRowId()', function() {
setUp();

// retrieve the last inserted id
// retrieve the last inserted id
var id = joli.connection.lastInsertRowId();
expect(id).toBeGreaterThan(0);
expect(id).toBeGreaterThan(0);

// retrieve this city from its id
var city = models.city.findOneById(id);
expect(city).not.toBeNull();
expect(city.get('name')).toBe('New York');
});
});
// retrieve this city from its id
var city = models.city.findOneById(id);
expect(city).not.toBeNull();
expect(city.get('name')).toBe('New York');
});
});
})();
8 changes: 4 additions & 4 deletions Resources/test/main.js
@@ -1,15 +1,15 @@
var joliTest = function() {
var john, sarah, newYork, paris;
var john, sarah, newYork, paris;
};

joliTest.prototype = {
/**
* clear model tables
*/
clearTables: function() {
models.city.truncate();
models.country.truncate();
models.human.truncate();
models.city.truncate();
models.country.truncate();
models.human.truncate();
},

/**
Expand Down
176 changes: 88 additions & 88 deletions Resources/test/model.js
@@ -1,95 +1,95 @@
(function() {
describe('joli.model', function() {
var test = new joliTest();

/**
* Set up the test conditions
*/
var setUp = function() {
test.clearTables();
};

it('joli.model.truncate()', function() {
setUp();

models.city.truncate();
models.country.truncate();
models.human.truncate();

expect(models.city.count()).toBe(0);
expect(models.country.count()).toBe(0);
expect(models.human.count()).toBe(0);
});

it('joli.model.all()', function() {
test.insertCities();
var cities = models.city.all();

expect(cities.length).toBe(2);
expect(cities[0].get('name')).toBe('New York');
expect(cities[1].get('name')).toBe('Paris');
});

it('joli.model.count()', function() {
test.createHumans();
expect(models.human.count()).toBe(1);
});

it('joli.model.deleteRecords()', function() {
models.human.deleteRecords(test.sarah.get('id'));
expect(models.human.count()).toBe(0);

test.createHumans();
test.john.save();
expect(models.human.count()).toBe(2);

models.human.deleteRecords([
test.john.get('id'),
test.sarah.get('id')
]);

expect(models.human.count()).toBe(0);
});

it('joli.model.exists()', function() {
expect(models.human.exists(test.sarah.get('id'))).toBeFalsy();

test.createHumans();
expect(models.human.exists(test.sarah.get('id'))).toBeTruthy();
});

it('joli.model.findBy()', function() {
test.clearTables();
test.createManyItems();

var paris_id = models.city.findOneBy('name', 'Paris').get('id');
var livingInParis = models.human.findBy('city_id', paris_id);

joli.each(livingInParis, function(item, key) {
expect(item.city_id).toBe(paris_id);
});
});

it('joli.model.findOneBy()', function() {
expect(models.city.findOneBy('name', 'Paris')).not.toBeNull();
expect(models.city.findOneBy('name', 'InexistantCity')).toBeFalsy();
});

it('joli.model.getColumns()', function() {
expect(models.city.getColumns()).toEqual({
describe('joli.model', function() {
var test = new joliTest();

/**
* Set up the test conditions
*/
var setUp = function() {
test.clearTables();
};

it('joli.model.truncate()', function() {
setUp();

models.city.truncate();
models.country.truncate();
models.human.truncate();

expect(models.city.count()).toBe(0);
expect(models.country.count()).toBe(0);
expect(models.human.count()).toBe(0);
});

it('joli.model.all()', function() {
test.insertCities();
var cities = models.city.all();

expect(cities.length).toBe(2);
expect(cities[0].get('name')).toBe('New York');
expect(cities[1].get('name')).toBe('Paris');
});

it('joli.model.count()', function() {
test.createHumans();
expect(models.human.count()).toBe(1);
});

it('joli.model.deleteRecords()', function() {
models.human.deleteRecords(test.sarah.get('id'));
expect(models.human.count()).toBe(0);

test.createHumans();
test.john.save();
expect(models.human.count()).toBe(2);

models.human.deleteRecords([
test.john.get('id'),
test.sarah.get('id')
]);

expect(models.human.count()).toBe(0);
});

it('joli.model.exists()', function() {
expect(models.human.exists(test.sarah.get('id'))).toBeFalsy();

test.createHumans();
expect(models.human.exists(test.sarah.get('id'))).toBeTruthy();
});

it('joli.model.findBy()', function() {
test.clearTables();
test.createManyItems();

var paris_id = models.city.findOneBy('name', 'Paris').get('id');
var livingInParis = models.human.findBy('city_id', paris_id);

joli.each(livingInParis, function(item, key) {
expect(item.city_id).toBe(paris_id);
});
});

it('joli.model.findOneBy()', function() {
expect(models.city.findOneBy('name', 'Paris')).not.toBeNull();
expect(models.city.findOneBy('name', 'InexistantCity')).toBeFalsy();
});

it('joli.model.getColumns()', function() {
expect(models.city.getColumns()).toEqual({
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
country_id: 'INTEGER',
name: 'TEXT',
description: 'TEXT'
});
});

it('model methods only for persisted items', function() {
test.clearTables();
test.insertCities();
test.createHumans();
expect(models.human.countIn('Paris')).toBe(0);
expect(models.human.countIn('New York')).toBe(1);
});
});
});

it('model methods only for persisted items', function() {
test.clearTables();
test.insertCities();
test.createHumans();
expect(models.human.countIn('Paris')).toBe(0);
expect(models.human.countIn('New York')).toBe(1);
});
});
})();
22 changes: 11 additions & 11 deletions Resources/test/models.js
@@ -1,15 +1,15 @@
(function() {
describe('joli.models', function() {
var test = new joliTest();
describe('joli.models', function() {
var test = new joliTest();

it('joli.models.get()', function() {
expect(joli.models.get('city')).toBe(models.city);
expect(joli.models.get('city')).not.toBe(models.human);
});
it('joli.models.get()', function() {
expect(joli.models.get('city')).toBe(models.city);
expect(joli.models.get('city')).not.toBe(models.human);
});

it('joli.models.has()', function() {
expect(joli.models.has('city')).toBeTruthy();
expect(joli.models.has('inexistant_model')).toBeFalsy();
});
});
it('joli.models.has()', function() {
expect(joli.models.has('city')).toBeTruthy();
expect(joli.models.has('inexistant_model')).toBeFalsy();
});
});
})();

0 comments on commit f5ed2de

Please sign in to comment.