-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-validations-tests.js
64 lines (59 loc) · 74.8 KB
/
ember-validations-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==========================================================================
// Project: Ember Validations
// Copyright: Copyright 2013 DockYard, LLC. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
var JSHINTRC = {
"predef": [
"console",
"Ember",
"DS",
"Handlebars",
"Metamorph",
"ember_assert",
"ember_warn",
"ember_deprecate",
"ember_deprecateFunc",
"require",
"equal",
"asyncTest",
"test",
"raises",
"deepEqual",
"start",
"stop",
"ok",
"strictEqual",
"module",
"expect",
"minispade",
"async",
"invokeAsync"
],
"node" : false,
"es5" : true,
"browser" : true,
"boss" : true,
"curly": false,
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false
}
;
minispade.register('ember-validations/~tests/conditional_validators_test', "(function() {var user, User;\n\nmodule('Conditional validations', {\n setup: function() {\n User = Ember.Object.extend(Ember.Validations.Mixin);\n }\n});\n\nasyncTest('if with function', function() {\n expect(4);\n User.reopen({\n validations: {\n firstName: {\n presence: {\n if: function(model) {\n return false;\n }\n }\n }\n }\n });\n\n Ember.run(function(){\n user = User.create();\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n var validator = user.validators.get('firstObject');\n validator.conditionals['if'] = function(model, property) {\n equal(user, model, \"the conditional validator is passed the model being validated\");\n equal(property, 'firstName', \"the conditional validator is passed the name of the property being validated\");\n return true;\n };\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\nasyncTest('if with property reference', function() {\n User.reopen({\n validations: {\n firstName: {\n presence: {\n if: 'canValidate'\n }\n }\n }\n });\n\n\n Ember.run(function(){\n user = User.create();\n user.set('canValidate', false);\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n user.set('canValidate', true);\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\nasyncTest('if with function reference', function() {\n User.reopen({\n validations: {\n firstName: {\n presence: {\n if: 'canValidate'\n }\n }\n },\n canValidate: function() {\n return false;\n }\n });\n\n Ember.run(function(){\n user = User.create();\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n user.set('canValidate', true);\n user.canValidate = function() {\n return true;\n };\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\nasyncTest('unless with function', function() {\n expect(4);\n User.reopen({\n validations: {\n firstName: {\n presence: {\n unless: function(model) {\n return true;\n }\n }\n }\n }\n });\n\n Ember.run(function(){\n user = User.create();\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n var validator = user.validators.get('firstObject');\n validator.conditionals['unless'] = function(model, property) {\n equal(user, model, \"the conditional validator is passed the model being validated\");\n equal(property, 'firstName', \"the conditional validator is passed the name of the property being validated\");\n return false;\n };\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\nasyncTest('unless with property reference', function() {\n User.reopen({\n validations: {\n firstName: {\n presence: {\n unless: 'canValidate'\n }\n }\n },\n canValidate: true\n });\n\n Ember.run(function(){\n user = User.create();\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n user.set('canValidate', false);\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\nasyncTest('unless with function reference', function() {\n User.reopen({\n validations: {\n firstName: {\n presence: {\n unless: 'canValidate'\n }\n }\n },\n canValidate: function() {\n return true;\n }\n });\n\n Ember.run(function(){\n user = User.create();\n user.validate().then(function(){\n deepEqual(user.errors.get('firstName'), []);\n user.set('canValidate', true);\n user.canValidate = function() {\n return false;\n };\n user.validate().then(null, function(){\n deepEqual(user.errors.get('firstName'), [\"can't be blank\"]);\n start();\n });\n });\n });\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/conditional_validators_test");minispade.register('ember-validations/~tests/errors_test', "(function() {var user, User;\n\nmodule('Errors test', {\n setup: function() {\n User = Ember.Object.extend(Ember.Validations.Mixin, {\n validations: {\n name: {\n presence: true\n },\n age: {\n presence: true,\n numericality: true\n }\n }\n });\n },\n teardown: function() {\n delete Ember.I18n;\n }\n});\n\ntest('validations are run on instantiation', function() {\n Ember.run(function() {\n user = User.create();\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.name'), [\"can't be blank\"]);\n deepEqual(user.get('errors.age'), [\"can't be blank\", 'is not a number']);\n Ember.run(function() {\n user = User.create({name: 'Brian', age: 33});\n });\n ok(user.get('isValid'));\n deepEqual(user.get('errors.name'), []);\n deepEqual(user.get('errors.age'), []);\n});\n\ntest('when errors are resolved', function() {\n Ember.run(function() {\n user = User.create();\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.name'), [\"can't be blank\"]);\n deepEqual(user.get('errors.age'), [\"can't be blank\", 'is not a number']);\n Ember.run(function() {\n user.set('name', 'Brian');\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.name'), []);\n deepEqual(user.get('errors.age'), [\"can't be blank\", 'is not a number']);\n Ember.run(function() {\n user.set('age', 'thirty three');\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.name'), []);\n deepEqual(user.get('errors.age'), ['is not a number']);\n Ember.run(function() {\n user.set('age', 33);\n });\n ok(user.get('isValid'));\n deepEqual(user.get('errors.name'), []);\n deepEqual(user.get('errors.age'), []);\n});\n\ntest('validations use Ember.I18n.t to render the message if Ember.I18n is present', function() {\n Ember.I18n = {\n translations: {\n errors: {\n blank: 'muss ausgefüllt werden',\n notANumber: 'ist keine Zahl'\n }\n },\n lookupKey: function(key, hash) {\n var firstKey, idx, remainingKeys;\n\n if (hash[key] !== null && hash[key] !== undefined) { return hash[key]; }\n\n if ((idx = key.indexOf('.')) !== -1) {\n firstKey = key.substr(0, idx);\n remainingKeys = key.substr(idx + 1);\n hash = hash[firstKey];\n if (hash) { return Ember.I18n.lookupKey(remainingKeys, hash); }\n }\n },\n t: function(key, context) {\n return Ember.I18n.lookupKey(key, Ember.I18n.translations);\n }\n };\n \n Ember.run(function() {\n user = User.create();\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.name'), ['muss ausgefüllt werden']);\n deepEqual(user.get('errors.age'), ['muss ausgefüllt werden', 'ist keine Zahl']);\n Ember.run(function() {\n user.set('age', 'thirty three');\n });\n equal(user.get('isValid'), false);\n deepEqual(user.get('errors.age'), ['ist keine Zahl']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/errors_test");minispade.register('ember-validations/~tests/validate_test', "(function() {var user, User;\n\nmodule('Validate test', {\n setup: function() {\n User = Ember.Object.extend(Ember.Validations.Mixin, {\n validations: {\n firstName: {\n presence: true,\n length: 5\n },\n lastName: {\n format: { with: /\\w+/ }\n }\n }\n });\n Ember.run(function() {\n user = User.create();\n });\n }\n});\n\nasyncTest('returns a promise', function() {\n Ember.run(function(){\n user.validate().then(function(){\n ok(false, 'expected validation failed');\n }, function() {\n equal(user.get('isValid'), false);\n start();\n });\n });\n});\n\ntest('isInvalid tracks isValid', function() {\n equal(user.get('isInvalid'), true);\n Ember.run(function() {\n user.setProperties({firstName: 'Brian', lastName: 'Cardarella'});\n });\n equal(user.get('isInvalid'), false);\n});\n\nasyncTest('runs all validations', function() {\n Ember.run(function(){\n user.validate().then(null, function(errors){\n deepEqual(errors.get('firstName'), [\"can't be blank\", 'is the wrong length (should be 5 characters)']);\n deepEqual(errors.get('lastName'), [\"is invalid\"]);\n equal(user.get('isValid'), false);\n user.set('firstName', 'Bob');\n user.validate('firstName').then(null, function(errors){\n deepEqual(errors.get('firstName'), ['is the wrong length (should be 5 characters)']);\n equal(user.get('isValid'), false);\n user.set('firstName', 'Brian');\n user.set('lastName', 'Cardarella');\n user.validate().then(function(errors){\n deepEqual(errors.get('firstName'), []);\n deepEqual(errors.get('lastName'), []);\n equal(user.get('isValid'), true);\n start();\n });\n });\n });\n });\n});\n\ntest('can be mixed into an object controller', function() {\n var Controller, controller, user;\n Controller = Ember.ObjectController.extend(Ember.Validations.Mixin, {\n validations: {\n name: {\n presence: true\n }\n }\n });\n\n Ember.run(function() {\n controller = Controller.create();\n });\n equal(controller.get('isValid'), false);\n user = Ember.Object.create();\n Ember.run(function() {\n controller.set('content', user);\n });\n equal(controller.get('isValid'), false);\n Ember.run(function() {\n user.set('name', 'Brian');\n });\n equal(controller.get('isValid'), true);\n});\n\nmodule('Array controller');\n\ntest('can be mixed into an array controller', function() {\n var Controller, controller, container, user, UserController;\n container = new Ember.Container();\n UserController = Ember.ObjectController.extend(Ember.Validations.Mixin, {\n validations: {\n name: {\n presence: true\n }\n }\n });\n container.register('controller:User', UserController);\n Controller = Ember.ArrayController.extend(Ember.Validations.Mixin, {\n itemController: 'User',\n container: container,\n validations: {\n '[]': true\n }\n });\n\n Ember.run(function() {\n controller = Controller.create();\n });\n equal(controller.get('isValid'), true);\n user = Ember.Object.create();\n Ember.run(function() {\n controller.pushObject(user);\n });\n equal(controller.get('isValid'), false);\n Ember.run(function() {\n user.set('name', 'Brian');\n });\n equal(controller.get('isValid'), true);\n Ember.run(function() {\n user.set('name', undefined);\n });\n equal(controller.get('isValid'), false);\n Ember.run(function() {\n controller.get('content').removeObject(user);\n });\n equal(controller.get('isValid'), true);\n});\n\nvar Profile, profile;\n\nmodule('Relationship validators', {\n setup: function() {\n Profile = Ember.Object.extend(Ember.Validations.Mixin, {\n validations: {\n title: {\n presence: true\n }\n }\n });\n\n Ember.run(function() {\n profile = Profile.create({hey: 'yo'});\n });\n\n User = Ember.Object.extend(Ember.Validations.Mixin);\n }\n});\n\ntest('validates other validatable property', function() {\n Ember.run(function() {\n user = User.create({\n validations: {\n profile: true\n }\n });\n });\n equal(user.get('isValid'), true);\n Ember.run(function() {\n user.set('profile', profile);\n });\n equal(user.get('isValid'), false);\n Ember.run(function() {\n profile.set('title', 'Developer');\n });\n equal(user.get('isValid'), true);\n});\n\n// test('validates custom validator', function() {\n // Ember.run(function() {\n // user = User.create({\n // profile: profile,\n // validations: [AgeValidator]\n // });\n // });\n // equal(user.get('isValid'), false);\n // Ember.run(function() {\n // user.set('age', 22);\n // });\n // equal(user.get('isValid'), true);\n// });\n\ntest('validates array of validable objects', function() {\n var friend1, friend2;\n\n Ember.run(function() {\n user = User.create({\n validations: {\n friends: true\n }\n });\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n user.set('friends', Ember.makeArray());\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n friend1 = User.create({\n validations: {\n name: {\n presence: true\n }\n }\n });\n });\n\n Ember.run(function() {\n user.friends.pushObject(friend1);\n });\n\n equal(user.get('isValid'), false);\n\n Ember.run(function() {\n friend1.set('name', 'Stephanie');\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n friend2 = User.create({\n validations: {\n name: {\n presence: true\n }\n }\n });\n\n user.friends.pushObject(friend2);\n });\n\n equal(user.get('isValid'), false);\n\n Ember.run(function() {\n user.friends.removeObject(friend2);\n });\n\n equal(user.get('isValid'), true);\n});\n\n\ntest('revalidates arrays when they are replaced', function() {\n var friend1, friend2;\n\n Ember.run(function() {\n user = User.create({\n validations: {\n friends: true\n }\n });\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n user.set('friends', Ember.makeArray());\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n friend1 = User.create({\n validations: {\n name: {\n presence: true\n }\n }\n });\n });\n\n Ember.run(function() {\n user.set('friends', [friend1]);\n });\n\n equal(user.get('isValid'), false);\n\n Ember.run(function() {\n friend1.set('name', 'Stephanie');\n });\n\n equal(user.get('isValid'), true);\n\n Ember.run(function() {\n friend2 = User.create({\n validations: {\n name: {\n presence: true\n }\n }\n });\n\n user.set('friends', [friend1, friend2]);\n });\n\n equal(user.get('isValid'), false);\n\n Ember.run(function() {\n user.friends.removeObject(friend2);\n });\n\n equal(user.get('isValid'), true);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validate_test");minispade.register('ember-validations/~tests/validators/absence_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Absence Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is not empty', function() {\n options = { message: 'failed validation' };\n Ember.run(function(){\n validator = Ember.Validations.validators.local.Absence.create({model: model, property: 'attribute', options: options});\n });\n deepEqual(validator.errors, []);\n Ember.run(function() {\n model.set('attribute', 'not empty');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when value is made empty', function() {\n model.set('attribute', 'not empty');\n options = { message: 'failed validation' };\n Ember.run(function(){\n validator = Ember.Validations.validators.local.Absence.create({model: model, property: 'attribute', options: options});\n model.set('attribute', undefined);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when options is true', function() {\n options = true;\n Ember.run(function(){\n validator = Ember.Validations.validators.local.Absence.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'not empty');\n });\n deepEqual(validator.errors, [\"must be blank\"]);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/absence_test");minispade.register('ember-validations/~tests/validators/acceptance_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Acceptance Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when attribute is true', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', true);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when attribute is not true', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', false);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when attribute is value of 1', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when attribute value is 2 and accept value is 2', function() {\n options = { message: 'failed validation', accept: 2 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 2);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when attribute value is 1 and accept value is 2', function() {\n options = { message: 'failed validation', accept: 2 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is true', function() {\n options = true;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', false);\n });\n deepEqual(validator.errors, ['must be accepted']);\n});\n\ntest('when no message is passed', function() {\n options = { accept: 2 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Acceptance.create({model: model, property: 'attribute', options: options});\n model.set('attribute', false);\n });\n deepEqual(validator.errors, ['must be accepted']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/acceptance_test");minispade.register('ember-validations/~tests/validators/base_test', "(function() {var model, Model, options, CustomValidator, validator;\n\nmodule('Base Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n CustomValidator = Ember.Validations.validators.Base.extend({\n init: function() {\n this._super();\n this._dependentValidationKeys.pushObject('otherAttribute');\n },\n call: function() {}\n });\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is not empty', function() {\n Ember.run(function() {\n validator = CustomValidator.create({model: model, property: 'attribute'});\n });\n equal(validator.get('isValid'), true);\n});\n\ntest('generates _dependentValidationKeys on the model', function() {\n Ember.run(function() {\n validator = CustomValidator.create({model: model, property: 'attribute'});\n });\n deepEqual(model.get('_dependentValidationKeys'), {attribute: ['otherAttribute']});\n});\n\ntest('inactive validators should be considered valid', function() {\n var canValidate = true;\n Ember.run(function() {\n validator = CustomValidator.createWithMixins({\n model: model,\n property: 'attribute',\n canValidate: function() {\n return canValidate;\n },\n call: function() {\n this.errors.pushObject(\"nope\");\n }\n });\n });\n equal(validator.get('isValid'), false);\n canValidate = false;\n Ember.run(validator, 'validate');\n equal(validator.get('isValid'), true);\n});\n\n\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/base_test");minispade.register('ember-validations/~tests/validators/confirmation_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Confirmation Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when values match', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Confirmation.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'test');\n model.set('attributeConfirmation', 'test');\n });\n deepEqual(validator.errors, []);\n Ember.run(function() {\n model.set('attributeConfirmation', 'newTest');\n });\n deepEqual(validator.errors, ['failed validation']);\n Ember.run(function() {\n model.set('attribute', 'newTest');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when values do not match', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Confirmation.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'test');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is true', function() {\n options = true;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Confirmation.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'test');\n });\n deepEqual(validator.errors, [\"doesn't match attribute\"]);\n});\n\ntest('message integration on model, prints message on Confirmation property', function() {\n var otherModel, OtherModel = Model.extend({\n validations: {\n attribute: {\n confirmation: true\n }\n }\n });\n\n Ember.run(function() {\n otherModel = OtherModel.create();\n otherModel.set('attribute', 'test');\n });\n\n deepEqual(otherModel.get('errors.attributeConfirmation'), [\"doesn't match attribute\"]);\n deepEqual(otherModel.get('errors.attribute'), []);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/confirmation_test");minispade.register('ember-validations/~tests/validators/exclusion_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Exclusion Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is not in the list', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 4);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is in the list', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowing blank', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3], allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not allowing blank', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when value is not in the range', function() {\n options = { 'message': 'failed validation', 'range': [1, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 4);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is in the range', function() {\n options = { 'message': 'failed validation', 'range': [1, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is an array', function() {\n options = [1, 2, 3];\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is reserved']);\n});\n\ntest('when no message is passed', function() {\n options = { in: [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Exclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is reserved']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/exclusion_test");minispade.register('ember-validations/~tests/validators/format_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Format Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when matching format', function() {\n options = { 'message': 'failed validation', 'with': /\\d+/ };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '123');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not matching format', function() {\n options = { 'message': 'failed validation', 'with': /\\d+/ };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'abc');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowing blank', function() {\n options = { 'message': 'failed validation', 'with': /\\d+/, 'allowBlank': true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not allowing blank', function() {\n options = { 'message': 'failed validation', 'with': /\\d+/ };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is regexp', function() {\n options = /\\d+/;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is invalid']);\n});\n\ntest('when no message is passed', function() {\n options = { 'with': /\\d+/ };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Format.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is invalid']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/format_test");minispade.register('ember-validations/~tests/validators/inclusion_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Inclusion Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is in the list', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is not in the list', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 4);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowing blank', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3], allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not allowing blank', function() {\n options = { 'message': 'failed validation', 'in': [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when value is in the range', function() {\n options = { 'message': 'failed validation', 'range': [1, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is not in the range', function() {\n options = { 'message': 'failed validation', 'range': [1, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 4);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is array', function() {\n options = [1, 2, 3];\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is not included in the list']);\n});\n\ntest('when no message is passed', function() {\n options = { in: [1, 2, 3] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Inclusion.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is not included in the list']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/inclusion_test");minispade.register('ember-validations/~tests/validators/length_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Length Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when allowed length is 3 and value length is 3', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '123');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when allowed length is 3 and value length is 4', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '1234');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowed length is 3 and value length is 2', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '12');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowing blank and allowed length is 3', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3, allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when allowing blank and minimum length is 3 and maximum length is 100', function() {\n options = { messages: { tooShort: 'failed minimum validation', tooLong: 'failed maximum validation' }, minimum: 3, maximum: 100, allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not allowing blank and allowed length is 3', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowed length is 3 and a different tokenizer', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3, tokenizer: function(value) { return value.split(' '); } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'one two three');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when allowed length minimum is 3 and value length is 3', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '123');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when allowed length minimum is 3 and value length is 2', function() {\n options = { messages: { tooShort: 'failed validation' }, minimum: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '12');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowed length maximum is 3 and value length is 3', function() {\n options = { messages: { wrongLength: 'failed validation' }, is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '123');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when allowed length maximum is 3 and value length is 4', function() {\n options = { messages: { tooLong: 'failed validation' }, maximum: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '1234');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when allowed length maximum is 3 and value is blank', function() {\n options = { maximum: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when options is a number', function() {\n model.set('attribute', '1234');\n options = 3;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is the wrong length (should be 3 characters)']);\n});\n\ntest('when options is a number and value is undefined', function() {\n options = 3;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is the wrong length (should be 3 characters)']);\n});\n\ntest('when allowed length is 3, value length is 4 and no message is set', function() {\n options = { is: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '1234');\n });\n deepEqual(validator.errors, ['is the wrong length (should be 3 characters)']);\n});\n\ntest('when allowed length minimum is 3, value length is 2 and no message is set', function() {\n options = { minimum: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '12');\n });\n deepEqual(validator.errors, ['is too short (minimum is 3 characters)']);\n});\n\ntest('when allowed length maximum is 3, value length is 4 and no message is set', function() {\n options = { maximum: 3 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '1234');\n });\n deepEqual(validator.errors, ['is too long (maximum is 3 characters)']);\n});\n\ntest('when using a property instead of a number', function() {\n options = { is: 'countProperty' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Length.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '123');\n });\n deepEqual(validator.errors, ['is the wrong length (should be 0 characters)']);\n Ember.run(function() {\n model.set('countProperty', 3);\n });\n deepEqual(validator.errors, []);\n Ember.run(function() {\n model.set('countProperty', 5);\n });\n deepEqual(validator.errors, ['is the wrong length (should be 5 characters)']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/length_test");minispade.register('ember-validations/~tests/validators/numericality_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('Numericality Validator', {\n setup: function() {\n Model = Ember.Object.extend(validator = Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is a number', function() {\n options = { messages: { numericality: 'failed validation' } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 123);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is a decimal number', function() {\n options = { messages: { numericality: 'failed validation' } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 123.456);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is not a number', function() {\n options = { messages: { numericality: 'failed validation' } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'abc123');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when no value', function() {\n options = { messages: { numericality: 'failed validation' } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when no value and allowing blank', function() {\n options = { messages: { numericality: 'failed validation' }, allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when bad value and allowing blank', function() {\n options = { messages: { numericality: 'failed validation' }, allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'abc123');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when only allowing integers and value is integer', function() {\n options = { messages: { onlyInteger: 'failed validation', numericality: 'failed validation' }, onlyInteger: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 123);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing integers and value is not integer', function() {\n options = { messages: { onlyInteger: 'failed integer validation', numericality: 'failed validation' }, onlyInteger: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 123.456);\n });\n deepEqual(validator.errors, ['failed integer validation']);\n});\n\ntest('when only integer and no message is passed', function() {\n options = { onlyInteger: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1.1);\n });\n deepEqual(validator.errors, ['must be an integer']);\n});\n\ntest('when only integer is passed directly', function() {\n options = 'onlyInteger';\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1.1);\n });\n deepEqual(validator.errors, ['must be an integer']);\n});\n\ntest('when only allowing values greater than 10 and value is greater than 10', function() {\n options = { messages: { greaterThan: 'failed validation', numericality: 'failed validation' }, greaterThan: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing values greater than 10 and value is 10', function() {\n options = { messages: { greaterThan: 'failed validation', numericality: 'failed validation' }, greaterThan: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when only allowing values greater than or deepEqual to 10 and value is 10', function() {\n options = { messages: { greaterThanOrEqualTo: 'failed validation', numericality: 'failed validation' }, greaterThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing values greater than or deepEqual to 10 and value is 9', function() {\n options = { messages: { greaterThanOrEqualTo: 'failed validation', numericality: 'failed validation' }, greaterThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 9);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when only allowing values less than 10 and value is less than 10', function() {\n options = { messages: { lessThan: 'failed validation', numericality: 'failed validation' }, lessThan: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 9);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing values less than 10 and value is 10', function() {\n options = { messages: { lessThan: 'failed validation', numericality: 'failed validation' }, lessThan: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when only allowing values less than or deepEqual to 10 and value is 10', function() {\n options = { messages: { lessThanOrEqualTo: 'failed validation', numericality: 'failed validation' }, lessThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing values less than or deepEqual to 10 and value is 11', function() {\n options = { messages: { lessThanOrEqualTo: 'failed validation', numericality: 'failed validation' }, lessThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n deepEqual(validator.errors, ['failed validation']);\n });\n});\n\ntest('when only allowing values equal to 10 and value is 10', function() {\n options = { messages: { equalTo: 'failed validation', numericality: 'failed validation' }, equalTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing values equal to 10 and value is 11', function() {\n options = { messages: { equalTo: 'failed equal validation', numericality: 'failed validation' }, equalTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, ['failed equal validation']);\n});\n\ntest('when only allowing value equal to 0 and value is 1', function() {\n options = { messages: { equalTo: 'failed equal validation', numericality: 'failed validation' }, equalTo: 0 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 1);\n });\n deepEqual(validator.errors, ['failed equal validation']);\n});\n\ntest('when only allowing odd values and the value is odd', function() {\n options = { messages: { odd: 'failed validation', numericality: 'failed validation' }, odd: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing odd values and the value is even', function() {\n options = { messages: { odd: 'failed validation', numericality: 'failed validation' }, odd: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when only allowing even values and the value is even', function() {\n options = { messages: { even: 'failed validation', numericality: 'failed validation' }, even: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when only allowing even values and the value is odd', function() {\n options = { messages: { even: 'failed validation', numericality: 'failed validation' }, even: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when value refers to another present property', function() {\n options = { messages: { greaterThan: 'failed to be greater', numericality: 'failed validation' }, greaterThan: 'attribute_2' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute_1', options: options});\n model.set('attribute_1', 0);\n model.set('attribute_2', 1);\n });\n deepEqual(validator.errors, ['failed to be greater']);\n Ember.run(function() {\n model.set('attribute_1', 2);\n model.set('attribute_2', 1);\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when options is true', function() {\n options = true;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['is not a number']);\n});\n\ntest('when equal to and no message is passed', function() {\n options = { equalTo: 11 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['must be equal to 11']);\n});\n\ntest('when greater than and no message is passed', function() {\n options = { greaterThan: 11 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['must be greater than 11']);\n});\n\ntest('when greater than or equal to and no message is passed', function() {\n options = { greaterThanOrEqualTo: 11 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['must be greater than or equal to 11']);\n});\n\ntest('when less than and no message is passed', function() {\n options = { lessThan: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, ['must be less than 10']);\n});\n\ntest('when less than or equal to and no message is passed', function() {\n options = { lessThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, ['must be less than or equal to 10']);\n});\n\ntest('when odd and no message is passed', function() {\n options = { odd: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 10);\n });\n deepEqual(validator.errors, ['must be odd']);\n});\n\ntest('when even and no message is passed', function() {\n options = { even: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n deepEqual(validator.errors, ['must be even']);\n});\n\ntest('when other messages are passed but not a numericality message', function() {\n options = { messages: { greaterThan: 'failed validation' } };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'abc');\n });\n deepEqual(validator.errors, ['is not a number']);\n});\n\ntest(\"numericality validators don't call addObserver on null props\", function() {\n expect(1);\n\n var stubbedObserverCalled = false;\n\n var realAddObserver = Ember.addObserver;\n Ember.addObserver = function(_, path) {\n stubbedObserverCalled = true;\n if (!path) {\n ok(false, \"shouldn't call addObserver with falsy path\");\n }\n return realAddObserver.apply(this, arguments);\n };\n\n options = { lessThanOrEqualTo: 10 };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Numericality.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 11);\n });\n Ember.addObserver = realAddObserver;\n\n ok(stubbedObserverCalled, \"stubbed addObserver was called\");\n});\n\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/numericality_test");minispade.register('ember-validations/~tests/validators/presence_test', "(function() {var model, Model, options, validator;\n\nmodule('Presence Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\ntest('when value is not empty', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Presence.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'not empty');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when value is empty', function() {\n options = { message: 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Presence.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when options is true', function() {\n options = true;\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Presence.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, [\"can't be blank\"]);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/presence_test");minispade.register('ember-validations/~tests/validators/uniqueness_test', "(function() {// module('Uniqueness options', {\n // setup: function() {\n // Ember.Validations.forms['new_user'] = {\n // type: 'ActionView::Helpers::FormBuilder',\n // input_tag: '<div class=\"field_with_errors\"><span id=\"input_tag\" /><label class=\"message\"></label></div>',\n // label_tag: '<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>',\n // validators: {'user[email]':{\"uniqueness\":[{\"message\": \"must be unique\", \"scope\":{'name':\"pass\"}}]},\"presence\":[{\"message\": \"must be present\"}]}\n // }\n\n // $('#qunit-fixture')\n // .append($('<form />', {\n // action: '/users',\n // 'data-validate': true,\n // method: 'post',\n // id: 'new_user'\n // }))\n // .find('form')\n // .append($('<input />', {\n // name: 'user[name]',\n // id: 'user_name',\n // type: 'text'\n // }))\n // .append($('<input />', {\n // name: 'user[email]',\n // id: 'user_email',\n // type: 'text'\n // }))\n\n // $('form#new_user').call();\n // }\n// });\n\n// test('when matching uniqueness on a non-nested resource', function() {\n // var element = $('<input type=\"text\" name=\"user[email]\"/>');\n // var options = { 'message': \"failed validation\" };\n // element.val('nottaken@test.com');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), undefined);\n// });\n\n// test('when matching uniqueness on a non-nested resource', function() {\n // var element = $('<input type=\"text\" name=\"user[email]\"/>');\n // var options = { 'message': \"failed validation\" };\n // element.val('taken@test.com');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), \"failed validation\");\n// });\n\n// test('when matching uniqueness on a nested singular resource', function() {\n // var element = $('<input type=\"text\" name=\"profile[user_attributes][email]\"/>');\n // var options = { 'message': \"failed validation\" };\n // element.val('nottaken@test.com');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), undefined);\n// });\n\n// test('when matching uniqueness on a nested singular resource', function() {\n // var element = $('<input type=\"text\" name=\"profile[user_attributes][email]\"/>');\n // var options = { 'message': \"failed validation\" };\n // element.val('taken@test.com');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), \"failed validation\");\n// });\n\n// test('when using scopes with no replacement', function() {\n // var element = $('<input type=\"text\" name=\"person[age]\" />');\n // var options = { 'message': \"failed validation\", 'with': /\\d+/, 'scope': { 'name': 'test name' } };\n // element.val('test');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), \"failed validation\");\n// });\n\n// test('when using scopes with replacement', function() {\n // var element = $('<input type=\"text\" name=\"person[age]\" />');\n // var options = { 'message': \"failed validation\", 'with': /\\d+/, 'scope': { 'name': 'test name' } };\n // element.val('test')\n // $('#qunit-fixture').append('<input type=\"text\" name=\"person[name]\" />').find('input[name=\"person[name]\"]').val('other name');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), undefined);\n// });\n\n// test('when validating by scope and mixed focus order', function() {\n // var unique_element = $('#user_email'), scope_element = $('#user_name');\n // unique_element.val('free@test.com');\n // unique_element.trigger('change');\n // unique_element.trigger('focusout');\n // equal($('.message[for=\"user_email\"]').text(), '');\n\n // scope_element.val('test name');\n // scope_element.trigger('change');\n // scope_element.trigger('focusout');\n // equal($('.message[for=\"user_email\"]').text(), 'must be unique');\n// });\n\n// test('when using scopes with replacement as checkboxes', function() {\n // var element = $('<input type=\"text\" name=\"person[age]\" />');\n // var options = { 'message': \"failed validation\", 'with': /\\d+/, 'scope': { 'name': 'test name' } };\n // element.val('test')\n // $('#qunit-fixture')\n // .append('<input type=\"hidden\" name=\"person[name]\" value=\"other name\"')\n // .append('<input type=\"checkbox\" name=\"person[name]\" value=\"test name\"/>')\n // .find('input[name=\"person[name]\"]').val('other name');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), undefined);\n // $('[name=\"person[name]\"]:checkbox')[0].checked = true;\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), 'failed validation');\n// });\n\n// test('when matching uniqueness on a resource with a defined class name', function() {\n // var element = $('<input type=\"text\" name=\"user2[email]\"/>');\n // var options = { 'message': \"failed validation\", 'class': \"active_record_test_module/user2\" };\n // element.val('nottaken@test.com');\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), 'failed validation');\n// });\n\n// test('when allowing blank', function() {\n // var element = $('<input type=\"text\" name=\"user2[email]\" />');\n // var options = { 'message': \"failed validation\", 'with': /\\d+/, 'allowBlank': true };\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), undefined);\n// });\n\n// test('when not allowing blank', function() {\n // var element = $('<input type=\"text\" name=\"user2[email]\" />');\n // var options = { 'message': \"failed validation\", 'with': /\\d+/ };\n // equal(Ember.Validations.validators.remote.uniqueness(model, property, options), \"failed validation\");\n// });\n\n// test('when matching local uniqueness for nested has-many resources', function() {\n // $('#qunit-fixture')\n // .append($('<form />', {\n // action: '/users',\n // 'data-validate': true,\n // method: 'post',\n // id: 'new_user_2'\n // }))\n // .find('form')\n // .append($('<input />', {\n // name: 'profile[user_attributes][0][email]',\n // id: 'user_0_email',\n // }))\n // .append($('<input />', {\n // name: 'profile[user_attributes][1][email]',\n // id: 'user_1_email',\n // }));\n\n // Ember.Validations.forms['new_user_2'] = {\n // type: 'ActionView::Helpers::FormBuilder',\n // input_tag: '<div class=\"field_with_errors\"><span id=\"input_tag\" /><label for=\"user_name\" class=\"message\"></label></div>',\n // label_tag: '<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>',\n // validators: { 'user[email]':{\"uniqueness\":[{\"message\": \"must be unique\"}]}}\n // }\n // $('form#new_user_2').call();\n\n // var user_0_email = $('#user_0_email'),\n // user_1_email = $('#user_1_email'),\n // options = { 'message': \"must be unique\" };\n\n // user_0_email.val('not-locally-unique');\n // user_1_email.val('not-locally-unique');\n\n // equal(Ember.Validations.validators.remote.uniqueness(user_1_email, options), undefined);\n // equal(Ember.Validations.validators.local.uniqueness(user_1_email, options), \"must be unique\");\n// });\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/uniqueness_test");minispade.register('ember-validations/~tests/validators/url_test', "(function() {var model, Model, options, validator;\nvar pass = function() {\n ok(true, 'validation is working');\n};\nvar fail = function() {\n ok(false, 'validation is not working');\n};\n\nmodule('URL Validator', {\n setup: function() {\n Model = Ember.Object.extend(Ember.Validations.Mixin);\n Ember.run(function() {\n model = Model.create();\n });\n }\n});\n\n// Test allowBlank\n\ntest('when allowing blank', function() {\n options = { 'message': 'failed validation', allowBlank: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when not allowing blank', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', '');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n// Test with valid URLs\n\ntest('when valid url with domain', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when valid uri with domain and port', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when valid uri with domain, port and path', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path/to/file.html');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when valid uri with domain, port, path and query', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path/to/file.html?one=two&three=four');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when valid uri with domain, port, path, query and fragment', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path/to/file.html?one=two&three=four#anchor=drop');\n });\n deepEqual(validator.errors, []);\n});\n\n\n// Tests to fail validation\n\ntest('when uri has space', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://example . com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when protocol not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'invalid://www.example.com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when domain not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.******.com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when port not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com:PORT');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when path not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path to file');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\ntest('when query not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path/to/file.html?one two');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n\ntest('when anchor not valid', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com/path/to/file.html?one=two&three=four#anchor drop');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n\n// Test domainOnly\n\ntest('when domain only', function() {\n options = { 'message': 'failed validation', domainOnly: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'www.example.com');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when domain only not valid', function() {\n options = { 'message': 'failed validation', domainOnly: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n// Protocols\n\ntest('when defined protocols', function() {\n options = { 'message': 'failed validation', protocols: ['https'] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'https://www.example.com');\n });\n deepEqual(validator.errors, []);\n});\n\ntest('when defined protocols not valid', function() {\n options = { 'message': 'failed validation', protocols: ['https'] };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n\n// Test allowPort\n\ntest('when port allowed', function() {\n options = { 'message': 'failed validation', allowPort: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com:80');\n });\n deepEqual(validator.errors, []);\n});\n\n\ntest('when port not allowed', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://www.example.com:80');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n// Test allowUserPass\n\ntest('when username and password allowed', function() {\n options = { 'message': 'failed validation', allowUserPass: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://username:password@example.com');\n });\n deepEqual(validator.errors, []);\n});\n\n\ntest('when username and password not allowed', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://username:password@example.com');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n\n// Test allowIp\n\ntest('when IP allowed', function() {\n options = { 'message': 'failed validation', allowIp: true };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://127.0.0.1');\n });\n deepEqual(validator.errors, []);\n});\n\n\ntest('when IP not allowed', function() {\n options = { 'message': 'failed validation' };\n Ember.run(function() {\n validator = Ember.Validations.validators.local.Url.create({model: model, property: 'attribute', options: options});\n model.set('attribute', 'http://127.0.0.1');\n });\n deepEqual(validator.errors, ['failed validation']);\n});\n\n})();\n//@ sourceURL=ember-validations/~tests/validators/url_test");