wonkavision 0.5.4 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/CHANGELOG.rdoc +28 -16
  2. data/Gemfile +5 -0
  3. data/LICENSE.txt +21 -21
  4. data/Rakefile +47 -47
  5. data/lib/wonkavision.rb +75 -74
  6. data/lib/wonkavision/acts_as_oompa_loompa.rb +22 -22
  7. data/lib/wonkavision/event_binding.rb +21 -21
  8. data/lib/wonkavision/event_context.rb +9 -9
  9. data/lib/wonkavision/event_coordinator.rb +75 -75
  10. data/lib/wonkavision/event_handler.rb +15 -15
  11. data/lib/wonkavision/event_namespace.rb +79 -79
  12. data/lib/wonkavision/event_path_segment.rb +35 -35
  13. data/lib/wonkavision/message_mapper.rb +30 -30
  14. data/lib/wonkavision/message_mapper/indifferent_access.rb +30 -26
  15. data/lib/wonkavision/message_mapper/map.rb +241 -153
  16. data/lib/wonkavision/persistence/mongo_mapper_adapter.rb +32 -32
  17. data/lib/wonkavision/persistence/mongoid_adapter.rb +32 -0
  18. data/lib/wonkavision/plugins.rb +30 -30
  19. data/lib/wonkavision/plugins/business_activity.rb +92 -92
  20. data/lib/wonkavision/plugins/business_activity/event_binding.rb +15 -15
  21. data/lib/wonkavision/plugins/callbacks.rb +182 -182
  22. data/lib/wonkavision/plugins/event_handling.rb +111 -111
  23. data/lib/wonkavision/plugins/timeline.rb +79 -79
  24. data/lib/wonkavision/version.rb +3 -3
  25. data/test/business_activity_test.rb +31 -31
  26. data/test/event_handler_test.rb +68 -69
  27. data/test/event_namespace_test.rb +108 -108
  28. data/test/event_path_segment_test.rb +41 -41
  29. data/test/log/test.log +817 -18354
  30. data/test/map_test.rb +315 -201
  31. data/test/message_mapper_test.rb +20 -20
  32. data/test/test_activity_models.rb +72 -72
  33. data/test/test_helper.rb +70 -63
  34. data/test/timeline_test.rb +55 -61
  35. data/test/wonkavision_test.rb +9 -9
  36. metadata +72 -12
  37. data/wonkavision.gemspec +0 -97
@@ -1,21 +1,21 @@
1
- require "test_helper"
2
-
3
- class Wonkavision::MessageMapperTest < ActiveSupport::TestCase
4
- context "Wonkavision::MessageMapper.execute" do
5
- setup do
6
- Wonkavision::MessageMapper.register("test_map") do
7
- context["i_was_here"] = true
8
- end
9
- end
10
- should "evaluate the named block against a new map" do
11
- data = {}
12
- Wonkavision::MessageMapper.execute("test_map",data)
13
- assert data["i_was_here"]
14
- end
15
- should "raise an error if the map is missing" do
16
- assert_raise RuntimeError do
17
- Wonkavision::MessageMapper.execute("I'm not really here", {})
18
- end
19
- end
20
- end
1
+ require "test_helper"
2
+
3
+ class Wonkavision::MessageMapperTest < ActiveSupport::TestCase
4
+ context "Wonkavision::MessageMapper.execute" do
5
+ setup do
6
+ Wonkavision::MessageMapper.register("test_map") do
7
+ context["i_was_here"] = true
8
+ end
9
+ end
10
+ should "evaluate the named block against a new map" do
11
+ data = {}
12
+ Wonkavision::MessageMapper.execute("test_map",data)
13
+ assert data["i_was_here"]
14
+ end
15
+ should "raise an error if the map is missing" do
16
+ assert_raise RuntimeError do
17
+ Wonkavision::MessageMapper.execute("I'm not really here", {})
18
+ end
19
+ end
20
+ end
21
21
  end
@@ -1,72 +1,72 @@
1
- unless defined?(::TestEventHandler)
2
- class TestEventHandler
3
- include Wonkavision::EventHandler
4
-
5
- def self.knids
6
- @@knids ||= []
7
- end
8
-
9
- def self.callbacks
10
- @@callbacks ||= []
11
- end
12
-
13
- def self.reset
14
- @@knids = []
15
- @@callbacks = []
16
- end
17
-
18
- before_event :before
19
- def before
20
- TestEventHandler.callbacks << {:kind=>"before_event",:path=>event_context.path}
21
- end
22
-
23
- after_event do |handler|
24
- TestEventHandler.callbacks << {:kind=>"after_event", :path=>handler.event_context.path}
25
- end
26
-
27
- event_namespace :vermicious
28
-
29
- handle :knid do |data,path|
30
- TestEventHandler.knids << [data,path]
31
- end
32
-
33
- #handle events in the vermicious namespace
34
- handle "*" do |data,path|
35
- TestEventHandler.knids << [data,path] if path !~ /.*knid/
36
- end
37
-
38
- #handle ALL events in any namespace
39
- handle "/*" do |data,path|
40
- TestEventHandler.knids << [data,path] if path !~ /^vermicious.*/
41
- end
42
-
43
- end
44
-
45
- class TestBusinessActivity
46
- include MongoMapper::Document
47
-
48
- acts_as_timeline
49
-
50
- event_namespace :test
51
- correlate_by :test_id
52
-
53
- milestone :ms1, :evt1
54
- milestone :ms2, :evt2
55
- milestone :ms3, :evt3, '/not_test/evt4'
56
-
57
- event :e1, :evt5, :correlate_by=>{:event=>:alt_event_id, :model=>:alt_model_id}
58
-
59
- map /not_test\/.*/i do
60
- import "evt4_test_map"
61
- string 'modified_another_field'=> "'#{context["another_field"]}' WAS SERVED!! OH YEAH!! IN-YOUR-FACE!!"
62
- end
63
-
64
- key :alt_model_id, String
65
- end
66
-
67
- Wonkavision::MessageMapper.register("evt4_test_map") do
68
- string 'test_id'
69
- date 'event_time'
70
- end
71
-
72
- end
1
+ unless defined?(::TestEventHandler)
2
+ class TestEventHandler
3
+ include Wonkavision::EventHandler
4
+
5
+ def self.knids
6
+ @@knids ||= []
7
+ end
8
+
9
+ def self.callbacks
10
+ @@callbacks ||= []
11
+ end
12
+
13
+ def self.reset
14
+ @@knids = []
15
+ @@callbacks = []
16
+ end
17
+
18
+ before_event :before
19
+ def before
20
+ TestEventHandler.callbacks << {:kind=>"before_event",:path=>event_context.path}
21
+ end
22
+
23
+ after_event do |handler|
24
+ TestEventHandler.callbacks << {:kind=>"after_event", :path=>handler.event_context.path}
25
+ end
26
+
27
+ event_namespace :vermicious
28
+
29
+ handle :knid do |data,path|
30
+ TestEventHandler.knids << [data,path]
31
+ end
32
+
33
+ #handle events in the vermicious namespace
34
+ handle "*" do |data,path|
35
+ TestEventHandler.knids << [data,path] if path !~ /.*knid/
36
+ end
37
+
38
+ #handle ALL events in any namespace
39
+ handle "/*" do |data,path|
40
+ TestEventHandler.knids << [data,path] if path !~ /^vermicious.*/
41
+ end
42
+
43
+ end
44
+
45
+ class TestBusinessActivity
46
+ include Wonkavision::Mongoid::Activity
47
+
48
+ acts_as_timeline
49
+
50
+ event_namespace :test
51
+ correlate_by :test_id
52
+
53
+ milestone :ms1, :evt1
54
+ milestone :ms2, :evt2
55
+ milestone :ms3, :evt3, '/not_test/evt4'
56
+
57
+ event :e1, :evt5, :correlate_by=>{:event=>:alt_event_id, :model=>:alt_model_id}
58
+
59
+ map /not_test\/.*/i do
60
+ import "evt4_test_map"
61
+ string 'modified_another_field'=> "'#{context["another_field"]}' WAS SERVED!! OH YEAH!! IN-YOUR-FACE!!"
62
+ end
63
+
64
+ field :alt_model_id, :type=>String
65
+ end
66
+
67
+ Wonkavision::MessageMapper.register("evt4_test_map") do
68
+ string 'test_id'
69
+ date 'event_time'
70
+ end
71
+
72
+ end
@@ -1,63 +1,70 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
-
3
- require "rubygems"
4
- require "mongo_mapper"
5
- require 'active_support/test_case'
6
- require "shoulda"
7
-
8
- dir = File.dirname(__FILE__)
9
- require File.join(dir,"..","lib","wonkavision")
10
-
11
- dir = File.expand_path(File.dirname(__FILE__))
12
- logdir = File.join(dir,'log')
13
- Dir.mkdir(logdir) unless File.directory?(logdir)
14
- MongoMapper.setup(YAML.load_file(File.join(dir,'config', 'database.yml')), "test", {
15
- :logger => Logger.new(File.join(logdir,'test.log')),
16
- :passenger => false
17
- })
18
-
19
- module ActiveSupport
20
- class TestCase
21
- def setup
22
-
23
- end
24
- def teardown
25
- MongoMapper.database.collections.each do |coll|
26
- coll.drop unless coll.name =~ /(.*\.)?system\..*/
27
- end
28
- Time.reset #Return Time.now to its original state
29
- end
30
-
31
- # Make sure that each test case has a teardown
32
- # method to clear the db after each test.
33
- def inherited(base)
34
- base.define_method teardown do
35
- super
36
- end
37
- base.define_method setup do
38
- super
39
- end
40
- end
41
- end
42
- end
43
- #This seems like an odd approach - why not just alias now, you ask
44
- #well, I did, and for whatever reason, got stack overflows
45
- #whenever I'd try to run the test suite. So...um...this doesn't
46
- #overflow the stack, so it will do.
47
- class Time
48
- @@old_now = method(:now)
49
- class << self
50
- def now=(new_now)
51
- @@new_now = new_now.to_time
52
- def Time.now
53
- @@new_now
54
- end
55
- end
56
-
57
- def reset
58
- def Time.now
59
- @@old_now.call
60
- end
61
- end
62
- end
63
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
+ require "rubygems"
4
+ require 'bundler'
5
+ Bundler.setup
6
+ require "mongoid"
7
+ require "erb"
8
+ require 'active_support/test_case'
9
+ require "shoulda"
10
+
11
+ dir = File.dirname(__FILE__)
12
+ require File.join(dir,"..","lib","wonkavision")
13
+
14
+ dir = File.expand_path(File.dirname(__FILE__))
15
+ logdir = File.join(dir,'log')
16
+ Dir.mkdir(logdir) unless File.directory?(logdir)
17
+
18
+ mcfg_file = File.join(dir,'config','database.yml')
19
+ msettings = YAML.load(ERB.new(File.new(mcfg_file).read).result)
20
+
21
+ Mongoid.configure do |config|
22
+ config.from_hash(msettings["test"])
23
+ config.logger = Logger.new(File.join(logdir,'test.log'))
24
+ end
25
+
26
+ module ActiveSupport
27
+ class TestCase
28
+ def setup
29
+
30
+ end
31
+ def teardown
32
+ Mongoid.master.collections.each do |coll|
33
+ coll.drop unless coll.name =~ /(.*\.)?system\..*/
34
+ end
35
+ Time.reset #Return Time.now to its original state
36
+ end
37
+
38
+ # Make sure that each test case has a teardown
39
+ # method to clear the db after each test.
40
+ def inherited(base)
41
+ base.define_method teardown do
42
+ super
43
+ end
44
+ base.define_method setup do
45
+ super
46
+ end
47
+ end
48
+ end
49
+ end
50
+ #This seems like an odd approach - why not just alias now, you ask
51
+ #well, I did, and for whatever reason, got stack overflows
52
+ #whenever I'd try to run the test suite. So...um...this doesn't
53
+ #overflow the stack, so it will do.
54
+ class Time
55
+ @@old_now = method(:now)
56
+ class << self
57
+ def now=(new_now)
58
+ @@new_now = new_now.to_time
59
+ def Time.now
60
+ @@new_now
61
+ end
62
+ end
63
+
64
+ def reset
65
+ def Time.now
66
+ @@old_now.call
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,61 +1,55 @@
1
- require "test_helper"
2
- require "test_activity_models"
3
-
4
- class TimelineTest < ActiveSupport::TestCase
5
- context "TestBusinessActivity" do
6
- should "create the appropriate keys" do
7
- assert TestBusinessActivity.keys.keys.include?("timeline")
8
- assert TestBusinessActivity.keys.keys.include?("latest_milestone")
9
- end
10
- should "configure milestones from DSL" do
11
- assert_equal 3, TestBusinessActivity.timeline_milestones.length
12
-
13
- assert_equal :ms1, TestBusinessActivity.timeline_milestones[0].name
14
- assert_equal "test/evt1", TestBusinessActivity.timeline_milestones[0].events[0]
15
-
16
- assert_equal :ms2, TestBusinessActivity.timeline_milestones[1].name
17
- assert_equal "test/evt2", TestBusinessActivity.timeline_milestones[1].events[0]
18
-
19
- assert_equal :ms3, TestBusinessActivity.timeline_milestones[2].name
20
- assert_equal "test/evt3", TestBusinessActivity.timeline_milestones[2].events[0]
21
- assert_equal "/not_test/evt4", TestBusinessActivity.timeline_milestones[2].events[1]
22
- end
23
- should "subscribe to all milestone events" do
24
- assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt1").subscribers.length > 0
25
- assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt2").subscribers.length > 0
26
- assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt3").subscribers.length > 0
27
- assert Wonkavision.event_coordinator.root_namespace.find_or_create("not_test/evt4").subscribers.length > 0
28
- end
29
- should "record appropriate milestone time and milestone upon relevant event being received" do
30
- event = {"test_id"=>"123","event_time"=>"1/1/2001","another_field"=>"hi there"}
31
- Wonkavision.event_coordinator.receive_event("test/evt1",event)
32
- assert activity = TestBusinessActivity.find_by_test_id("123")
33
- assert_equal "1/1/2001".to_time.utc,activity.timeline["ms1"]
34
- assert_equal "hi there", activity.another_field
35
- Wonkavision.event_coordinator.receive_event("test/evt2",event)
36
- activity = activity.reload
37
- assert_equal "1/1/2001".to_time.utc,activity.timeline["ms2"]
38
- Wonkavision.event_coordinator.receive_event("test/evt3",event)
39
- activity = activity.reload
40
- assert_equal "1/1/2001".to_time.utc, activity.timeline["ms3"]
41
- event["event_time"] = "1/1/2010"
42
- Wonkavision.event_coordinator.receive_event("not_test/evt4",event)
43
- activity = activity.reload
44
- # timeline for milestone ms3 already set
45
- assert_equal "1/1/2001".to_time.utc, activity.timeline["ms3"]
46
- assert_equal "ms3", activity.latest_milestone
47
- end
48
- should "not overwrite latest_milestone when processing an event that occurred prior to the latest milestone event" do
49
- event = {"test_id"=>"123","event_time"=>"1/1/2001 08:00"}
50
- Wonkavision.event_coordinator.receive_event("test/evt2",event)
51
- assert activity = TestBusinessActivity.find_by_test_id("123")
52
- assert_equal "1/1/2001 08:00".to_time.utc,activity.timeline["ms2"]
53
- assert_equal "ms2", activity.latest_milestone
54
- event = {"test_id"=>"123","event_time"=>"1/1/2001 07:00"}
55
- Wonkavision.event_coordinator.receive_event("test/evt1",event)
56
- activity = activity.reload
57
- assert_equal "1/1/2001 07:00".to_time.utc, activity.timeline["ms1"]
58
- assert_equal "ms2", activity.latest_milestone
59
- end
60
- end
61
- end
1
+ require "test_helper"
2
+ require "test_activity_models"
3
+
4
+ class TimelineTest < ActiveSupport::TestCase
5
+ context "TestBusinessActivity" do
6
+ should "create the appropriate keys" do
7
+ assert TestBusinessActivity.fields.keys.include?("timeline")
8
+ assert TestBusinessActivity.fields.keys.include?("latest_milestone")
9
+ end
10
+ should "configure milestones from DSL" do
11
+ assert_equal 3, TestBusinessActivity.timeline_milestones.length
12
+
13
+ assert_equal :ms1, TestBusinessActivity.timeline_milestones[0].name
14
+ assert_equal "test/evt1", TestBusinessActivity.timeline_milestones[0].events[0]
15
+
16
+ assert_equal :ms2, TestBusinessActivity.timeline_milestones[1].name
17
+ assert_equal "test/evt2", TestBusinessActivity.timeline_milestones[1].events[0]
18
+
19
+ assert_equal :ms3, TestBusinessActivity.timeline_milestones[2].name
20
+ assert_equal "test/evt3", TestBusinessActivity.timeline_milestones[2].events[0]
21
+ assert_equal "/not_test/evt4", TestBusinessActivity.timeline_milestones[2].events[1]
22
+ end
23
+ should "subscribe to all milestone events" do
24
+ assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt1").subscribers.length > 0
25
+ assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt2").subscribers.length > 0
26
+ assert Wonkavision.event_coordinator.root_namespace.find_or_create("test/evt3").subscribers.length > 0
27
+ assert Wonkavision.event_coordinator.root_namespace.find_or_create("not_test/evt4").subscribers.length > 0
28
+ end
29
+ should "record appropriate milestone time and milestone upon relevant event being received" do
30
+ event = {"test_id"=>"123","event_time"=>"1/1/2001","another_field"=>"hi there"}
31
+ Wonkavision.event_coordinator.receive_event("test/evt1",event)
32
+ assert activity = TestBusinessActivity.first(:conditions=>{:test_id=>"123"})
33
+ assert_equal "1/1/2001".to_time.utc,activity.timeline["ms1"]
34
+ assert_equal "hi there", activity.another_field
35
+ Wonkavision.event_coordinator.receive_event("test/evt2",event)
36
+ activity = activity.reload
37
+ assert_equal "1/1/2001".to_time.utc,activity.timeline["ms2"]
38
+ Wonkavision.event_coordinator.receive_event("test/evt3",event)
39
+ activity = activity.reload
40
+ assert_equal "1/1/2001".to_time.utc, activity.timeline["ms3"]
41
+ end
42
+ should "not overwrite latest_milestone when processing an event that occurred prior to the latest milestone event" do
43
+ event = {"test_id"=>"123","event_time"=>"1/1/2001 08:00"}
44
+ Wonkavision.event_coordinator.receive_event("test/evt2",event)
45
+ assert activity = TestBusinessActivity.first(:conditions=>{:test_id=>"123"})
46
+ assert_equal "1/1/2001 08:00".to_time.utc,activity.timeline["ms2"]
47
+ assert_equal "ms2", activity.latest_milestone
48
+ event = {"test_id"=>"123","event_time"=>"1/1/2001 07:00"}
49
+ Wonkavision.event_coordinator.receive_event("test/evt1",event)
50
+ activity = activity.reload
51
+ assert_equal "1/1/2001 07:00".to_time.utc, activity.timeline["ms1"]
52
+ assert_equal "ms2", activity.latest_milestone
53
+ end
54
+ end
55
+ end
@@ -1,10 +1,10 @@
1
- require "test_helper"
2
-
3
- class WonkavisionTest < ActiveSupport::TestCase
4
-
5
- context "Jumping into an experimental teleportation device built by a madman" do
6
- should "wreak some kind of humerous havoc" do
7
- assert_equal true, true
8
- end
9
- end
1
+ require "test_helper"
2
+
3
+ class WonkavisionTest < ActiveSupport::TestCase
4
+
5
+ context "Jumping into an experimental teleportation device built by a madman" do
6
+ should "wreak some kind of humerous havoc" do
7
+ assert_equal true, true
8
+ end
9
+ end
10
10
  end