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 for missing name and add tests #320

Merged
merged 4 commits into from
Feb 14, 2024
Merged

Conversation

FionaDL
Copy link
Member

@FionaDL FionaDL commented Jan 16, 2024

Jira Ticket

DT-455

Motivation / Context

#318 This fixes this issue.
If anyone on the team didn't have a name in Github no name was being saved that user and it was causing issues if a user was attached to a story through an estimation. Updated so that any time there isn't a name we can fall back on the email so we won't have this issue anywhere again in the future. Also added a test to make sure this was working.

QA / Testing Instructions

Try adding changing a user in the test db to not have a name and make sure madmin still works.
Follow the steps in issue #318 to make sure it is still fixed.

Screenshots:


I will abide by the code of conduct.

spec/models/user_spec.rb Outdated Show resolved Hide resolved

# Returns the email if the user doesn't have a name in Github
def name
read_attribute(:name) || email
Copy link
Member

@JuanVqz JuanVqz Jan 23, 2024

Choose a reason for hiding this comment

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

is the email required/validated to be present? what if the email is nil?

Copy link
Member

Choose a reason for hiding this comment

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

@JuanVqz Users come from GitHub and we always collect their email address. So there is no way for the email to be nil.

@FionaDL On the other hand, this doesn't look very straightforward, why do we need the call to read_attribute?

I would recommend two different alternatives:

Suggested change
read_attribute(:name) || email
name || email

Or:

Suggested change
read_attribute(:name) || email
name.presence || email

Copy link
Member Author

Choose a reason for hiding this comment

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

@etagwerker I tested with your suggestions, but I think it is creating an infinite loop, I get "stack level too deep (SystemStackError)".

I think we could do self[:name] || email if it feels more straightforward. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@FionaDL Oh, I understand why that would do that.

How about this instead?

  def name_or_email
    name || email
  end

Copy link
Member Author

@FionaDL FionaDL Feb 7, 2024

Choose a reason for hiding this comment

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

@etagwerker I could do that, but then we will have to be sure that name_or_email gets called everywhere that we would want to call user.name, right?

Copy link
Member

Choose a reason for hiding this comment

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

When it comes to presentation logic, I think it is usually best to have this sort of code in a view helper file.

So maybe it would be best to move this code to the application_helper file and later change the references in the view to this new method.

So yeah, that means that all view files that call user.name will now have to call something like display_name(user)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @etagwerker I think I updated with what you are aiming towards.

Copy link
Member

@etagwerker etagwerker left a comment

Choose a reason for hiding this comment

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

@FionaDL I think this is very close. I think there is one last place to add this:

comments << "#{comment.user.name}: #{comment.body}"

Copy link
Member

@etagwerker etagwerker left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@etagwerker etagwerker merged commit afb39c8 into main Feb 14, 2024
3 checks passed
@etagwerker etagwerker deleted the DT-455-fix-name-issue branch February 14, 2024 16:54
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.

4 participants