serf 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/NOTICE.txt CHANGED
@@ -1,4 +1,4 @@
1
1
  Serf
2
- Copyright 2011-2012 Benjamin Yu
2
+ Copyright 2011-2013 Benjamin Yu
3
3
  This software includes code written by Benjamin Yu <http://benjaminyu.org/>
4
4
  covered under the Apache License <http://www.apache.org/licenses/LICENSE-2.0>.
data/README.md CHANGED
@@ -27,7 +27,7 @@ The piece of work to be done. This takes in a request, represented by the
27
27
  "Message" within the given "Parcel", and returns an "Event" as its result.
28
28
  The Interactor is the "Domain Controller" with respect to performing
29
29
  Domain Layer business logic in coordinating and interacting with
30
- the Domain Layer's Entities (Value Objects and Entity Gateways).
30
+ the Domain Layer's Model (Entities, Value Objects and Entity Gateways).
31
31
 
32
32
  1. Include the "Serf::Interactor" module in your class.
33
33
  2. Implement the 'call(parcel)' method.
@@ -51,11 +51,14 @@ introspect the parcel's message.
51
51
  Example:
52
52
 
53
53
  require 'hashie'
54
+ require 'optser'
54
55
 
55
56
  class MyInteractor
57
+ attr_reader :model
56
58
 
57
- def initialize(*contructor_params, &block)
59
+ def initialize(*args, &block)
58
60
  # Do some validation here, or extra parameter setting with the args
61
+ opts = Optser.extract_options! args
59
62
  @model = opts :model, MyModel
60
63
  end
61
64
 
@@ -63,7 +66,7 @@ Example:
63
66
  # Do something w/ the message and opts.
64
67
  # Simple data structures for the Interactor's "Request".
65
68
 
66
- item = @model.find parcel.message.model_id
69
+ item = model.find parcel.message.model_id
67
70
 
68
71
  # Make a simple data structure as the Interactor "Response".
69
72
  response = Hashie::Mash.new
@@ -84,13 +87,30 @@ This simplifies marshalling over the network. It also gives us easier
84
87
  semantics in defining Request and Responses without need of extra classes,
85
88
  code, etc.
86
89
 
87
- The Parcel in Ruby (Datastructure) is represented simply as:
90
+ The Parcel in Ruby (Datastructure) is represented simply as a hash.
88
91
 
89
- * A 2 element Hash: { headers: headers, message: message }.
92
+ * The *message* is stored in the "message" property of the parcel.
93
+ * And *header* fields exist in the top level namespace of the parcel.
90
94
 
91
- NOTE: Hashie::Mash is *Awesome*. (https://github.com/intridea/hashie)
92
- NOTE: Serf passes the parcel as frozen Hashie::Mash instances
93
- to Interactor' call method by default.
95
+ For example,
96
+
97
+ {
98
+ kind: 'serf/messages/my_kind',
99
+ uuid: 'gvGshlXTEeKj-AQMzuOZ7g',
100
+ another_header_field: '123456',
101
+ message: {
102
+ # Some message object
103
+ }
104
+ }
105
+
106
+ Serf *RESERVES* the following set of header names:
107
+
108
+ * kind
109
+ * message
110
+ * uuid
111
+ * parent_uuid
112
+ * origin_uuid
113
+ * serf_*
94
114
 
95
115
  *Messages* are the representation of a Business Request or Business Event.
96
116
 
@@ -106,19 +126,54 @@ be in the message.
106
126
  *Headers* are the processing meta data that is associated with a Message.
107
127
 
108
128
  Headers provide information that would assist in processing, tracking
109
- a Message. But does not provide business relevant information to
110
- the Request or Event Message.
129
+ a Message. But SHOULD NOT provide business relevant information to
130
+ the Interactor for it to process a Request or Event Message.
111
131
 
112
- RECOMMENDED: Recommended to be placed in headers is the 'kind' field.
113
-
114
- The "kind" field identifies the ontological meaning of the message, which
132
+ *kind* field identifies the ontological meaning of the message, which
115
133
  may be used to route messages over messaging channels to Interactors.
116
134
  The convention is 'mymodule/requests/my_business_request' for Requests,
117
135
  and 'mymodule/events/my_business_event' for Events.
118
136
 
119
- Examples are:
120
- * UUIDs to track request and events, providing a sequential order of
121
- execution of commands. (Already Implemented by Serf).
137
+ *UUIDs* are used to track request and events, providing a sequential
138
+ order of execution of commands. Already Implemented by Serf middleware.
139
+
140
+ * uuid - The identification of the specific parcel.
141
+ * parent_uuid - The identification of the parcel that caused the current
142
+ parcel to be generated.
143
+ * origin_uuid - The original parcel (request or event) that started
144
+ the chain of requests and event parcels to be generated from Interactors
145
+ processing.
146
+
147
+ The format of the UUIDs is Serf's `coded_uuid`. It is a URI safe base64
148
+ string encoded from a UTC timestamped Type 1 UUID. This allows for both
149
+ good uniqueness and timestamp auditing (if servers are network time synced).
150
+
151
+ *serf headers* are prefixed with the "serf_" string. Example:
152
+
153
+ {
154
+ kind: 'my_lib/messages/my_kind',
155
+ serf_elapsed_time: 12034,
156
+ message: {
157
+ }
158
+ }
159
+
160
+ Applications can add their own headers to parcels for application
161
+ specific tracking. Namespacing SHOULD be used.
162
+
163
+ For example,
164
+
165
+ {
166
+ kind: 'my_lib/messages/my_kind',
167
+ my_middleware: {
168
+ data_point_a: 1234
169
+ },
170
+ my_middleware_data_poing_b: 5678,
171
+ message: {
172
+ }
173
+ }
174
+
175
+ Examples of other header uses:
176
+
122
177
  * Current User that sent the request. For authentication and authorization.
123
178
  * Host and Application Server that is processing this request.
124
179
 
@@ -134,6 +189,10 @@ chained requests to other Interactors. For example, the UUIDs in headers in
134
189
  UUID headers for "Request B" that is sent to "Interactor B". This allows
135
190
  us to track the origin point of any piece of processing request and event..
136
191
 
192
+ NOTE: Hashie::Mash is *Awesome*. (https://github.com/intridea/hashie)
193
+ NOTE: Serf passes the parcel as frozen Hashie::Mash instances
194
+ to Interactor' call method by default.
195
+
137
196
  Policies
138
197
  --------
139
198
 
@@ -249,7 +308,7 @@ Serf Builder Example
249
308
  class MyPolicy
250
309
 
251
310
  def check!(parcel)
252
- raise 'Policy Error: User is nil' unless parcel.headers.user
311
+ raise 'Policy Error: User is nil' unless parcel.current_user
253
312
  end
254
313
 
255
314
  end
@@ -284,18 +343,14 @@ Serf Builder Example
284
343
 
285
344
  # Here is good result
286
345
  results = serf.call(
287
- headers: {
288
- user: 'user_info_1'
289
- },
346
+ current_user: 'user_info_1',
290
347
  message: {
291
348
  })
292
349
  my_logger.info "Call 2: #{results.to_json}"
293
350
 
294
351
  # Here get an error that was raised from the interactor
295
352
  results = serf.call(
296
- headers: {
297
- user: 'user_info_1'
298
- },
353
+ current_user: 'user_info_1',
299
354
  message: {
300
355
  raise_an_error: true
301
356
  })
@@ -369,9 +424,7 @@ Look inside the example subdirectory for the serf files in this example.
369
424
 
370
425
  # Make an example request parcel
371
426
  request_parcel = {
372
- headers: {
373
- kind: 'subsystem/requests/create_widget'
374
- },
427
+ kind: 'subsystem/requests/create_widget',
375
428
  message: {
376
429
  name: 'some widget name'
377
430
  }
@@ -380,7 +433,7 @@ Look inside the example subdirectory for the serf files in this example.
380
433
  #
381
434
  # Look up the create widget serf by a request kind name,
382
435
  # execute the serf, and log the results
383
- serf = serf_map[request_parcel[:headers][:kind]]
436
+ serf = serf_map[request_parcel[:kind]]
384
437
  results = serf.call request_parcel
385
438
  logger.info results.to_json
386
439
 
@@ -1,4 +1,5 @@
1
1
  require 'hashie'
2
+ require 'optser'
2
3
 
3
4
  module Serf
4
5
  module Loader
@@ -37,10 +38,10 @@ module Loader
37
38
  # # Now obtain the build serf, all wired up, by the parcel kind
38
39
  # # and execute the found serf.
39
40
  # parcel = {
40
- # headers: { kind: 'subsystem/request/my_request' },
41
+ # kind: 'subsystem/request/my_request',
41
42
  # message: {}
42
43
  # }
43
- # serf = registry[parcel[:headers][:kind]]
44
+ # serf = registry[parcel[:kind]]
44
45
  # puts serf.call(parcel)
45
46
  #
46
47
  class Registry
@@ -37,8 +37,7 @@ module Middleware
37
37
  # Return on success
38
38
  return response_parcel if response_parcel
39
39
 
40
- # We got an error message instead, so build out the headers
41
- # and return the parcel.
40
+ # We got an error message, so build out and return the error parcel
42
41
  return parcel_factory.create(
43
42
  kind: 'serf/events/caught_error',
44
43
  parent: parcel,
@@ -5,7 +5,7 @@ module Serf
5
5
  module Middleware
6
6
 
7
7
  ##
8
- # Middleware to add uuids to the headers of the parcel hash.
8
+ # Middleware to add uuids to freeze the parcel.
9
9
  #
10
10
  class ParcelFreezer
11
11
  attr_reader :app
@@ -5,7 +5,7 @@ module Serf
5
5
  module Middleware
6
6
 
7
7
  ##
8
- # Middleware to add uuids to the headers of the parcel hash.
8
+ # Middleware to coerce the parcel to Hashie::Mash.
9
9
  #
10
10
  class ParcelMasher
11
11
  attr_reader :app
@@ -22,10 +22,9 @@ module Middleware
22
22
 
23
23
  ##
24
24
  # Coerces the parcel into a Hashie::Mash, makes sure that
25
- # the headers and message are set, and then passes it along the chain.
25
+ # the message field is set, and then passes it along the chain.
26
26
  def call(parcel)
27
27
  mashed_parcel = masher_class.new parcel
28
- mashed_parcel[:headers] ||= {}
29
28
  mashed_parcel[:message] ||= {}
30
29
  app.call mashed_parcel
31
30
  end
@@ -3,6 +3,9 @@ require 'optser'
3
3
  module Serf
4
4
  module Middleware
5
5
 
6
+ ##
7
+ # Middleware to time the execution of the remaining stack, saving the
8
+ # timing into the 'serf_elapsed_time' field in the parcel.
6
9
  class RequestTimer
7
10
  attr_reader :app
8
11
  attr_reader :timer
@@ -16,7 +19,7 @@ module Middleware
16
19
  def call(parcel)
17
20
  t = timer.start
18
21
  response_parcel = app.call parcel
19
- response_parcel.headers[:elapsed_time] = t.mark
22
+ response_parcel[:serf_elapsed_time] = t.mark
20
23
  return response_parcel
21
24
  end
22
25
 
@@ -7,7 +7,7 @@ module Serf
7
7
  module Middleware
8
8
 
9
9
  ##
10
- # Middleware to add uuids to the headers of the parcel hash.
10
+ # Middleware to add the uuid to the parcel hash if not already present.
11
11
  #
12
12
  class UuidTagger
13
13
  attr_reader :app
@@ -23,13 +23,13 @@ module Middleware
23
23
  end
24
24
 
25
25
  def call(parcel)
26
- # Makes sure our parcel has headers
27
- parcel[:headers] ||= {}
26
+ # Duplicate the parcel
27
+ parcel = parcel.dup
28
28
 
29
- # Tag headers with a UUID unless it already has one
30
- parcel[:headers][:uuid] ||= uuidable.create_coded_uuid
29
+ # Tag with a UUID unless it already has one
30
+ parcel[:uuid] ||= uuidable.create_coded_uuid
31
31
 
32
- # Pass on the given parcel with newly annotated headers
32
+ # Pass on the given parcel with the uuid
33
33
  app.call parcel
34
34
  end
35
35
 
@@ -8,6 +8,18 @@ module Serf
8
8
  ##
9
9
  # Creates Parcels as Hashie::Mash objects with headers and messages.
10
10
  #
11
+ # The headers this factory sets are:
12
+ # * kind
13
+ # * uuid
14
+ # * parent_uuid
15
+ # * origin_uuid
16
+ #
17
+ # The message field:
18
+ # * message
19
+ #
20
+ # The UUID fields are created using the uuidable processed from the parent
21
+ # parcel.
22
+ #
11
23
  class ParcelFactory
12
24
  attr_reader :mash_class
13
25
  attr_reader :uuidable
@@ -28,16 +40,14 @@ module Serf
28
40
  headers = opts.get :headers, {}
29
41
  message = opts.get :message, {}
30
42
 
31
- # Coerce to mashes.
32
- parent = mash_class.new(parent) unless parent.kind_of? mash_class
33
- headers = mash_class.new(headers) unless headers.kind_of? mash_class
34
-
35
- # Create a new headers object w/ uuids set from the parent and kind.
36
- headers = headers.merge uuidable.create_uuids(parent.headers)
37
- headers.kind = kind
43
+ # Create a new parcel, with the header fields as base of object.
44
+ # Merge in the new UUIDs, overwriting anything set in headers.
45
+ # Merge in the kind and message, overwriting anything already set.
46
+ parcel = mash_class.new(headers)
47
+ parcel.merge! uuidable.create_uuids(parent)
48
+ parcel.merge! kind: kind, message: message
38
49
 
39
- # Return a final parcel, coerced as a mash.
40
- mash_class.new headers: headers, message: message
50
+ return parcel
41
51
  end
42
52
 
43
53
  end
data/lib/serf/version.rb CHANGED
@@ -2,7 +2,7 @@ module Serf
2
2
 
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 13
5
+ MINOR = 14
6
6
  PATCH = 0
7
7
  BUILD = nil
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join '.'
@@ -33,7 +33,7 @@ describe Serf::Builder do
33
33
  it 'runs the app' do
34
34
  response = subject.to_app.call request_parcel
35
35
  expect(response.message).to eq(request_parcel)
36
- expect(response.headers.kind).to eq(response_kind)
36
+ expect(response.kind).to eq(response_kind)
37
37
  end
38
38
 
39
39
  end
@@ -9,7 +9,7 @@ describe Serf::Loader::Loader do
9
9
 
10
10
  context '#serfup Serf Map' do
11
11
  let(:random_message) {
12
- FactoryGirl.create :random_message
12
+ FactoryGirl.create :random_hash
13
13
  }
14
14
  subject {
15
15
  Serf::Loader::Loader.new.serfup(
@@ -39,7 +39,7 @@ describe Serf::Loader::Loader do
39
39
 
40
40
  results = serf.call({})
41
41
  expect(results).to_not be_nil
42
- expect(results.headers.kind).to_not eq('serf/events/caught_error')
42
+ expect(results.kind).to_not eq('serf/events/caught_error')
43
43
  end
44
44
 
45
45
  it 'returns nil on not found parcel kind' do
@@ -49,7 +49,7 @@ describe Serf::Loader::Loader do
49
49
  it 'passes in a good environment' do
50
50
  serf = subject['subsystem/requests/create_widget']
51
51
  results = serf.call({})
52
- expect(results.headers.kind).to eq('subsystem/events/mywidget_created')
52
+ expect(results.kind).to eq('subsystem/events/mywidget_created')
53
53
  expect(results.message.success_message).to eq(random_message)
54
54
  end
55
55
  end
@@ -4,7 +4,7 @@ require 'serf/loader/registry'
4
4
 
5
5
  describe Serf::Loader::Registry do
6
6
  let(:random_message) {
7
- FactoryGirl.create :random_message
7
+ FactoryGirl.create :random_hash
8
8
  }
9
9
 
10
10
  context '#add' do
@@ -9,7 +9,7 @@ describe Serf::Loader do
9
9
 
10
10
  context '.serfup' do
11
11
  let(:random_message) {
12
- FactoryGirl.create :random_message
12
+ FactoryGirl.create :random_hash
13
13
  }
14
14
  subject {
15
15
  Serf::Loader.serfup(
@@ -39,7 +39,7 @@ describe Serf::Loader do
39
39
 
40
40
  results = serf.call({})
41
41
  expect(results).to_not be_nil
42
- expect(results.headers.kind).to_not eq('serf/events/caught_error')
42
+ expect(results.kind).to_not eq('serf/events/caught_error')
43
43
  end
44
44
 
45
45
  it 'returns nil on not found parcel kind' do
@@ -49,7 +49,7 @@ describe Serf::Loader do
49
49
  it 'passes in a good environment' do
50
50
  serf = subject['subsystem/requests/create_widget']
51
51
  results = serf.call({})
52
- expect(results.headers.kind).to eq('subsystem/events/mywidget_created')
52
+ expect(results.kind).to eq('subsystem/events/mywidget_created')
53
53
  expect(results.message.success_message).to eq(random_message)
54
54
  end
55
55
  end
@@ -31,7 +31,7 @@ describe Serf::Middleware::ErrorHandler do
31
31
 
32
32
  it 'has an error parcel kind' do
33
33
  parcel = subject.call({})
34
- expect(parcel[:headers][:kind]).to eq('serf/events/caught_error')
34
+ expect(parcel[:kind]).to eq('serf/events/caught_error')
35
35
  end
36
36
 
37
37
  it 'uses parcel factory w/ kind, parent, and error message' do
@@ -16,10 +16,9 @@ describe Serf::Middleware::ParcelMasher do
16
16
  app.call parcel
17
17
  end
18
18
 
19
- it 'autocreate headers and message' do
19
+ it 'autocreate message field' do
20
20
  parcel = nil
21
21
  app = described_class.new proc { |parcel|
22
- expect(parcel.headers).to be_a_kind_of(Hashie::Mash)
23
22
  expect(parcel.message).to be_a_kind_of(Hashie::Mash)
24
23
  }
25
24
  app.call parcel
@@ -35,7 +35,7 @@ describe Serf::Middleware::RequestTimer do
35
35
  # Execute the Test
36
36
  request_timer = described_class.new mock_app, :timer => mock_timer_class
37
37
  response_parcel = request_timer.call({})
38
- expect(response_parcel.headers.elapsed_time).to eq(elapsed_time)
38
+ expect(response_parcel.serf_elapsed_time).to eq(elapsed_time)
39
39
  end
40
40
 
41
41
  end
@@ -6,10 +6,10 @@ describe Serf::Middleware::UuidTagger do
6
6
 
7
7
  describe '#call' do
8
8
 
9
- it 'adds uuid the parcel header' do
9
+ it 'adds uuid to the parcel' do
10
10
  parcel = {}
11
11
  app = described_class.new proc { |parcel|
12
- expect(parcel[:headers][:uuid]).to_not be_nil
12
+ expect(parcel[:uuid]).to_not be_nil
13
13
  }
14
14
  app.call parcel
15
15
  end
@@ -17,12 +17,10 @@ describe Serf::Middleware::UuidTagger do
17
17
  it 'does not change the existing uuid' do
18
18
  uuid = '0d3eccaabcc46c3bcbe2a53c4505e352'
19
19
  parcel = {
20
- headers: {
21
- uuid: uuid
22
- }
20
+ uuid: uuid
23
21
  }
24
22
  app = described_class.new proc { |parcel|
25
- expect(parcel[:headers][:uuid]).to eq(uuid)
23
+ expect(parcel[:uuid]).to eq(uuid)
26
24
  }
27
25
  app.call parcel
28
26
  end
@@ -15,7 +15,7 @@ describe Serf::ParcelFactory do
15
15
  FactoryGirl.create :random_headers
16
16
  }
17
17
  let(:response_message) {
18
- FactoryGirl.create :random_message
18
+ FactoryGirl.create :random_hash
19
19
  }
20
20
  let(:parent_parcel) {
21
21
  FactoryGirl.create :random_parcel
@@ -26,41 +26,35 @@ describe Serf::ParcelFactory do
26
26
  expect(parcel).to be_a_kind_of(Hashie::Mash)
27
27
  end
28
28
 
29
- it 'returns the headers as a Hashie Mash' do
29
+ it 'sets nil kind in parcel' do
30
30
  parcel = subject.create
31
- expect(parcel.headers).to be_a_kind_of(Hashie::Mash)
31
+ expect(parcel.kind).to be_nil
32
32
  end
33
33
 
34
- it 'sets nil kind in parcel headers' do
35
- parcel = subject.create
36
- expect(parcel.headers.kind).to be_nil
37
- end
38
-
39
- it 'sets nil kind in parcel headers to overwrite headers kind' do
34
+ it 'sets nil kind in parcel to overwrite headers kind' do
40
35
  parcel = subject.create headers: response_headers
41
36
  expect(response_headers.kind).to_not be_nil
42
- expect(parcel.headers.kind).to be_nil
37
+ expect(parcel.kind).to be_nil
43
38
  end
44
39
 
45
- it 'sets a kind in parcel headers to overwrite headers' do
40
+ it 'sets a kind in parcel to overwrite headers' do
46
41
  parcel = subject.create kind: response_kind, headers: response_headers
47
42
  expect(response_headers.kind).to_not eq(response_kind)
48
- expect(parcel.headers.kind).to eq(response_kind)
43
+ expect(parcel.kind).to eq(response_kind)
49
44
  end
50
45
 
51
- it 'sets uuid, w/ nil origin and parent in parcel headers' do
46
+ it 'sets uuid, w/ nil origin and parent in parcel' do
52
47
  parcel = subject.create
53
- expect(parcel.headers.uuid).to_not be_nil
54
- expect(parcel.headers.parent_uuid).to be_nil
55
- expect(parcel.headers.origin_uuid).to be_nil
48
+ expect(parcel.uuid).to_not be_nil
49
+ expect(parcel.parent_uuid).to be_nil
50
+ expect(parcel.origin_uuid).to be_nil
56
51
  end
57
52
 
58
- it 'sets uuid, origin and parent in response headers from parent' do
53
+ it 'sets uuid, origin and parent in response parent' do
59
54
  parcel = subject.create parent: parent_parcel
60
- expect(parcel.headers.uuid).to_not be_nil
61
- expect(parcel.headers.parent_uuid).to eq(parent_parcel.headers.uuid)
62
- expect(parcel.headers.origin_uuid).
63
- to eq(parent_parcel.headers.origin_uuid)
55
+ expect(parcel.uuid).to_not be_nil
56
+ expect(parcel.parent_uuid).to eq(parent_parcel.uuid)
57
+ expect(parcel.origin_uuid).to eq(parent_parcel.origin_uuid)
64
58
  end
65
59
 
66
60
  it 'returns the message as a Hashie Mash' do
@@ -78,19 +72,19 @@ describe Serf::ParcelFactory do
78
72
  expect(parcel.message).to eq(response_message)
79
73
  end
80
74
 
81
- it 'sets meets expectations given kind, headers, message and parent' do
75
+ it 'uses correct fields given kind, extra headers, message and parent' do
82
76
  parcel = subject.create(
83
77
  parent: parent_parcel,
84
78
  kind: response_kind,
85
79
  headers: response_headers,
86
80
  message: response_message)
87
81
  expect(response_headers.kind).to_not eq(response_kind)
88
- expect(parcel.headers.kind).to eq(response_kind)
89
- expect(parcel.headers.uuid).to_not be_nil
90
- expect(parcel.headers.parent_uuid).to eq(parent_parcel.headers.uuid)
91
- expect(parcel.headers.origin_uuid).
92
- to eq(parent_parcel.headers.origin_uuid)
93
- expect(parcel.headers.option_a).to eq(response_headers.option_a)
82
+ expect(parcel.kind).to eq(response_kind)
83
+ expect(parcel.uuid).to_not be_nil
84
+ expect(parcel.uuid).to_not eq(response_headers.uuid)
85
+ expect(parcel.parent_uuid).to eq(parent_parcel.uuid)
86
+ expect(parcel.origin_uuid).to eq(parent_parcel.origin_uuid)
87
+ expect(parcel.random_header_a).to eq(response_headers.random_header_a)
94
88
  expect(parcel.message).to eq(response_message)
95
89
  end
96
90
 
@@ -9,21 +9,13 @@ describe Serf::Serfer do
9
9
 
10
10
  describe '#call' do
11
11
  let(:request_parcel) {
12
- Hashie::Mash.new(
13
- headers: request_headers,
14
- message: request_message)
15
- }
16
- let(:request_headers) {
17
- FactoryGirl.create :random_headers
18
- }
19
- let(:request_message) {
20
- FactoryGirl.create :random_message
12
+ FactoryGirl.create :random_parcel
21
13
  }
22
14
  let(:response_kind) {
23
15
  SecureRandom.hex
24
16
  }
25
17
  let(:response_message) {
26
- FactoryGirl.create :random_message
18
+ FactoryGirl.create :random_hash
27
19
  }
28
20
  let(:disconnected_response_parcel) {
29
21
  FactoryGirl.create :random_parcel
@@ -50,16 +42,14 @@ describe Serf::Serfer do
50
42
  # We also expect that the uuid is some value
51
43
  # We also expect that the response parent uuid matches request uuid
52
44
  # We also expect that the response origin uuid matches request origin's.
53
- expect(parcel.headers.kind).to eq(response_kind)
54
- expect(parcel.headers.uuid).to_not be_nil
55
- expect(parcel.headers.origin_uuid).
56
- to eq(request_parcel.headers.origin_uuid)
57
- expect(parcel.headers.parent_uuid).
58
- to eq(request_parcel.headers.uuid)
45
+ expect(parcel.kind).to eq(response_kind)
46
+ expect(parcel.uuid).to_not be_nil
47
+ expect(parcel.origin_uuid).to eq(request_parcel.origin_uuid)
48
+ expect(parcel.parent_uuid).to eq(request_parcel.uuid)
59
49
  expect(parcel.message).to eq(response_message)
60
50
  end
61
51
 
62
- it 'uses parcel factory w/ message and headers' do
52
+ it 'uses parcel factory w/ kind, parent and message' do
63
53
  mock_parcel_factory = double 'parcel_factory'
64
54
  mock_parcel_factory.
65
55
  should_receive(:create).
@@ -6,39 +6,30 @@ FactoryGirl.define do
6
6
  sequence(:random_string) { SecureRandom.hex }
7
7
 
8
8
  factory :empty_parcel, class: Hashie::Mash do
9
- headers {{
10
- }}
11
9
  message {{
12
10
  }}
13
11
  end
14
12
 
13
+ factory :random_hash, class: Hashie::Mash do
14
+ option_a { generate(:random_string) }
15
+ end
16
+
15
17
  factory :random_parcel, class: Hashie::Mash do
16
- headers {{
17
- uuid: generate(:random_string),
18
- origin_uuid: generate(:random_string),
19
- parent_uuid: generate(:random_string),
20
- kind: generate(:random_string)
21
- }}
18
+ kind { generate(:random_string) }
19
+ uuid { generate(:random_string) }
20
+ origin_uuid { generate(:random_string) }
21
+ parent_uuid { generate(:random_string) }
22
+ random_header_a { generate(:random_string) }
22
23
  message {{
23
24
  some_data: generate(:random_string)
24
25
  }}
25
26
  end
26
27
 
27
28
  factory :random_headers, class: Hashie::Mash do
28
- uuid { generate(:random_string) }
29
- origin_uuid { generate(:random_string) }
30
- parent_uuid { generate(:random_string) }
31
- kind { generate(:random_string) }
32
- option_a { generate(:random_string) }
33
- end
34
-
35
- factory :random_message, class: Hashie::Mash do
36
- data { generate(:random_string) }
37
- end
38
-
39
- factory :random_options, class: Hashie::Mash do
40
- option_a { generate(:random_string) }
41
- option_b { generate(:random_string) }
42
- option_c { generate(:random_string) }
29
+ kind { generate(:random_string) }
30
+ uuid { generate(:random_string) }
31
+ origin_uuid { generate(:random_string) }
32
+ parent_uuid { generate(:random_string) }
33
+ random_header_a { generate(:random_string) }
43
34
  end
44
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: 1409923119992406308
158
+ hash: -3964117889067138578
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 1409923119992406308
167
+ hash: -3964117889067138578
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.23