Sha256: 2f604510233c4c2dae542bcd9c3f223b9f2fcf9906613f93d8bd72512d87f5e6

Contents?: true

Size: 1.7 KB

Versions: 25

Compression:

Stored size: 1.7 KB

Contents

# Load the helper class
require File.join(File.dirname(__FILE__), '..', 'test_helper')

module TaliaCore

  # Test the ActiveSource
  class ActiveSourcePredicateTest < Test::Unit::TestCase

    def setup
      setup_once(:flush) { TestHelper::flush_store }
    end

    def test_each_cached
      src = ActiveSource.new('http://pred_test/each_cached')
      src[N::RDF.rew] << 'value'
      cached = []
      src.each_cached_wrapper do |w|
        cached << w
      end
      assert_equal(2, cached.size)
    end
    
    def test_cached_predicate
      src = ActiveSource.new('http://pred_test/cached_predicate')
      src[N::RDF.rew] << 'value'
      # We assume that the cached thing is now in the internal structure
      w = src.instance_variable_get(:@type_cache)[N::RDF.rew.to_s]
      items = w.instance_variable_get(:@items)
      assert_kind_of(Array, items)
      assert_equal(['value'], items.collect { |i| i.value })
      assert_same(src[N::RDF.rew], w)
    end

    def test_cached_after_save
      src = ActiveSource.new('http://pred_test/cached_after_save')
      src[N::RDF.rew] << 'value'
      src.save!
      # We assume that the cached thing is now in the internal structure
      w = src.instance_variable_get(:@type_cache)[N::RDF.rew.to_s]
      items = w.send(:items) # This should correctly reload the items
      assert_kind_of(Array, items)
      assert_equal(['value'], items.collect { |i| i.value })
      assert_same(src[N::RDF.rew], w)
      # Check if the RDF was updated. The RDF must be updated from the cached wrappers
      # before the wrappers are saved themselves
      assert_equal(['value'], src.my_rdf[N::RDF.rew], "Mismatch of the RDF, maybe the callbacks in wrong order?")
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
talia_core-0.7.0 test/talia_core/active_source_predicate_test.rb
talia_core-0.5.4 test/talia_core/active_source_predicate_test.rb
talia_core-0.5.3 test/talia_core/active_source_predicate_test.rb
talia_core-0.5.2 test/talia_core/active_source_predicate_test.rb
talia_core-0.5.1 test/talia_core/active_source_predicate_test.rb
talia_core-0.5.0 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.22 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.20 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.19 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.18 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.17 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.16 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.15 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.14 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.13 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.12 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.11 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.10 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.9 test/talia_core/active_source_predicate_test.rb
talia_core-0.4.8 test/talia_core/active_source_predicate_test.rb