This repository was archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmaxcdn_test.rb
More file actions
108 lines (88 loc) · 2.45 KB
/
Copy pathmaxcdn_test.rb
File metadata and controls
108 lines (88 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require File.expand_path("../helper", __FILE__)
# stub
require "maxcdn"
module MaxCDN
class Client
def initialize *args
@purge_calls = 0
@fake_error = false
end
def purge id
raise ::MaxCDN::APIException.new("test error") if @fake_error
@purge_calls += 1
return { "code" => "200" }
end
def fake_error
@fake_error = true
end
end
end
class MaxCDNTest < Service::TestCase
def setup
@arguments ||= {
"alias" => "foobar_alias",
"key" => "foobar_key",
"secret" => "foobar_secret",
"zone_id" => 123456,
"static_only" => '0'
}
@svc = service(@arguments, dynamic_payload)
end
def test_maxcdn
assert @svc.maxcdn
end
def test_extensions
assert_includes @svc.extensions, :js
end
def test_has_static?
refute @svc.has_static?
svc = service(@arguments, static_payload)
assert svc.has_static?
end
def test_receive_push
assert @svc.receive_push
assert_equal 1, @svc.maxcdn.instance_variable_get(:@purge_calls)
@svc.maxcdn.fake_error
error = assert_raises ::Service::ConfigurationError do
@svc.receive_push
end
assert_match /test error/, error.message
arguments = @arguments.clone
arguments["static_only"] = '1'
svc = service(arguments, payload)
refute svc.receive_push
arguments = @arguments.clone
arguments["static_only"] = '1'
svc = service(arguments, static_payload)
assert svc.receive_push
end
def dynamic_payload
unless defined? @dynamic_payload
# Default payload is all .rb files and thus, a
# non-static payload. However, to be sure (should
# something change in the future) I'll ensure it.
@dynamic_payload = payload.clone
@dynamic_payload["commits"].each_index do |commit|
@dynamic_payload["commits"][commit]["modified"].each_index do |file|
@dynamic_payload["commits"][commit]["modified"][file].gsub!(/\.[a-z0-9]+$/, ".rb")
end
end
end
@dynamic_payload
end
def static_payload
unless defined? @static_payload
# Creating a static payload, by replacing a single
# file in the payload with a static file extension.
@static_payload = payload.clone
@static_payload["commits"]
.first["modified"]
.last
.gsub!(/\.[a-z0-9]+$/, ".js")
end
@static_payload
end
def service(*args)
super Service::MaxCDN, *args
end
end