Skip to content

Commit 857942f

Browse files
committed
Fix nested resource lookup by type in update requests
1 parent ca94cab commit 857942f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/graphiti/resource/polymorphism.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def children
5858
end
5959

6060
def resource_for_type(type)
61-
resource = children.find { |c| c.type == type }
61+
resource = children.find { |c| c.type.to_s == type.to_s }
6262
if resource.nil?
6363
raise Errors::PolymorphicResourceChildNotFound.new(self, type: type)
6464
else

spec/request_validator_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ def self.name
175175

176176
expect(instance.errors).to be_blank
177177
end
178+
179+
context "when updating" do
180+
before do
181+
payload["action"] = "update"
182+
payload[:data][:id] = 1
183+
payload[:filter] = { id: 1 }
184+
end
185+
186+
it "accepts the child type" do
187+
validate
188+
189+
expect(instance.errors).to be_blank
190+
end
191+
end
178192
end
179193
end
180194

0 commit comments

Comments
 (0)