-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest_transloadit.rb
More file actions
131 lines (106 loc) · 3.57 KB
/
Copy pathtest_transloadit.rb
File metadata and controls
131 lines (106 loc) · 3.57 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require "test_helper"
describe Transloadit do
before do
@key = "a"
@secret = "b"
@duration = 10
@max_size = 100
end
it "must allow initialization" do
t = Transloadit.new(key: @key, secret: @secret)
_(t).must_be_kind_of Transloadit
end
it "must not be initialized with no arguments" do
_(lambda { Transloadit.new }).must_raise ArgumentError
end
it "must require a key" do
_(lambda { Transloadit.new(secret: @secret) }).must_raise ArgumentError
end
it "must not require a secret" do
t = Transloadit.new(key: @key)
_(t).must_be_kind_of Transloadit
end
it "must provide a default duration" do
_(Transloadit.new(key: @key).duration).wont_be_nil
end
describe "when initialized" do
before do
@transloadit = Transloadit.new(
key: @key,
secret: @secret,
duration: @duration,
max_size: @max_size
)
end
it "must allow access to the key" do
_(@transloadit.key).must_equal @key
end
it "must allow access to the secret" do
_(@transloadit.secret).must_equal @secret
end
it "must allow access to the duration" do
_(@transloadit.duration).must_equal @duration
end
it "must allow access to the max_size" do
_(@transloadit.max_size).must_equal @max_size
end
it "must create steps" do
step = @transloadit.step("resize", "/image/resize", width: 320)
_(step).must_be_kind_of Transloadit::Step
_(step.name).must_equal "resize"
_(step.robot).must_equal "/image/resize"
_(step.options).must_equal width: 320
end
it "must create assembly api instances" do
step = @transloadit.step(nil, nil)
assembly = @transloadit.assembly steps: step
_(assembly).must_be_kind_of Transloadit::Assembly
_(assembly.steps).must_equal step.to_hash
end
it "must create assemblies with multiple steps" do
steps = [
@transloadit.step("step1", nil),
@transloadit.step("step2", nil)
]
assembly = @transloadit.assembly steps: steps
_(assembly.steps).must_equal steps.inject({}) { |h, s| h.merge s }
end
it "must get user billing report" do
VCR.use_cassette "fetch_billing" do
bill = Transloadit.new(key: "").bill(9, 2016)
_(bill["ok"]).must_equal "BILL_FOUND"
_(bill["invoice_id"]).must_equal "76fe5df1c93a0a530f3e583805cf98b4"
end
end
it "must create template api instances" do
template = @transloadit.template
_(template).must_be_kind_of Transloadit::Template
end
it "must inspect like a hash" do
_(@transloadit.inspect).must_equal @transloadit.to_hash.inspect
end
it "must produce Transloadit-compatible hash output" do
_(@transloadit.to_hash[:key]).must_equal @key
_(@transloadit.to_hash[:max_size]).must_equal @max_size
_(@transloadit.to_hash[:expires])
.must_match %r{\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\+00:00}
end
it "must produce Transloadit-compatible JSON output" do
fixed_time = Time.utc(2025, 10, 28, 0, 0, 0)
with_singleton_method(Time, :now, proc { fixed_time }) do
_(@transloadit.to_json).must_equal MultiJson.dump(@transloadit.to_hash)
end
end
end
describe "with no secret" do
before do
@transloadit = Transloadit.new(key: @key)
end
it "must not include a secret in its hash output" do
_(@transloadit.to_hash.keys).wont_include :secret
end
it "must not include a secret in its JSON output" do
_(@transloadit.to_json).must_equal MultiJson.dump(@transloadit.to_hash)
end
end
end