Skip to content

Commit

Permalink
Make all parameters in RecordNotFound.new optional (#44)
Browse files Browse the repository at this point in the history
* make all parameters in RecordNotFound.new optional

* update version and changelog
  • Loading branch information
rferg authored May 1, 2023
1 parent 896823c commit d0dbb5e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Not released

## 0.13.1

- Fix constructor of `ActiveForce::RecordNotFound` (https://github.com/Beyond-Finance/active_force/pull/44)
- Add `.to_json` and `.as_json` to `SObject` to allow JSON serialization (https://github.com/Beyond-Finance/active_force/pull/37)
- Memoize the `ActiveForce::Mapping#mappings` Hash since it is based on the fields and those are generally only set when the class is loaded. Also use `Hash#key` which returns the key for a value rather than `Hash#invert` which creates a new Hash with key/value inverted. (https://github.com/Beyond-Finance/active_force/pull/41)

Expand Down
13 changes: 9 additions & 4 deletions lib/active_force/active_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ module ActiveForce
class PreparedStatementInvalid < ArgumentError; end

class RecordNotFound < StandardError
def initialize(table_name, conditions)
super("Couldn't find #{table_name} with #{conditions}")
attr_reader :table_name, :conditions

def initialize(message = nil, table_name = nil, conditions = nil)
@table_name = table_name
@conditions = conditions

super(message)
end
end

Expand Down Expand Up @@ -71,7 +76,7 @@ def select *fields

def find!(id)
result = find(id)
raise RecordNotFound.new(table_name, id: id) if result.nil?
raise RecordNotFound.new("Couldn't find #{table_name} with id #{id}", table_name, id: id) if result.nil?

result
end
Expand All @@ -82,7 +87,7 @@ def find_by conditions

def find_by!(conditions)
result = find_by(conditions)
raise RecordNotFound.new(table_name, conditions) if result.nil?
raise RecordNotFound.new("Couldn't find #{table_name} with #{conditions}", table_name, conditions) if result.nil?

result
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_force/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveForce
VERSION = '0.13.0'
VERSION = '0.13.1'
end
2 changes: 1 addition & 1 deletion spec/active_force/active_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@

it 'raises RecordNotFound' do
expect { active_query.find!(id) }
.to raise_error(ActiveForce::RecordNotFound, "Couldn't find #{sobject.table_name} with #{{ id: id }}")
.to raise_error(ActiveForce::RecordNotFound, "Couldn't find #{sobject.table_name} with id #{id}")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/active_force/sobject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class IceCream < ActiveForce::SObject

it 'raises RecordNotFound if nothing found' do
expect { Whizbang.find!(id) }
.to raise_error(ActiveForce::RecordNotFound, "Couldn't find #{Whizbang.table_name} with #{{ id: id }}")
.to raise_error(ActiveForce::RecordNotFound, "Couldn't find #{Whizbang.table_name} with id #{id}")
end
end

Expand Down

0 comments on commit d0dbb5e

Please sign in to comment.