Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all parameters in RecordNotFound.new optional #44

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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