neuron-client 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,149 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Neuron
|
4
|
+
module Schema
|
5
|
+
describe AdZone do
|
6
|
+
before(:each) do
|
7
|
+
@datetime = "2011-11-11T11:11:11Z"
|
8
|
+
@monkey_wrench = {"monkey_wrench" => {"id" => 42, "name" => "a", "updated_at" => @datetime}}
|
9
|
+
@monkey_wrenches = [
|
10
|
+
{"monkey_wrench" => {"id" => 1, "name" => "a", "updated_at" => @datetime}},
|
11
|
+
{"monkey_wrench" => {"id" => 2, "name" => "b", "updated_at" => @datetime}},
|
12
|
+
{"monkey_wrench" => {"id" => 3, "name" => "c", "updated_at" => @datetime}}
|
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 ad-zones" do
|
28
|
+
validate(
|
29
|
+
[{"ad_zone" => {"ad_id" => 42, "zone_id" => "zone101", "weight" => 1.5, "priority" => 1}},
|
30
|
+
{"ad_zone" => {"ad_id" => 82, "zone_id" => "zone101", "weight" => 1.0, "priority" => 2}},
|
31
|
+
{"ad_zone" => {"ad_id" => 246, "zone_id" => "zone102", "weight" => 1.5, "priority" => 1}}
|
32
|
+
],
|
33
|
+
:against => AdZone::SCHEMA.index)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should approve an empty list" do
|
37
|
+
validate([], :against => AdZone::SCHEMA.index)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not approve an example ad_zone outside of a list" do
|
41
|
+
invalidate(
|
42
|
+
{"ad_zone" => {"ad_id" => 42, "zone_id" => "zone101", "weight" => 1.5, "priority" => 1}},
|
43
|
+
:against => AdZone::SCHEMA.index)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
47
|
+
invalidate(@monkey_wrenches, :against => AdZone::SCHEMA.index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "create" do
|
52
|
+
it "should approve an example ad-zone" do
|
53
|
+
validate({"ad_zone" => {
|
54
|
+
"ad_id" => 1,
|
55
|
+
"zone_id" => "zone1",
|
56
|
+
"weight" => 1.0,
|
57
|
+
"priority" => 1
|
58
|
+
}}, :against => AdZone::SCHEMA.create)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not approve a ad-zone with missing information" do
|
62
|
+
invalidate({"ad_zone" => {
|
63
|
+
"ad_id" => 1,
|
64
|
+
"zone_id" => "zone1",
|
65
|
+
}}, :against => AdZone::SCHEMA.create)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not approve a ad-zone with extra information" do
|
69
|
+
invalidate({"ad_zone" => {
|
70
|
+
"ad_id" => 1,
|
71
|
+
"zone_id" => "zone1",
|
72
|
+
"weight" => 1.0,
|
73
|
+
"priority" => 1,
|
74
|
+
"id" => 9
|
75
|
+
}}, :against => AdZone::SCHEMA.create)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not approve a monkey wrench" do
|
79
|
+
invalidate(@monkey_wrench, :against => AdZone::SCHEMA.create)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "show" do
|
84
|
+
it "should approve an example ad-zone" do
|
85
|
+
validate({"ad_zone" => {
|
86
|
+
"ad_id" => 1,
|
87
|
+
"zone_id" => "zone1",
|
88
|
+
"weight" => 1.0,
|
89
|
+
"priority" => 1
|
90
|
+
}}, :against => AdZone::SCHEMA.show)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not approve a ad-zone with missing information" do
|
94
|
+
invalidate({"ad_zone" => {
|
95
|
+
"ad_id" => 1,
|
96
|
+
"zone_id" => "zone1",
|
97
|
+
}}, :against => AdZone::SCHEMA.show)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not approve a ad-zone with extra information" do
|
101
|
+
invalidate({"ad_zone" => {
|
102
|
+
"ad_id" => 1,
|
103
|
+
"zone_id" => "zone1",
|
104
|
+
"weight" => 1.0,
|
105
|
+
"priority" => 1,
|
106
|
+
"id" => 9
|
107
|
+
}}, :against => AdZone::SCHEMA.show)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not approve a monkey wrench" do
|
111
|
+
invalidate(@monkey_wrench, :against => AdZone::SCHEMA.show)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "update" do
|
116
|
+
it "should approve an example ad-zone" do
|
117
|
+
validate({"ad_zone" => {
|
118
|
+
"ad_id" => 1,
|
119
|
+
"zone_id" => "zone1",
|
120
|
+
"weight" => 1.0,
|
121
|
+
"priority" => 1
|
122
|
+
}}, :against => AdZone::SCHEMA.update)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not approve a ad-zone with missing information" do
|
126
|
+
invalidate({"ad_zone" => {
|
127
|
+
"ad_id" => 1,
|
128
|
+
"zone_id" => "zone1",
|
129
|
+
"priority" => 1
|
130
|
+
}}, :against => AdZone::SCHEMA.update)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not approve a ad-zone with extra information" do
|
134
|
+
invalidate({"ad_zone" => {
|
135
|
+
"ad_id" => 1,
|
136
|
+
"zone_id" => "zone1",
|
137
|
+
"weight" => 1.0,
|
138
|
+
"priority" => 1,
|
139
|
+
"id" => 1
|
140
|
+
}}, :against => AdZone::SCHEMA.update)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not approve a monkey wrench" do
|
144
|
+
invalidate(@monkey_wrench, :against => AdZone::SCHEMA.update)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Neuron
|
4
|
+
module Schema
|
5
|
+
describe BlockedReferer 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 blocked referers" do
|
28
|
+
validate(
|
29
|
+
[{"blocked_referer" => {"id" => 42, "referer" => "127.0.0.1"}},
|
30
|
+
{"blocked_referer" => {"id" => 82, "referer" => "an.example.com"}},
|
31
|
+
{"blocked_referer" => {"id" => 246, "referer" => "another.example.com/site/page.html"}}
|
32
|
+
],
|
33
|
+
:against => BlockedReferer::SCHEMA.index)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should approve an empty list" do
|
37
|
+
validate([], :against => BlockedReferer::SCHEMA.index)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not approve an example blocked_referer outside of a list" do
|
41
|
+
invalidate(
|
42
|
+
{"blocked_referer" => {"id" => 42, "referer" => "127.0.0.1"}},
|
43
|
+
:against => BlockedReferer::SCHEMA.index)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
47
|
+
invalidate(@monkey_wrenches, :against => BlockedReferer::SCHEMA.index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "create" do
|
52
|
+
it "should approve an example blocked referer" do
|
53
|
+
validate({"blocked_referer" => {
|
54
|
+
"referer" => "an.example.com"
|
55
|
+
}}, :against => BlockedReferer::SCHEMA.create)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not approve a blocked referer with missing information" do
|
59
|
+
invalidate({"blocked_referer" => {
|
60
|
+
}}, :against => BlockedReferer::SCHEMA.create)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not approve a blocked referer with extra information" do
|
64
|
+
invalidate({"blocked_referer" => {
|
65
|
+
"referer" => "an.example.com",
|
66
|
+
"name" => "extra"
|
67
|
+
}}, :against => BlockedReferer::SCHEMA.create)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not approve a monkey wrench" do
|
71
|
+
invalidate(@monkey_wrench, :against => BlockedReferer::SCHEMA.create)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "show" do
|
76
|
+
it "should approve an example blocked referer" do
|
77
|
+
validate({"blocked_referer" => {
|
78
|
+
"referer" => "an.example.com",
|
79
|
+
"created_at" => @datetime,
|
80
|
+
"updated_at" => @datetime,
|
81
|
+
"id" => 1
|
82
|
+
}}, :against => BlockedReferer::SCHEMA.show)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not approve a blocked referer with missing information" do
|
86
|
+
invalidate({"blocked_referer" => {
|
87
|
+
"referer" => "an.example.com",
|
88
|
+
"updated_at" => @datetime,
|
89
|
+
"id" => 1
|
90
|
+
}}, :against => BlockedReferer::SCHEMA.show)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not approve a blocked referer with extra information" do
|
94
|
+
invalidate({"blocked_referer" => {
|
95
|
+
"referer" => "an.example.com",
|
96
|
+
"created_at" => @datetime,
|
97
|
+
"updated_at" => @datetime,
|
98
|
+
"id" => 1,
|
99
|
+
"name" => "extra"
|
100
|
+
}}, :against => BlockedReferer::SCHEMA.show)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not approve a monkey wrench" do
|
104
|
+
invalidate(@monkey_wrench, :against => BlockedReferer::SCHEMA.show)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "update" do
|
109
|
+
it "should approve an example blocked referer" do
|
110
|
+
validate({"blocked_referer" => {
|
111
|
+
"referer" => "an.example.com",
|
112
|
+
"id" => 1
|
113
|
+
}}, :against => BlockedReferer::SCHEMA.update)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should not approve a blocked referer with missing information" do
|
117
|
+
invalidate({"blocked_referer" => {
|
118
|
+
"id" => 1
|
119
|
+
}}, :against => BlockedReferer::SCHEMA.update)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not approve a blocked referer with extra information" do
|
123
|
+
invalidate({"blocked_referer" => {
|
124
|
+
"referer" => "an.example.com",
|
125
|
+
"id" => 1,
|
126
|
+
"name" => "extra"
|
127
|
+
}}, :against => BlockedReferer::SCHEMA.update)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not approve a monkey wrench" do
|
131
|
+
invalidate(@monkey_wrench, :against => BlockedReferer::SCHEMA.update)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Neuron
|
4
|
+
module Schema
|
5
|
+
describe BlockedUserAgent 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 blocked user agents" do
|
28
|
+
validate(
|
29
|
+
[{"blocked_user_agent" => {"id" => 42, "description" => nil, "user_agent" => ".*robot.*"}},
|
30
|
+
{"blocked_user_agent" => {"id" => 82, "description" => nil, "user_agent" => "^Badbot"}},
|
31
|
+
{"blocked_user_agent" => {"id" => 246, "description" => nil, "user_agent" => "crawler$"}}
|
32
|
+
],
|
33
|
+
:against => BlockedUserAgent::SCHEMA.index)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should approve an empty list" do
|
37
|
+
validate([], :against => BlockedUserAgent::SCHEMA.index)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not approve an example blocked user agent outside of a list" do
|
41
|
+
invalidate(
|
42
|
+
{"blocked_user_agent" => {"id" => 42, "description" => nil, "user_agent" => ".*robot.*"}},
|
43
|
+
:against => BlockedUserAgent::SCHEMA.index)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
47
|
+
invalidate(@monkey_wrenches, :against => BlockedUserAgent::SCHEMA.index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "create" do
|
52
|
+
it "should approve an example blocked user agent" do
|
53
|
+
validate({"blocked_user_agent" => {
|
54
|
+
"description" => 'Anything with "robot" in it',
|
55
|
+
"user_agent" => ".*robot.*"
|
56
|
+
}}, :against => BlockedUserAgent::SCHEMA.create)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not approve a blocked user agent with missing information" do
|
60
|
+
invalidate({"blocked_user_agent" => {
|
61
|
+
"description" => 'Anything with "robot" in it',
|
62
|
+
#"user_agent" => ".*robot.*",
|
63
|
+
}}, :against => BlockedUserAgent::SCHEMA.create)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not approve a blocked user agent with extra information" do
|
67
|
+
invalidate({"blocked_user_agent" => {
|
68
|
+
"description" => 'Anything with "robot" in it',
|
69
|
+
"user_agent" => ".*robot.*",
|
70
|
+
"name" => "extra"
|
71
|
+
}}, :against => BlockedUserAgent::SCHEMA.create)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not approve a monkey wrench" do
|
75
|
+
invalidate(@monkey_wrench, :against => BlockedUserAgent::SCHEMA.create)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "show" do
|
80
|
+
it "should approve an example blocked user agent" do
|
81
|
+
validate({"blocked_user_agent" => {
|
82
|
+
"description" => 'Anything with "robot" in it',
|
83
|
+
"user_agent" => ".*robot.*",
|
84
|
+
"created_at" => @datetime,
|
85
|
+
"updated_at" => @datetime,
|
86
|
+
"id" => 1
|
87
|
+
}}, :against => BlockedUserAgent::SCHEMA.show)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not approve a blocked user agent with missing information" do
|
91
|
+
invalidate({"blocked_user_agent" => {
|
92
|
+
"user_agent" => ".*robot.*",
|
93
|
+
"created_at" => @datetime,
|
94
|
+
"updated_at" => @datetime,
|
95
|
+
"id" => 1
|
96
|
+
}}, :against => BlockedUserAgent::SCHEMA.show)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not approve a blocked user agent with extra information" do
|
100
|
+
invalidate({"blocked_user_agent" => {
|
101
|
+
"description" => 'Anything with "robot" in it',
|
102
|
+
"user_agent" => ".*robot.*",
|
103
|
+
"created_at" => @datetime,
|
104
|
+
"updated_at" => @datetime,
|
105
|
+
"id" => 1,
|
106
|
+
"name" => "extra"
|
107
|
+
}}, :against => BlockedUserAgent::SCHEMA.show)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not approve a monkey wrench" do
|
111
|
+
invalidate(@monkey_wrench, :against => BlockedUserAgent::SCHEMA.show)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "update" do
|
116
|
+
it "should approve an example blocked user agent" do
|
117
|
+
validate({"blocked_user_agent" => {
|
118
|
+
"description" => 'Anything with "robot" in it',
|
119
|
+
"user_agent" => ".*robot.*",
|
120
|
+
"id" => 1
|
121
|
+
}}, :against => BlockedUserAgent::SCHEMA.update)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not approve a blocked user agent with missing id" do
|
125
|
+
invalidate({"blocked_user_agent" => {
|
126
|
+
"description" => 'Anything with "robot" in it',
|
127
|
+
"user_agent" => ".*robot.*",
|
128
|
+
#"id" => 1
|
129
|
+
}}, :against => BlockedUserAgent::SCHEMA.update)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should not approve a blocked user agent with extra information" do
|
133
|
+
invalidate({"blocked_user_agent" => {
|
134
|
+
"description" => 'Anything with "robot" in it',
|
135
|
+
"user_agent" => ".*robot.*",
|
136
|
+
"id" => 1,
|
137
|
+
"name" => "extra"
|
138
|
+
}}, :against => BlockedUserAgent::SCHEMA.update)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should not approve a monkey wrench" do
|
142
|
+
invalidate(@monkey_wrench, :against => BlockedUserAgent::SCHEMA.update)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Neuron
|
4
|
+
module Schema
|
5
|
+
describe GeoTarget 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 geo targets" do
|
28
|
+
validate(
|
29
|
+
[{"geo_target" => {"id" => 42, "abbreviation" => "A", "name" => "A", "full_name" => "A, Texas, USA", "geo_type" => "CITY", "netacuity_id" => 1}},
|
30
|
+
{"geo_target" => {"id" => 82, "abbreviation" => "TX", "name" => "Texas", "full_name" => "Texas, USA", "geo_type" => "REGION", "netacuity_id" => 2}},
|
31
|
+
{"geo_target" => {"id" => 246, "abbreviation" => "USA", "name" => "United States", "full_name" => "United States", "geo_type" => "COUNTRY", "netacuity_id" => 3}},
|
32
|
+
],
|
33
|
+
:against => GeoTarget::SCHEMA.index)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should approve an empty list" do
|
37
|
+
validate([], :against => GeoTarget::SCHEMA.index)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not approve an example geo_target outside of a list" do
|
41
|
+
invalidate(
|
42
|
+
{"geo_target" => {"id" => 42, "abbreviation" => "A", "name" => "A", "full_name" => "A, Texas, USA", "geo_type" => "CITY", "netacuity_id" => 1}},
|
43
|
+
:against => GeoTarget::SCHEMA.index)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
47
|
+
invalidate(@monkey_wrenches, :against => GeoTarget::SCHEMA.index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "show" do
|
52
|
+
it "should approve an example geo target" do
|
53
|
+
validate({"geo_target" => {
|
54
|
+
"id" => 42,
|
55
|
+
"abbreviation" => "A",
|
56
|
+
"name" => "A",
|
57
|
+
"full_name" => "A, Texas, USA",
|
58
|
+
"geo_type" => "CITY",
|
59
|
+
"netacuity_id" => 1
|
60
|
+
}}, :against => GeoTarget::SCHEMA.show)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not approve a geo target with missing information" do
|
64
|
+
invalidate({"geo_target" => {
|
65
|
+
"id" => 42,
|
66
|
+
"abbreviation" => "A",
|
67
|
+
#"name" => "A",
|
68
|
+
"full_name" => "A, Texas, USA",
|
69
|
+
"geo_type" => "CITY",
|
70
|
+
"netacuity_id" => 1
|
71
|
+
}}, :against => GeoTarget::SCHEMA.show)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not approve a geo target with extra information" do
|
75
|
+
invalidate({"geo_target" => {
|
76
|
+
"id" => 42,
|
77
|
+
"abbreviation" => "A",
|
78
|
+
"name" => "A",
|
79
|
+
"full_name" => "A, Texas, USA",
|
80
|
+
"geo_type" => "CITY",
|
81
|
+
"netacuity_id" => 1,
|
82
|
+
"extra" => "extra"
|
83
|
+
}}, :against => GeoTarget::SCHEMA.show)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not approve a monkey wrench" do
|
87
|
+
invalidate(@monkey_wrench, :against => GeoTarget::SCHEMA.show)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Neuron
|
4
|
+
module Schema
|
5
|
+
describe Pixel 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 pixels" do
|
28
|
+
validate(
|
29
|
+
[{"pixel" => {"id" => 42}},
|
30
|
+
{"pixel" => {"id" => 82}},
|
31
|
+
{"pixel" => {"id" => 246}}
|
32
|
+
],
|
33
|
+
:against => Pixel::SCHEMA.index)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should approve an empty list" do
|
37
|
+
validate([], :against => Pixel::SCHEMA.index)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not approve an example pixel outside of a list" do
|
41
|
+
invalidate(
|
42
|
+
{"pixel" => {"id" => 42}},
|
43
|
+
:against => Pixel::SCHEMA.index)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not approve an example list of monkey wrenches" do
|
47
|
+
invalidate(@monkey_wrenches, :against => Pixel::SCHEMA.index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "create" do
|
52
|
+
it "should approve an example pixel" do
|
53
|
+
validate({"pixel" => {
|
54
|
+
"ad_ids" => []
|
55
|
+
}}, :against => Pixel::SCHEMA.create)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not approve a pixel with extra information" do
|
59
|
+
invalidate({"pixel" => {
|
60
|
+
"ad_ids" => [1,2,3],
|
61
|
+
"name" => "extra"
|
62
|
+
}}, :against => Pixel::SCHEMA.create)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not approve a monkey wrench" do
|
66
|
+
invalidate(@monkey_wrench, :against => Pixel::SCHEMA.create)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "show" do
|
71
|
+
it "should approve an example pixel" do
|
72
|
+
validate({"pixel" => {
|
73
|
+
"ad_ids" => [1,2,3],
|
74
|
+
"id" => 1
|
75
|
+
}}, :against => Pixel::SCHEMA.show)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not approve a pixel with missing information" do
|
79
|
+
invalidate({"pixel" => {
|
80
|
+
"id" => 1
|
81
|
+
}}, :against => Pixel::SCHEMA.show)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should not approve a pixel with extra information" do
|
85
|
+
invalidate({"pixel" => {
|
86
|
+
"ad_ids" => [1,2,3],
|
87
|
+
"id" => 1,
|
88
|
+
"name" => "extra"
|
89
|
+
}}, :against => Pixel::SCHEMA.show)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not approve a monkey wrench" do
|
93
|
+
invalidate(@monkey_wrench, :against => Pixel::SCHEMA.show)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "update" do
|
98
|
+
it "should approve an example pixel" do
|
99
|
+
validate({"pixel" => {
|
100
|
+
"ad_ids" => [1,2,3],
|
101
|
+
"id" => 1
|
102
|
+
}}, :against => Pixel::SCHEMA.update)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not approve a pixel with missing information" do
|
106
|
+
invalidate({"pixel" => {
|
107
|
+
"id" => 1
|
108
|
+
}}, :against => Pixel::SCHEMA.update)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should not approve a pixel with extra information" do
|
112
|
+
invalidate({"pixel" => {
|
113
|
+
"ad_ids" => [1,2,3],
|
114
|
+
"id" => 1,
|
115
|
+
"name" => "extra"
|
116
|
+
}}, :against => Pixel::SCHEMA.update)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not approve a monkey wrench" do
|
120
|
+
invalidate(@monkey_wrench, :against => Pixel::SCHEMA.update)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|