-
-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Has many validator should work with simple arrays/objects #116
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import PresenceValidator from 'dummy/validators/presence'; | |
import { validator, buildValidations } from 'ember-cp-validations'; | ||
import { moduleFor, test } from 'ember-qunit'; | ||
|
||
var Validators = { | ||
const Validators = { | ||
presence(value, options, model, attr) { | ||
var isValid = !Ember.isNone(value); | ||
if (Ember.isNone(value)) { | ||
|
@@ -23,6 +23,14 @@ var Validations = buildValidations({ | |
lastName: validator(Validators.presence) | ||
}); | ||
|
||
const BelongsToValidations = buildValidations({ | ||
friend: validator('belongs-to') | ||
}); | ||
|
||
const HasManyValidations = buildValidations({ | ||
friends: validator('has-many') | ||
}); | ||
|
||
moduleFor('foo', 'Integration | Validations | Model Relationships', { | ||
integration: true, | ||
beforeEach() { | ||
|
@@ -33,10 +41,6 @@ moduleFor('foo', 'Integration | Validations | Model Relationships', { | |
test("belong to validation - no cycle", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var BelongsToValidations = buildValidations({ | ||
friend: validator('belongs-to') | ||
}); | ||
|
||
var user2 = setupObject(this, Ember.Object.extend(Validations), { | ||
firstName: 'John' | ||
}); | ||
|
@@ -64,10 +68,6 @@ test("belong to validation - no cycle", function(assert) { | |
test("belong to validation - with cycle", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var BelongsToValidations = buildValidations({ | ||
friend: validator('belongs-to') | ||
}); | ||
|
||
var user = setupObject(this, Ember.Object.extend(BelongsToValidations)); | ||
user.set('friend', user); | ||
|
||
|
@@ -87,13 +87,59 @@ test("belong to validation - with cycle", function(assert) { | |
|
||
}); | ||
|
||
test("has-many relationship is async", function(assert) { | ||
this.register('validator:has-many', HasManyValidator); | ||
test("has-many relationship is sync", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var friend = setupObject(this, Ember.Object.extend(Validations), { | ||
firstName: 'John' | ||
}); | ||
|
||
var user = setupObject(this, Ember.Object.extend(HasManyValidations), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let |
||
friends: [friend] | ||
}); | ||
|
||
const { | ||
validations, | ||
model | ||
} = user.get('validations').validateSync(); | ||
|
||
assert.equal(model, user, 'expected model to be the correct model'); | ||
assert.deepEqual(validations.get('content').getEach('attribute').sort(), ['friends'].sort()); | ||
|
||
let friends = validations.get('content').findBy('attribute', 'friends'); | ||
|
||
assert.equal(friends.get('isValid'), false); | ||
assert.equal(friends.get('message'), 'lastName should be present'); | ||
}); | ||
|
||
test("has-many relationship is sync with proxy", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var HasManyValidations = buildValidations({ | ||
friends: validator('has-many') | ||
var friend = setupObject(this, Ember.Object.extend(Validations), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let |
||
firstName: 'John' | ||
}); | ||
|
||
var user = setupObject(this, Ember.Object.extend(HasManyValidations), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let |
||
friends: Ember.ArrayProxy.create({ content: Ember.A([friend]) }) | ||
}); | ||
|
||
const { | ||
validations, | ||
model | ||
} = user.get('validations').validateSync(); | ||
|
||
assert.equal(model, user, 'expected model to be the correct model'); | ||
assert.deepEqual(validations.get('content').getEach('attribute').sort(), ['friends'].sort()); | ||
|
||
let friends = validations.get('content').findBy('attribute', 'friends'); | ||
|
||
assert.equal(friends.get('isValid'), false); | ||
assert.equal(friends.get('message'), 'lastName should be present'); | ||
}); | ||
|
||
test("has-many relationship is async", function(assert) { | ||
this.register('validator:has-many', HasManyValidator); | ||
|
||
var friend = setupObject(this, Ember.Object.extend(Validations), { | ||
firstName: 'Offir' | ||
}); | ||
|
@@ -126,10 +172,6 @@ test("has-many relationship is async", function(assert) { | |
test("belongs-to relationship is async", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var BelongsToValidations = buildValidations({ | ||
friend: validator('belongs-to') | ||
}); | ||
|
||
var friend = setupObject(this, Ember.Object.extend(Validations), { | ||
firstName: 'Offir' | ||
}); | ||
|
@@ -163,10 +205,6 @@ test("belongs-to relationship is async", function(assert) { | |
test("belongs-to relationship returns undefined", function(assert) { | ||
this.register('validator:belongs-to', BelongsToValidator); | ||
|
||
var BelongsToValidations = buildValidations({ | ||
friend: validator('belongs-to') | ||
}); | ||
|
||
var user = setupObject(this, Ember.Object.extend(BelongsToValidations), { | ||
friend: new Ember.RSVP.Promise((resolve, reject) => { | ||
resolve({}); // validations object will be undefined | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let