Skip to content
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

update task model tests #547

Merged
merged 1 commit into from Oct 2, 2016

Conversation

WenInCode
Copy link
Contributor

What's in this PR?

Update task unit model tests

References

@begedin
Copy link
Contributor

begedin commented Oct 2, 2016

I discussed this with @joshsmith and we think we should sort of look at ember-side model tests as if they were phoenix-side view tests.

@filipecrosk did this when submitting his PR, by adding a test to assert all required attributes are accounted for. You can see an example at https://github.com/filipecrosk/code-corps-ember/blob/2197e7926fa6f3b1d30eee63a3705623e2a15f18/tests/unit/models/project-test.js#L17

Adding something like this here would probably bee a good idea.

On one hand, we could look at this as "requiring the contributor to add a new attribute to the model twice", but really, we should look at a test like that as a fail-safe to make sure the contributor hasn't accidentally removed a model attribute. Sort of a "you did this, are you sure?".

@WenInCode
Copy link
Contributor Author

I've updated this to test attribute existence. I tried a few methods and the simplest was the Object.keys route that @filipecrosk used in his PR.

Copy link
Contributor

@joshsmith joshsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 we should either create an issue or start solving here, but I wouldn't proceed with further model tests without DRYing things up like suggested below.

assert.ok(attributes.includes('markdown'), 'task should have the markdown attribute');
assert.ok(attributes.includes('number'), 'task should have the number attribute');
assert.ok(attributes.includes('taskType'), 'task should have the taskType attribute');
assert.ok(attributes.includes('status'), 'task should have the status attribute');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would move up one to stay alpha-ordered.

const relationship = get(task, 'relationshipsByName').get('user');

assert.equal(relationship.key, 'user', 'has relationship with user');
assert.equal(relationship.kind, 'belongsTo', 'kind of relationship is belongsTo');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are starting to seem really duplicative. Wondering if we can instead do something like assert.hasManyRelationship('task', 'user') or assert.belongsToRelationship('task', 'project') which just wraps everything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshsmith ya that's a good idea. Want to put that in a separate PR? Then I can circle back and update all of these.

@@ -17,6 +22,72 @@ test('it exists', function(assert) {
assert.ok(!!model);
});

test('it should have all of it\'s attributes', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \' isn't needed here, since it's "its".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

english 👍

@joshsmith
Copy link
Contributor

@WenInCode improved but could use some minor changes first, then you can decide whether to open a separate issue (we'll need one to circle back anyway) or handle here.

@WenInCode
Copy link
Contributor Author

@joshsmith I brought in those helpers, and addressed remaining feedback. How does this look now?

Copy link
Contributor

@joshsmith joshsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change to make here, then good to go and apply to other PRs.

// source: https://gist.github.com/he9qi/b6354a81a0672dc63294
export function testForHasMany(name, many) {
test('should have many ' + many, function(assert) {
const Model = this.store().modelFor(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would insert assert.expect(2); before everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I'll update this

testForBelongsTo('task', 'user');
testForHasMany('task', 'comments');
testForHasMany('task', 'commentUserMentions');
testForHasMany('task', 'taskUserMentions');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks so much better, don't you think? Way easier to write, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya it's a lot better

@joshsmith
Copy link
Contributor

Rebase, squash, and merge! 🎉

@WenInCode WenInCode merged commit 02cae93 into code-corps:develop Oct 2, 2016
@WenInCode WenInCode deleted the update-task-model-tests branch October 2, 2016 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants