Skip to content

Commit adfa545

Browse files
author
Amir Tocker
committed
Raise instead of throw.
1 parent 2685bca commit adfa545

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

lib/cloudinary/auth_token.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ module AuthToken
1212

1313
def self.generate(options = {})
1414
key = options[:key]
15-
throw "Missing auth token key configuration" unless key
16-
name = options[:token_name] || "__cld_token__"
17-
start = options[:start_time]
18-
expiration = options[:expiration]
19-
ip = options[:ip]
20-
acl = options[:acl]
21-
duration = options[:duration]
22-
url = options[:url]
15+
raise "Missing auth token key configuration" unless key
16+
name = options[:token_name] || "__cld_token__"
17+
start = options[:start_time]
18+
expiration = options[:expiration]
19+
ip = options[:ip]
20+
acl = options[:acl]
21+
duration = options[:duration]
22+
url = options[:url]
2323
start = Time.new.getgm.to_i if start == 'now'
2424
if expiration.nil? || expiration == 0
2525
if !(duration.nil? || duration == 0)
2626
expiration = (start || Time.new.getgm.to_i) + duration
2727
else
28-
throw 'Must provide either expiration or duration'
28+
raise 'Must provide either expiration or duration'
2929
end
3030
end
3131

spec/auth_token_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@
5858
expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3")
5959

6060
end
61-
it "should throw if expiration and duration are not provided" do
61+
it "should raise if key is not provided" do
62+
Cloudinary.config.auth_token[:key] = nil
63+
token = { :expiration => 111111, :duration => 0 }
64+
expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_error
65+
end
66+
it "should raise if expiration and duration are not provided" do
6267
token = { :key => KEY, :expiration => 0, :duration => 0 }
63-
expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_exception
68+
expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_error
6469
end
6570
end
6671
describe "authentication token" do

0 commit comments

Comments
 (0)