Sha256: b786e107f96ad36874656794a9943d05c8ec366e20b24a3911743bfbed76db52

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

require_relative "../spec_helper"

begin
  require 'tilt/erb'
rescue LoadError
  warn "tilt not installed, skipping precompiled_templates plugin test"  
else
describe "precompile_templates plugin" do 
  it "adds support for template precompilation" do
    app(:bare) do
      plugin :render, :views=>'spec/views'
      plugin :precompile_templates
      route do |r|
        @a = 1
        render('iv')
      end
    end

    app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].must_be_nil
    app.precompile_templates 'spec/views/iv.erb'
    app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].wont_equal nil
    app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].instance_variable_get(:@compiled_method)[[]].wont_equal nil
    body.strip.must_equal '1'
  end

  it "adds support for template precompilation with :locals" do
    app(:bare) do
      plugin :render, :views=>'spec/views'
      plugin :precompile_templates
      route do |r|
        render('about', :locals=>{:title=>'1'})
      end
    end

    app.render_opts[:cache][File.expand_path('spec/views/about.erb')].must_be_nil
    app.precompile_templates 'spec/views/about.erb', :locals=>[:title]
    app.render_opts[:cache][File.expand_path('spec/views/about.erb')].wont_equal nil
    app.render_opts[:cache][File.expand_path('spec/views/about.erb')].instance_variable_get(:@compiled_method)[[:title]].wont_equal nil
    body.strip.must_equal '<h1>1</h1>'
  end

  it "adds support for template precompilation with :inline" do
    app(:bare) do
      plugin :render, :views=>'spec/views'
      plugin :precompile_templates
      route do |r|
        render(:inline=>'a', :cache_key=>'a')
      end
    end

    app.render_opts[:cache]['a'].must_be_nil
    app.precompile_templates :inline=>'a', :cache_key=>'a'
    app.render_opts[:cache]['a'].wont_equal nil
    app.render_opts[:cache]['a'].instance_variable_get(:@compiled_method)[[]].wont_equal nil
    body.strip.must_equal "a"
  end
end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
roda-3.24.0 spec/plugin/precompile_templates_spec.rb
roda-3.23.0 spec/plugin/precompile_templates_spec.rb
roda-3.22.0 spec/plugin/precompile_templates_spec.rb
roda-3.21.0 spec/plugin/precompile_templates_spec.rb
roda-3.20.0 spec/plugin/precompile_templates_spec.rb
roda-3.19.0 spec/plugin/precompile_templates_spec.rb
roda-3.18.0 spec/plugin/precompile_templates_spec.rb
roda-3.17.0 spec/plugin/precompile_templates_spec.rb
roda-3.16.0 spec/plugin/precompile_templates_spec.rb
roda-3.15.0 spec/plugin/precompile_templates_spec.rb
roda-3.14.1 spec/plugin/precompile_templates_spec.rb
roda-3.14.0 spec/plugin/precompile_templates_spec.rb
roda-3.13.0 spec/plugin/precompile_templates_spec.rb
roda-3.12.0 spec/plugin/precompile_templates_spec.rb
roda-3.11.0 spec/plugin/precompile_templates_spec.rb
roda-3.10.0 spec/plugin/precompile_templates_spec.rb
roda-3.9.0 spec/plugin/precompile_templates_spec.rb
roda-3.8.0 spec/plugin/precompile_templates_spec.rb
roda-3.7.0 spec/plugin/precompile_templates_spec.rb
roda-3.6.0 spec/plugin/precompile_templates_spec.rb