Sha256: 2455a0f6e72729fe96cd17b739159d6aca04f52a4e1f770711bf6d07304ff791

Contents?: true

Size: 1.23 KB

Versions: 165

Compression:

Stored size: 1.23 KB

Contents

require 'contest'
require 'tilt'
require 'thread'

class CompileSiteTest < Test::Unit::TestCase
  def setup
    GC.start
  end

  class CompilingTemplate < Tilt::Template
    def prepare
    end

    def precompiled_template(locals)
      @data.inspect
    end
  end

  class Scope
  end

  test "compiling template source to a method" do
    template = CompilingTemplate.new { |t| "Hello World!" }
    template.render(Scope.new)
    method = template.send(:compiled_method, [])
    assert_kind_of UnboundMethod, method
  end

  # This test attempts to surface issues with compiling templates from
  # multiple threads.
  test "using compiled templates from multiple threads" do
    template = CompilingTemplate.new { 'template' }
    main_thread = Thread.current
    10.times do |i|
      threads =
        (1..50).map do |j|
          Thread.new {
            begin
              locals = { "local#{i}" => 'value' }
              res = template.render(self, locals)
              thread_id = Thread.current.object_id
              res = template.render(self, "local#{thread_id.abs.to_s}" => 'value')
            rescue => boom
              main_thread.raise(boom)
            end
          }
        end
      threads.each { |t| t.join }
    end
  end
end

Version data entries

165 entries across 140 versions & 26 rubygems

Version Path
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
classiccms-0.7.0 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.7/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.5/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/tilt-1.3.5/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.5/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/tilt-1.3.5/test/tilt_compilesite_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.7/test/tilt_compilesite_test.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.3.7/test/tilt_compilesite_test.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
tilt-1.4.1 test/tilt_compilesite_test.rb
tilt-1.4.0 test/tilt_compilesite_test.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/test/tilt_compilesite_test.rb
challah-1.0.0.beta2 vendor/bundle/gems/tilt-1.3.7/test/tilt_compilesite_test.rb
challah-1.0.0.beta vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
challah-1.0.0.beta vendor/bundle/gems/tilt-1.3.6/test/tilt_compilesite_test.rb
tilt-1.3.7 test/tilt_compilesite_test.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/test/tilt_compilesite_test.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/test/tilt_compilesite_test.rb