cpi-event-connector 0.0.3 → 0.0.4

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.
@@ -4,12 +4,10 @@ require 'uuidtools'
4
4
  module Cpi
5
5
  class Generator
6
6
 
7
- def self.create_event(event_type, tenant_uid, root_path)
7
+ def self.create_event(event_type, tenant_uid, content)
8
8
  uid = UUIDTools::UUID.timestamp_create().to_s
9
9
 
10
- hash = {"outbound_event" =>
11
- {"event_type" => event_type, "tenant" => tenant_uid, "root_path" => root_path, "uid" => uid}
12
- }
10
+ hash = {"event_type" => event_type, "tenant" => tenant_uid, "content" => content, "uid" => uid}
13
11
 
14
12
  json = ActiveSupport::JSON.encode(hash)
15
13
 
@@ -1,3 +1,3 @@
1
1
  module Cpi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/event_spec.rb CHANGED
@@ -40,12 +40,12 @@ enabled: false"
40
40
 
41
41
  describe ".transmit" do
42
42
 
43
- let(:root_path) { "http://example.com/shipment/1" }
43
+ let(:content) { "<test />" }
44
44
 
45
45
  it "generates and sends an event" do
46
46
  Cpi::Event.configure(YAML::load(yaml_config))
47
47
 
48
- Cpi::Event.transmit("shipment_shipped", "stuff", root_path)
48
+ Cpi::Event.transmit("shipment_shipped", "stuff", content)
49
49
 
50
50
  b = Bunny.new
51
51
  b.start
@@ -54,7 +54,7 @@ enabled: false"
54
54
  h = ActiveSupport::JSON.decode(message[:payload])
55
55
  b.stop
56
56
 
57
- h.should unify({"outbound_event" => {"event_type" => "shipment_shipped", "tenant" => "stuff", "root_path" => root_path, "uid" => :_x}})
57
+ h.should unify({"event_type" => "shipment_shipped", "tenant" => "stuff", "content" => content, "uid" => :_x})
58
58
  end
59
59
 
60
60
  it "does not transmit when it is not enabled" do
@@ -65,12 +65,12 @@ enabled: false"
65
65
  Cpi::Generator.should_not_receive(:create_event)
66
66
  # And there shouldn't be an exception
67
67
 
68
- Cpi::Event.transmit("message", "tenant_uid", "root_path")
68
+ Cpi::Event.transmit("message", "tenant_uid", "content")
69
69
  end
70
70
 
71
71
  it "does nothing when called before being configured" do
72
72
  Cpi::Generator.should_not_receive(:create_event)
73
- Cpi::Event.transmit("message", "tenant_uid", "root_path")
73
+ Cpi::Event.transmit("message", "tenant_uid", "content")
74
74
  end
75
75
  end
76
76
  end
@@ -3,32 +3,27 @@ require 'lib/cpi_event_connector/generator'
3
3
  require 'active_support'
4
4
 
5
5
  describe Cpi::Generator do
6
+ let(:event_type) { "shipment shipped" }
7
+ let(:tenant_uid) { "123123" }
8
+ let(:content) { "content" }
6
9
 
7
10
  it "generates json for an event" do
8
- event_type = "shipment shipped"
9
- tenant_uid = "123123"
10
- root_path = "http://example.com"
11
+ expected = {"event_type" => event_type, "tenant_uid" => tenant_uid, "content" => content, "uid" => "123123123"}
11
12
 
12
- expected = {"outbound_event" => {"event_type" => event_type, "tenant_uid" => tenant_uid, "root_path" => root_path, "uid" => "123123123"}}
13
-
14
- event = Cpi::Generator.create_event(event_type, tenant_uid, root_path)
13
+ event = Cpi::Generator.create_event(event_type, tenant_uid, content)
15
14
 
16
15
  result = ActiveSupport::JSON.decode(event)
17
16
 
18
- result["outbound_event"]["event_type"].should == event_type
19
- result["outbound_event"]["tenant"].should == tenant_uid
20
- result["outbound_event"]["root_path"].should == root_path
21
- result["outbound_event"]["uid"].should_not be_nil
17
+ result["event_type"].should == event_type
18
+ result["tenant"].should == tenant_uid
19
+ result["content"].should == content
20
+ result["uid"].should_not be_nil
22
21
  end
23
22
 
24
23
  it "generates a different uid for each event" do
25
- event_type = "shipment shipped"
26
- tenant_uid = "123123"
27
- root_path = "http://example.com"
28
-
29
- event1 = ActiveSupport::JSON.decode(Cpi::Generator.create_event(event_type, tenant_uid, root_path))
30
- event2 = ActiveSupport::JSON.decode(Cpi::Generator.create_event(event_type, tenant_uid, root_path))
24
+ event1 = ActiveSupport::JSON.decode(Cpi::Generator.create_event(event_type, tenant_uid, content))
25
+ event2 = ActiveSupport::JSON.decode(Cpi::Generator.create_event(event_type, tenant_uid, content))
31
26
 
32
- event1["outbound_event"]["uid"].should_not == event2["outbound_event"]["uid"]
27
+ event1["uid"].should_not == event2["uid"]
33
28
  end
34
- end
29
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpi-event-connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nulogy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-05 00:00:00 Z
18
+ date: 2012-03-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec