Skip to content

Commit

Permalink
Describe ArgumentError when id is nil or empty
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLima committed Jun 22, 2021
1 parent 39d3e24 commit f9ddadf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
* Add a log message to the `ArgumentError` at `TransactionGateway.find`

# Changelog

## 4.2.0
Expand Down
2 changes: 1 addition & 1 deletion lib/braintree/transaction_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def credit!(*args)
end

def find(id)
raise ArgumentError if id.nil? || id.strip.to_s == ""
raise ArgumentError, "id can not be empty" if id.nil? || id.strip.to_s == ""
response = @config.http.get("#{@config.base_merchant_path}/transactions/#{id}")
Transaction._new(@gateway, response[:transaction])
rescue NotFoundError
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/braintree/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
it "raises error if passed empty string" do
expect do
Braintree::Transaction.find("")
end.to raise_error(ArgumentError)
end.to raise_error(ArgumentError, "id can not be empty")
end

it "raises error if passed empty string wth space" do
expect do
Braintree::Transaction.find(" ")
end.to raise_error(ArgumentError)
end.to raise_error(ArgumentError, "id can not be empty")
end

it "raises error if passed nil" do
expect do
Braintree::Transaction.find(nil)
end.to raise_error(ArgumentError)
end.to raise_error(ArgumentError, "id can not be empty")
end
end

Expand Down

0 comments on commit f9ddadf

Please sign in to comment.