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

Avoid using meta-programming for solving code duplication. #1457

Merged
merged 4 commits into from Jan 11, 2019
Merged

Avoid using meta-programming for solving code duplication. #1457

merged 4 commits into from Jan 11, 2019

Conversation

delbetu
Copy link

@delbetu delbetu commented Jan 3, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

Small refactor avoid using meta-programming for solving code duplication.

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

@CLAassistant
Copy link

CLAassistant commented Jan 3, 2019

CLA assistant check
All committers have signed the CLA.

private

def callback_for(provider)
raise '9999999999999999999999'
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you left a raise.

Copy link
Author

Choose a reason for hiding this comment

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

@abraham Yes this is intentional, tests don't work locally for me.
I wanted to know which tests were covering this line, so I created this commit and let the CI run the specs.
For my surprise nothing break, I'll create a test for covering these lines before refactoring.
The PR is not ready for review yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might I suggest a descriptive error in the future like raise 'Checking if run on CI' or similar.

This might be difficult to test with its reliance on external services.

@delbetu delbetu changed the title [WIP] Avoid using meta-programming for solving code duplication. Avoid using meta-programming for solving code duplication. Jan 7, 2019
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Jan 7, 2019
@delbetu
Copy link
Author

delbetu commented Jan 7, 2019

After extracting the method out from the class_eval codeclimate detected high complexity over the method.
I'll keep working on that later.

def callback_for(provider)
cta_variant = request.env["omniauth.params"]["state"].to_s
@user = AuthorizationService.new(request.env["omniauth.auth"], current_user, cta_variant).get_user
if @user.persisted? && @user.valid?
Copy link
Contributor

Choose a reason for hiding this comment

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

Extracting the if and elsif conditions into their own methods like if persisted_and_valid and elsif persisted_but_username_taken or something like that would clean this up and solve this CodeClimate issue.

Copy link
Author

Choose a reason for hiding this comment

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

@benhalpern thanks for the suggestion.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Jan 11, 2019
@benhalpern benhalpern merged commit a52af3d into forem:master Jan 11, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Jan 11, 2019
@delbetu delbetu deleted the avoid-class-eval branch January 14, 2019 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants