File tree Expand file tree Collapse file tree 2 files changed +0
-48
lines changed
app/serializers/forest_liana
spec/services/forest_liana Expand file tree Collapse file tree 2 files changed +0
-48
lines changed Original file line number Diff line number Diff line change @@ -131,33 +131,6 @@ def relationship_related_link(attribute_name)
131
131
ret
132
132
end
133
133
134
- def has_one_relationships
135
- return { } if self . class . to_one_associations . nil?
136
- data = { }
137
- self . class . to_one_associations . each do |attribute_name , attr_data |
138
- relation = object . class . reflect_on_all_associations . find { |a | a . name == attribute_name }
139
-
140
- next if !should_include_attr? ( attribute_name , attr_data )
141
-
142
- unless relation . nil? || ( relation . respond_to? ( :polymorphic? ) && relation . polymorphic? )
143
- relation_class_name = ForestLiana . name_for ( relation . klass ) . demodulize
144
-
145
- if object . respond_to? ( relation . foreign_key . to_sym ) &&
146
- @options [ :fields ] [ relation_class_name ] &.size == 1 &&
147
- @options [ :fields ] [ relation_class_name ] &.include? ( relation . klass . primary_key . to_sym )
148
-
149
- attr_data [ :attr_or_block ] = proc {
150
- foreign_key_value = object . send ( relation . foreign_key . to_sym )
151
- foreign_key_value . nil? ? nil : relation . klass . new ( relation . klass . primary_key => foreign_key_value )
152
- }
153
- end
154
- end
155
-
156
- data [ attribute_name ] = attr_data
157
- end
158
- data
159
- end
160
-
161
134
private
162
135
163
136
def intercom_integration?
Original file line number Diff line number Diff line change @@ -5,27 +5,6 @@ module ForestLiana
5
5
let ( :island ) { Island . create! ( name : 'TestIsland' ) }
6
6
let ( :tree ) { Tree . create! ( name : 'TestTree' , island : island , owner : user ) }
7
7
8
- it 'simulates has_one relation with only primary key' do
9
- factory = described_class . new
10
- serializer_class = factory . serializer_for ( Tree )
11
-
12
- serializer_class . send ( :has_one , :island ) { }
13
-
14
- instance = serializer_class . new ( tree , fields : {
15
- 'Island' => [ :id ] ,
16
- 'Tree' => [ :island ]
17
- } )
18
-
19
- relationships = instance . send ( :has_one_relationships )
20
- expect ( relationships ) . to have_key ( :island )
21
- relation_data = relationships [ :island ]
22
- expect ( relation_data [ :attr_or_block ] ) . to be_a ( Proc )
23
- model = relation_data [ :attr_or_block ] . call
24
-
25
- expect ( model ) . to be_a ( Island )
26
- expect ( model . id ) . to eq ( island . id )
27
- end
28
-
29
8
it 'returns nil if foreign key is nil' do
30
9
tree_without_island = Tree . create! ( name : 'NoIslandTree' , island_id : nil , owner : user )
31
10
You can’t perform that action at this time.
0 commit comments