Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #100 from mozilla/74-encoding

74 encoding [closes #74]
  • Loading branch information...
commit 4d91de5daa0f3364230bbd2cb3bccab477554866 2 parents 369e6a7 + c5d8cb1
@brianloveswords brianloveswords authored
View
6 .puppet-manifests/openbadges.pp
@@ -1,17 +1,19 @@
class openbadges::db {
- define mysqldb( $user, $password ) {
+ define mysqldb( $user, $password, $encoding ) {
exec { "create-${name}-db":
unless => "/usr/bin/mysql -u${user} -p${password} ${name}",
- command => "/usr/bin/mysql -uroot -p$mysql_password -e \"create database ${name}; grant all on ${name}.* to ${user}@localhost identified by '$password';\"",
+ command => "/usr/bin/mysql -uroot -p$mysql_password -e \"create database ${name} character set ${encoding}; grant all on ${name}.* to ${user}@localhost identified by '$password';\"",
}
}
mysqldb { "openbadges":
user => "badgemaker",
password => "secret",
+ encoding => "utf8",
}
mysqldb { "test_openbadges":
user => "badgemaker",
password => "secret",
+ encoding => "utf8",
}
}
View
4 lib/mysql.js
@@ -3,6 +3,8 @@ var mysql = require('mysql')
, client = mysql.createClient(conf)
, testDb = "`test_" + conf.database + "`";
+var dbEncoding = 'utf8';
+
var schemas = [
"CREATE TABLE IF NOT EXISTS `user` ("
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY,"
@@ -58,7 +60,7 @@ exports.createTables = function () {
})
}
exports.useTestDatabase = function () {
- client.query("CREATE DATABASE IF NOT EXISTS " + testDb);
+ client.query("CREATE DATABASE IF NOT EXISTS " + testDb + " CHARACTER SET '" + dbEncoding + "'");
client.query("USE "+ testDb);
}
exports.dropTestDatabase = function () {
View
21 test/mysql-test.js
@@ -12,12 +12,23 @@ var toObj = function (arr) { var r = {}; arr.forEach(function (a) { r[a] = 1; })
mysql.prepareTesting();
vows.describe('Testing database').addBatch({
"After running test prep": {
- topic: function () {
- client.query('show databases', this.callback);
+ 'proper database': {
+ topic: function () {
+ client.query('show databases', this.callback);
+ },
+ 'is created': function (err, results) {
+ var databases = extractFirstValues(results);
+ assert.includes(databases, testDb);
+ }
},
- 'proper database is created': function (err, results) {
- var databases = extractFirstValues(results);
- assert.includes(databases, testDb);
+ 'database encoding': {
+ topic: function () {
+ client.query("show variables like 'character_set_database'", this.callback);
+ },
+ 'is utf8': function (err, results) {
+ // #TODO: maybe shouldn't hardcode the encoding? (defined in puppet manifests)
+ assert.equal(results[0].Value, 'utf8');
+ }
},
'expected tables': {
topic: function () {
View
53 test/portfolio-model-test.js
@@ -0,0 +1,53 @@
+var vows = require('vows')
+ , mysql = require('../lib/mysql')
+ , Portfolio = require('../models/portfolio')
+ , should = require('should')
+
+var UNICODE_TITLE = "てすと";
+
+var createDbFixtures = function (callback) {
+ var addUser = "INSERT INTO `user` (email) VALUES ('brian@example.com')";
+ var addBadge = "INSERT INTO `badge`"
+ + "(user_id, type, endpoint, image_path, body, body_hash)"
+ + "VALUES"
+ + "(1, 'hosted', 'http://example.com', '/dev/null', '{\"wut\":\"lol\"}', 'sha256$lol')";
+ var addGroup = "INSERT INTO `group`"
+ + "(user_id, name, badges)"
+ + "VALUES"
+ + "(1, 'group 1', '{}')";
+ mysql.client.query(addUser);
+ mysql.client.query(addBadge);
+ mysql.client.query(addGroup, callback);
+};
+
+vows.describe('Portfolio model').addBatch({
+ 'A portfolio': {
+ topic: function () {
+ mysql.prepareTesting();
+ createDbFixtures(this.callback);
+ },
+ 'with unicode characters in its title': {
+ topic: function () {
+ return new Portfolio({
+ group_id: 1,
+ title: UNICODE_TITLE,
+ stories:{}
+ });
+ },
+ 'when saved': {
+ topic: function(portfolio) {
+ portfolio.save(this.callback);
+ },
+ 'and restored': {
+ topic: function(portfolio) {
+ Portfolio.findOne({group_id: portfolio.get('group_id')}, this.callback);
+ },
+ 'should not garble the title': function(portfolio) {
+ portfolio.get('title').should.equal(UNICODE_TITLE);
+ }
+ }
+ }
+ }
+ }
+}).export(module);
+
Please sign in to comment.
Something went wrong with that request. Please try again.