Sha256: 02cbcb104dfbd827cbc13cadcdb871e55263fbe3a72ba17580765fe237f4a7df

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

#
# testing ruote
#
# Thu Mar  4 10:24:30 JST 2010
#

require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')

require_json
require 'ruote/context'
require 'ruote/part/template'
require 'ruote/storage/hash_storage'


class UtPartTemplateTest < Test::Unit::TestCase

  class MyParticipant
    include ::Ruote::TemplateMixin

    def initialize

      @context = ::Ruote::Context.new(::Ruote::HashStorage.new)
    end
  end

  DEFAULT = %{
workitem for gonzalo

{
  "wfid": "20100304-bidehachina",
  "expid": "0_0_1"
}

 - 'car'  ==>  "BMW"
 - 'model'  ==>  "BMW 328 Mille Miglia"
  }.strip

  def setup

    @workitem = {
      'fei'=> { 'wfid' => '20100304-bidehachina', 'expid' => '0_0_1' },
      'participant_name' => 'gonzalo',
      'fields' => {
        'car' => 'BMW',
        'model' => 'BMW 328 Mille Miglia'
      }
    }
  end

  def test_default_template

    assert_equal(
      DEFAULT,
      MyParticipant.new.render_default_template(@workitem))

    assert_equal(
      DEFAULT,
      MyParticipant.new.render_template(nil, nil, @workitem))
  end

  def test_file_template

    fn = "#{__FILE__}.template"

    File.open(fn, 'wb') { |f| f.write('the model is ${f:model}') }

    assert_equal(
      'the model is BMW 328 Mille Miglia',
      MyParticipant.new.render_template(fn, nil, @workitem))

    FileUtils.rm_f(fn)
  end

  def test_string_template

    template = %{
My car is a ${f:car}
    }.strip

    assert_equal(
      'My car is a BMW',
      MyParticipant.new.render_template(template, nil, @workitem))
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
ruote-maestrodev-2.2.1 test/unit/ut_19_part_template.rb
ruote-2.2.0 test/unit/ut_19_part_template.rb
ruote-2.1.11 test/unit/ut_19_part_template.rb