Skip to content

Allow defining remote method without isStatic flag #173

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

Merged
merged 1 commit into from
May 31, 2016

Conversation

0candy
Copy link
Contributor

@0candy 0candy commented Apr 7, 2016

Connect to https://github.com/strongloop-internal/scrum-loopback/issues/813

  • Update generator-loopback remote-method to make isStatic prompt not required. If not specified, it will default to true if method name does not contain prototype. and false otherwise.
  • Add new validation for method name to allow for prototype. otherwise . is still invalid.
  • Add unit test cases.

@0candy 0candy self-assigned this Apr 7, 2016
@0candy 0candy added the #review label Apr 7, 2016
@0candy 0candy force-pushed the update_remote_method branch from db48529 to b814032 Compare April 7, 2016 20:19
@0candy 0candy changed the title Include new style of defining remote method Allow defining remote method without isStatic flag Apr 7, 2016
@0candy 0candy force-pushed the update_remote_method branch 2 times, most recently from ed88078 to 31750fe Compare April 7, 2016 20:59
@0candy 0candy assigned bajtos and unassigned 0candy Apr 7, 2016
default: true
default: function(answers) {
return !answers.methodName.match(/^prototype\.(.*)$/);
}
Copy link
Member

Choose a reason for hiding this comment

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

Indentation - L101 and L102 are indented by one extra level.

@bajtos
Copy link
Member

bajtos commented Apr 8, 2016

@0candy could you please describe in pull request description what exactly are you changing here? I am mostly able to get that by reading the code, however other people and especially our users may not.

@bajtos bajtos assigned 0candy and unassigned bajtos Apr 8, 2016
@bajtos
Copy link
Member

bajtos commented Apr 8, 2016

As I commented in strongloop/loopback-workspace#273, I would like to preserve the current workspace API, i.e. a remote prototype method should still have the name without prototype. prefix and isStatic flag set to true.

@0candy 0candy force-pushed the update_remote_method branch from 31750fe to fb1f66a Compare April 8, 2016 15:07
@0candy 0candy assigned bajtos and unassigned 0candy Apr 13, 2016
var definition = common.readJsonSync('common/models/car.json');
var methods = definition.methods || {};
expect(methods).to.have.property('prototype.myRemote');
expect(methods['prototype.myRemote']).to.eql({
Copy link
Member

Choose a reason for hiding this comment

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

This is true when the project is using LoopBack 3.0, i.e. when common.createDummyProject creates a LB 3.0 project. However, since 3.0 was not released yet, I think we are using LB 2.0 and thus the entry should use the old convention (name + isStatic). Am I missing something?

@bajtos
Copy link
Member

bajtos commented Apr 13, 2016

The implementation itself looks good to me, however the tests are suspicious. Let's figure out the loopback-workspace part fist and then come back to generator-loopback.

@0candy
Copy link
Contributor Author

0candy commented Apr 13, 2016

The change in generator-loopback was that either methods of defining the remote method should work. Only loopback-workspace distinguishes between LB 2.0 and 3.0.

@0candy 0candy force-pushed the update_remote_method branch 2 times, most recently from 67806a5 to a9448c7 Compare April 25, 2016 18:22
* @returns {String|Boolean}
*/
exports.checkRemoteMethodName = function(name) {
if (name.match(/\./) && !name.match(/^prototype\.(.*)$/)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is . character allowed after prototype.? I believe the current code allows that.

I think you need to change the second regexp to /^prototype\.([^.]*)$/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't the \. after prototype include the . character?

Copy link
Member

Choose a reason for hiding this comment

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

Here is the test case to add to your unit-tests:

testValidationRejectsValue(validateRemoteMethodName, 'prototype.dotted.method');

@bajtos bajtos assigned 0candy and unassigned bajtos Apr 29, 2016
type: 'confirm',
default: true
default: function(answers) {
return !answers.methodName.match(/^prototype\.(.*)$/);
Copy link
Member

Choose a reason for hiding this comment

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

If we allow methodName to start with prototype. prefix, then I think we need to remove that prefix before we pass the name to ModelMethod constructor. See strongloop/loopback-workspace#273 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

If we allow methodName to start with prototype. prefix, then I think we need to remove that prefix before we pass the name to ModelMethod constructor. See strongloop/loopback-workspace#273 (comment)

@0candy ^^^ thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, hence I removed the prefix before passing the name to the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

@bajtos
Copy link
Member

bajtos commented Apr 29, 2016

@0candy could you please add a unit-test to verify that the generator correctly handles the case where the user enters prototype.instanceMethod as the method name?

@0candy 0candy force-pushed the update_remote_method branch from a9448c7 to 15ec7ee Compare May 2, 2016 22:05
@0candy 0candy assigned bajtos and unassigned 0candy May 2, 2016
* @returns {String|Boolean}
*/
exports.validateRemoteMethodName = function(name) {
if (name.match(/\./) && !name.match(/^prototype\.(.*)$/)) {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the \. after prototype include the . character?

Here is the test case to add to your unit-tests:

testValidationRejectsValue(validateRemoteMethodName, 'prototype.dotted.method');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, sorry. I misunderstood. Thought you said it doesn't allow prototype., but you meant any other . after prototype.. Fixed.

@bajtos bajtos assigned 0candy and unassigned bajtos May 3, 2016
@0candy 0candy assigned bajtos and unassigned 0candy May 3, 2016
@bajtos
Copy link
Member

bajtos commented May 4, 2016

Here is the test case to add to your unit-tests:

testValidationRejectsValue(validateRemoteMethodName, 'prototype.dotted.method');

@0candy I don't see that test case in the unit-tests. It makes me wonder, what is the reason behind that decision? We it perhaps left out by a mistake?

@0candy
Copy link
Contributor Author

0candy commented May 4, 2016

*/
exports.validateRemoteMethodName = function(name) {
if (name.match(/\./) && !name.match(/^prototype\.([^.]*)$/)) {
return 'Name cannot contain special characters . ' +
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: I think "special characters ." is not grammatically correct. How about the following?

'Name cannot contain "." characters except the dot in "prototype." prefix'

@bajtos
Copy link
Member

bajtos commented May 4, 2016

One more nitpick, the patch LGTM otherwise. Please squash the commits before landing, no further review is needed.

@bajtos bajtos assigned 0candy and unassigned bajtos May 4, 2016
@bajtos
Copy link
Member

bajtos commented May 4, 2016

Oh, and please make sure CI builds are passing, they are all red ATM.

@0candy 0candy force-pushed the update_remote_method branch 3 times, most recently from 49afc41 to 0ca7f26 Compare May 4, 2016 20:43
@0candy
Copy link
Contributor Author

0candy commented May 4, 2016

CI is all failing on master right now.

@0candy
Copy link
Contributor Author

0candy commented May 5, 2016

Yeoman's latest release has a breaking change in prompts. We probably have to update our code.
yeoman/generator#926

The latest version of yeoman-environment 1.6.1 is breaking the unit test. The promptModule is causing problems.

@superkhau
Copy link
Contributor

@0candy Please let me know when you got this working. The fails are also making me cautious of merging #180 (comment)

@0candy 0candy force-pushed the update_remote_method branch from 0ca7f26 to 6959163 Compare May 31, 2016 17:42
@0candy 0candy merged commit 4a70425 into master May 31, 2016
@0candy 0candy deleted the update_remote_method branch May 31, 2016 18:38
@0candy 0candy removed the #review label May 31, 2016
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.

3 participants