Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added travis conf file

  • Loading branch information...
commit 1ccd032240d2fc1e81031865c221fc3087c657d1 1 parent 51e11a0
@bjpirt authored
Showing with 80 additions and 0 deletions.
  1. +9 −0 .travis.yml
  2. +71 −0 test/hmmm.js
View
9 .travis.yml
@@ -0,0 +1,9 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+before_script:
+ - psql -c 'create database bb_pg_test;' -U postgres
+ - psql bb_pg_test -c 'CREATE EXTENSION hstore' -U postgres
+ - psql -c "CREATE USER bb_pg WITH PASSWORD 'test'" -U postgres
+ - psql -c 'ALTER DATABASE bb_pg_test OWNER TO bb_pg' -U postgres
View
71 test/hmmm.js
@@ -0,0 +1,71 @@
+var should = require('should'),
+ Backbone = require('../backbone-postgresql'),
+ table_name = 'test_hstore';
+
+var Test = Backbone.Model.extend({
+ urlRoot: table_name
+});
+
+var TestCollection = Backbone.Collection.extend({
+ urlRoot: table_name,
+ model: Test
+});
+
+Backbone.pg_connector.config = {
+ "name":"bb_pg_test",
+ "user":"bb_pg",
+ "password":"test"
+};
+
+var conString = 'pg://' + Backbone.pg_connector.config.user + ':' + Backbone.pg_connector.config.password + '@localhost/' + Backbone.pg_connector.config.name
+var pg = require('pg').native;
+
+describe('PostgreSQL hstore support', function() {
+ var client;
+
+ before(function(done){
+ Backbone.Model.column_defs = {};
+ pg.connect(conString, function(err, client_arg){
+ client = client_arg;
+ client.query('DROP TABLE ' + table_name, function(err, result){
+ client.query('CREATE TABLE ' + table_name + '(id SERIAL, one VARCHAR(64), two VARCHAR(64), attributes hstore)', function(err, result){
+console.log(result);
+ done();
+ });
+ });
+ });
+ });
+
+ beforeEach(function(done){
+ client.query("TRUNCATE TABLE " + table_name + " CASCADE;", [], function(err, result) {
+console.log(result);
+ done();
+ });
+ });
+ describe('saving a new model', function(done){
+ it('should save the extra attributes correctly', function(done){
+ var test_model = new Test({one: 'testone', two: 'testtwo', three: 'testthree', four: 'testfour'});
+ should.not.exist(test_model.id);
+ test_model.save(null, {success: function(model){
+console.log(model.id);
+console.log(typeof model.id);
+ // model.id.should.be.a('number');
+ model.attributes.should.eql({id: model.id, one: 'testone', two: 'testtwo', three: 'testthree', four: 'testfour'});
+ client.query("SELECT *, %# attributes as attributes FROM " + table_name + " WHERE id = $1", [model.id], function(err, result) {
+ result.rows.length.should.eql(1);
+ var new_attrs = {};
+ result.rows[0].attributes.map(function(attr){; new_attrs[attr[0]] = attr[1]; });
+ result.rows[0].attributes = new_attrs;
+ result.rows[0].should.eql({
+ id: model.id,
+ one: 'testone',
+ two: 'testtwo',
+ attributes: {three: 'testthree', four: 'testfour'}
+ });
+ done();
+ });
+ }});
+ });
+ });
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.