Skip to content

Small refactor and a bit clean up #535

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 3 commits into from
Aug 21, 2023

Conversation

khezam
Copy link

@khezam khezam commented May 17, 2023

The logic of ==(other) method was a bit confusing so I tried to clean it up to make it easy to read. I also moved new_from_response class method of Data into class << self for consistency.

Let me know if there is anything I can change and make it better.

@khezam khezam marked this pull request as ready for review May 17, 2023 16:09
@khezam khezam requested a review from a team as a code owner May 17, 2023 16:09
@ecoologic
Copy link
Contributor

Thank you @khezam for your contribution ❤️

I might agree in principle on the == changes, but I'm concerned about unexpected changes for all existing clients.

This PR also lacks testing, but don't worry about test/spec live just yet, at this point they are expected to fail, we'll run them if we decide to proceed.

cc @snatchblock, what do you think of these changes?

@khezam
Copy link
Author

khezam commented Jun 9, 2023

My pleasure @ecoologic :)

I see your concerns about unexpected changes for all existing clients and the lack of testing. I was/am expecting the existing tests would catch any unexpected behaviors since this PR only cleans up the current logic of ==.

I'm happy to add a test coverage if needed.

Let me know :)

@khezam
Copy link
Author

khezam commented Jun 12, 2023

Hey @ecoologic, any update on this PR?

Copy link
Contributor

@snatchblock snatchblock left a comment

Choose a reason for hiding this comment

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

Hi Khezam,

Thank you for the cleanup. Can you add test cases for the code to ensure these changes does not impact the library behaviour? Specifically if objects that before didn’t match with equality might start matching.

Thank you. We will merge this once the test cases and validation is done.

@khezam
Copy link
Author

khezam commented Aug 9, 2023

Hi @snatchblock,

I definitely can add test cases, but this PR does not need test cases because it does not add/remove from the existing logic, it's only rearranging the existing logic. The test cases already exist here, and if I add test cases, they'll be exactly the same.

The two methods below are exactly the same but the only difference is that the top one is easy to read.

def ==(other)
    return false unless other

    return true if other.object_id == object_id

    return other.id && (other.id == id) if other.is_a?(Data)

    return id == other if other.is_a?(Integer)

    warn "Trying to compare #{other.class} to a Resource
      from #{caller.first}"
 end
  def ==(other)
      return true if other.object_id == object_id

      if other && !(other.is_a?(Data) || other.is_a?(Integer))
        warn "Trying to compare #{other.class} to a Resource from #{caller.first}"
      end

     if other.is_a?(Data)
        other.id && other.id == id
     elsif other.is_a?(Integer)
        id == other
     else
        false
     end
  end

Let me know if I'm missing anything and I'm happy to add test cases accordingly.

@ecoologic ecoologic changed the base branch from master to RED-1856-eq-cleanup August 21, 2023 00:22
@ecoologic ecoologic merged commit b792814 into zendesk:RED-1856-eq-cleanup Aug 21, 2023
@ecoologic ecoologic mentioned this pull request Aug 21, 2023
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