File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -137,11 +137,16 @@ def link_filter(parents)
137137 end
138138
139139 def link_extra_fields
140+ return unless context &.respond_to? ( :params )
141+
140142 extra_fields_name = [ association_name , resource . type ] . find { |param |
141143 context . params . dig ( :extra_fields , param )
142144 }
143145
144- { resource . type => context . params . dig ( :extra_fields , extra_fields_name ) } if extra_fields_name
146+ if extra_fields_name
147+ extra_fields = context . params . dig ( :extra_fields , extra_fields_name )
148+ { resource . type => extra_fields }
149+ end
145150 end
146151
147152 # The parent resource is a remote,
Original file line number Diff line number Diff line change 11module Graphiti
2- VERSION = "1.2.39 "
2+ VERSION = "1.2.40 "
33end
Original file line number Diff line number Diff line change @@ -29,6 +29,45 @@ def attributes
2929 . to match_array ( %w[ first_name last_name age stack_ranking ] )
3030 end
3131
32+ context "when sideloading/linking" do
33+ before do
34+ allow_any_instance_of ( PORO ::Employee )
35+ . to receive ( :linked_positions ) { [ ] }
36+ resource . has_many :linked_positions ,
37+ resource : PORO ::PositionResource ,
38+ link : true
39+ params [ :include ] = "linked_positions"
40+ end
41+
42+ context "and the context is missing" do
43+ around do |e |
44+ Graphiti . with_context nil do
45+ e . run
46+ end
47+ end
48+
49+ it "does not blow up" do
50+ params [ :extra_fields ] = { positions : "foo" }
51+ expect { render } . to_not raise_error
52+ end
53+ end
54+
55+ context "and the context does not respond to params" do
56+ around do |e |
57+ # current_user referenced in resource fixtures
58+ ctx = Struct . new ( :current_user ) . new
59+ Graphiti . with_context ctx do
60+ e . run
61+ end
62+ end
63+
64+ it "does not blow up" do
65+ params [ :extra_fields ] = { positions : "foo" }
66+ expect { render } . to_not raise_error
67+ end
68+ end
69+ end
70+
3271 context "when multiple extra attributes" do
3372 context "added with blocks" do
3473 before do
You can’t perform that action at this time.
0 commit comments