neuron-client 0.2.6 → 0.3.0
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/README.md +11 -8
- data/lib/neuron-client/api.rb +5 -0
- data/lib/neuron-client/model/ad.rb +142 -0
- data/lib/neuron-client/model/ad_calculations.rb +325 -0
- data/lib/neuron-client/model/ad_zone.rb +45 -0
- data/lib/neuron-client/model/base.rb +233 -18
- data/lib/neuron-client/model/blocked_referer.rb +20 -0
- data/lib/neuron-client/model/blocked_user_agent.rb +21 -0
- data/lib/neuron-client/model/geo_target.rb +36 -0
- data/lib/neuron-client/model/pixel.rb +22 -0
- data/lib/neuron-client/model/report.rb +35 -0
- data/lib/neuron-client/model/s3_file.rb +30 -0
- data/lib/neuron-client/model/zone.rb +64 -0
- data/lib/neuron-client/model/zone_calculations.rb +37 -0
- data/lib/neuron-client/schema/ad.rb +406 -0
- data/lib/neuron-client/schema/ad_zone.rb +49 -0
- data/lib/neuron-client/schema/blocked_referer.rb +52 -0
- data/lib/neuron-client/schema/blocked_user_agent.rb +64 -0
- data/lib/neuron-client/schema/common.rb +220 -0
- data/lib/neuron-client/schema/event.rb +17 -0
- data/lib/neuron-client/schema/geo_target.rb +33 -0
- data/lib/neuron-client/schema/pixel.rb +39 -0
- data/lib/neuron-client/schema/report.rb +59 -0
- data/lib/neuron-client/schema/s3_file.rb +87 -0
- data/lib/neuron-client/schema/zone.rb +214 -0
- data/lib/neuron-client/version.rb +1 -1
- data/lib/neuron-client.rb +24 -59
- data/neuron-client.gemspec +3 -0
- data/spec/lib/admin_connection_spec.rb +234 -0
- data/spec/lib/api_spec.rb +41 -63
- data/spec/lib/model/ad_calculations_spec.rb +1146 -0
- data/spec/lib/model/ad_spec.rb +253 -0
- data/spec/lib/model/ad_zone_spec.rb +15 -0
- data/spec/lib/model/base_spec.rb +5 -83
- data/spec/lib/model/blocked_referer_spec.rb +36 -0
- data/spec/lib/model/blocked_user_agent_spec.rb +36 -0
- data/spec/lib/model/geo_target_spec.rb +28 -0
- data/spec/lib/model/pixel_spec.rb +36 -0
- data/spec/lib/model/report_spec.rb +17 -0
- data/spec/lib/{s3_file_spec.rb → model/s3_file_spec.rb} +6 -5
- data/spec/lib/model/zone_calculations_spec.rb +49 -0
- data/spec/lib/model/zone_spec.rb +155 -0
- data/spec/lib/schema/ad_spec.rb +515 -0
- data/spec/lib/schema/ad_zone_spec.rb +149 -0
- data/spec/lib/schema/blocked_referer_spec.rb +136 -0
- data/spec/lib/schema/blocked_user_agent_spec.rb +147 -0
- data/spec/lib/schema/geo_target_spec.rb +92 -0
- data/spec/lib/schema/pixel_spec.rb +125 -0
- data/spec/lib/schema/report_spec.rb +129 -0
- data/spec/lib/schema/s3_file_spec.rb +164 -0
- data/spec/lib/schema/zone_spec.rb +243 -0
- data/spec/spec_helper.rb +2 -1
- metadata +141 -121
- data/lib/neuron-client/model/admin/ad.rb +0 -22
- data/lib/neuron-client/model/admin/ad_zone.rb +0 -15
- data/lib/neuron-client/model/admin/base.rb +0 -91
- data/lib/neuron-client/model/admin/blocked_referer.rb +0 -12
- data/lib/neuron-client/model/admin/blocked_user_agent.rb +0 -12
- data/lib/neuron-client/model/admin/geo_target.rb +0 -16
- data/lib/neuron-client/model/admin/pixel.rb +0 -12
- data/lib/neuron-client/model/admin/report.rb +0 -15
- data/lib/neuron-client/model/admin/s3_file.rb +0 -12
- data/lib/neuron-client/model/admin/zone.rb +0 -15
- data/lib/neuron-client/model/common/ad.rb +0 -42
- data/lib/neuron-client/model/common/ad_calculations.rb +0 -329
- data/lib/neuron-client/model/common/ad_zone.rb +0 -17
- data/lib/neuron-client/model/common/base.rb +0 -67
- data/lib/neuron-client/model/common/blocked_referer.rb +0 -16
- data/lib/neuron-client/model/common/blocked_user_agent.rb +0 -16
- data/lib/neuron-client/model/common/geo_target.rb +0 -16
- data/lib/neuron-client/model/common/pixel.rb +0 -18
- data/lib/neuron-client/model/common/report.rb +0 -21
- data/lib/neuron-client/model/common/s3_file.rb +0 -16
- data/lib/neuron-client/model/common/zone.rb +0 -22
- data/lib/neuron-client/model/common/zone_calculations.rb +0 -41
- data/lib/neuron-client/model/membase/ad.rb +0 -49
- data/lib/neuron-client/model/membase/ad_zone.rb +0 -11
- data/lib/neuron-client/model/membase/blocked_referer.rb +0 -20
- data/lib/neuron-client/model/membase/blocked_user_agent.rb +0 -20
- data/lib/neuron-client/model/membase/geo_target.rb +0 -11
- data/lib/neuron-client/model/membase/pixel.rb +0 -22
- data/lib/neuron-client/model/membase/report.rb +0 -11
- data/lib/neuron-client/model/membase/s3_file.rb +0 -11
- data/lib/neuron-client/model/membase/zone.rb +0 -30
- data/lib/neuron-client/model/models.rb +0 -15
- data/spec/lib/model/admin/ad_spec.rb +0 -34
- data/spec/lib/model/admin/ad_zone_spec.rb +0 -19
- data/spec/lib/model/admin/base_spec.rb +0 -11
- data/spec/lib/model/admin/blocked_referer_spec.rb +0 -11
- data/spec/lib/model/admin/blocked_user_agent_spec.rb +0 -11
- data/spec/lib/model/admin/geo_target_spec.rb +0 -30
- data/spec/lib/model/admin/report_spec.rb +0 -21
- data/spec/lib/model/admin/s3_spec.rb +0 -11
- data/spec/lib/model/admin/zone_spec.rb +0 -21
- data/spec/lib/model/common/ad_calculations_spec.rb +0 -1151
- data/spec/lib/model/common/ad_spec.rb +0 -11
- data/spec/lib/model/common/ad_zone_spec.rb +0 -11
- data/spec/lib/model/common/base_spec.rb +0 -11
- data/spec/lib/model/common/blocked_referer_spec.rb +0 -11
- data/spec/lib/model/common/blocked_user_agent_spec.rb +0 -11
- data/spec/lib/model/common/geo_target_spec.rb +0 -11
- data/spec/lib/model/common/report_spec.rb +0 -11
- data/spec/lib/model/common/s3_spec.rb +0 -11
- data/spec/lib/model/common/zone_calculations_spec.rb +0 -54
- data/spec/lib/model/common/zone_spec.rb +0 -11
- data/spec/lib/model/membase/ad_spec.rb +0 -54
- data/spec/lib/model/membase/ad_zone_spec.rb +0 -11
- data/spec/lib/model/membase/base_spec.rb +0 -11
- data/spec/lib/model/membase/blocked_referer_spec.rb +0 -34
- data/spec/lib/model/membase/blocked_user_agent_spec.rb +0 -34
- data/spec/lib/model/membase/geo_target_spec.rb +0 -11
- data/spec/lib/model/membase/pixel_spec.rb +0 -34
- data/spec/lib/model/membase/report_spec.rb +0 -11
- data/spec/lib/model/membase/s3_spec.rb +0 -11
- data/spec/lib/model/membase/zone_spec.rb +0 -32
- data/spec/lib/old_spec.rb +0 -437
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
require 'json-schema'
|
|
2
|
+
|
|
3
|
+
module Neuron
|
|
4
|
+
module Schema
|
|
5
|
+
describe Report do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@datetime = "2011-11-11T11:11:11Z"
|
|
8
|
+
@monkey_wrench = {"monkey_wrench" => {"id" => 42, "name" => "a"}}
|
|
9
|
+
@monkey_wrenches = [
|
|
10
|
+
{"monkey_wrench" => {"id" => 1, "name" => "a"}},
|
|
11
|
+
{"monkey_wrench" => {"id" => 2, "name" => "b"}},
|
|
12
|
+
{"monkey_wrench" => {"id" => 3, "name" => "c"}}
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def validate(data, opts={})
|
|
17
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
18
|
+
JSON::Validator.validate!(schema, data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def invalidate(data, opts={})
|
|
22
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
23
|
+
JSON::Validator.validate(schema, data).should be_false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "index" do
|
|
27
|
+
it "should approve an example list of reports" do
|
|
28
|
+
validate(
|
|
29
|
+
[{"report" => {"id" => 42, "state" => "RUNNING", "template" => "delivery_metrics"}},
|
|
30
|
+
{"report" => {"id" => 82, "state" => "FAILED", "template" => "post_activities"}},
|
|
31
|
+
{"report" => {"id" => 246, "state" => "READY", "template" => "ad_events"}}
|
|
32
|
+
],
|
|
33
|
+
:against => Report::SCHEMA.index)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should approve an empty list" do
|
|
37
|
+
validate([], :against => Report::SCHEMA.index)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should not approve an example report outside of a list" do
|
|
41
|
+
invalidate(
|
|
42
|
+
{"report" => {"id" => 246, "state" => "READY", "template" => "ad_events"}},
|
|
43
|
+
:against => Report::SCHEMA.index)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
|
47
|
+
invalidate(@monkey_wrenches, :against => Report::SCHEMA.index)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "create" do
|
|
52
|
+
it "should approve an example report" do
|
|
53
|
+
validate({"report" => {
|
|
54
|
+
"template" => "ad_events",
|
|
55
|
+
"parameters" => {"start" => @datetime, "end" => @datetime}
|
|
56
|
+
}}, :against => Report::SCHEMA.create)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should not approve a report with missing information" do
|
|
60
|
+
invalidate({"report" => {
|
|
61
|
+
"template" => "ad_events",
|
|
62
|
+
"parameters" => {"start" => @datetime}
|
|
63
|
+
}}, :against => Report::SCHEMA.create)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should not approve a report with extra information" do
|
|
67
|
+
invalidate({"report" => {
|
|
68
|
+
"template" => "ad_events",
|
|
69
|
+
"parameters" => {"start" => @datetime, "end" => @datetime},
|
|
70
|
+
"state" => "WAITING" #extra
|
|
71
|
+
}}, :against => Report::SCHEMA.create)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should not approve a monkey wrench" do
|
|
75
|
+
invalidate(@monkey_wrench, :against => Report::SCHEMA.create)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "show" do
|
|
80
|
+
it "should approve an example report" do
|
|
81
|
+
validate({"report" => {
|
|
82
|
+
"template" => "ad_events",
|
|
83
|
+
"parameters" => {"start" => @datetime, "end" => @datetime},
|
|
84
|
+
"state" => "RUNNING",
|
|
85
|
+
"started_at" => @datetime,
|
|
86
|
+
"finished_at" => nil,
|
|
87
|
+
"accessed_at" => nil,
|
|
88
|
+
"created_at" => @datetime,
|
|
89
|
+
"updated_at" => @datetime,
|
|
90
|
+
"id" => 1
|
|
91
|
+
}}, :against => Report::SCHEMA.show)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should not approve a report with missing information" do
|
|
95
|
+
invalidate({"report" => {
|
|
96
|
+
"template" => "ad_events",
|
|
97
|
+
"parameters" => {"start" => @datetime, "end" => @datetime},
|
|
98
|
+
"state" => "RUNNING",
|
|
99
|
+
"started_at" => @datetime,
|
|
100
|
+
"finished_at" => nil,
|
|
101
|
+
"accessed_at" => nil,
|
|
102
|
+
# "created_at" => @datetime,
|
|
103
|
+
"updated_at" => @datetime,
|
|
104
|
+
"id" => 1
|
|
105
|
+
}}, :against => Report::SCHEMA.show)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should not approve a report with extra information" do
|
|
109
|
+
invalidate({"report" => {
|
|
110
|
+
"template" => "ad_events",
|
|
111
|
+
"parameters" => {"start" => @datetime, "end" => @datetime},
|
|
112
|
+
"state" => "RUNNING",
|
|
113
|
+
"started_at" => @datetime,
|
|
114
|
+
"finished_at" => nil,
|
|
115
|
+
"accessed_at" => nil,
|
|
116
|
+
"created_at" => @datetime,
|
|
117
|
+
"updated_at" => @datetime,
|
|
118
|
+
"id" => 1,
|
|
119
|
+
"name" => "extra"
|
|
120
|
+
}}, :against => Report::SCHEMA.show)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "should not approve a monkey wrench" do
|
|
124
|
+
invalidate(@monkey_wrench, :against => Report::SCHEMA.show)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
require 'json-schema'
|
|
2
|
+
|
|
3
|
+
module Neuron
|
|
4
|
+
module Schema
|
|
5
|
+
describe S3File do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@datetime = "2011-11-11T11:11:11Z"
|
|
8
|
+
@monkey_wrench = {"monkey_wrench" => {"id" => 42, "name" => "a"}}
|
|
9
|
+
@monkey_wrenches = [
|
|
10
|
+
{"monkey_wrench" => {"id" => 1, "name" => "a"}},
|
|
11
|
+
{"monkey_wrench" => {"id" => 2, "name" => "b"}},
|
|
12
|
+
{"monkey_wrench" => {"id" => 3, "name" => "c"}}
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def validate(data, opts={})
|
|
17
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
18
|
+
JSON::Validator.validate!(schema, data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def invalidate(data, opts={})
|
|
22
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
23
|
+
JSON::Validator.validate(schema, data).should be_false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "index" do
|
|
27
|
+
it "should approve an example list of S3 files" do
|
|
28
|
+
validate(
|
|
29
|
+
[{"s3_file" => {"id" => 42, "bucket" => "abc", "filename" => "1.log", "filesize" => 123, "purpose" => "RAW_EVENT_LOG", "created_at" => @datetime, "updated_at" => @datetime}},
|
|
30
|
+
{"s3_file" => {"id" => 82, "bucket" => "abc", "filename" => "2.log", "filesize" => 123, "purpose" => "RAW_EVENT_LOG", "created_at" => @datetime, "updated_at" => @datetime}},
|
|
31
|
+
{"s3_file" => {"id" => 246, "bucket" => "abc", "filename" => "3.log", "filesize" => 123, "purpose" => "RAW_EVENT_LOG", "created_at" => @datetime, "updated_at" => @datetime}},
|
|
32
|
+
],
|
|
33
|
+
:against => S3File::SCHEMA.index)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should approve an empty list" do
|
|
37
|
+
validate([], :against => S3File::SCHEMA.index)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should not approve an example S3 file outside of a list" do
|
|
41
|
+
invalidate(
|
|
42
|
+
{"s3_file" => {"id" => 42, "bucket" => "abc", "filename" => "1.log", "filesize" => 123, "purpose" => "RAW_EVENT_LOG", "created_at" => @datetime, "updated_at" => @datetime}},
|
|
43
|
+
:against => S3File::SCHEMA.index)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
|
47
|
+
invalidate(@monkey_wrenches, :against => S3File::SCHEMA.index)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "create" do
|
|
52
|
+
it "should approve an example S3 file" do
|
|
53
|
+
validate({"s3_file" => {
|
|
54
|
+
"bucket" => "abc",
|
|
55
|
+
"filename" => "1.log",
|
|
56
|
+
"filesize" => nil,
|
|
57
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
58
|
+
}}, :against => S3File::SCHEMA.create)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should not approve a S3 file with missing information" do
|
|
62
|
+
invalidate({"s3_file" => {
|
|
63
|
+
"bucket" => "abc",
|
|
64
|
+
"filename" => "1.log",
|
|
65
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
66
|
+
}}, :against => S3File::SCHEMA.create)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should not approve a S3 file with extra information" do
|
|
70
|
+
invalidate({"s3_file" => {
|
|
71
|
+
"bucket" => "abc",
|
|
72
|
+
"filename" => "1.log",
|
|
73
|
+
"filesize" => nil,
|
|
74
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
75
|
+
"name" => "extra"
|
|
76
|
+
}}, :against => S3File::SCHEMA.create)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should not approve a monkey wrench" do
|
|
80
|
+
invalidate(@monkey_wrench, :against => S3File::SCHEMA.create)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "show" do
|
|
85
|
+
it "should approve an example S3 file" do
|
|
86
|
+
validate({"s3_file" => {
|
|
87
|
+
"bucket" => "abc",
|
|
88
|
+
"filename" => "1.log",
|
|
89
|
+
"filesize" => nil,
|
|
90
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
91
|
+
"created_at" => @datetime,
|
|
92
|
+
"updated_at" => @datetime,
|
|
93
|
+
"id" => 1
|
|
94
|
+
}}, :against => S3File::SCHEMA.show)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should not approve a S3 file with missing information" do
|
|
98
|
+
invalidate({"s3_file" => {
|
|
99
|
+
"bucket" => "abc",
|
|
100
|
+
"filename" => "1.log",
|
|
101
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
102
|
+
"created_at" => @datetime,
|
|
103
|
+
"updated_at" => @datetime,
|
|
104
|
+
"id" => 1
|
|
105
|
+
}}, :against => S3File::SCHEMA.show)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should not approve a S3 file with extra information" do
|
|
109
|
+
invalidate({"s3_file" => {
|
|
110
|
+
"bucket" => "abc",
|
|
111
|
+
"filename" => "1.log",
|
|
112
|
+
"filesize" => nil,
|
|
113
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
114
|
+
"created_at" => @datetime,
|
|
115
|
+
"updated_at" => @datetime,
|
|
116
|
+
"id" => 1,
|
|
117
|
+
"name" => "extra"
|
|
118
|
+
}}, :against => S3File::SCHEMA.show)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should not approve a monkey wrench" do
|
|
122
|
+
invalidate(@monkey_wrench, :against => S3File::SCHEMA.show)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe "update" do
|
|
127
|
+
it "should approve an example S3 file" do
|
|
128
|
+
validate({"s3_file" => {
|
|
129
|
+
"bucket" => "abc",
|
|
130
|
+
"filename" => "1.log",
|
|
131
|
+
"filesize" => 1234,
|
|
132
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
133
|
+
"id" => 1
|
|
134
|
+
}}, :against => S3File::SCHEMA.update)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should not approve a S3 file with missing id" do
|
|
138
|
+
invalidate({"s3_file" => {
|
|
139
|
+
"bucket" => "abc",
|
|
140
|
+
"filename" => "1.log",
|
|
141
|
+
"filesize" => 1234,
|
|
142
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
143
|
+
#"id" => 1
|
|
144
|
+
}}, :against => S3File::SCHEMA.update)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should not approve a S3 file with extra information" do
|
|
148
|
+
invalidate({"s3_file" => {
|
|
149
|
+
"bucket" => "abc",
|
|
150
|
+
"filename" => "1.log",
|
|
151
|
+
"filesize" => nil,
|
|
152
|
+
"purpose" => "RAW_EVENT_LOG",
|
|
153
|
+
"id" => 1,
|
|
154
|
+
"name" => "extra"
|
|
155
|
+
}}, :against => S3File::SCHEMA.update)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "should not approve a monkey wrench" do
|
|
159
|
+
invalidate(@monkey_wrench, :against => S3File::SCHEMA.update)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
require 'json-schema'
|
|
2
|
+
|
|
3
|
+
module Neuron
|
|
4
|
+
module Schema
|
|
5
|
+
describe Zone do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@datetime = "2011-11-11T11:11:11Z"
|
|
8
|
+
@monkey_wrench = {"monkey_wrench" => {"id" => 42, "name" => "a"}}
|
|
9
|
+
@monkey_wrenches = [
|
|
10
|
+
{"monkey_wrench" => {"id" => 1, "name" => "a"}},
|
|
11
|
+
{"monkey_wrench" => {"id" => 2, "name" => "b"}},
|
|
12
|
+
{"monkey_wrench" => {"id" => 3, "name" => "c"}}
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def validate(data, opts={})
|
|
17
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
18
|
+
JSON::Validator.validate!(schema, data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def invalidate(data, opts={})
|
|
22
|
+
schema = opts[:against] || raise("You forgot to specify the schema!")
|
|
23
|
+
JSON::Validator.validate(schema, data).should be_false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "index" do
|
|
27
|
+
it "should approve an example list of zones" do
|
|
28
|
+
validate(
|
|
29
|
+
[{"zone" => {"id" => "abc123", "name" => nil}},
|
|
30
|
+
{"zone" => {"id" => "efg456", "name" => nil}},
|
|
31
|
+
{"zone" => {"id" => "hij789", "name" => nil}}
|
|
32
|
+
],
|
|
33
|
+
:against => Zone::SCHEMA.index)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should approve an empty list" do
|
|
37
|
+
validate([], :against => Zone::SCHEMA.index)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should not approve an example zone outside of a list" do
|
|
41
|
+
invalidate(
|
|
42
|
+
{"zone" => {"id" => "abc123", "name" => "fred"}},
|
|
43
|
+
:against => Zone::SCHEMA.index)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
|
47
|
+
invalidate(@monkey_wrenches, :against => Zone::SCHEMA.index)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "create" do
|
|
52
|
+
it "should approve an example redirect zone" do
|
|
53
|
+
validate({"zone" => {
|
|
54
|
+
"name" => "example_redirect_zone",
|
|
55
|
+
"response_type" => "Redirect",
|
|
56
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
57
|
+
"2" => {"weight" => 2.5, "priority" => 2}}
|
|
58
|
+
}}, :against => Zone::SCHEMA.create)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should approve an example iris zone" do
|
|
62
|
+
validate({"zone" => {
|
|
63
|
+
"name" => "example_iris_zone",
|
|
64
|
+
"response_type" => "Iris",
|
|
65
|
+
"ad_links" => {},
|
|
66
|
+
"expand" => "Yes",
|
|
67
|
+
"mute" => "No",
|
|
68
|
+
"autoplay" => "Yes",
|
|
69
|
+
"channel" => "drivel",
|
|
70
|
+
"template_slug" => "300x250",
|
|
71
|
+
"text_overlay" => "Yes",
|
|
72
|
+
"nami_feed_url" => "http://example.com/"
|
|
73
|
+
}}, :against => Zone::SCHEMA.create)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should approve an example vast zone" do
|
|
77
|
+
validate({"zone" => {
|
|
78
|
+
"name" => "example_vast_zone",
|
|
79
|
+
"response_type" => "Vast",
|
|
80
|
+
"ad_links" => {}
|
|
81
|
+
}}, :against => Zone::SCHEMA.create)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should not approve a zone with missing information" do
|
|
85
|
+
invalidate({"zone" => {
|
|
86
|
+
"name" => "example_redirect_zone",
|
|
87
|
+
#"response_type" => "Redirect",
|
|
88
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
89
|
+
"2" => {"weight" => 2.5, "priority" => 2}}
|
|
90
|
+
}}, :against => Zone::SCHEMA.create)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should not approve a zone with extra information" do
|
|
94
|
+
invalidate({"zone" => {
|
|
95
|
+
"name" => "example_redirect_zone",
|
|
96
|
+
"response_type" => "Redirect",
|
|
97
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
98
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
99
|
+
"channel" => "extra"
|
|
100
|
+
}}, :against => Zone::SCHEMA.create)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should not approve a monkey wrench" do
|
|
104
|
+
invalidate(@monkey_wrench, :against => Zone::SCHEMA.create)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe "show" do
|
|
109
|
+
it "should approve an example redirect zone" do
|
|
110
|
+
validate({"zone" => {
|
|
111
|
+
"name" => "example_redirect_zone",
|
|
112
|
+
"response_type" => "Redirect",
|
|
113
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
114
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
115
|
+
"created_at" => @datetime,
|
|
116
|
+
"updated_at" => @datetime,
|
|
117
|
+
"id" => "abc123"
|
|
118
|
+
}}, :against => Zone::SCHEMA.show)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should approve an example iris zone" do
|
|
122
|
+
validate({"zone" => {
|
|
123
|
+
"name" => "example_iris_zone",
|
|
124
|
+
"response_type" => "Iris",
|
|
125
|
+
"ad_links" => {},
|
|
126
|
+
"expand" => "Yes",
|
|
127
|
+
"mute" => "No",
|
|
128
|
+
"autoplay" => "Yes",
|
|
129
|
+
"channel" => "drivel",
|
|
130
|
+
"template_slug" => "300x250",
|
|
131
|
+
"text_overlay" => "No",
|
|
132
|
+
"nami_feed_url" => nil,
|
|
133
|
+
"created_at" => @datetime,
|
|
134
|
+
"updated_at" => @datetime,
|
|
135
|
+
"id" => "abc123"
|
|
136
|
+
}}, :against => Zone::SCHEMA.show)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should approve an example vast zone" do
|
|
140
|
+
validate({"zone" => {
|
|
141
|
+
"name" => "example_vast_zone",
|
|
142
|
+
"response_type" => "Vast",
|
|
143
|
+
"ad_links" => {},
|
|
144
|
+
"created_at" => @datetime,
|
|
145
|
+
"updated_at" => @datetime,
|
|
146
|
+
"id" => "abc123"
|
|
147
|
+
}}, :against => Zone::SCHEMA.show)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should not approve a zone with missing information" do
|
|
151
|
+
invalidate({"zone" => {
|
|
152
|
+
#"name" => "example_redirect_zone",
|
|
153
|
+
"response_type" => "Redirect",
|
|
154
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
155
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
156
|
+
"created_at" => @datetime,
|
|
157
|
+
"updated_at" => @datetime,
|
|
158
|
+
"id" => "abc123"
|
|
159
|
+
}}, :against => Zone::SCHEMA.show)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should not approve a zone with extra information" do
|
|
163
|
+
invalidate({"zone" => {
|
|
164
|
+
"name" => "example_redirect_zone",
|
|
165
|
+
"response_type" => "Redirect",
|
|
166
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
167
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
168
|
+
"created_at" => @datetime,
|
|
169
|
+
"updated_at" => @datetime,
|
|
170
|
+
"id" => "abc123",
|
|
171
|
+
"channel" => "extra"
|
|
172
|
+
}}, :against => Zone::SCHEMA.show)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "should not approve a monkey wrench" do
|
|
176
|
+
invalidate(@monkey_wrench, :against => Zone::SCHEMA.show)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "update" do
|
|
181
|
+
it "should approve an example redirect zone" do
|
|
182
|
+
validate({"zone" => {
|
|
183
|
+
"name" => "example_redirect_zone",
|
|
184
|
+
"response_type" => "Redirect",
|
|
185
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
186
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
187
|
+
"id" => "abc123"
|
|
188
|
+
}}, :against => Zone::SCHEMA.update)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should approve an example iris zone" do
|
|
192
|
+
validate({"zone" => {
|
|
193
|
+
"name" => "example_iris_zone",
|
|
194
|
+
"response_type" => "Iris",
|
|
195
|
+
"ad_links" => {},
|
|
196
|
+
"expand" => "Yes",
|
|
197
|
+
"mute" => "No",
|
|
198
|
+
"autoplay" => "Yes",
|
|
199
|
+
"channel" => "drivel",
|
|
200
|
+
"text_overlay" => "No",
|
|
201
|
+
"nami_feed_url" => nil,
|
|
202
|
+
"template_slug" => "300x250",
|
|
203
|
+
"id" => "abc123"
|
|
204
|
+
}}, :against => Zone::SCHEMA.update)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "should approve an example vast zone" do
|
|
208
|
+
validate({"zone" => {
|
|
209
|
+
"name" => "example vast zone",
|
|
210
|
+
"response_type" => "Vast",
|
|
211
|
+
"ad_links" => {},
|
|
212
|
+
"id" => "abc123"
|
|
213
|
+
}}, :against => Zone::SCHEMA.update)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "should not approve a zone with missing id" do
|
|
217
|
+
invalidate({"zone" => {
|
|
218
|
+
"name" => "example_redirect_zone",
|
|
219
|
+
"response_type" => "Redirect",
|
|
220
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
221
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
222
|
+
#"id" => "abc123"
|
|
223
|
+
}}, :against => Zone::SCHEMA.update)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "should not approve a zone with extra information" do
|
|
227
|
+
invalidate({"zone" => {
|
|
228
|
+
"name" => "example_redirect_zone",
|
|
229
|
+
"response_type" => "Redirect",
|
|
230
|
+
"ad_links" => {"1" => {"weight" => 1.5, "priority" => 1},
|
|
231
|
+
"2" => {"weight" => 2.5, "priority" => 2}},
|
|
232
|
+
"id" => "abc123",
|
|
233
|
+
"channel" => "drivel"
|
|
234
|
+
}}, :against => Zone::SCHEMA.update)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it "should not approve a monkey wrench" do
|
|
238
|
+
invalidate(@monkey_wrench, :against => Zone::SCHEMA.update)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|