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

Commit 8bcee88

Browse files
committed
Merge pull request #1480 from YaleSTC/1479_edit_overdue_55
[1479] Fix issue with editing overdue reservations
2 parents 54d49d1 + 1686bf8 commit 8bcee88

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
* This file will be updated whenever a new release is put into production.
33
* Any problems should be reported via the "report an issue" link in the footer of the application.
44

5-
## v5.5.5 - 2016-02-03
5+
## v5.5.5 - 2016-02-05
66
### Fixed
7+
* Updated Rails Admin to allow editing of reservations ([#1449](https://github.com/YaleSTC/reservations/issues/1449#issuecomment-180207219)).
78
* The start and end dates of reports can now actually be changed ([#1476](https://github.com/YaleSTC/reservations/issues/1476)).
9+
* The reservation overdue parameter correctly updates when editing the due date of checked out reservations ([#1479](https://github.com/YaleSTC/reservations/issues/1479)).
810

911
## v5.5.4 - 2016-02-02
1012
### Fixed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ gem 'cancancan', '~> 1.10.1'
2020
gem 'whenever', '~> 0.9.4'
2121

2222
# administrative panel
23-
gem 'rails_admin', '~> 0.6.6'
23+
gem 'rails_admin', '~> 0.8.1'
2424

2525
# ldap integration
2626
gem 'net-ldap', '~> 0.11'

Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ GEM
154154
guard (~> 2.1)
155155
guard-compat (~> 1.1)
156156
rspec (>= 2.99.0, < 4.0)
157-
haml (4.0.6)
157+
haml (4.0.7)
158158
tilt
159159
highline (1.7.2)
160160
hike (1.2.3)
@@ -269,7 +269,7 @@ GEM
269269
rails_12factor (0.0.3)
270270
rails_serve_static_assets
271271
rails_stdout_logging
272-
rails_admin (0.6.6)
272+
rails_admin (0.8.1)
273273
builder (~> 3.1)
274274
coffee-rails (~> 4.0)
275275
font-awesome-rails (>= 3.0, < 5)
@@ -455,7 +455,7 @@ DEPENDENCIES
455455
rails (~> 4.1.9)
456456
rails4-autocomplete (~> 1.1.1)
457457
rails_12factor (~> 0.0.3)
458-
rails_admin (~> 0.6.6)
458+
rails_admin (~> 0.8.1)
459459
rake (~> 10.4.2)
460460
rdoc (~> 4.2.0)
461461
redcarpet (~> 3.2.2)

app/models/reservation.rb

+19-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Reservation < ActiveRecord::Base
2020
validate :status_final_state
2121
validate :not_in_past, :available, :check_banned, on: :create
2222

23+
# correctly update the overdue flag if necessary
24+
before_save :update_overdue, if: :checked_out?
25+
2326
nilify_blanks only: [:notes]
2427

2528
# see https://robots.thoughtbot.com/whats-new-in-edge-rails-active-record-enum
@@ -338,13 +341,20 @@ def update(current_user, new_params, new_notes) # rubocop:disable all
338341
name = 'Due Date'
339342
old_val = diff[0].to_s(:long)
340343
new_val = diff[1].to_s(:long)
344+
if checked_out?
345+
if overdue? && diff[1] > Time.zone.today - 1.day
346+
overdue_str = "\nReservation marked as not overdue."
347+
elsif !overdue? && diff[1] <= Time.zone.today - 1.day
348+
overdue_str = "\nReservation marked as overdue."
349+
end
350+
end
341351
when 'equipment_item_id'
342352
name = 'Item'
343353
old_val = diff[0] ? EquipmentItem.find(diff[0]).md_link : 'nil'
344354
new_val = diff[1] ? EquipmentItem.find(diff[1]).md_link : 'nil'
345355
end
346356
self.notes += "\n#{name} changed from " + old_val + ' to '\
347-
+ new_val + '.'
357+
+ new_val + '.' + overdue_str.to_s
348358
end
349359
end
350360
# rubocop:enable BlockNesting
@@ -399,4 +409,12 @@ def markdown_listify(items)
399409
def md_link
400410
"[res. \##{id}](#{reservation_url(self, only_path: false)})"
401411
end
412+
413+
private
414+
415+
def update_overdue
416+
return true unless checked_out?
417+
self.overdue = due_date <= Time.zone.today - 1.day
418+
true # so we don't halt the transaction if it's not overdue
419+
end
402420
end

spec/features/reservations_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@
524524
end
525525

526526
context 'cannot renew if the reservation is overdue' do
527-
before { @res.update_attributes(overdue: true) }
527+
before { @res.update_columns(overdue: true) }
528528

529529
it_behaves_like 'cannot see renew button'
530530
end

spec/lib/tasks/flag_rake_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
it 'flags reservations due yesterday as overdue' do
1212
@res.update_attributes(
1313
FactoryGirl.attributes_for(:overdue_reservation))
14-
@res.update_attributes(overdue: false)
14+
@res.update_columns(overdue: false)
1515
expect { subject.invoke }.to(
1616
change { Reservation.find(@res.id).overdue }.from(false).to(true))
1717
end
@@ -24,9 +24,9 @@
2424
it 'flags past overdue reservations' do
2525
old_res = FactoryGirl.build(:overdue_reservation)
2626
old_res.assign_attributes(start_date: Time.zone.today - 7.days,
27-
due_date: Time.zone.today - 6.days,
28-
overdue: false)
27+
due_date: Time.zone.today - 6.days)
2928
old_res.save!(validate: false)
29+
old_res.update_columns(overdue: false)
3030

3131
expect { subject.invoke }.to \
3232
change { Reservation.find(old_res.id).overdue }

0 commit comments

Comments
 (0)