Extracting the InviteRedeemer class from the Invite model in Discourse – Part 2

0
116

In the previous post, the InviteRedeemer struct was extracted in order to isolate the functionality required to redeem an invite.  When we left off, the redeem method had been moved to InviteRedeemer and all the tests were passing which gives the assurance that we have preserved all of the functionality required.

The starting point for the next steps are based around the comments within the method.  Each highlights different pieces of functionality that can be split out into a private method with a name that is indicative of its responsibility. I started by extracting a private method for each of the actions marked by a comment.

At this point, InviteRedeemer looks better because we can see that there are very procedural steps to what is happening but there are still many things that need to be corrected.

The multiple assignments to the result variable as well as the number of times result is passed around shows us that there’s still a lot of work to be done.

One thing it does do is to make the next step of cleaning up the row_count assignment and comparison a little easier to see.  The result of this step is shown below.

This still looks a little weird with the result of the update being checked to see if it is equal to one, but we will deal with that in the next post.

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here