Skip to content

Commit

Permalink
Use Time instead of DateTime in Revocable concern to play nice with AR
Browse files Browse the repository at this point in the history
Fixes NoMethodError - undefined method 'getlocal' when calling the
/oauth/token path.

Active record works better with Time, as opposed to DateTime objects,
see issue doorkeeper-gem#668 for more details. Also see
https://gist.github.com/pixeltrix/e2298822dd89d854444b for more about when to use DateTime.
  • Loading branch information
emeryamiller committed Jun 2, 2015
1 parent 8b59c77 commit 3af2f51
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ User-visible changes worth mentioning.

---

## 3.0.0 (rc2)

- [#671] Fixes NoMethodError - undefined method 'getlocal' when calling
the /oauth/token path. Switch from using a DateTime object to update
AR to using a Time object. (Issue #668)

## 3.0.0 (rc1)

### Backward incompatible changes
Expand Down
4 changes: 2 additions & 2 deletions lib/doorkeeper/models/concerns/revocable.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Doorkeeper
module Models
module Revocable
def revoke(clock = DateTime)
def revoke(clock = Time)
update_attribute :revoked_at, clock.now
end

def revoked?
!!(revoked_at && revoked_at <= DateTime.now)
!!(revoked_at && revoked_at <= Time.now)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/models/revocable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

describe :revoked? do
it 'is revoked if :revoked_at has passed' do
allow(subject).to receive(:revoked_at).and_return(DateTime.now - 1000)
allow(subject).to receive(:revoked_at).and_return(Time.now - 1000)
expect(subject).to be_revoked
end

it 'is not revoked if :revoked_at has not passed' do
allow(subject).to receive(:revoked_at).and_return(DateTime.now + 1000)
allow(subject).to receive(:revoked_at).and_return(Time.now + 1000)
expect(subject).not_to be_revoked
end

Expand Down

0 comments on commit 3af2f51

Please sign in to comment.