DEV: Use AR enums in reviewables related code (PR #15330)

:construction: :construction: :construction:

GitHub

The title of this pull request changed from “WIP: DEV: Use AR enums in reviewables related code” to "DEV: Use AR enums in reviewables related code

Is there a way to avoid public_send? That’s asking for trouble :stuck_out_tongue:

Other than that use of #public_send, lgtm!

Well it allows to use the automatically defined scopes from AR and if the status isn’t a valid one for whatever reason it will break. #who_did is a protected method and is only used in two places (L36 and L40), we control the value of status, nothing inherits from QueuedPostSerializer so I guess the trouble should be quite contained :slightly_smiling_face: Wdyt?

If it’s used in just two places, with :approved and :rejected as args, I would consider inlining this method. But I guess I’m fine with it as is too. :slightly_smiling_face:

Oh, or a half-way inlining solution would work too, e.g.

def approved_by_id
  scope.approved.last&.created_by_id
end

def rejected_by_id
  scope.rejected.last&.created_by_id
end

protected

# not necessarily the best name 😉
def scope
  object.
    reviewable_histories.
    transitioned.
    order(:created_at)
end

Ah yes this hybrid solution seems nice enough :ok_hand: I’m going to update the PR accordingly :slightly_smiling_face:

Updated! I wasn’t that inspired either and went with #post_history for the name.

Pushing this to 2.9