Skip to content

Commit

Permalink
Ensure scope override is honored on update/destroy
Browse files Browse the repository at this point in the history
If you were passing a scope override for an update or destroy operation,
that scope wouldn't be properly honored. This PR ensures an error will
be correctly thrown if no record is found.

The downside is we look up the record twice, now, but I think we should
get a fix in ASAP.
  • Loading branch information
Lee Richmond committed Aug 24, 2020
1 parent e63586d commit 6f7ed7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/graphiti/resource_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def save(action: :create)
end

def destroy
data
transaction_response = @resource.transaction do
metadata = {method: :destroy}
model = @resource.destroy(@query.filters[:id], metadata)
Expand All @@ -135,6 +136,7 @@ def destroy
end

def update_attributes
data
save(action: :update)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Graphiti
VERSION = "1.2.21"
VERSION = "1.2.22"
end
34 changes: 34 additions & 0 deletions spec/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ def self.name
expect(employee.data.first_name).to eq("Jane")
end

describe 'updating' do
let!(:employee) { PORO::Employee.create(first_name: 'asdf') }

before do
payload[:data][:id] = employee.id.to_s
end

describe 'with scope override' do
it 'is honored' do
employee = klass.find(payload, { type: 'foo' })
expect {
employee.update_attributes
}.to raise_error(Graphiti::Errors::RecordNotFound)
end
end
end

describe 'destroying' do
let!(:employee) { PORO::Employee.create(first_name: 'asdf') }

before do
payload[:data][:id] = employee.id.to_s
end

describe 'with scope override' do
it 'is honored' do
employee = klass.find(payload, { type: 'foo' })
expect {
employee.destroy
}.to raise_error(Graphiti::Errors::RecordNotFound)
end
end
end

describe "overrides" do
before do
klass.class_eval do
Expand Down

0 comments on commit 6f7ed7e

Please sign in to comment.