Class: TestSubstitutionSupport

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/lti2_commons/test/test_substitution_support.rb

Constant Summary collapse

ARGV =
['', "--name", "test_nested_resolver"]

Instance Method Summary collapse

Instance Method Details

#resource_transform_sample(name) ⇒ Object



34
35
36
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 34

def resource_transform_sample(name)
  name.reverse
end

#setupObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 23

def setup
  @resolver = Resolver.new
  @resolver.add_resolver "user", {'name' => "jt", 'id' => "1234"}
  @resolver.add_resolver "user", {'name' => "jt", 'id' => "9876", 'sport' => 'judo'}
  @resolver.add_resolver "course", lambda { |x| "COURSE-#{x}"}
  @resolver.add_resolver "resource", self.method(:resource_transform_sample)
  @resolver.add_resolver "testobject", TestObject.new
  @resolver.add_resolver "testnest", {'nestlevel' => 'inner'}
  @resolver.add_resolver "*",  {'ip'=> '192.168.2.177'}
end

#test_add_blockObject



46
47
48
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 46

def test_add_block
  assert_equal "COURSE-anything", @resolver.resolve('course.anything')
end

#test_add_hashObject



38
39
40
41
42
43
44
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 38

def test_add_hash
  assert_equal "jt", @resolver.resolve('user.name')
  assert_equal "judo", @resolver.resolve('user.sport')
  assert_equal "192.168.2.177", @resolver.resolve('user.ip')
  assert_equal "192.168.2.177", @resolver.resolve('foo.ip')
  assert_equal "user.notfound", @resolver.resolve('user.notfound')
end

#test_internal_methodObject



50
51
52
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 50

def test_internal_method
  assert_equal "fdsa", @resolver.resolve('resource.asdf')
end

#test_nested_resolverObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 58

def test_nested_resolver
  outer_resolver = Resolver.new
  outer_resolver.add_resolver "testnest", {'nestlevel' => 'outer'}
  outer_resolver.add_resolver "inner", @resolver

  assert_equal "inner", @resolver.resolve('testnest.nestlevel')
  assert_equal "outer", outer_resolver.resolve('testnest.nestlevel')
  assert_equal "jt", outer_resolver.resolve('user.name')
  assert_equal "COURSE-anything", outer_resolver.resolve('course.anything')
end

#test_testobjectObject



54
55
56
# File 'lib/lti2_commons/test/test_substitution_support.rb', line 54

def test_testobject
  assert_equal "john.thomas", @resolver.resolve('testobject.name')
end