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

Fix for #142 #143

Closed
wants to merge 1 commit into from
Closed

Fix for #142 #143

wants to merge 1 commit into from

Conversation

shadyvd
Copy link

@shadyvd shadyvd commented Jan 25, 2019

Explicit check for not-null and not-undefined when setting the default values from the configuration.

The current code will not set defaultPrepend / defaultReplace to "false" because the check will fail. The Pr fixes #142

@ghost
Copy link

ghost commented Jun 14, 2019

@shadyvd thank you for fixing this! Could you add a test that asserts the behavior? By adding the failing test, applying your fix should ensure it passes and make it safe for us to further improve the logic in the future.

@@ -7,7 +7,7 @@ function capitalize(key) {

let defaults = {};
['separator', 'prepend', 'replace'].forEach(function (key) {
if (config.pageTitle && config.pageTitle[key]) {
if (config.pageTitle && (config.pageTitle[key] !== null) && (config.pageTitle[key] !== undefined)) {
Copy link

Choose a reason for hiding this comment

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

NOTE: Adding safety checks is a great idea. I wonder if we can make this logic clearer using a more functional programming style:

let defaults = {};
let {pageTitle = {}} = config;
['separator', 'prepend', 'replace']
  .filter(key => {
    return key in pageTitle && pageTitle[key];
  })
  .forEach(function (key) {
    defaults[`default${capitalize(key)}`] = pageTitle[key];
  });

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if a functional programming style makes it clearer, actually. How about if we go to ember utils, and use isPresent, instead?

Do you think

if(config.pageTitle && isPresent(config.pageTitle[key]))...

is clearer?

@ghost ghost added the Needs Tests label Jun 27, 2019
@ghost
Copy link

ghost commented Jan 24, 2020

@shadyvd can you add tests that assert the conditionals introduced here? Thanks 🚀

@cah-brian-gantzler
Copy link
Contributor

Given that the config is an import, how would you even write a test to use varying configs?

Shouldn't this code be done in the init of the service? Anyone that would want to extend this service would completely lose the config default code.

You could also use either of the following getOwner(this).resolveRegistration('config:environment') or getOwner(this).factoryFor('config:environment').class. they both work. Now sure if one is better than the other, but it would allow in the tests to register a config (register it before the very first access) so that you could test various configs.

If needed I can put together a PR taking this approach if you would like?

@knownasilya
Copy link
Contributor

@cah-briangantzler sounds good to me.

@shadyvd
Copy link
Author

shadyvd commented Mar 20, 2020

My apologies for dropping the ball on this. I'll try and get the tests done using the approach suggested by @cah-briangantzler in the next two or three days.

@cah-brian-gantzler
Copy link
Contributor

Seems I must have missed the sounds good and never did a PR either. Sorry. Currently time is a little short.

@knownasilya
Copy link
Contributor

Resolved in #168

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.

3 participants