-
Notifications
You must be signed in to change notification settings - Fork 1
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
Raise UnknownAttributeError
if .where
is given invalid attribute names
#80
Changes from all commits
fa321b5
412a9f2
26dbedf
105ee37
d039d63
0e4b235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
class TestSObject < ActiveForce::SObject | ||
def self.decorate(records) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a spec failing below when I changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I never fully understood why the original authors of this library did something like that but I guess we're stuck with it for now. 🤷 |
||
records | ||
end | ||
end | ||
|
||
describe ActiveForce::ActiveQuery do | ||
let(:sobject) do | ||
double("sobject", { | ||
table_name: "table_name", | ||
fields: [], | ||
mappings: mappings | ||
}) | ||
class_double( | ||
TestSObject, | ||
{ table_name: 'table_name', fields: [], mappings: mappings, name: 'TableName' } | ||
) | ||
end | ||
let(:mappings){ { id: "Id", field: "Field__c", other_field: "Other_Field" } } | ||
let(:client) { double('client', query: nil) } | ||
|
@@ -296,6 +301,13 @@ | |
end | ||
end | ||
end | ||
|
||
context 'when given attributes Hash with fields that do not exist on the SObject' do | ||
it 'raises UnknownFieldError' do | ||
expect { active_query.where(xyz: 1) } | ||
.to raise_error(ActiveForce::UnknownFieldError, /unknown field 'xyz' for #{sobject.name}/i) | ||
end | ||
end | ||
end | ||
|
||
describe '#not' do | ||
|
@@ -329,6 +341,11 @@ | |
new_query = active_query.find_by field: 123 | ||
expect(new_query).to be_nil | ||
end | ||
|
||
it 'should raise UnknownFieldError if given invalid field' do | ||
expect { active_query.find_by(invalid: true) } | ||
.to raise_error(ActiveForce::UnknownFieldError, /unknown field 'invalid' for #{sobject.name}/i) | ||
end | ||
end | ||
|
||
describe '#find_by!' do | ||
|
@@ -337,6 +354,11 @@ | |
expect { active_query.find_by!(field: 123) } | ||
.to raise_error(ActiveForce::RecordNotFound, "Couldn't find #{sobject.table_name} with {:field=>123}") | ||
end | ||
|
||
it 'should raise UnknownFieldError if given invalid field' do | ||
expect { active_query.find_by!(invalid: true) } | ||
.to raise_error(ActiveForce::UnknownFieldError, /unknown field 'invalid' for #{sobject.name}/i) | ||
end | ||
end | ||
|
||
describe '#find!' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed appropriate to change this as well, since it's basically the same thing.