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
arcabouco-0.2.13 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
classiccms-0.7.5 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
classiccms-0.7.4 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
classiccms-0.7.3 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/tilt-1.3.4/test/tilt_compilesite_test.rb
challah-1.0.0 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
classiccms-0.7.2 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
classiccms-0.7.1 vendor/bundle/gems/tilt-1.3.3/test/tilt_compilesite_test.rb
swipe-rails-0.0.5 vendor/bundle/gems/tilt-1.4.1/test/tilt_compilesite_test.rb
active_mailer-0.0.9 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.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_compilesite_test.rb