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

Improve compatibility with Ember.ArrayProxy. Fixes #109 #110

Merged
merged 1 commit into from
Jul 7, 2017

Conversation

mwpastore
Copy link
Contributor

@mwpastore mwpastore commented May 22, 2017

Any new test suggestions? Not quite sure how to approach it.

@kellyselden
Copy link
Owner

I'm going to make some changes to ember-macro-test-helpers so it is easier to test with different base classes.

@kellyselden
Copy link
Owner

kellyselden commented Jun 20, 2017

With kellyselden/ember-macro-test-helpers#62, you should be able to structure your tests:

let { subject } = compute({
  baseClass: Ember.ArrayProxy,
  computed: computed('[]', getCallback)
});

getCallback.reset();

subject.pushObject('foo');

assert.deepEqual(getCallback.args, [['foo']]);

The individual functions changed should get unit tested too.

@mwpastore
Copy link
Contributor Author

@kellyselden Great! I'll take a whack at it.

I didn't change the behavior of any functions, per se, just tweaked how they achieve the same results. I think the existing bevy of unit tests should be sufficient? I'll at least add a new unit test for getValue since it has a bit of new behavior.

@mwpastore
Copy link
Contributor Author

mwpastore commented Jun 21, 2017

@kellyselden Okay, please take a look! The sinon stub is weirdly wrapping the ArrayProxy argument in an array; it looks like [arrayProxy] so we have to extract arrayProxy and call toArray() on it to get something usable to pass to assert.deepEqual().

It's currently pointing at your ember-macro-test-helpers feature branch so I can fix that if/when you decide to release that add-on with the new baseClass feature. Just let me know.

Copy link
Owner

@kellyselden kellyselden left a comment

Choose a reason for hiding this comment

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

I think additional tests are needed:

tests\unit\collapse-key-test.js

collapseKey('@each.bar')
collapseKey('[]')

tests\unit\normalize-array-key-test.js

normalizeArrayKey('@each.prop')
normalizeArrayKey('[]')

Then it should be good to go.

@@ -10,5 +11,9 @@ export default function({ context, macro, key } = {}) {
return macro;
}

if (isBlank(macro)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you comment under what conditions this will hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kellyselden
Copy link
Owner

Released that branch in [email protected]

@mwpastore
Copy link
Contributor Author

@kellyselden Thanks for the hand-holding, and thanks for being clear on what you want to see before accepting this patch. I really appreciate it. Here's the latest round of changes, submitted for your approval!

@mwpastore
Copy link
Contributor Author

@kellyselden Any further feedback on this?

@kellyselden
Copy link
Owner

Sorry for letting this sit so long. Going to try to review today.

Copy link
Owner

@kellyselden kellyselden left a comment

Choose a reason for hiding this comment

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

A simplification and module import updates are needed. Thanks in advance.

}

if (atEachIndex === 0) {
return [''];
Copy link
Owner

Choose a reason for hiding this comment

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

I tried this branch out, and I think you want to return []; in this case. Then you can remove the extra blank handling from get-value.js.

Copy link
Contributor Author

@mwpastore mwpastore Jul 6, 2017

Choose a reason for hiding this comment

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

Hrrm, I can't get this to work. With this change, collapsedKeys() returns an empty array, then bundledKeys in createArgs() is an empty array, and getValue() never gets called, so there's no logic anywhere that sets the value at that key to context. What am I missing? I agree that return ['']; is kind of clumsy.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm I will keep digging, maybe I'm wrong.

Copy link
Owner

Choose a reason for hiding this comment

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

So I messed with it a bit, and I was wrong. Your empty string is the best way to handle this. Thanks for schooling me!

@@ -4,6 +4,8 @@ import { module } from 'qunit';
import sinon from 'sinon';
import compute from 'ember-macro-test-helpers/compute';
import namedTest from '../helpers/named-test';
import ArrayProxy from 'ember-controller/proxy';
Copy link
Owner

Choose a reason for hiding this comment

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

This will need to update to new module API that @Turbo87 added please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kellyselden
Copy link
Owner

Finally this bad boy is merged!

@kellyselden kellyselden merged commit 8a9f33a into kellyselden:master Jul 7, 2017
@mwpastore
Copy link
Contributor Author

Huzzah! Thanks Kelly!

@mwpastore mwpastore deleted the fix-array-proxy branch July 7, 2017 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants