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

[462] status overhaul #1220

Merged
merged 1 commit into from
Apr 20, 2015
Merged

[462] status overhaul #1220

merged 1 commit into from
Apr 20, 2015

Conversation

esoterik
Copy link
Collaborator

@esoterik esoterik commented Apr 6, 2015

resolves #462

@@ -42,15 +42,14 @@ def bar_span_positioning_fix
def manage_reservations_btn # rubocop:disable all
return if (cannot? :manage, Reservation) || @reservation.reserver.id.nil?
if (can? :override, :reservation_errors) &&
@reservation.approval_status == 'requested'
@reservation.flags & Reservation::FLAGS[:request]
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome bitmasking! but I think it'll be more readable and less prone to screwing up if we wrap it in a higher level model method to access flags. Something like

def flag(flag_type)
  return self.flags  & Reservation::FLAGS[flag_type]
end

or something

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, we could set up getter and setter methods (get_flag, set_flag) to make this easier to use / understand in the future.

@squidgetx
Copy link
Contributor

Is it necessary to note the flag and the status as requested? (As in, we can't just have 'requested' as a first-class status? And move it to 'reserved' when it's approved?)

@orenyk orenyk changed the title 462 status overhaul [462] status overhaul Apr 6, 2015
where('checked_out IS NOT NULL').not_returned.recent

scope :not_available, lambda {
where(status: Reservation.statuses.values_at(
Copy link
Contributor

Choose a reason for hiding this comment

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

According to this, we should be able to write this query as where(status: [:reserved, :checked_out]), unless I'm missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why did we need the compact call? Shouldn't the where call return an array of Reservation objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

compact is unnecessary, but for some reason where(status: [:reserved, :checked_out]) is not equivalent to where(status: Reservation.statuses.values_at( *%w(reserved checked_out)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Really not sure what's going on there...

Copy link
Contributor

Choose a reason for hiding this comment

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

Not equivalent in the sense that it's returning a different set of objects, or in the sense that it's not working?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for the record: we can't use the more simple query because it's not supported in rails 4.1

@orenyk
Copy link
Contributor

orenyk commented Apr 7, 2015

Ok, this looks really good! I left a bunch of comments throughout, mostly in the scopes but a few more elsewhere. One critical issue that needs to be resolved is the fact that most of your specs aren't actually testing anything; it looks like RSpec doesn't actually evaluate assertions unless you call .to on them.

Overall, though, this seems pretty close to me; I think we can definitely get it merged in for v5.2.0. Nice job!

@@ -4,7 +4,7 @@ task email_missed_reservations: :environment do
# user to inform them
if AppConfig.first.send_notifications_for_deleted_missed_reservations
missed_reservations = Reservation.where(
"(approval_status = 'approved' or approval_status = 'auto')").missed
'flags & ? = 0', Reservation::FLAGS[:missed_email_sent]).missed
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm, is there no way for us to write a scope for flags?

@esoterik esoterik force-pushed the 462_status_overhaul branch from 83c202e to 1cd5c12 Compare April 17, 2015 00:14
@esoterik
Copy link
Collaborator Author

I think this is done!

@@ -259,7 +262,9 @@ def mark_checked_in(res, checkout_length)
def mark_checked_out(res)
if rand < MISSED_CHANCE
res.checked_out = nil
res.status = 'mmissed'
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

@orenyk
Copy link
Contributor

orenyk commented Apr 17, 2015

Ok, left a few more comments; in particular, let's test out the migration at least once manually before we commit. Nice work!

@orenyk
Copy link
Contributor

orenyk commented Apr 17, 2015

Looks good to me! This one is a big one, @squidgetx, do you want to take one last look at it before we squash / merge?

closes #462
- updated test for reservation model
- add status enum to reservation model
- add flags column to reservation
- replaced all other instances of not_returned scope with not_available
- removed denied_requests scope, replaced with denied
- status validations
- removed approval status
- prevent status from changing when in a final state
- human readable status moved to model
- replace not_available scope with active
@esoterik esoterik force-pushed the 462_status_overhaul branch from 5e06bdb to 766e9ab Compare April 20, 2015 00:32
@orenyk
Copy link
Contributor

orenyk commented Apr 20, 2015

:shipit:

orenyk added a commit that referenced this pull request Apr 20, 2015
@orenyk orenyk merged commit e56baa0 into master Apr 20, 2015
Reservation.where('checked_out IS NOT NULL and checked_in IS NULL and '\
'due_date >= ? and due_date < ?',
Time.zone.today, Time.zone.today + 1.day)
upcoming_reservations = Reservation.due_soon
Copy link
Contributor

Choose a reason for hiding this comment

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

@esoterik here's the issue - we only added the date condition to the due_soon scope, but not the checked_out condition. It's probably just this scope then, I'll merge #1322 back into #1288.

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.

Reservation Status Overhaul
3 participants