Skip to content

Commit

Permalink
Create record validates mandatory attribute presence
Browse files Browse the repository at this point in the history
  • Loading branch information
jacegu committed May 5, 2016
1 parent 0b1343d commit 8600d7e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dnsimple/client/templates_records.rb
Expand Up @@ -66,6 +66,7 @@ def all_records(account_id, template_id, options = {})
#
# @raise [Dnsimple::RequestError]
def create_record(account_id, template_id, attributes, options = {})
Extra.validate_mandatory_attributes(attributes, [:type, :name, :content])
endpoint = Client.versioned("/%s/templates/%s/records" % [account_id, template_id])
response = client.post(endpoint, attributes, options)

Expand Down
20 changes: 20 additions & 0 deletions spec/dnsimple/client/templates_records_spec.rb
Expand Up @@ -81,6 +81,26 @@
expect(result.updated_at).to eq("2016-05-03T07:51:33.202Z")
end

context "with missing data" do
it "raises an error when the type is missing" do
expect {
subject.create_record(account_id, template_id, name: "", content: "192.168.1.1")
}.to raise_error(ArgumentError)
end

it "raises an error when the name is missing" do
expect {
subject.create_record(account_id, template_id, type: "A", content: "192.168.1.1")
}.to raise_error(ArgumentError)
end

it "raises an error when the content is missing" do
expect {
subject.create_record(account_id, template_id, type: "A", name: "")
}.to raise_error(ArgumentError)
end
end

context "when the template does not exist" do
it "raises NotFoundError" do
stub_request(:post, %r{/v2}).
Expand Down

0 comments on commit 8600d7e

Please sign in to comment.