Sha256: aa14f23f2bbf2dae6dc2b14a2bec51db2100ded2110483a735842ba11c39d7d6

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

require 'spec/helper'

# Tests the file_cache facility that saves rendered content to files in
# /public and hence serves up the static files for subsequent requests.
class TCActionCache < Ramaze::Controller
  map '/'
  helper :cache

  def index
    rand
  end
  cache :index
end

class TCOtherCache < Ramaze::Controller
  map '/other'
  helper :cache

  def index
    rand
  end
  cache :index
end

class TCIndexCache < Ramaze::Controller
  map '/withparams'
  helper :cache

  def index(somearg = nil)
    rand + somearg.to_f
  end
  alias :nonindex :index

  cache :index, :nonindex
end

describe 'Action rendering' do
  behaves_like 'http'

  FileUtils.mkdir_p(public_root = __DIR__/:public)

  ramaze :file_cache => true, :public_root => public_root

  def req(path)
    r = get(path)
    [ r.content_type, r.body ]
  end

  should 'cache to file' do
    lambda{ req('/') }.should.not.change{ req('/') }
    File.file?(public_root/'index').should == true
  end

  should 'create subdirs as needed' do
    lambda{ req('/other') }.should.not.change{ req('/other') }
    File.file?(public_root/'other/index').should == true
  end

  should 'cache action with params' do
    lambda{ req('/withparams/nonindex/42') }.should.not.change{ req('/withparams/nonindex/42') }
    File.file?(public_root/'withparams/nonindex/42').should == true
  end

  should 'cache index action with params' do
    lambda{ req('/withparams/42') }.should.not.change{ req('/withparams/42') }
    File.file?(public_root/'withparams/42').should == true
  end

  FileUtils.rm_rf public_root
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
Pistos-ramaze-2008.09 spec/ramaze/action/file_cache.rb
manveru-ramaze-2008.08 spec/ramaze/action/file_cache.rb
manveru-ramaze-2008.09 spec/ramaze/action/file_cache.rb
manveru-ramaze-2008.10 spec/ramaze/action/file_cache.rb
ramaze-2008.11 spec/ramaze/action/file_cache.rb