forest_liana 9.14.3 → 9.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82aa2dffa179fa0be6398321388077e3ad04f66583969c4fbb68112983dcd5d6
4
- data.tar.gz: 9e84f6554455e681cf00ca15cee8bb337c4e9ae22289e11959caa889297a0ee1
3
+ metadata.gz: fc578d6e8079646a883e1fa6685a272b47ea49c956fb90cc2bcb3e946d04de9a
4
+ data.tar.gz: 938d02f609606ef9ed4e5efed2038ed1f93715339cb874b90c3effbbb308dc37
5
5
  SHA512:
6
- metadata.gz: 0cd4367dcab7b965bccf0b49e289509ce0b97b9763491b67273444c06db7a226d4c1fc019da63167567de45afcb752fb76751b4512d0c5ff0754f217679bac0d
7
- data.tar.gz: 67eb9531fc902db2a9db22cffb6b53ba2f5ff9635f67ef5668db5b107102fb2ddac46b901fa56a7ac245c0fff3215c064b66cede4c37ea819985ce78539346dd
6
+ metadata.gz: 0410aade693b10507faf1977d767aeafe0d9cac0cf9ba08ff948815d219a3885bc7c4a4b5da7442f4347466862f2c9750d0c97b2e48bae751dca90bedd5093ce
7
+ data.tar.gz: 8d693fe4ef1ace2bb391eaf2d4c062d27c0d59d74725328f2cf28eee2a17759610c6c01a091ed8e6abf52a187700ebdfae64a1fd13713f35167c8ea2877354da
@@ -146,7 +146,10 @@ module ForestLiana
146
146
  @options[:fields][relation_class_name]&.size == 1 &&
147
147
  @options[:fields][relation_class_name]&.include?(relation.klass.primary_key.to_sym)
148
148
 
149
- attr_data[:attr_or_block] = proc { relation.klass.new(relation.klass.primary_key => object.send(relation.foreign_key.to_sym)) }
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
+ }
150
153
  end
151
154
  end
152
155
 
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.14.3"
2
+ VERSION = "9.14.4"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  class Tree < ActiveRecord::Base
2
2
  belongs_to :owner, class_name: 'User', inverse_of: :trees_owned
3
3
  belongs_to :cutter, class_name: 'User', inverse_of: :trees_cut
4
- belongs_to :island
4
+ belongs_to :island, optional: true
5
5
  belongs_to :eponymous_island,
6
6
  ->(record) { where(name: record.name) },
7
7
  class_name: 'Island',
@@ -0,0 +1,53 @@
1
+ module ForestLiana
2
+ describe SerializerFactory do
3
+ describe '#serializer_for has_one_relationships patch' do
4
+ let(:user) { User.create!(name: 'PatchTest') }
5
+ let(:island) { Island.create!(name: 'TestIsland') }
6
+ let(:tree) { Tree.create!(name: 'TestTree', island: island, owner: user) }
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
+ it 'returns nil if foreign key is nil' do
30
+ tree_without_island = Tree.create!(name: 'NoIslandTree', island_id: nil, owner: user)
31
+
32
+ factory = described_class.new
33
+ serializer_class = factory.serializer_for(Tree)
34
+
35
+ serializer_class.send(:has_one, :island) { }
36
+
37
+ instance = serializer_class.new(tree_without_island, fields: {
38
+ 'Island' => [:id],
39
+ 'Tree' => [:island]
40
+ })
41
+
42
+ relationships = instance.send(:has_one_relationships)
43
+ expect(relationships).to have_key(:island)
44
+ relation_data = relationships[:island]
45
+ expect(relation_data[:attr_or_block]).to be_a(Proc)
46
+ model = relation_data[:attr_or_block].call
47
+
48
+ expect(model).to be_nil
49
+ end
50
+
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.14.3
4
+ version: 9.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-19 00:00:00.000000000 Z
11
+ date: 2025-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -431,6 +431,7 @@ files:
431
431
  - spec/services/forest_liana/resources_getter_spec.rb
432
432
  - spec/services/forest_liana/schema_adapter_spec.rb
433
433
  - spec/services/forest_liana/scope_manager_spec.rb
434
+ - spec/services/forest_liana/serializer_factory_spec.rb
434
435
  - spec/services/forest_liana/smart_action_field_validator_spec.rb
435
436
  - spec/services/forest_liana/smart_action_form_parser_spec.rb
436
437
  - spec/services/forest_liana/utils/context_variables_injector_spec.rb
@@ -736,6 +737,7 @@ test_files:
736
737
  - spec/services/forest_liana/resources_getter_spec.rb
737
738
  - spec/services/forest_liana/schema_adapter_spec.rb
738
739
  - spec/services/forest_liana/scope_manager_spec.rb
740
+ - spec/services/forest_liana/serializer_factory_spec.rb
739
741
  - spec/services/forest_liana/smart_action_field_validator_spec.rb
740
742
  - spec/services/forest_liana/smart_action_form_parser_spec.rb
741
743
  - spec/services/forest_liana/utils/context_variables_injector_spec.rb