schemata-router 0.0.1.beta9 → 0.0.1.beta10
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.
- data/lib/schemata/common/componentbase.rb +42 -0
- data/lib/schemata/common/msgbase.rb +13 -11
- data/lib/schemata/common/msgtypebase.rb +20 -0
- data/lib/schemata/common/parsed_msg.rb +1 -1
- data/lib/schemata/helpers/decamelize.rb +23 -0
- data/lib/schemata/helpers/hash_copy.rb +1 -1
- data/lib/schemata/helpers/stringify.rb +1 -1
- data/lib/schemata/router.rb +2 -9
- data/lib/schemata/router/register_request.rb +0 -4
- data/lib/schemata/router/start_message.rb +0 -4
- data/lib/schemata/router/version.rb +1 -1
- data/spec/common/helpers_spec.rb +16 -16
- data/spec/support/component_helpers.rb +16 -2
- data/spec/support/helpers.rb +0 -20
- data/spec/support/message_helpers.rb +23 -19
- data/spec/support/message_type_helpers.rb +59 -55
- metadata +11 -15
- data/spec/router/register_request_spec.rb +0 -10
- data/spec/router/router_spec.rb +0 -6
- data/spec/router/start_message_spec.rb +0 -10
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'schemata/helpers/decamelize'
|
2
|
+
|
3
|
+
module Schemata
|
4
|
+
module ComponentBase
|
5
|
+
|
6
|
+
def message_types
|
7
|
+
self.constants.select { |x| x != :VERSION }
|
8
|
+
end
|
9
|
+
|
10
|
+
def component_name
|
11
|
+
self.name.split("::")[1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def eigenclass
|
15
|
+
class << self; self; end
|
16
|
+
end
|
17
|
+
|
18
|
+
def register_mock_methods
|
19
|
+
message_types.each do |type|
|
20
|
+
message_type = self::const_get(type)
|
21
|
+
mock_method_name = "mock_#{Schemata::Helpers.decamelize(type.to_s)}"
|
22
|
+
eigenclass.send(:define_method, mock_method_name) do |*args|
|
23
|
+
version = args[0] || message_type.current_version
|
24
|
+
message_type::const_get("V#{version}").mock
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def require_message_classes
|
30
|
+
path = "./lib/schemata/"
|
31
|
+
path << Schemata::Helpers.decamelize(component_name)
|
32
|
+
path << "/*.rb"
|
33
|
+
Dir.glob(path, &method(:require))
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.extended(klass)
|
37
|
+
klass.require_message_classes
|
38
|
+
klass.register_mock_methods
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -14,7 +14,7 @@ module Schemata
|
|
14
14
|
@contents = {}
|
15
15
|
|
16
16
|
data.each do |key, field_value|
|
17
|
-
key = Schemata::
|
17
|
+
key = Schemata::Helpers.stringify(key)
|
18
18
|
field_schema = @schema.schemas[key]
|
19
19
|
next unless field_schema
|
20
20
|
|
@@ -27,7 +27,7 @@ module Schemata
|
|
27
27
|
# symbols, but on the decoding side, it should expect strings. To allow
|
28
28
|
# for this in the schema definition, Schemata stringifies all symbols during
|
29
29
|
# construction of Schemata objects.
|
30
|
-
field_value = Schemata::
|
30
|
+
field_value = Schemata::Helpers.stringify(field_value)
|
31
31
|
|
32
32
|
begin
|
33
33
|
field_schema.validate(field_value)
|
@@ -35,7 +35,7 @@ module Schemata
|
|
35
35
|
raise Schemata::UpdateAttributeError.new(key, e.message)
|
36
36
|
end
|
37
37
|
|
38
|
-
@contents[key] = Schemata::
|
38
|
+
@contents[key] = Schemata::Helpers.deep_copy(field_value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,7 +45,7 @@ module Schemata
|
|
45
45
|
schema.schemas.each do |key, field_schema|
|
46
46
|
vc_klass.send(:define_method, key) do
|
47
47
|
unless @contents[key].nil?
|
48
|
-
return Schemata::
|
48
|
+
return Schemata::Helpers.deep_copy(@contents[key])
|
49
49
|
end
|
50
50
|
nil
|
51
51
|
end
|
@@ -53,13 +53,15 @@ module Schemata
|
|
53
53
|
# TODO This call to stringify should be removed when cc/dea stops using
|
54
54
|
# symbols. See comment above for a better description.
|
55
55
|
vc_klass.send(:define_method, "#{key}=") do |field_value|
|
56
|
-
field_value = Schemata::
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
field_value = Schemata::Helpers.stringify(field_value)
|
57
|
+
unless schema.optional_keys.include?(key) && field_value == nil
|
58
|
+
begin
|
59
|
+
field_schema.validate(field_value)
|
60
|
+
rescue Membrane::SchemaValidationError => e
|
61
|
+
raise Schemata::UpdateAttributeError.new(key, e.message)
|
62
|
+
end
|
61
63
|
end
|
62
|
-
@contents[key] = Schemata::
|
64
|
+
@contents[key] = Schemata::Helpers.deep_copy(field_value)
|
63
65
|
field_value
|
64
66
|
end
|
65
67
|
end
|
@@ -67,7 +69,7 @@ module Schemata
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def contents
|
70
|
-
Schemata::
|
72
|
+
Schemata::Helpers.deep_copy(@contents)
|
71
73
|
end
|
72
74
|
|
73
75
|
def empty?
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'schemata/common/msgbase'
|
2
2
|
require 'schemata/common/parsed_msg'
|
3
|
+
require 'schemata/helpers/decamelize'
|
3
4
|
|
4
5
|
module Schemata
|
5
6
|
module MessageTypeBase
|
@@ -70,8 +71,27 @@ module Schemata
|
|
70
71
|
Schemata::const_get(component)
|
71
72
|
end
|
72
73
|
|
74
|
+
def component_name
|
75
|
+
self.name.split("::")[1]
|
76
|
+
end
|
77
|
+
|
78
|
+
def message_type_name
|
79
|
+
self.name.split("::")[2]
|
80
|
+
end
|
81
|
+
|
82
|
+
def require_message_versions
|
83
|
+
path = "./lib/schemata/"
|
84
|
+
path << Schemata::Helpers.decamelize(component_name)
|
85
|
+
path << "/"
|
86
|
+
path << Schemata::Helpers.decamelize(message_type_name)
|
87
|
+
path << "/*.rb"
|
88
|
+
|
89
|
+
Dir.glob(path, &method(:require))
|
90
|
+
end
|
91
|
+
|
73
92
|
def self.extended(o)
|
74
93
|
o.extend Dsl
|
94
|
+
o.require_message_versions
|
75
95
|
end
|
76
96
|
|
77
97
|
module Dsl
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Schemata
|
2
|
+
module Helpers
|
3
|
+
def self.decamelize(str)
|
4
|
+
words = []
|
5
|
+
curr_word = ""
|
6
|
+
0.upto(str.length - 1) do |i|
|
7
|
+
ch = str[i]
|
8
|
+
if ch =~ /[A-Z]/
|
9
|
+
words.push(curr_word)
|
10
|
+
curr_word = ""
|
11
|
+
end
|
12
|
+
curr_word += ch
|
13
|
+
end
|
14
|
+
words.push(curr_word)
|
15
|
+
words.map! { |x| x.downcase }
|
16
|
+
|
17
|
+
# If the first letter is capitalized, then the first word here is empty
|
18
|
+
words.shift if words[0] == ""
|
19
|
+
|
20
|
+
words.join('_')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/schemata/router.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
require 'schemata/
|
2
|
-
require 'schemata/router/start_message'
|
1
|
+
require 'schemata/common/componentbase'
|
3
2
|
|
4
3
|
module Schemata
|
5
4
|
module Router
|
6
|
-
|
7
|
-
RegisterRequest::const_get("V#{version}").mock
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.mock_start_message(version=StartMessage.current_version)
|
11
|
-
StartMessage::const_get("V#{version}").mock
|
12
|
-
end
|
5
|
+
extend Schemata::ComponentBase
|
13
6
|
end
|
14
7
|
end
|
data/spec/common/helpers_spec.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
require 'schemata/helpers/hash_copy'
|
2
2
|
require 'schemata/helpers/stringify'
|
3
3
|
|
4
|
-
describe Schemata::
|
4
|
+
describe Schemata::Helpers do
|
5
5
|
describe "#deep_copy" do
|
6
6
|
it "should deep copy nil" do
|
7
|
-
copy = Schemata::
|
7
|
+
copy = Schemata::Helpers.deep_copy(nil)
|
8
8
|
copy.should == nil
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should deep copy a given string" do
|
12
12
|
original = "foo"
|
13
|
-
copy = Schemata::
|
13
|
+
copy = Schemata::Helpers.deep_copy(original)
|
14
14
|
copy.should be_instance_of String
|
15
15
|
copy.should == original
|
16
16
|
copy.object_id.should_not == original.object_id
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should deep copy a given boolean" do
|
20
|
-
Schemata::
|
20
|
+
Schemata::Helpers.deep_copy(true).
|
21
21
|
should be_an_instance_of TrueClass
|
22
|
-
Schemata::
|
22
|
+
Schemata::Helpers.deep_copy(false).
|
23
23
|
should be_an_instance_of FalseClass
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should deep copy a given numeric type" do
|
27
27
|
original = 0
|
28
|
-
copy = Schemata::
|
28
|
+
copy = Schemata::Helpers.deep_copy(original)
|
29
29
|
copy.should == original
|
30
30
|
copy.should be_an_instance_of Fixnum
|
31
31
|
|
32
32
|
# set original to be max fixnum + 1
|
33
33
|
original = 2**(0.size * 8 - 2)
|
34
|
-
copy = Schemata::
|
34
|
+
copy = Schemata::Helpers.deep_copy(original)
|
35
35
|
copy.should == original
|
36
36
|
copy.should be_an_instance_of Bignum
|
37
37
|
|
38
38
|
original = 0.0
|
39
|
-
copy = Schemata::
|
39
|
+
copy = Schemata::Helpers.deep_copy(original)
|
40
40
|
copy.should == original
|
41
41
|
copy.should be_an_instance_of Float
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should deep copy a given hash" do
|
45
45
|
original = {"foo" => "bar"}
|
46
|
-
copy = Schemata::
|
46
|
+
copy = Schemata::Helpers.deep_copy(original)
|
47
47
|
copy.should be_instance_of Hash
|
48
48
|
copy.should == original
|
49
49
|
|
@@ -53,7 +53,7 @@ describe Schemata::HashCopyHelpers do
|
|
53
53
|
|
54
54
|
it "should deep copy a given array" do
|
55
55
|
original = [1, 2, "hello"]
|
56
|
-
copy = Schemata::
|
56
|
+
copy = Schemata::Helpers.deep_copy(original)
|
57
57
|
copy.should be_instance_of Array
|
58
58
|
copy.should == original
|
59
59
|
|
@@ -69,7 +69,7 @@ describe Schemata::HashCopyHelpers do
|
|
69
69
|
"hello" => "goodbye",
|
70
70
|
},
|
71
71
|
}
|
72
|
-
copy = Schemata::
|
72
|
+
copy = Schemata::Helpers.deep_copy(original)
|
73
73
|
copy.should be_instance_of Hash
|
74
74
|
copy.should == original
|
75
75
|
|
@@ -83,32 +83,32 @@ describe Schemata::HashCopyHelpers do
|
|
83
83
|
it "should raise error for unknown type" do
|
84
84
|
klass = Class.new
|
85
85
|
expect do
|
86
|
-
Schemata::
|
86
|
+
Schemata::Helpers.deep_copy(klass.new)
|
87
87
|
end.to raise_error(described_class::CopyError, /Unexpected class: /)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
describe "#stringify" do
|
92
92
|
it "should stringify nil" do
|
93
|
-
str = Schemata::
|
93
|
+
str = Schemata::Helpers.stringify(nil)
|
94
94
|
str.should == nil
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should stringify a string" do
|
98
98
|
original = "foo"
|
99
|
-
str = Schemata::
|
99
|
+
str = Schemata::Helpers.stringify(original)
|
100
100
|
str.should == "foo"
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should stringify a symbol" do
|
104
104
|
original = :foo
|
105
|
-
str = Schemata::
|
105
|
+
str = Schemata::Helpers.stringify(original)
|
106
106
|
str.should == "foo"
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should stringify a hash" do
|
110
110
|
original = { "foo" => :foo }
|
111
|
-
str = Schemata::
|
111
|
+
str = Schemata::Helpers.stringify(original)
|
112
112
|
str.should == { "foo" => "foo" }
|
113
113
|
end
|
114
114
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'support/helpers'
|
2
|
+
require 'schemata/helpers/decamelize'
|
2
3
|
|
3
4
|
shared_examples "a schemata component" do
|
4
5
|
|
5
6
|
described_class.constants.select { |x| x != :VERSION }.each do |msg_type|
|
6
|
-
describe ".mock_#{decamelize(msg_type.to_s)}" do
|
7
|
+
describe ".mock_#{Schemata::Helpers.decamelize(msg_type.to_s)}" do
|
7
8
|
versions = described_class::const_get(msg_type).constants.select { |x| x =~ /V[0-9]+/ }
|
8
9
|
versions.map { |x| x = x.to_s[1..-1].to_i }.each do |version|
|
9
10
|
it_behaves_like "a mocking method", version do
|
@@ -12,11 +13,24 @@ shared_examples "a schemata component" do
|
|
12
13
|
let(:component) { described_class }
|
13
14
|
let(:component_name) { component.name.split("::")[1] }
|
14
15
|
|
15
|
-
let(:mock_method) { "mock_#{decamelize(msg_type)}"}
|
16
|
+
let(:mock_method) { "mock_#{Schemata::Helpers.decamelize(msg_type)}"}
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
describe msg_type do
|
22
|
+
message_type = described_class::const_get(msg_type)
|
23
|
+
it_behaves_like "a message type", message_type do
|
24
|
+
let (:message_type) { described_class::const_get(msg_type) }
|
25
|
+
let (:message_type_name) { msg_type.to_s }
|
26
|
+
let (:component) { described_class }
|
27
|
+
let (:component_name) { component.name.split("::")[1] }
|
28
|
+
|
29
|
+
let (:mock_method) { "mock_#{Schemata::Helpers.decamelize(msg_type)}" }
|
30
|
+
end
|
31
|
+
end
|
19
32
|
end
|
33
|
+
|
20
34
|
end
|
21
35
|
|
22
36
|
shared_examples "a mocking method" do |version|
|
data/spec/support/helpers.rb
CHANGED
@@ -26,26 +26,6 @@ def greater_version?(version, benchmark)
|
|
26
26
|
version > benchmark
|
27
27
|
end
|
28
28
|
|
29
|
-
def decamelize(str)
|
30
|
-
words = []
|
31
|
-
curr_word = ""
|
32
|
-
0.upto(str.length - 1) do |i|
|
33
|
-
ch = str[i]
|
34
|
-
if ch =~ /[A-Z]/
|
35
|
-
words.push(curr_word)
|
36
|
-
curr_word = ""
|
37
|
-
end
|
38
|
-
curr_word += ch
|
39
|
-
end
|
40
|
-
words.push(curr_word)
|
41
|
-
words.map! { |x| x.downcase }
|
42
|
-
|
43
|
-
# If the first letter is capitalized, then the first word here is empty
|
44
|
-
words.shift if words[0] == ""
|
45
|
-
|
46
|
-
words.join('_')
|
47
|
-
end
|
48
|
-
|
49
29
|
def num_mandatory_fields(msg_obj)
|
50
30
|
optional = msg_obj.class.schema.optional_keys
|
51
31
|
mandatory = Set.new(msg_obj.class.schema.schemas.keys)
|
@@ -1,16 +1,5 @@
|
|
1
|
-
shared_examples "a message" do
|
2
|
-
|
3
|
-
version = described_class.version
|
4
|
-
|
5
|
-
let(:component_name) { described_class.name.split("::")[1] }
|
6
|
-
let(:message_type_name) { described_class.name.split("::")[2] }
|
7
|
-
let(:message_name) { described_class.name.split("::")[3] }
|
8
|
-
|
9
|
-
let(:component) { Schemata::const_get(component_name) }
|
10
|
-
let(:message_type) { component::const_get(message_type_name) }
|
11
|
-
let(:message) { described_class }
|
12
|
-
|
13
|
-
let(:mock_method) { "mock_#{decamelize(message_type_name)}" }
|
1
|
+
shared_examples "a message" do |msg|
|
2
|
+
version = msg.version
|
14
3
|
|
15
4
|
before :each do
|
16
5
|
set_current_version(message_type, version)
|
@@ -21,7 +10,7 @@ shared_examples "a message" do
|
|
21
10
|
end
|
22
11
|
|
23
12
|
describe "#new" do
|
24
|
-
it "should create a #{
|
13
|
+
it "should create a #{msg} object with an incomplete hash" do
|
25
14
|
mock_hash = component.send(mock_method, 1).contents
|
26
15
|
first_key = mock_hash.keys[0]
|
27
16
|
first_value = mock_hash[first_key]
|
@@ -68,7 +57,7 @@ shared_examples "a message" do
|
|
68
57
|
json_hash.should have_key "V1"
|
69
58
|
json_hash.should have_key "min_version"
|
70
59
|
|
71
|
-
data = Schemata::
|
60
|
+
data = Schemata::Helpers.deep_copy(json_hash["V1"])
|
72
61
|
|
73
62
|
json_hash.delete("V1")
|
74
63
|
json_hash.delete("min_version")
|
@@ -86,7 +75,7 @@ shared_examples "a message" do
|
|
86
75
|
end
|
87
76
|
json_hash.should have_key "min_version"
|
88
77
|
|
89
|
-
data = Schemata::
|
78
|
+
data = Schemata::Helpers.deep_copy(json_hash["V#{version}"])
|
90
79
|
1.upto(version) do |i|
|
91
80
|
json_hash.delete("V#{i}")
|
92
81
|
end
|
@@ -97,9 +86,9 @@ shared_examples "a message" do
|
|
97
86
|
end
|
98
87
|
end
|
99
88
|
|
100
|
-
|
89
|
+
msg.schema.schemas.keys.each do |attr|
|
101
90
|
describe "##{attr}" do
|
102
|
-
it "should the attribute if it was specified at instantiation" do
|
91
|
+
it "should return the attribute if it was specified at instantiation" do
|
103
92
|
mock_value = component.send(mock_method, version).contents[attr]
|
104
93
|
msg_obj = message.new({ attr => mock_value })
|
105
94
|
msg_obj.send(attr).should == mock_value
|
@@ -116,6 +105,21 @@ shared_examples "a message" do
|
|
116
105
|
msg_obj = message.new
|
117
106
|
msg_obj.send(attr).should be_nil
|
118
107
|
end
|
108
|
+
|
109
|
+
if msg.schema.optional_keys.include? attr
|
110
|
+
context "the attribute is optional" do
|
111
|
+
it "should allow nil values during instantiation" do
|
112
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
113
|
+
hash = { attr => mock_value }
|
114
|
+
msg_obj = message.new(hash)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be able to set the attribute to nil" do
|
118
|
+
msg_obj = message.new
|
119
|
+
msg_obj.send("#{attr}=", nil)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
119
123
|
end
|
120
124
|
|
121
125
|
describe "##{attr}=" do
|
@@ -127,7 +131,7 @@ shared_examples "a message" do
|
|
127
131
|
ret.should == mock_value
|
128
132
|
end
|
129
133
|
|
130
|
-
unless
|
134
|
+
unless msg.schema.schemas[attr].kind_of? Membrane::Schema::Any
|
131
135
|
it "should raise an error if the wrong type is written" do
|
132
136
|
mock_value = component.send(mock_method, version).contents[attr]
|
133
137
|
|
@@ -1,15 +1,8 @@
|
|
1
|
-
shared_examples "a message type" do
|
1
|
+
shared_examples "a message type" do |msg_type|
|
2
2
|
|
3
|
-
versions =
|
3
|
+
versions = msg_type.constants.select {|x| x =~ /V[0-9]+/ }
|
4
4
|
.map {|x| x.to_s[1..-1].to_i}
|
5
5
|
|
6
|
-
let(:message_type_name) { described_class.name.split("::")[2] }
|
7
|
-
let(:message_type) { described_class }
|
8
|
-
let(:component_name) { described_class.name.split("::")[1] }
|
9
|
-
let(:component) { Schemata::const_get(component_name) }
|
10
|
-
|
11
|
-
let(:mock_method) { "mock_#{decamelize(message_type_name)}" }
|
12
|
-
|
13
6
|
describe ".decode" do
|
14
7
|
context "when the current version is 1" do
|
15
8
|
before :each do
|
@@ -50,7 +43,7 @@ shared_examples "a message type" do
|
|
50
43
|
msg_hash = {
|
51
44
|
"V1" => data,
|
52
45
|
"min_version" => 1
|
53
|
-
}.merge(Schemata::
|
46
|
+
}.merge(Schemata::Helpers.deep_copy(data))
|
54
47
|
json = Yajl::Encoder.encode(msg_hash)
|
55
48
|
|
56
49
|
msg_obj = message_type.decode(json)
|
@@ -96,68 +89,68 @@ structure or a complete flash hash" do
|
|
96
89
|
}.to raise_error(Schemata::DecodeError)
|
97
90
|
end
|
98
91
|
end
|
99
|
-
end
|
100
92
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
if versions.include?(2)
|
94
|
+
context "when the current version is 2" do
|
95
|
+
before :each do
|
96
|
+
set_current_version(message_type, 2)
|
97
|
+
end
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
after :each do
|
100
|
+
reset_version(message_type)
|
101
|
+
end
|
110
102
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
103
|
+
it "should raise an error given a flat hash" do
|
104
|
+
data = component.send(mock_method, 2).contents
|
105
|
+
json = Yajl::Encoder.encode(data)
|
106
|
+
expect {
|
107
|
+
msg_obj = message_type.decode(json)
|
108
|
+
}.to raise_error(Schemata::DecodeError)
|
109
|
+
end
|
118
110
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
111
|
+
it "should return a V2 object a given a mixed (flat hash + V1-encoded) json" do
|
112
|
+
msg_hash = component.send(mock_method, 2).contents
|
113
|
+
v1_hash = Schemata::Helpers.deep_copy(msg_hash)
|
114
|
+
msg_hash["V1"] = v1_hash
|
115
|
+
msg_hash["min_version"] = 1
|
124
116
|
|
125
|
-
|
117
|
+
json = Yajl::Encoder.encode(msg_hash)
|
126
118
|
|
127
|
-
|
128
|
-
|
119
|
+
msg_obj = message_type.decode(json)
|
120
|
+
msg_obj.class.should == message_type::V2
|
129
121
|
|
130
|
-
|
131
|
-
|
122
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
123
|
+
msg_obj.send(key).should == v1_hash[key]
|
124
|
+
end
|
132
125
|
end
|
133
|
-
end
|
134
126
|
|
135
|
-
|
136
|
-
|
137
|
-
|
127
|
+
it "should return a V2 object given a V1-encoded json" do
|
128
|
+
v1_hash = component.send(mock_method, 1).contents
|
129
|
+
msg_hash = {"V1" => v1_hash, 'min_version' => 1}
|
138
130
|
|
139
|
-
|
131
|
+
json = Yajl::Encoder.encode(msg_hash)
|
140
132
|
|
141
|
-
|
142
|
-
|
133
|
+
msg_obj = message_type.decode(json)
|
134
|
+
msg_obj.class.should == message_type::V2
|
143
135
|
|
144
|
-
|
145
|
-
|
136
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
137
|
+
msg_obj.send(key).should == v1_hash[key]
|
138
|
+
end
|
146
139
|
end
|
147
|
-
end
|
148
140
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
141
|
+
it "should return a V2 object given a V2-encoded object" do
|
142
|
+
data = component.send(mock_method, 2).contents
|
143
|
+
v2_hash = Schemata::Helpers.deep_copy(data)
|
144
|
+
msg_hash = {"V2" => v2_hash, "V1" => {}, "min_version" => 1}
|
153
145
|
|
154
|
-
|
146
|
+
json = Yajl::Encoder.encode(msg_hash)
|
155
147
|
|
156
|
-
|
157
|
-
|
148
|
+
msg_obj = message_type.decode(json)
|
149
|
+
msg_obj.class.should == message_type::V2
|
158
150
|
|
159
|
-
|
160
|
-
|
151
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
152
|
+
msg_obj.send(key).should == data[key]
|
153
|
+
end
|
161
154
|
end
|
162
155
|
end
|
163
156
|
end
|
@@ -168,4 +161,15 @@ structure or a complete flash hash" do
|
|
168
161
|
versions.select { |x| x > 2 }.each do |version|
|
169
162
|
|
170
163
|
end
|
164
|
+
|
165
|
+
# Test message version types
|
166
|
+
versions.each do |version|
|
167
|
+
msg = msg_type::const_get("V#{version}")
|
168
|
+
describe "V#{version}" do
|
169
|
+
it_behaves_like "a message", msg do
|
170
|
+
let (:message) { message_type::const_get("V#{version}") }
|
171
|
+
let (:message_name) { message.to_s }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
171
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemata-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta10
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -115,24 +115,23 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- lib/schemata/common/componentbase.rb
|
119
|
+
- lib/schemata/common/error.rb
|
120
|
+
- lib/schemata/common/msgbase.rb
|
121
|
+
- lib/schemata/common/msgtypebase.rb
|
122
|
+
- lib/schemata/common/parsed_msg.rb
|
123
|
+
- lib/schemata/helpers/decamelize.rb
|
124
|
+
- lib/schemata/helpers/hash_copy.rb
|
125
|
+
- lib/schemata/helpers/stringify.rb
|
118
126
|
- lib/schemata/router/register_directory_server_request/register_directory_server_request_v1.rb
|
119
|
-
- lib/schemata/router/register_request.rb
|
120
127
|
- lib/schemata/router/register_request/register_request_v1.rb
|
128
|
+
- lib/schemata/router/register_request.rb
|
129
|
+
- lib/schemata/router/start_message/start_message_v1.rb
|
121
130
|
- lib/schemata/router/start_message.rb
|
122
131
|
- lib/schemata/router/version.rb
|
123
|
-
- lib/schemata/router/start_message/start_message_v1.rb
|
124
132
|
- lib/schemata/router.rb
|
125
|
-
- lib/schemata/common/msgtypebase.rb
|
126
|
-
- lib/schemata/common/parsed_msg.rb
|
127
|
-
- lib/schemata/common/msgbase.rb
|
128
|
-
- lib/schemata/common/error.rb
|
129
|
-
- lib/schemata/helpers/stringify.rb
|
130
|
-
- lib/schemata/helpers/hash_copy.rb
|
131
133
|
- spec/common/helpers_spec.rb
|
132
134
|
- spec/common/parsed_msg_spec.rb
|
133
|
-
- spec/router/register_request_spec.rb
|
134
|
-
- spec/router/router_spec.rb
|
135
|
-
- spec/router/start_message_spec.rb
|
136
135
|
- spec/spec_helper.rb
|
137
136
|
- spec/support/component_helpers.rb
|
138
137
|
- spec/support/helpers.rb
|
@@ -165,9 +164,6 @@ summary: validation for cloundfoundry Router messages
|
|
165
164
|
test_files:
|
166
165
|
- spec/common/helpers_spec.rb
|
167
166
|
- spec/common/parsed_msg_spec.rb
|
168
|
-
- spec/router/register_request_spec.rb
|
169
|
-
- spec/router/router_spec.rb
|
170
|
-
- spec/router/start_message_spec.rb
|
171
167
|
- spec/spec_helper.rb
|
172
168
|
- spec/support/component_helpers.rb
|
173
169
|
- spec/support/helpers.rb
|
data/spec/router/router_spec.rb
DELETED