cpi-event-connector 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cpi_event_connector/generator.rb +2 -4
- data/lib/cpi_event_connector/version.rb +1 -1
- data/spec/event_spec.rb +5 -5
- data/spec/generator_spec.rb +13 -18
- metadata +4 -4
@@ -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,
|
7
|
+
def self.create_event(event_type, tenant_uid, content)
|
8
8
|
uid = UUIDTools::UUID.timestamp_create().to_s
|
9
9
|
|
10
|
-
hash = {"
|
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
|
|
data/spec/event_spec.rb
CHANGED
@@ -40,12 +40,12 @@ enabled: false"
|
|
40
40
|
|
41
41
|
describe ".transmit" do
|
42
42
|
|
43
|
-
let(:
|
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",
|
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({"
|
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", "
|
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", "
|
73
|
+
Cpi::Event.transmit("message", "tenant_uid", "content")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
data/spec/generator_spec.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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["
|
19
|
-
result["
|
20
|
-
result["
|
21
|
-
result["
|
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
|
-
|
26
|
-
|
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["
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2012-03-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|