Sha256: d5126f8b64d782a137658e4cfe49fe31c3a3a523c769bd42dd748ffe2f1390e4

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe Accelerator do

  before(:all) do
    @accelerator = Accelerator.new
    @accelerator.delete("/test")
  end

  it "should create cache on first request" do
    time = Time.new.to_i
    request.should == time
    body, options = @accelerator.get("/test")
    response_tests(time)
  end

  it "should return same cache on next request" do
    $expires_at = Time.now.to_f.ceil
    request.should == $last_time
    body, options = @accelerator.get("/test")
    response_tests($last_time)
  end

  it "should not expire naturally before 1 second" do
    if Time.now.to_f < $expires_at
      expires_in = $expires_at - Time.now.to_f
      request(0.5 * expires_in).should == $last_time
    end
  end

  it "should expire naturally after 1 second" do
    if Time.now.to_f < $expires_at
      expires_in = $expires_at - Time.now.to_f
      request(expires_in).should == $last_time
    end
    response_tests(Time.new.to_i)
  end

  it "should obey client expiration" do
    @accelerator.expire("/test")
    request.should == $last_time
    response_tests($last_time)
  end

  it "should set cache body from the client" do
    @accelerator.set("/test", "123")
    $expires_at = Time.now.to_f.ceil
    request.should == 123
  end

  it "should not expire naturally before 1 second" do
    if Time.now.to_f < $expires_at
      expires_in = $expires_at - Time.now.to_f
      request(0.5 * expires_in).should == 123
    end
  end

  it "should expire naturally after 1 second" do
    if Time.now.to_f < $expires_at
      expires_in = $expires_at - Time.now.to_f
      request(expires_in).should == 123
    end
    response_tests(Time.new.to_i)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
accelerator-0.1.1 spec/accelerator_spec.rb
accelerator-0.1.0 spec/accelerator_spec.rb