fdebc3d1 by Adam Heath

First set of sharable backbone models; they don't do a whole lot yet.

1 parent 31f6715f
{
"directory": "src/lib"
}
.*.swp
.tmp/
bin/coverage/
dist/
node_modules/
src/lib/
......
// Generated on 2014-02-06 using generator-webapp 0.4.7
/* global module */
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
/* global require */
'use strict';
var jasmineRequirejsTemplateOptions = function(withInstanbul) {
/* global requirejs */
var callback;
if (withInstanbul) {
callback = function() {
var oldLoad = requirejs.load;
requirejs.load = function (context, moduleName, url) {
//console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
var parts = url.split('/');
for (var i = 0; i < parts.length; ) {
var part = parts[i];
if (part === '.') {
parts.splice(i, 1);
} else if (part === '') {
parts.splice(i, 1);
} else if (part === '..') {
if (i > 0) {
i--;
parts.splice(i, 2);
} else {
parts.splice(i, 1);
}
} else {
i++;
}
}
url = parts.join('/');
if (url.indexOf('src/scripts/') === 0) {
url = './.grunt/grunt-contrib-jasmine/' + url;
}
//console.log('url=' + url);
return oldLoad.apply(this, [context, moduleName, url]);
};
};
}
return {
requireConfigFile: '<%= yeoman.src %>/scripts/config.js',
requireConfig: {
baseUrl: '<%= yeoman.src %>/scripts',
callback: callback
}
};
};
var jasmineInstanbulTemplateOptions = function(nestedTemplate, nestedOptions) {
return {
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage',
replace: false,
template: require(nestedTemplate),
templateOptions: nestedOptions
};
};
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
bower: {
target: {
options: {
exclude: [
'requirejs',
]
},
rjsConfig: '<%= yeoman.src %>/scripts/config.js'
}
},
// Project settings
yeoman: {
// Configurable paths
app: 'app',
dist: 'dist',
src: 'src',
},
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['<%= yeoman.src %>/scripts/{,*/}*.js'],
tasks: ['jshint'],
},
jstest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['test:watch']
},
gruntfile: {
files: ['Gruntfile.js']
},
styles: {
files: ['<%= yeoman.src %>/styles/{,*/}*.css'],
tasks: ['newer:copy:styles', 'autoprefixer']
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
app: {
options: {
open: false,
base: [
'.tmp',
'<%= yeoman.src %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.src %>'
]
}
},
dist: {
options: {
open: false,
base: '<%= yeoman.dist %>',
}
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
browser: true,
esnext: true,
bitwise: true,
camelcase: true,
curly: true,
eqeqeq: true,
immed: true,
indent: 4,
latedef: true,
newcap: true,
noarg: true,
quotmark: 'single',
undef: true,
unused: true,
strict: true,
trailing: true,
smarttabs: true,
jquery: true,
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
],
scripts: {
options: {
globals: {
define: false,
}
},
files: {
src: [
'<%= yeoman.src %>/scripts/**/*.js',
'!<%= yeoman.src %>/scripts/vendor/*',
]
}
},
specs: {
options: {
globals: {
define: false,
describe: false,
expect: false,
it: false,
}
},
files: {
src: [
'test/specs/**/*.spec.js'
]
}
}
},
jasmine: {
all: {
src: '<%= yeoman.src %>/scripts/{,**/}*.js',
options: {
specs: 'test/specs/**/*.spec.js',
template: require('grunt-template-jasmine-istanbul'),
templateOptions: jasmineInstanbulTemplateOptions('grunt-template-jasmine-requirejs', jasmineRequirejsTemplateOptions(true))
}
}
},
// Mocha testing framework configuration options
mocha: {
all: {
options: {
run: true,
urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html']
}
}
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// Automatically inject Bower components into the HTML file
'bower-install': {
app: {
html: '<%= yeoman.src %>/index.html',
ignorePath: '<%= yeoman.src %>/'
}
},
// Renames files for browser caching purposes
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/scripts/*/**/*.js',
'<%= yeoman.dist %>/scripts/!(config)*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{gif,jpeg,jpg,png,webp}',
'<%= yeoman.dist %>/styles/fonts/{,*/}*.*'
]
}
},
requireconfig: {
files: {
src: [
'<%= yeoman.dist %>/scripts/config.js'
]
}
}
},
requirejs: {
dist: {
options: {
done: function(done) {
var requireModules = grunt.config('requireModules') || {};
var lines = [
'require.bundles = (function(bundles) {',
];
for (var key in requireModules) {
var keyS = JSON.stringify(key);
var value = requireModules[key];
var included = [];
for (var i = 0; i < value.included.length; i++) {
var file = value.included[i];
if (file.match(/\.js$/)) {
included.push(file.substring(0, file.length - 3));
}
}
lines.push('bundles[' + keyS + '] = ' + JSON.stringify(included) + ';');
}
lines.push('return bundles;');
lines.push('})(require.bundles || {});');
grunt.file.write('.tmp/scripts/bundles.js', lines.join('\n'));
done();
},
baseUrl: '<%= yeoman.src %>/scripts',
mainConfigFile: '<%= yeoman.src %>/scripts/config.js',
wrapShim: true,
dir: '<%= yeoman.dist %>/scripts',
optimize: 'none',
removeCombined: true,
onModuleBundleComplete: function(data) {
if (data.name.slice(0, 'bundles/'.length) === 'bundles/') {
var requireModules = grunt.config('requireModules') || {};
requireModules[data.name] = data;
grunt.config('requireModules', requireModules);
}
},
modules: [
{
name: 'main',
include: [
'jquery',
'underscore',
'backbone',
'backbone-validation',
],
},
{
name: 'bundles/ofbiz-Base',
create: true,
exclude: [
'main',
],
include: [
'ofbiz/model/Base',
],
},
{
name: 'bundles/ofbiz-ContactMechs',
create: true,
exclude: [
'main',
'bundles/ofbiz-Party',
],
include: [
'ofbiz/model/EmailAddress',
'ofbiz/model/TelecomNumber',
'ofbiz/model/PostalAddress',
],
},
{
name: 'bundles/ofbiz-Party',
create: true,
exclude: [
'main',
'bundles/ofbiz-Base',
'bundles/ofbiz-ContactMechs',
],
include: [
'ofbiz/model/Party',
'ofbiz/model/Person',
'ofbiz/model/PartyGroup',
],
},
],
}
},
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
options: {
dest: '<%= yeoman.dist %>'
},
html: '<%= yeoman.src %>/index.html'
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
options: {
assetsDirs: ['<%= yeoman.dist %>']
},
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css']
},
// The following *-min tasks produce minified files in the dist folder
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.src %>/images',
src: '{,*/}*.{gif,jpeg,jpg,png}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.src %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
htmlmin: {
dist: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeCommentsFromCDATA: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
useShortDoctype: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: '{,*/}*.html',
dest: '<%= yeoman.dist %>'
}]
}
},
// By default, your `index.html`'s <!-- Usemin block --> will take care of
// minification. These next options are pre-configured if you do not wish
// to use the Usemin blocks.
// cssmin: {
// dist: {
// files: {
// '<%= yeoman.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css',
// '<%= yeoman.src %>/styles/{,*/}*.css'
// ]
// }
// }
// },
// uglify: {
// dist: {
// files: {
// '<%= yeoman.dist %>/scripts/scripts.js': [
// '<%= yeoman.dist %>/scripts/scripts.js'
// ]
// }
// }
// },
// concat: {
// dist: {}
// },
concat: {
requireconfig: {
}
},
uglify: {
dist: {
},
requireconfig: {
files: {
'<%= yeoman.dist %>/scripts/config.js': [
'<%= yeoman.dist %>/scripts/config.js',
'.tmp/scripts/config.js',
],
}
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.src %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'images/{,*/}*.webp',
'{,*/}*.html',
'styles/fonts/{,*/}*.*'
]
}]
},
styles: {
expand: true,
dot: true,
cwd: '<%= yeoman.src %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Run some tasks in parallel to speed up build process
concurrent: {
server: [
'copy:styles'
],
test: [
'copy:styles'
],
dist: [
'copy:styles',
'imagemin',
'svgmin'
]
}
});
grunt.loadNpmTasks('grunt-bower-requirejs');
grunt.registerTask('revconfig', function () {
var prefix = grunt.template.process('<%= yeoman.dist %>/scripts/');
var pattern = prefix + '**/*.{js,html}';
var files = grunt.file.expand(pattern);
var lines = [];
grunt.util._.each(files, function(file) {
file = file.substring(prefix.length);
var res = file.match(/^(.*\/)?([0-9a-f]+)\.([^\/]+)\.([^\.]+)$/);
if (!res) {
return;
}
//grunt.log.oklns(JSON.stringify(res));
var dir = res[1] || '';
//var hash = res[2];
var base = res[3];
var ext = res[4];
var id;
if (ext === 'js') {
id = dir + base;
file = file.substring(0, file.length - ext.length - 1);
} else if (ext === 'html') {
id = 'text!' + dir + base + '.' + ext;
}
grunt.log.oklns('map: ' + id + ' -> ' + file);
lines.push('require.paths[' + JSON.stringify(id) + ']=' + JSON.stringify(file) + ';\n');
});
grunt.file.write('.tmp/scripts/config.js', lines.join(''));
});
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'autoprefixer',
'connect:app',
'watch'
]);
});
grunt.registerTask('server', function () {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve']);
});
grunt.registerTask('test', function(target) {
if (target !== 'watch') {
grunt.task.run([
'clean:server',
'concurrent:test',
'autoprefixer',
]);
}
grunt.task.run([
'connect:test',
'mocha'
]);
});
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'requirejs',
'concurrent:dist',
'autoprefixer',
'concat',
'cssmin',
'uglify:dist',
'copy:dist',
// 'rev:dist',
'revconfig',
'uglify:requireconfig',
// 'rev:requireconfig',
'usemin',
'htmlmin'
]);
grunt.registerTask('dist', [
'bower',
'newer:jshint',
// 'test',
'build'
]);
grunt.registerTask('default', []);
};
{
"name": "ofbiz-shared",
"version": "0.0.0",
"authors": [
"Adam Heath <doogie@brainfood.com>"
],
"private": true,
"ignore": [
"**/.*",
"node_modules",
"src/lib",
"test"
],
"dependencies": {
"backbone": "~1.1.0",
"backbone-validation": "0.9.1",
"requirejs": "~2.1.10"
}
}
{
"name": "ofbiz-shared",
"version": "0.0.0",
"_main": [
"dist/scripts/bundles/ofbiz-Base.js",
"dist/scripts/bundles/ofbiz-Party.js",
"dist/scripts/bundles/ofbiz-ContactMechs.js"
],
"dependencies": {
"backbone": "~1.1.0",
"backbone-validation": "0.9.1",
"requirejs": "~2.1.10"
},
"devDependencies": {
"bower-requirejs": "~0.9.2",
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-bower-install": "~0.7.0",
"grunt-contrib-imagemin": "~0.2.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-rev": "~0.1.0",
"grunt-autoprefixer": "~0.5.0",
"grunt-usemin": "~0.1.10",
"grunt-mocha": "~0.4.0",
"grunt-newer": "~0.6.0",
"grunt-svgmin": "~0.2.0",
"grunt-concurrent": "~0.4.0",
"load-grunt-tasks": "~0.2.0",
"time-grunt": "~0.2.0",
"jshint-stylish": "~0.1.3",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-bower-requirejs": "~0.8.4",
"grunt-template-jasmine-istanbul": "~0.2.6",
"grunt-template-jasmine-requirejs": "~0.1.10",
"grunt-contrib-jasmine": "~0.5.3"
},
"engines": {
"node": ">=0.8.0"
}
}
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>ofbiz shared</title>
<meta name="description" content="">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css({src, .tmp}) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body>
<script src="scripts/config.js"></script>
<!-- build:js({src,.tmp}) scripts/require.js -->
<script src="scripts/bundles.js"></script>
<script src="lib/requirejs/require.js"></script>
<!-- endbuild -->
<script src="scripts/main.js"></script>
</body>
</html>
/* global require:true */
var require;
require = (function() {
'use strict';
var require = {
shim: {
},
paths: {
underscore: '../lib/underscore/underscore',
'backbone-validation': '../lib/backbone-validation/dist/backbone-validation-amd',
backbone: '../lib/backbone/backbone'
}
};
return require;
})();
define([], {});
/* global require */
require(
[
'backbone',
],
function(
Backbone
) {
'use strict';
Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;
}
);
define(
[],
function() {
/* global console */
'use strict';
console.log('ofbiz/model/Base: loaded');
var Base = {
createRequiredChecker: function(label) {
return function() {
console.log(label + ':required');
return this._isRequired;
};
},
createRequiredValidator: function(label) {
return {
required: Base.createRequiredChecker(),
};
},
};
return Base;
}
);
/* global console */
define(
[
'backbone',
],
function(
Backbone
) {
'use strict';
console.log('ofbiz/model/ContactMech: loaded');
return Backbone.Model.extend({
defaults: {
contactMechId: null,
},
validation: {
contactMechId: null,
},
});
}
);
/* global console */
define(
[
'underscore',
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
_,
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/EmailAddress: loaded');
return ContactMech.extend({
defaults: {
emailAddress: null,
},
validation: {
emailAddress: [
{
pattern: 'email',
required: Base.createRequiredChecker('ofbiz/model/EmailAddress.emailAddress'),
},
]
},
parse: function(data) {
if (data.infoString !== undefined) {
data = _.clone(data);
if (data.emailAddress === undefined) {
data.emailAddress = data.infoString;
}
delete data.infoString;
}
return data;
},
});
}
);
/* global console */
define(
[
'backbone',
],
function(
Backbone
) {
'use strict';
console.log('ofbiz/model/Party: loaded');
return Backbone.Model.extend({
idAttribute: 'partyId',
defaults: {
partyId: null,
},
validation: {
partyId: null,
}
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/Party',
],
function(
Base,
Party
) {
'use strict';
console.log('ofbiz/model/PartyGroup: loaded');
return Party.extend({
defaults: {
groupName: null,
},
validation: {
groupName: [
Base.createRequiredValidator('ofbiz/model/PartyGroup.groupName'),
],
},
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/Party',
],
function(
Base,
Party
) {
'use strict';
console.log('ofbiz/model/Person: loaded');
return Party.extend({
defaults: {
firstName: null,
lastName: null,
},
validation: {
firstName: [
Base.createRequiredValidator('ofbiz/model/Person.firstName'),
],
lastName: [
Base.createRequiredValidator('ofbiz/model/Person.lastName'),
],
},
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/PostalAddress: loaded');
return ContactMech.extend({
defaults: {
address1: null,
city: null,
postalCode: null,
},
validation: {
address1: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.address1'),
],
city: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.city'),
],
postalCode: [
Base.createRequiredValidator('ofbiz/model/PostalAddress.postalCode'),
],
}
});
}
);
/* global console */
define(
[
'ofbiz/model/Base',
'ofbiz/model/ContactMech',
],
function(
Base,
ContactMech
) {
'use strict';
console.log('ofbiz/model/TelecomNumber: loaded');
return ContactMech.extend({
defaults: {
contactNumber: null,
},
validation: {
contactNumber: [
Base.createRequiredValidator('ofbiz/model/TelecomNumber.contactNumber'),
]
}
});
}
);
File mode changed
define(function(require) {
'use strict';
var Base = require('ofbiz/model/Base');
var Backbone = require('backbone');
describe('Base', function() {
it('exists', function() {
expect(Base).toBeTruthy();
});
});
describe('Base', function() {
it('_createRequiredValidator', function() {
var TestModel = Backbone.Model.extend({
required: function() {
return this.validators.all[0].required.call(this, arguments);
},
validators: {
all: [
Base.createRequiredValidator('jasmine test'),
],
},
});
var testModel = new TestModel();
expect(testModel.required()).toBe(undefined);
testModel._isRequired = false;
expect(testModel.required()).toBe(false);
testModel._isRequired = true;
expect(testModel.required()).toBe(true);
});
});
});
define(function(require) {
'use strict';
var EmailAddress= require('ofbiz/model/EmailAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('EmailAddress', function() {
it('exists', function() {
expect(EmailAddress).toBeTruthy();
});
});
describe('EmailAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, emailAddress;
emailAddress = new EmailAddress();
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(emailAddress.isValid()).toBe(true);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'foo');
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'name@example.com');
result = emailAddress.validate();
expect(result).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress.set('emailAddress', null);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress._isRequired = false;
expect(emailAddress.isValid()).toBe(false);
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
});
it('parse', function() {
var result, emailAddress;
emailAddress = new EmailAddress({infoString: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({infoString: 'foo', emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
});
});
});
define(function(require) {
'use strict';
var PostalAddress= require('ofbiz/model/PostalAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('PostalAddress', function() {
it('exists', function() {
expect(PostalAddress).toBeTruthy();
});
});
if (true) describe('PostalAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, postalAddress;
postalAddress = new PostalAddress();
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
postalAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(postalAddress.isValid()).toBe(true);
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'city', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['city']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress.set('city', 'Anytown');
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress._isRequired = false;
expect(postalAddress.isValid()).toBe(false);
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
});
});
});
define(function(require) {
'use strict';
var TelecomNumber = require('ofbiz/model/TelecomNumber');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('TelecomNumber', function() {
it('exists', function() {
expect(TelecomNumber).toBeTruthy();
});
});
if (true) describe('TelecomNumber', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, telecomNumber;
telecomNumber = new TelecomNumber();
expect(telecomNumber.validate()).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
telecomNumber._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(telecomNumber.isValid()).toBe(true);
result = telecomNumber.validate()
expect(result).not.toBeUndefined();
expect(telecomNumber.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['contactNumber']);
expect(result['contactNumber']).toEqual(jasmine.any(String));
telecomNumber.set('contactNumber', '123-456-7890');
result = telecomNumber.validate()
expect(result).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
telecomNumber._isRequired = false;
expect(telecomNumber.isValid()).toBe(true);
expect(telecomNumber.validate()).toBeUndefined();
expect(telecomNumber.isValid()).toBe(true);
});
});
});