Skip to content

Commit

Permalink
Merge pull request #268 from richmolj/update_scope
Browse files Browse the repository at this point in the history
Ensure scope override is honored on update/destroy
  • Loading branch information
richmolj authored Aug 24, 2020
2 parents e63586d + 6f7ed7e commit e3306ad
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 e3306ad

Please sign in to comment.