Serialize the `last_request_at` entry as an Integer #2954

Merged
merged 1 commit into from Apr 3, 2014

Conversation

Projects
None yet
3 participants
Contributor

lucasmazza commented Mar 29, 2014

Possible solution for #2930.

My first though was of adding support for timedout? to receive Strings, but this logic really belongs to the callback. Thinking out loud on Campfire I realized that storing the object as an integer would make more sense than bending Strings around, but I don't know if this change might break existing session data on apps out there.

Regarding to the testing bits, the existing integration tests felt a bit pointless due the semantics of numbers vs dates - between requests not just the values are the same, but the objects in memory too.

I wanted to cover this better with a unit test for the callback code, but the current state of just passing the blocks to Warden makes it impossible. What do you guys think of extracting these blocks to classes like Devise::Hooks::Timeoutable instead? I can do this on another Pull Request.

Serialize the `last_request_at` entry as an Integer
Pushing the `Time` object inside the session has inconsistencies
across different serializers and we should use a more primitive type
so we don't need any specific parsing logic for the JSON serializer.
@@ -9,6 +9,11 @@
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
last_request_at = warden.session(scope)['last_request_at']
+
+ if last_request_at.is_a? Integer
@rafaelfranca

rafaelfranca Mar 29, 2014

Collaborator

Will YAML and JSON read this values as integer? I thought JSON read as string.

@lucasmazza

lucasmazza Mar 29, 2014

Contributor

JSON support numbers too. If we want to store this as a String we would have to cast it back to Integer before casting it to a Time 🏃

@rafaelfranca

rafaelfranca Mar 29, 2014

Collaborator

Cool.

@@ -9,6 +9,11 @@
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
last_request_at = warden.session(scope)['last_request_at']
+
+ if last_request_at.is_a? Integer
+ last_request_at = Time.at(last_request_at).utc
@josevalim

josevalim Mar 29, 2014

Owner

I think Time.at always returns the value in UTC. :)

@lucasmazza

lucasmazza Mar 29, 2014

Contributor

nope :/

require 'time'
now = Time.now.utc
# 2014-03-29 13:52:18 UTC
Time.at(now.to_i)
# 2014-03-29 10:52:18 -0300
Time.at(now.to_i).utc
# 2014-03-29 13:52:18 UTC
Owner

josevalim commented Mar 29, 2014

:shipit:

lucasmazza added a commit that referenced this pull request Apr 3, 2014

Merge pull request #2954 from plataformatec/lm-last-request-at-json-s…
…erialization

Serialize the `last_request_at` entry as an Integer

@lucasmazza lucasmazza merged commit 6027787 into master Apr 3, 2014

1 check passed

default The Travis CI build passed
Details

@lucasmazza lucasmazza deleted the lm-last-request-at-json-serialization branch Apr 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment