schemata-staging 0.0.1.1 → 0.0.3.beta2

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.
@@ -1,186 +0,0 @@
1
- require 'yajl'
2
- require 'support/helpers'
3
- require 'schemata/staging'
4
-
5
- describe Schemata::Staging do
6
- describe ".mock_message" do
7
- it "should return a V1 object" do
8
- msg_obj = Schemata::Staging.mock_message(1)
9
- msg_obj.class.should == Schemata::Staging::Message::V1
10
- end
11
- end
12
- end
13
-
14
- describe Schemata::Staging::Message do
15
- describe ".decode" do
16
- context "current version is 1" do
17
-
18
- before :each do
19
- set_current_version(Schemata::Staging::Message, 1)
20
- end
21
-
22
- after :each do
23
- reset_version(Schemata::Staging::Message)
24
- end
25
-
26
- it "should return a V1 object when given a flat hash" do
27
- json = Yajl::Encoder.encode(
28
- Schemata::Staging::Message::V1::MOCK_VALUES)
29
- msg_obj = Schemata::Staging::Message.decode(json)
30
- msg_obj.class.should == Schemata::Staging::Message::V1
31
-
32
- msg_obj.app_id.should == 1
33
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
34
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
35
- msg_obj.properties.should ==
36
- Schemata::Staging::Message::V1::MOCK_VALUES["properties"]
37
- end
38
-
39
- it "should return a V1 object when given a V1-encoded json" do
40
- v1_hash = Schemata::HashCopyHelpers.deep_copy(
41
- Schemata::Staging::Message::V1::MOCK_VALUES)
42
- msg_hash = {"V1" => v1_hash, "min_version" => 1}
43
-
44
- json = Yajl::Encoder.encode(msg_hash)
45
-
46
- msg_obj = Schemata::Staging::Message.decode(json)
47
- msg_obj.class.should == Schemata::Staging::Message::V1
48
-
49
- msg_obj.app_id.should == 1
50
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
51
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
52
- msg_obj.properties.should ==
53
- Schemata::Staging::Message::V1::MOCK_VALUES["properties"]
54
- end
55
-
56
- it "should return a V1 object when given a mixed (flat hash + V1-encoded) json" do
57
- msg_hash = Schemata::HashCopyHelpers.deep_copy(
58
- Schemata::Staging::Message::V1::MOCK_VALUES)
59
-
60
- v1_hash = Schemata::HashCopyHelpers.deep_copy(msg_hash)
61
- msg_hash["V1"] = v1_hash
62
-
63
- msg_hash["min_version"] = 1
64
-
65
- json = Yajl::Encoder.encode(msg_hash)
66
-
67
- msg_obj = Schemata::Staging::Message.decode(json)
68
- msg_obj.class.should == Schemata::Staging::Message::V1
69
-
70
- msg_obj.app_id.should == 1
71
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
72
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
73
- msg_obj.properties.should ==
74
- Schemata::Staging::Message::V1::MOCK_VALUES["properties"]
75
- end
76
-
77
- it "should return a V1 object when given a V2-encoded json message" do
78
- v2_hash = Schemata::HashCopyHelpers.deep_copy(
79
- Schemata::Staging::Message::V1::MOCK_VALUES
80
- )
81
- msg_hash = {
82
- "V2" => v2_hash, "V1" => {}, "min_version" => 1
83
- }
84
-
85
- json = Yajl::Encoder.encode(msg_hash)
86
-
87
- msg_obj = Schemata::Staging::Message.decode(json)
88
- msg_obj.class.should == Schemata::Staging::Message::V1
89
-
90
- msg_obj.app_id.should == 1
91
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
92
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
93
- msg_obj.properties.should ==
94
- Schemata::Staging::Message::V1::MOCK_VALUES["properties"]
95
- end
96
-
97
- it "should raise an error if the input does not have the valid Schemata structure or a complete flat hash of the data" do
98
- json = Yajl::Encoder.encode({"app_id" => 1})
99
- expect {
100
- msg_obj = Schemata::Staging::Message.decode(json)
101
- }.to raise_error(Schemata::DecodeError)
102
- end
103
- end
104
- end
105
- end
106
-
107
- describe Schemata::Staging::Message::V1 do
108
- before :each do
109
- set_current_version(Schemata::Staging::Message, 1)
110
- end
111
-
112
- after :each do
113
- reset_version(Schemata::Staging::Message)
114
- end
115
-
116
- describe "#new" do
117
- it "should create a V1 obj with an incomplete hash" do
118
- msg_obj = Schemata::Staging::Message::V1.new({"app_id" => 1})
119
- end
120
-
121
- it "should raise an error if the hash contains incorrect types" do
122
- expect {
123
- msg_obj = Schemata::Staging::Message::V1.new({"app_id" => "foo"})
124
- }.to raise_error(Schemata::UpdateAttributeError)
125
- end
126
- end
127
-
128
- describe "#encode" do
129
- it "should return a json string, with V1 hash also in the raw payload" do
130
- msg_obj = Schemata::Staging.mock_message(1)
131
- json = msg_obj.encode
132
- json_hash = Yajl::Parser.parse(json)
133
-
134
- json_hash.should have_key "V1"
135
- json_hash.should have_key "min_version"
136
-
137
- v1_hash = json_hash['V1']
138
- min_version = json_hash['min_version']
139
- json_hash.delete('V1')
140
- json_hash.delete('min_version')
141
-
142
- v1_hash.should == json_hash
143
- end
144
-
145
- it "should raise an error if the object is not complete" do
146
- msg_obj = Schemata::Staging::Message::V1.new({"app_id" => 1})
147
- expect {
148
- json = msg_obj.encode
149
- }.to raise_error(Schemata::EncodeError)
150
- end
151
- end
152
-
153
- describe "#app_id" do
154
- it "should return the app_id if it was specified at instantiation" do
155
- msg_obj = Schemata::Staging::Message::V1.new({"app_id" => 1})
156
- msg_obj.app_id.should == 1
157
- end
158
-
159
- it "should return the app_id if it was set with an attr wrtier" do
160
- msg_obj = Schemata::Staging::Message::V1.new({})
161
- msg_obj.app_id = 1
162
- msg_obj.app_id.should == 1
163
- end
164
-
165
- it "should return nil if the app_id was never set" do
166
- msg_obj = Schemata::Staging::Message::V1.new({})
167
- msg_obj.app_id.should be_nil
168
- end
169
- end
170
-
171
- describe "#app_id=" do
172
- it "should change the app_id and return the new value" do
173
- msg_obj = Schemata::Staging::Message::V1.new({"app_id" => 1})
174
- ret = (msg_obj.app_id = 2)
175
- msg_obj.app_id.should == 2
176
- ret.should == 2
177
- end
178
-
179
- it "should raise an error if the wrong type is written" do
180
- msg_obj = Schemata::Staging::Message::V1.new({})
181
- expect {
182
- msg_obj.app_id = "foo"
183
- }.to raise_error(Schemata::UpdateAttributeError)
184
- end
185
- end
186
- end