Skip to content

Commit

Permalink
changed the whole application in order to use titanium-jasmine
Browse files Browse the repository at this point in the history
* updated to the last version of joli.js * now uses the unit tests
framework
[titanium-jasmine](https://github.com/guilhermechapiewski/titanium-jasmine)
* added a bunch of tests, covering almost all the framework classes,
under Resources/test * use a Makefile (freely inspired from [this post
of
Guilherme](http://guilherme.pro/2011/04/06/titanium-mobile-hack-execute-your-projects-from-the-command-line-using-make/))
  • Loading branch information
xavierlacot committed Jul 22, 2011
1 parent 5d152e4 commit 9ecbf34
Show file tree
Hide file tree
Showing 16 changed files with 3,088 additions and 80 deletions.
28 changes: 28 additions & 0 deletions Makefile
@@ -0,0 +1,28 @@
# Makefile to start Titanium Mobile project from the command line.
# More info at http://github.com/guilhermechapiewski/titanium-jasmine

PROJECT_NAME=joliDemo
PROJECT_ROOT=$(shell pwd)

run-iphone:
@DEVICE_TYPE=iphone make run

run-ipad:
@DEVICE_TYPE=ipad make run

run:
@if [ "${DEVICE_TYPE}" == "" ]; then\
echo "Please run \"make run-[iphone|ipad]\" instead.";\
exit 1;\
fi
@make launch-titanium

clean:
@rm -rf ${PROJECT_ROOT}/build/iphone/*
@mkdir -p ${PROJECT_ROOT}//build/iphone/
@echo "Deleted: ${PROJECT_ROOT}/build/iphone/*"

launch-titanium:
@echo "Building with Titanium... (DEVICE_TYPE:${DEVICE_TYPE})"
@mkdir -p ${PROJECT_ROOT}/build/iphone/
@PROJECT_NAME=${PROJECT_NAME} PROJECT_ROOT=${PROJECT_ROOT} DEVICE_TYPE=${DEVICE_TYPE} bash ${PROJECT_ROOT}/bin/titanium.sh
5 changes: 0 additions & 5 deletions README

This file was deleted.

12 changes: 10 additions & 2 deletions README.markdown
@@ -1,5 +1,13 @@
# joli.js demo project

[joli.js](https://github.com/xavierlacot/joli.js) is a javascript ORM for the mobile applications framework [Appcelerator Titanium](http://www.appcelerator.com/).
[joli.js](https://github.com/xavierlacot/joli.js) is a javascript ORM for the
mobile applications framework [Appcelerator Titanium](http://www.appcelerator.com/).

This repository contains a simple example which demonstrates how to use joli.js. This ready-to-use project has been tested with Titanium 1.6.2.
This repository contains a simple example which demonstrates how to use joli.js. This ready-to-use project has been tested with Titanium 1.6.2, and uses the unit tests framework [titanium-jasmine](https://github.com/guilhermechapiewski/titanium-jasmine), based on the excellent [Jasmine BDD framework](http://pivotal.github.com/jasmine/).

## How to start the project

* download the source code,
* go to the project root and type:

$ make
100 changes: 28 additions & 72 deletions Resources/app.js
@@ -1,72 +1,28 @@
Ti.include('lib/vendor/joli.js/joli.js');
Ti.include('lib/model/models.js');

Titanium.UI.setBackgroundColor('#fff');

// create a Window and a TextArea in it
var win = Titanium.UI.createWindow({
title:'joli.js demonstration',
backgroundColor:'#fff'
});
var label = Titanium.UI.createLabel({
top:10,
left:10,
width:'auto',
height:'auto'
});
win.add(label);
win.open();



joli.models.initialize();

// create some "City" records and persist them
var newYork = models.city.newRecord({
name: 'New York',
description: 'A big Apple'
});
newYork.save();
var paris = models.city.newRecord({
name: 'Paris',
description: 'Cheese and Baguette'
});
paris.save();

label.text = 'New York and Paris saved in database';

// create a "human" record (not persisted)
var john = models.human.newRecord({
first_name: 'John',
last_name: 'Doe'
});
label.text = label.text + '\nJohn created';

// move him to New York
john.move('New York');
label.text = label.text + '\nJohn moved to New York';

// persist it
john.save();
label.text = label.text + '\nJohn saved in database';

// create an other "human" record (not persisted)
var sarah = models.human.newRecord({
first_name: 'Sarah',
last_name: 'Sure'
});
sarah.move('New York');
sarah.save();
label.text = label.text + '\nSarah created and saved in database';

// count the number of New York habitants
var count = models.human.countIn('New York');
label.text = label.text + '\nThere are ' + count + ' inhabitants in New York';

var john = models.human.findOneById(1);
john.move('Paris');
label.text = label.text + '\nJohn moved to Paris';
john.save();

var john = models.human.findOneById(1);
label.text = label.text + '\nJohn now lives in: ' + john.getCityName();
(function(){
// load joli library and models definition file
Ti.include('/lib/vendor/joli.js/joli.js');
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');

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

// 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');

// execute the tests
jasmine.getEnv().addReporter(new jasmine.TitaniumReporter());
jasmine.getEnv().execute();
})();

0 comments on commit 9ecbf34

Please sign in to comment.