Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

How to correctly use travel_to in rspec test

$
0
0

Searched a lot of examples but still can't get this to work

Seems pretty straightforward, I need to create a record, and then travel an hour in time ahead to make sure it has expired.

Records are being set in Redis and set to expire after 1 hour, I have actually verified this is happening by manual test.

@redis.expire("#{params[:key]}", 3600) # Expire inserts after 1 hour

but the test just keeps adding up the values

it 'it does not get results that are older than one hour' do  key = 'active_books'  post("/inventory/#{key}?value=30")  travel_to(1.hours.from_now) do    get("/inventory/#{key}/sum")    parsed_body = JSON.parse(response.body)    expect(parsed_body).to eql(0)  endend

So when getting the records here it should return 0 because they expire. In real time I have tested this with the app, and at the moment it is actually set to expire in 60 seconds, which is happening. But in this test it returns the value 30 which was just created, even though if manually testing this it expires after a minute. If I run the test after a minutes it also only returns 30, not 60, so the record is expiring as expected, this is just not traveling forward in time (which is what I assumed it was suppose to do)

parsed_body returns a count, a sum of all the records. But none should be found, and again, on the app it is actually doing this but I want to get this test to reflect that accurately.


Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>