Skip to content

Commit

Permalink
Add missing specs and all_email_forwards
Browse files Browse the repository at this point in the history
  • Loading branch information
aeden committed Feb 4, 2016
1 parent 31d613f commit 4ff67e1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/dnsimple/client/domains_email_forwards.rb
Expand Up @@ -24,6 +24,27 @@ def email_forwards(account_id, domain_id, options = {})
Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::EmailForward.new(r) })
end

# Lists ALL the email forwards for the domain.
#
# This method is similar to {#email_forwards}, but instead of returning the results of a specific page
# it iterates all the pages and returns the entire collection.
#
# Please use this method carefully, as fetching the entire collection will increase the number of requests
# you send to the API server and you may eventually risk to hit the throttle limit.
#
# @see https://developer.dnsimple.com/v2/domains/email-forwards/#list
# @see #email_forwards
#
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
# @param [#to_s] domain_id the domain id or domain name
# @param [Hash] options the filtering and sorting option
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::EmailForward>]
#
# @raise [Dnsimple::RequestError]
def all_email_forwards(account_id, domain_id, options = {})
paginate(:email_forwards, account_id, domain_id, options)
end

# Creates an email forward for the domain.
#
# @see https://developer.dnsimple.com/v2/domains/email-forwards/#create
Expand Down
31 changes: 31 additions & 0 deletions spec/dnsimple/client/domains_email_forwards_spec.rb
Expand Up @@ -45,6 +45,37 @@
expect(result.id).to be_a(Fixnum)
end
end

it "exposes the pagination information" do
response = subject.email_forwards(account_id, domain_id)

expect(response.respond_to?(:page)).to be_truthy
expect(response.page).to eq(1)
expect(response.per_page).to be_a(Fixnum)
expect(response.total_entries).to be_a(Fixnum)
expect(response.total_pages).to be_a(Fixnum)
end

context "when the domain does not exist" do
it "raises NotFoundError" do
stub_request(:get, %r[/v2])
.to_return(read_http_fixture("notfound-domain.http"))

expect {
subject.email_forwards(account_id, domain_id)
}.to raise_error(Dnsimple::NotFoundError)
end
end
end

describe "#all_email_forwards" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }

it "delegates to client.paginate" do
expect(subject).to receive(:paginate).with(:email_forwards, account_id, domain_id, { foo: "bar" })
subject.all_email_forwards(account_id, domain_id, { foo: "bar" })
end
end

describe "#create_email_forward" do
Expand Down

0 comments on commit 4ff67e1

Please sign in to comment.