Skip to content

Commit

Permalink
a QuotaReachedError is raised if you have reached your quota and you …
Browse files Browse the repository at this point in the history
…try to create a new job
  • Loading branch information
alainravet committed Mar 15, 2012
1 parent 5242a99 commit 35605cb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/cron-io.rb
Expand Up @@ -5,13 +5,19 @@ module Cron
module Io

class Error < RuntimeError ; end

class CredentialsError < Cron::Io::Error ; end

class CronNotFoundError < Cron::Io::Error ; end

class UserCreationError < Cron::Io::Error ; end
class UsernameTakenError < Cron::Io::UserCreationError; end
class EmailTakenError < Cron::Io::UserCreationError; end
class InvalidEmailError < Cron::Io::UserCreationError; end

class CronCreationError < Cron::Io::Error ; end
class QuotaReachedError < Cron::Io::CronCreationError; end

private
def self.hashify_and_enrich(response)
success = response.response.code.start_with?("20")
Expand Down
4 changes: 4 additions & 0 deletions lib/cron-io/cron.rb
Expand Up @@ -36,6 +36,10 @@ def self.create(username, password, name, url, schedule )
new response['id'], response['name'], response['url'], response['schedule']
elsif response['code'] == '403'
raise CredentialsError.new(error)
elsif error =~ /quota.*reached/i
raise QuotaReachedError.new(error)
else
raise CronCreationError.new(error)
end
end

Expand Down
13 changes: 12 additions & 1 deletion spec/create_cron_spec.rb
Expand Up @@ -20,7 +20,7 @@

use_vcr_cassette "create cron/with valid parameters", :record => :new_episodes

it 'adds 1 cron in my cron.io account' do
it 'adds 1 cron job in my cron.io account' do
Cron::Io::Cron.list(valid_username, valid_pwd).size.should == 1
Cron::Io::Cron.create(valid_username, valid_pwd, a_name, a_url, a_schedule)

Expand All @@ -46,6 +46,7 @@




##########
# FAILURE
##########
Expand All @@ -60,5 +61,15 @@
end
end

context "when you have reached your jobs quota" do
use_vcr_cassette "create cron/quota reached", :record => :new_episodes

it 'raises a Cron:Io::QuotaReachedError' do
expect {
Cron::Io::Cron.create(valid_username, valid_pwd, a_name, a_url, a_schedule)
}.to raise_error Cron::Io::QuotaReachedError
end

end
end
end
23 changes: 23 additions & 0 deletions spec/vcr_cassette_library/create_cron/quota_reached.yml
@@ -0,0 +1,23 @@
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :post
uri: http://croniogemY:secret@api.cron.io:80/v1/crons
body: ! '{"name":"fake job - can be purged","url":"http://example.com","schedule":"46
0 * * *"}'
headers:
content-type:
- application/json
authorization:
- Basic Y3JvbmlvZ2VtWTpzZWNyZXQ=
response: !ruby/struct:VCR::Response
status: !ruby/struct:VCR::ResponseStatus
code: 409
message: Conflict
headers:
content-type:
- application/json
transfer-encoding:
- chunked
body: ! '{"error":"The quota of 5 total crons has been reached for this account."}'
http_version: '1.1'

0 comments on commit 35605cb

Please sign in to comment.