Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

1608 extract checkout object #1667

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

zeffman
Copy link
Contributor

@zeffman zeffman commented Feb 19, 2017

resolves #1608

--create manage route for managing users' reservations
--extract checkin/checkout functionality to manage controller
--extract as much functionality to checkoutHelper service object as possible

@zeffman zeffman force-pushed the 1608_extract_checkout_object branch 3 times, most recently from 1c87731 to bd43812 Compare February 22, 2017 00:53
resolves #1608

--create manage route for managing users' reservations
--extract checkin/checkout functionality to manage controller
--extract as much functionality to checkoutHelper service object as possible

--replace set_reservation before action with ||=

--put repeated before_action into application controller
@zeffman zeffman force-pushed the 1608_extract_checkout_object branch from 80003de to a4ab639 Compare March 31, 2017 19:59
Copy link
Collaborator

@esoterik esoterik left a comment

Choose a reason for hiding this comment

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

Looking good overall, except for the missing tests

Left a few suggestions to make a new form object and to restructure your current service object a bit

return unless @user.role == 'banned'
flash[:error] = 'This user is banned and cannot check out equipment.'
params[:banned] = true
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be renamed -- it does more than set the user

before_action :set_user, only: [:show, :checkout]
before_action :set_reservation, only: [:send_receipt]

private
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should swap the order of the public and private sections

# Overdue validation
return unless handle_overdue_reservations
true
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

all these checks can live inside a service object -- check out these examples from vesta:
service object, controller method, and handle_action

you can probably do something very similar by adding a less-generalized handle_action to this controller

render :show, layout: 'application'
end

def checkout
Copy link
Collaborator

Choose a reason for hiding this comment

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

this process should also live in a service object (example)

end

CheckoutHelper.update_tos(@user)
CheckoutHelper.send_checkout_receipts(checked_out_reservations)
Copy link
Collaborator

Choose a reason for hiding this comment

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

these methods belong in the batch/bulk service object

prep_receipt_page(check_in_set: [], check_out_set: checked_out_reservations)
end

def checkin
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as the above -- this method should live inside a service object

end

# for editing reservations; not for checkout or check-in
def update # rubocop:disable all
@reservation = Reservation.find(params[:id])
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should be able to just call reservation, right?

@@ -0,0 +1,3 @@
# frozen_string_literal: true
class Manage < ActiveRecord::Base
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be a form object that handles all of the checks and bulk processing that you currently have in the controller (example)

@@ -0,0 +1,3 @@
# frozen_string_literal: true
class Manage < ActiveRecord::Base
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs to inherit from ActiveRecord::Base?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also this should probably be renamed to something that implies that this is for reservations only

@@ -0,0 +1,67 @@
# frozen_string_literal: true
class CheckoutHelper
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is really good but needs a bit of reorganizing:

  • The only methods on self should be check_in! and check_out!, which should read like this:
def self.check_out!(**params)
  new(**params).check_out!
end
  • There should be an initialize method that sets some instance variables so you don't have to pass them around. It should use keyword args.
  • Any method that can raise an un-rescued exception should end in a !

Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to be tested!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract Checkin/Checkout to Service Object
3 participants