test/webgen/test_item_tracker.rb in webgen-1.0.0.beta3 vs test/webgen/test_item_tracker.rb in webgen-1.0.0

- old
+ new

@@ -15,11 +15,15 @@ def item_id(data) #:nodoc: data end def item_data(data) #:nodoc: - 'alcn' + TestItemTracker::Data[data].to_s + if TestItemTracker::Data.has_key?(data) + 'alcn' + TestItemTracker::Data[data].to_s + else + raise "Unkown key" + end end def item_changed?(iid, old_data) #:nodoc: 'alcn' + TestItemTracker::Data[iid].to_s != old_data end @@ -28,24 +32,24 @@ [iid] end end -class TestItemTracker < MiniTest::Unit::TestCase +class TestItemTracker < Minitest::Test - DummyNode = Struct.new(:alcn) + DummyNode = Struct.new(:alcn, :node_info) Data = {'/alcn' => 'mydata'} def test_functionality # Needed stub objects website = Struct.new(:blackboard, :cache, :tree).new website.blackboard = blackboard = Webgen::Blackboard.new website.cache = cache = Webgen::Cache.new - node = DummyNode.new('/alcn') - other = DummyNode.new('/other') + node = DummyNode.new('/alcn', {}) + other = DummyNode.new('/other', {}) website.tree = {'/alcn' => node, '/other' => other} tracker = Webgen::ItemTracker.new(website) tracker.register('Sample') tracker.add(node, :sample, '/alcn') @@ -69,9 +73,26 @@ # Node should not be changed anymore blackboard.dispatch_msg(:after_node_written, node) blackboard.dispatch_msg(:after_all_nodes_written) blackboard.dispatch_msg(:before_all_nodes_written) refute(tracker.node_changed?(node)) + + # Node should be changed because item id got invalid + blackboard.dispatch_msg(:after_node_written, node) + blackboard.dispatch_msg(:after_all_nodes_written) + Data.delete('/alcn') + blackboard.dispatch_msg(:before_all_nodes_written) + assert(tracker.node_changed?(node)) + + # Node should not be changed anymore, again + blackboard.dispatch_msg(:after_node_written, node) + blackboard.dispatch_msg(:after_all_nodes_written) + blackboard.dispatch_msg(:before_all_nodes_written) + refute(tracker.node_changed?(node)) + + # Re-add needed item and data + Data['/alcn'] = 'other' + tracker.add(node, :sample, '/alcn') # Test the initial loading of the cache data cache[:item_tracker_data] = { :node_dependencies => {'/alcn' => [[:sample, '/alcn']], 'alcn' => ['data']}, :item_data => {[:sample, '/alcn'] => 'alcnother', [:sample, 'other'] => 'alcnother'}