hay 0.0.1.pre.alpha.1

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 (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE +21 -0
  6. data/README.md +3 -0
  7. data/Rakefile +60 -0
  8. data/hay.gemspec +30 -0
  9. data/lib/hay/consumer.rb +27 -0
  10. data/lib/hay/dispatcher.rb +23 -0
  11. data/lib/hay/message.rb +28 -0
  12. data/lib/hay/queue.rb +22 -0
  13. data/lib/hay/route.rb +29 -0
  14. data/lib/hay/router.rb +25 -0
  15. data/lib/hay/routes.rb +24 -0
  16. data/lib/hay/task/decorator.rb +35 -0
  17. data/lib/hay/task/exception/transient_exception.rb +10 -0
  18. data/lib/hay/task/exception/unknown_template_error.rb +16 -0
  19. data/lib/hay/task/exception.rb +11 -0
  20. data/lib/hay/task/flow.rb +41 -0
  21. data/lib/hay/task/hydrator/registry.rb +21 -0
  22. data/lib/hay/task/hydrator.rb +21 -0
  23. data/lib/hay/task/hydrators.rb +28 -0
  24. data/lib/hay/task/registry.rb +16 -0
  25. data/lib/hay/task/resolver/hash.rb +19 -0
  26. data/lib/hay/task/resolver/registry.rb +11 -0
  27. data/lib/hay/task/resolver/task.rb +18 -0
  28. data/lib/hay/task/resolver.rb +17 -0
  29. data/lib/hay/task/resolvers.rb +20 -0
  30. data/lib/hay/task/resulter.rb +23 -0
  31. data/lib/hay/task/template/hash.rb +21 -0
  32. data/lib/hay/task/template/hydrator.rb +23 -0
  33. data/lib/hay/task/template/registry.rb +18 -0
  34. data/lib/hay/task/template/task.rb +28 -0
  35. data/lib/hay/task/template.rb +18 -0
  36. data/lib/hay/task/templates.rb +23 -0
  37. data/lib/hay/task.rb +29 -0
  38. data/lib/hay/tasks.rb +18 -0
  39. data/lib/hay/version.rb +4 -0
  40. data/lib/hay.rb +19 -0
  41. data/rakelib/hay/rake.rb +36 -0
  42. data/test/alfalfa.log +47 -0
  43. data/test/integration/hay_test.rb +239 -0
  44. data/test/simplecov_helper.rb +31 -0
  45. data/test/unit/hay/dispatcher_test.rb +38 -0
  46. data/test/unit/hay/message_test.rb +43 -0
  47. data/test/unit/hay/route_test.rb +56 -0
  48. data/test/unit/hay/router_test.rb +26 -0
  49. data/test/unit/hay/routes_test.rb +37 -0
  50. data/test/unit/hay/task/decorator_test.rb +68 -0
  51. data/test/unit/hay/task/flow_test.rb +45 -0
  52. data/test/unit/hay/task/hydrator_test.rb +38 -0
  53. data/test/unit/hay/task/hydrators_test.rb +26 -0
  54. data/test/unit/hay/task/resulter_test.rb +27 -0
  55. data/test/unit/hay/task/template/hash_test.rb +30 -0
  56. data/test/unit/hay/task/template/hydrator_test.rb +30 -0
  57. data/test/unit/hay/task/template/task_test.rb +33 -0
  58. data/test/unit/hay/task/template_test.rb +36 -0
  59. data/test/unit/hay/task_test.rb +6 -0
  60. data/test/unit/test_helper.rb +24 -0
  61. metadata +206 -0
@@ -0,0 +1,23 @@
1
+ require 'hay/task/template/hydrator'
2
+
3
+ module Hay
4
+ module Task
5
+ class Resulter
6
+ def initialize(flow, dispatcher)
7
+ @hydrator = Hay::Task::Template::Hydrator.new(flow)
8
+ @dispatcher = dispatcher
9
+ end
10
+
11
+ def inject(task)
12
+ @dispatcher.push(task)
13
+ end
14
+
15
+ def submit(data)
16
+ tasks = @hydrator.hydrate_with(data)
17
+ tasks.each do |task|
18
+ @dispatcher.push(task)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ module Hay
2
+ module Task
3
+ module Template
4
+ class Hash
5
+
6
+ def initialize(params)
7
+ @params = params
8
+
9
+ @name = params.fetch("name")
10
+ end
11
+
12
+ def render(params = {})
13
+ merged = @params.merge(params)
14
+ Hay::Task::Hydrators.for(merged).hydrate
15
+ end
16
+
17
+ Hay::Task::Templates.register(::Hash, self)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'hay'
2
+
3
+ module Hay
4
+ module Task
5
+ module Template
6
+ class Hydrator
7
+ def initialize(flow)
8
+ @templates = flow.inflate
9
+ end
10
+
11
+ def hydrate
12
+ hydrate_with({})
13
+ end
14
+
15
+ def hydrate_with(params)
16
+ @templates.map do |template|
17
+ template.render(params).tap {|t| Hay.logger.debug "HYDRATED TEMPLATE: #{t.inspect}" }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Hay
2
+ module Task
3
+ module Template
4
+ module Registry
5
+ @@template_maps = {}
6
+
7
+ def self.register(task_class, template)
8
+ Hay.logger.info "Registering template #{template} for #{task_class}"
9
+ @@template_maps[task_class] = template
10
+ end
11
+
12
+ def self.template_for(task_class)
13
+ @@template_maps[task_class]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'hay/task/decorator'
2
+
3
+ module Hay
4
+ module Task
5
+ module Template
6
+ class Task
7
+ def initialize(params)
8
+ @name = params.task_name
9
+ @payload = params.payload
10
+ @flow = params.flow
11
+ end
12
+
13
+ def render(params = {})
14
+ merged = params.merge(@payload)
15
+
16
+ task_class = Hay::Tasks.for(@name)
17
+ task = task_class.new(merged).to_hay
18
+
19
+ task.flow = @flow
20
+ task
21
+ end
22
+
23
+ Hay::Task::Templates.register(Hay::Task::Decorator, self)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,18 @@
1
+ require 'hay'
2
+
3
+ require 'hay/task/templates'
4
+ require 'hay/task/exception/unknown_template_error'
5
+
6
+ module Hay
7
+ module Task
8
+ module Template
9
+ def self.new(params)
10
+ template_class = Hay::Task::Templates.for(params)
11
+ if template_class.nil?
12
+ raise Hay::Task::Exception::UnknownTemplateError.new("No template for #{params.class}")
13
+ end
14
+ template_class.new(params)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'punchout'
2
+ require 'punchout/matcher/ancestry'
3
+
4
+ module Hay
5
+ module Task
6
+ module Templates
7
+ extend Punchout::Punchable
8
+
9
+ def self.register(type, template)
10
+ Hay.logger.info "Registering template #{type} for #{template}"
11
+ matchable = Punchout::Matcher::Ancestry.new(type).punches(template)
12
+ puncher.add(matchable)
13
+ end
14
+
15
+ def self.for(type)
16
+ punch(type)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'hay/task/template/hash'
23
+ require 'hay/task/template/task'
data/lib/hay/task.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'hay'
2
+
3
+ require 'hay/task/decorator'
4
+ require 'hay/task/hydrator'
5
+ require 'hay/task/hydrators'
6
+ require 'hay/tasks'
7
+
8
+ module Hay
9
+ ##
10
+ # An Hay::Task is made up of a Task, and that Task's associated Flow.
11
+ #
12
+ # A Task is any object that can respond to task_name, process, and
13
+ # dehydrate.
14
+ #
15
+ module Task
16
+ def self.included(base)
17
+ Hay::Tasks.register(base)
18
+ Hay::Task::Hydrators.register(base, Hay::Task::Hydrator)
19
+ end
20
+
21
+ def task_name
22
+ self.class.task_name
23
+ end
24
+
25
+ def to_hay
26
+ Hay::Task::Decorator.new(self)
27
+ end
28
+ end
29
+ end
data/lib/hay/tasks.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Hay
2
+ module Tasks
3
+ extend Punchout::Punchable
4
+ def self.register(task)
5
+ matchable = Punchout::Matcher::Equal.new(task.task_name).punches(task)
6
+ puncher.add(matchable)
7
+ end
8
+
9
+ def self.for(task)
10
+ punch(task)
11
+ end
12
+
13
+ def self.for_name(name)
14
+ punch(name)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,4 @@
1
+ module Hay
2
+ VERSION = "0.0.1-alpha.1"
3
+ end
4
+
data/lib/hay.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'logger'
2
+
3
+ module Hay
4
+ class << self
5
+ def logger
6
+ return @logger if @logger
7
+
8
+ @logger = Logger.new(STDOUT)
9
+ @logger.formatter = proc { |severity, datetime, progname, msg|
10
+ "[#{datetime}, #{severity}] #{msg}\n"
11
+ }
12
+ @logger
13
+ end
14
+
15
+ def logger=(logger)
16
+ @logger = logger
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ require 'pathname'
2
+ require 'rubygems/package'
3
+ require 'rubygems/installer'
4
+
5
+ module Edger
6
+ module Rake
7
+ class Tasks
8
+
9
+ include ::Rake::DSL
10
+
11
+ def initialize
12
+ yield self
13
+ task :build do
14
+ path = Pathname.glob("*.gemspec")
15
+ spec = Gem::Specification.load(path.first.to_s)
16
+ package = Gem::Package.build(spec)
17
+ Gem::Installer.new(package).install
18
+ end
19
+
20
+ task :clean do
21
+ path = Pathname.glob("*.gemspec")
22
+ spec = Gem::Specification.load(path.first.to_s)
23
+ if File.exists?(spec.file_name)
24
+ File.unlink(spec.file_name)
25
+ end
26
+ end
27
+
28
+ task :install => :build do
29
+ path = Pathname.glob("*.gemspec")
30
+ spec = Gem::Specification.load(path.first.to_s)
31
+ Gem::Installer.new(spec.file_name).install
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
data/test/alfalfa.log ADDED
@@ -0,0 +1,47 @@
1
+ /Users/ecarrel/.rbenv/versions/2.0.0-p247/bin/ruby -I"lib:test:config" -I"/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib" "/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/unit/alfalfa/dispatcher_test.rb" "test/unit/alfalfa/message_test.rb" "test/unit/alfalfa/route_test.rb" "test/unit/alfalfa/router_test.rb" "test/unit/alfalfa/routes_test.rb" "test/unit/alfalfa/task/flowable_test.rb" "test/unit/alfalfa/task/resulter_test.rb" "test/unit/alfalfa/task/template/hydrator_test.rb" "test/unit/alfalfa/task/template_test.rb" "test/unit/alfalfa/task_test.rb"
2
+ [2013-10-24 15:01:51 -0700, INFO] Registering template Alfalfa::Task::Template::HashTemplate for Hash
3
+ [2013-10-24 15:01:51 -0700, INFO] Registering template Alfalfa::Task::Template::TaskTemplate for Alfalfa::Task
4
+ Run options:
5
+
6
+ # Running tests:
7
+
8
+ ..................S.[2013-10-24 15:01:51 -0700, INFO] Running #<Mocha::Mock:0x007ffea5065670> with #<Mocha::Mock:0x007ffea5065468>
9
+ .
10
+
11
+ Finished tests in 0.018424s, 1139.8176 tests/s, 4776.3786 assertions/s.
12
+
13
+ 21 tests, 88 assertions, 0 failures, 0 errors, 1 skips
14
+
15
+ ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]
16
+ /Users/ecarrel/.rbenv/versions/2.0.0-p247/bin/ruby -I"lib:test:config" -I"/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib" "/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/integration/alfalfa_test.rb"
17
+ Run options:
18
+
19
+ # Running tests:
20
+
21
+ DIS: #<#<Class:0x007fd3ca84d898>:0x007fd3ca84d758>
22
+ FOO #<Alfalfa::Dispatcher:0x007fd3ca84d5a0>
23
+ .DIS: #<#<Class:0x007fd3ca8542d8>:0x007fd3ca85ff48>
24
+ [2013-10-24 15:01:52 -0700, ERROR] Unknown route for task #<#<Class:0x007fd3ca85fbd8>:0x007fd3ca85f778>
25
+ E
26
+
27
+ Finished tests in 0.007172s, 278.8622 tests/s, 0.0000 assertions/s.
28
+
29
+ 1) Error:
30
+ AlfalfaTest#test_consuming_and_producing:
31
+ RuntimeError: Unknown route for task #<#<Class:0x007fd3ca85fbd8>:0x007fd3ca85f778>
32
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/lib/alfalfa/message.rb:16:in `initialize'
33
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/lib/alfalfa/dispatcher.rb:17:in `new'
34
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/lib/alfalfa/dispatcher.rb:17:in `push'
35
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/test/integration/alfalfa_test.rb:54:in `block (3 levels) in <class:AlfalfaTest>'
36
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/lib/alfalfa/queue.rb:18:in `run'
37
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/lib/alfalfa/consumer.rb:16:in `push'
38
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/test/integration/alfalfa_test.rb:58:in `block in <class:AlfalfaTest>'
39
+
40
+ 2 tests, 0 assertions, 0 failures, 1 errors, 0 skips
41
+
42
+ ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]
43
+ rake aborted!
44
+ Command failed with status (1): [ruby -I"lib:test:config" -I"/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib" "/Users/ecarrel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/integration/alfalfa_test.rb" ]
45
+ /Users/ecarrel/Documents/pc/coinstar/coinstar-gems/alfalfa/Rakefile:28:in `block in <top (required)>'
46
+ Tasks: TOP => test:integration
47
+ (See full trace by running task with --trace)
@@ -0,0 +1,239 @@
1
+ require File.expand_path('../../unit/test_helper', __FILE__)
2
+
3
+ require 'hay/consumer'
4
+ require 'hay/route'
5
+ require 'hay/task'
6
+
7
+ require 'hay/task/templates'
8
+
9
+ class HayTest < Test::Unit::TestCase
10
+ class Consumer
11
+ include Hay::Consumer
12
+
13
+ def tasks
14
+ [TerminalTask]
15
+ end
16
+ end
17
+
18
+ module MockTask
19
+ def self.included(base)
20
+ base.instance_exec do
21
+ include Hay::Task
22
+ end
23
+ end
24
+
25
+ def payload
26
+ {}
27
+ end
28
+
29
+ def self.task_name
30
+ "outtask"
31
+ end
32
+
33
+ def dehydrate
34
+ {}
35
+ end
36
+ end
37
+
38
+
39
+ class RemoteTask
40
+ def self.task_name
41
+ "out_task"
42
+ end
43
+
44
+ include MockTask
45
+
46
+ def initialize(params = {})
47
+ end
48
+ end
49
+
50
+ class TerminalTask
51
+
52
+ def self.task_name
53
+ "terminal_task"
54
+ end
55
+
56
+ include MockTask
57
+
58
+ def initialize(params = {})
59
+ @ran = false
60
+ end
61
+
62
+ def process(dispatcher)
63
+ @ran = true
64
+ end
65
+
66
+ attr_reader :ran
67
+ end
68
+
69
+ class InjectingLocalTask
70
+ def initialize(params = {})
71
+ @ran = false
72
+ end
73
+
74
+ def self.task_name
75
+ "injecting_local_task"
76
+ end
77
+
78
+ include MockTask
79
+
80
+ def process(dispatcher)
81
+ dispatcher.inject(TerminalTask.new.to_hay)
82
+ @ran = true
83
+ end
84
+
85
+ attr_reader :ran
86
+ end
87
+
88
+ class InjectingRemoteTask
89
+ def initialize(params = {})
90
+ @ran = false
91
+ end
92
+
93
+ def self.task_name
94
+ "injecting_remote_task"
95
+ end
96
+
97
+ include MockTask
98
+
99
+ def process(dispatcher)
100
+ dispatcher.inject(RemoteTask.new.to_hay)
101
+ @ran = true
102
+ end
103
+
104
+ attr_reader :ran
105
+ end
106
+
107
+ class FlowableTask
108
+ def initialize(params = {})
109
+ @ran = false
110
+ end
111
+
112
+ def self.task_name
113
+ "flowable_task"
114
+ end
115
+
116
+ include MockTask
117
+
118
+ def process(dispatcher)
119
+ dispatcher.submit({})
120
+ @ran = true
121
+ end
122
+
123
+ attr_writer :data
124
+ attr_reader :ran
125
+ end
126
+
127
+ class Agent
128
+ def initialize
129
+ @messages = []
130
+ end
131
+
132
+ def publish(message)
133
+ @messages << message
134
+ end
135
+
136
+ attr_reader :messages
137
+
138
+ end
139
+
140
+ class RemoteRoute
141
+ def self.tasks
142
+ [RemoteTask]
143
+ end
144
+
145
+ include Hay::Route
146
+
147
+ end
148
+
149
+ test 'consuming' do
150
+ agent = Agent.new
151
+
152
+ consumer = Consumer.new(agent)
153
+
154
+ task = TerminalTask.new.to_hay
155
+
156
+ consumer.push(task)
157
+
158
+ assert task.ran
159
+ assert_equal 0, agent.messages.length
160
+ end
161
+
162
+ test 'consuming dehydrated' do
163
+ agent = Agent.new
164
+
165
+ consumer = Consumer.new(agent)
166
+
167
+ task = TerminalTask.new.to_hay
168
+
169
+ consumer.push(task.dehydrate)
170
+
171
+ assert_equal 0, agent.messages.length
172
+ end
173
+
174
+ test 'consuming and injecting local' do
175
+ agent = Agent.new
176
+
177
+ consumer = Consumer.new(agent)
178
+
179
+ task = InjectingLocalTask.new.to_hay
180
+
181
+ consumer.push(task)
182
+
183
+ assert task.ran
184
+ assert_equal 0, agent.messages.length
185
+ end
186
+
187
+ test 'consuming and injecting remote' do
188
+ agent = Agent.new
189
+
190
+ consumer = Consumer.new(agent)
191
+
192
+ task = InjectingRemoteTask.new.to_hay
193
+
194
+ consumer.push(task)
195
+
196
+ assert task.ran
197
+ assert_equal 1, agent.messages.length
198
+ assert_kind_of RemoteTask, agent.messages.first.task.__getobj__
199
+ end
200
+
201
+ test 'consuming and flowing' do
202
+ agent = Agent.new
203
+
204
+ consumer = Consumer.new(agent)
205
+
206
+ terminal_task = RemoteTask.new.to_hay
207
+ flow = Hay::Task::Flow.new([terminal_task])
208
+
209
+ task = FlowableTask.new.to_hay
210
+ task.flow = flow
211
+
212
+ consumer.push(task)
213
+
214
+ assert task.ran
215
+ assert_equal 1, agent.messages.length
216
+ assert_kind_of RemoteTask, agent.messages.first.task.__getobj__
217
+ assert_kind_of Hay::Task::Decorator, agent.messages.first.task
218
+ end
219
+
220
+ test 'consuming and flowing dehydrated' do
221
+ agent = Agent.new
222
+
223
+ consumer = Consumer.new(agent)
224
+
225
+ terminal_task = RemoteTask.new.to_hay
226
+ flow = Hay::Task::Flow.new([terminal_task])
227
+
228
+ task = FlowableTask.new.to_hay
229
+ task.flow = flow
230
+
231
+ dtask = task.dehydrate
232
+
233
+ consumer.push(dtask)
234
+
235
+ assert_equal 1, agent.messages.length
236
+ assert_kind_of RemoteTask, agent.messages.first.task.__getobj__
237
+ assert_kind_of Hay::Task::Decorator, agent.messages.first.task
238
+ end
239
+ end
@@ -0,0 +1,31 @@
1
+ SimpleCov.adapters.define 'pocketchange' do
2
+
3
+ # Lib
4
+ %w(quiet_assets pry memcache email).each do |file|
5
+ add_filter "/config\/initializers\/#{file}.rb"
6
+ end
7
+
8
+ # Initializers
9
+ %w(populator method_cache functor models/list).each do |file|
10
+ add_filter "/lib\/#{file}.rb"
11
+ end
12
+
13
+ # Tests
14
+ %w(functional factories).each do |dir|
15
+ add_filter "/test\/#{dir}/"
16
+ end
17
+
18
+ add_group "Model", "redshift/model"
19
+ add_group "Tasks", "redshift/steps"
20
+ add_group 'API', "app/controllers/api"
21
+ add_group 'Admin', "app/controllers/admin"
22
+ add_group 'Dashboard', "app/controllers/dashboard"
23
+ add_group 'Store', "app/controllers/store"
24
+ add_group 'Recent' do |source|
25
+ changes = `find lib -maxdepth 5 -mtime -1 -ls`
26
+ changes.include?(source.filename)
27
+ end
28
+ add_group "Bad" do |source|
29
+ source.covered_percent < 80
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ require 'hay/dispatcher'
4
+
5
+ class Hay::DispatcherTest < Test::Unit::TestCase
6
+ setup do
7
+ @mock_agent = mock
8
+ @mock_consumer = mock
9
+ @mock_task = mock
10
+ @mock_task_name = mock
11
+
12
+ @mock_router = mock
13
+ Hay::Router.expects(:new).with(@mock_agent).returns(@mock_router)
14
+
15
+ @dispatcher = Hay::Dispatcher.new(@mock_consumer, @mock_agent)
16
+ end
17
+
18
+ test '#push ours' do
19
+ @mock_consumer.expects(:ours?).with(@mock_task).returns(true)
20
+
21
+ @mock_router.expects(:push).never
22
+ @mock_consumer.expects(:push).with(@mock_task)
23
+
24
+ @dispatcher.push(@mock_task)
25
+ end
26
+
27
+ test '#push not ours' do
28
+ @mock_consumer.expects(:ours?).with(@mock_task).returns(false)
29
+
30
+ mock_message = mock
31
+ Hay::Message.expects(:new).with(@mock_task).returns(mock_message)
32
+
33
+ @mock_router.expects(:push).with(mock_message)
34
+ @mock_consumer.expects(:push).never
35
+
36
+ @dispatcher.push(@mock_task)
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+
2
+ require File.expand_path('../../test_helper', __FILE__)
3
+
4
+ require 'hay/message'
5
+
6
+ class Hay::MessageTest < Test::Unit::TestCase
7
+ setup do
8
+ @mock_task = mock
9
+
10
+ @message = Hay::Message.new(@mock_task)
11
+ end
12
+
13
+ test "#payload" do
14
+ mock_payload = mock
15
+ @mock_task.expects(:dehydrate).returns(mock_payload)
16
+
17
+ result = @message.payload
18
+
19
+ assert_equal mock_payload, result
20
+ end
21
+
22
+ test "#destination" do
23
+ mock_route = mock
24
+
25
+ mock_name = mock
26
+ @mock_task.expects(:task_name).returns(mock_name)
27
+
28
+ Hay::Routes.expects(:for_name).with(mock_name).returns(mock_route)
29
+
30
+ result = @message.destination
31
+
32
+ assert_equal mock_route, result
33
+ end
34
+
35
+ test "#initialize fails when passed a task hash" do
36
+ mock_task = {}
37
+
38
+ assert_raise(RuntimeError) do
39
+ message = Hay::Message.new(mock_task)
40
+ end
41
+
42
+ end
43
+ end