forest_liana 7.6.9 → 7.6.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/forest_liana/base_getter.rb +2 -2
- data/app/services/forest_liana/schema_adapter.rb +1 -1
- data/app/services/forest_liana/schema_utils.rb +1 -28
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/models/manufacturer.rb +3 -0
- data/spec/dummy/app/models/product.rb +3 -0
- data/spec/dummy/db/migrate/20220727114450_create_manufacturers.rb +7 -0
- data/spec/dummy/db/migrate/20220727114930_add_columns_to_products.rb +9 -0
- data/spec/dummy/db/schema.rb +10 -1
- data/spec/lib/forest_liana/bootstrapper_spec.rb +1 -0
- data/spec/services/forest_liana/resources_getter_spec.rb +101 -8
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '095735ab97e1d107e2746eb6c118198798434aed96e915fdc2e476249bf24cc9'
|
4
|
+
data.tar.gz: 4d37f6fa5b27393ebb2ddfc06bddb1fb5c3398c9157c527625a37d9b87fdb380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efdfdb98774e37d1dbd7d641f518a7ea9c62ececca98b7cc2ca06eb3bd27ca6638d03c3a7f4077b11fd77002033d379fd784b2e5226f4030ff41614e56fa2520
|
7
|
+
data.tar.gz: '029ba78907e4996a79d6b3a58849beb37f1f9bfe18b34cfa011e60dde7a2e7a3cb0312d26a45ceaa14f7d4585b5bf87e7f18d0b681fddaf4848bb554d5c03a28'
|
@@ -34,10 +34,10 @@ module ForestLiana
|
|
34
34
|
instance_dependent_associations = instance_dependent_associations(resource)
|
35
35
|
|
36
36
|
preload_loads = @includes.select do |name|
|
37
|
-
targetModelConnection = resource.reflect_on_association(name).
|
37
|
+
targetModelConnection = resource.reflect_on_association(name).klass.connection
|
38
38
|
targetModelDatabase = targetModelConnection.current_database if targetModelConnection.respond_to? :current_database
|
39
39
|
resourceConnection = resource.connection
|
40
|
-
resourceDatabase = resourceConnection if resourceConnection.respond_to? :current_database
|
40
|
+
resourceDatabase = resourceConnection.current_database if resourceConnection.respond_to? :current_database
|
41
41
|
|
42
42
|
targetModelDatabase != resourceDatabase
|
43
43
|
end + instance_dependent_associations
|
@@ -8,7 +8,7 @@ module ForestLiana
|
|
8
8
|
add_columns
|
9
9
|
add_associations
|
10
10
|
|
11
|
-
collection.fields.sort_by
|
11
|
+
collection.fields.sort_by!.with_index { |k, idx| [k[:field].to_s, idx] }
|
12
12
|
|
13
13
|
# NOTICE: Add ActsAsTaggable fields
|
14
14
|
if @model.try(:taggable?) && @model.respond_to?(:acts_as_taggable) &&
|
@@ -31,11 +31,7 @@ module ForestLiana
|
|
31
31
|
if model.abstract_class?
|
32
32
|
model_found = self.find_model_from_abstract_class(model, collection_name)
|
33
33
|
elsif ForestLiana.name_for(model) == collection_name
|
34
|
-
|
35
|
-
model_found = model
|
36
|
-
else
|
37
|
-
model_found = model.base_class
|
38
|
-
end
|
34
|
+
model_found = model
|
39
35
|
end
|
40
36
|
|
41
37
|
break if model_found
|
@@ -90,28 +86,5 @@ module ForestLiana
|
|
90
86
|
def self.is_active_type? model
|
91
87
|
Object.const_defined?('ActiveType::Object') && model < ActiveType::Object
|
92
88
|
end
|
93
|
-
|
94
|
-
def self.sti_child?(model)
|
95
|
-
begin
|
96
|
-
parent = model.try(:superclass)
|
97
|
-
return false unless parent.try(:table_name)
|
98
|
-
|
99
|
-
if ForestLiana.name_for(parent)
|
100
|
-
inheritance_column = parent.columns.find do |column|
|
101
|
-
(parent.inheritance_column && column.name == parent.inheritance_column)\
|
102
|
-
|| column.name == 'type'
|
103
|
-
end
|
104
|
-
|
105
|
-
return inheritance_column.present?
|
106
|
-
end
|
107
|
-
rescue NoMethodError
|
108
|
-
# NOTICE: ActiveRecord::Base throw the exception "undefined method
|
109
|
-
# `abstract_class?' for Object:Class" when calling the existing method
|
110
|
-
# "table_name".
|
111
|
-
return false
|
112
|
-
end
|
113
|
-
|
114
|
-
return false
|
115
|
-
end
|
116
89
|
end
|
117
90
|
end
|
data/lib/forest_liana/version.rb
CHANGED
data/spec/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2022_07_27_114930) do
|
14
14
|
|
15
15
|
create_table "isle", force: :cascade do |t|
|
16
16
|
t.string "name"
|
@@ -27,6 +27,10 @@ ActiveRecord::Schema.define(version: 2021_05_26_084712) do
|
|
27
27
|
t.index ["island_id"], name: "index_locations_on_island_id"
|
28
28
|
end
|
29
29
|
|
30
|
+
create_table "manufacturers", force: :cascade do |t|
|
31
|
+
t.string "name"
|
32
|
+
end
|
33
|
+
|
30
34
|
create_table "owners", force: :cascade do |t|
|
31
35
|
t.string "name"
|
32
36
|
t.datetime "hired_at"
|
@@ -34,6 +38,11 @@ ActiveRecord::Schema.define(version: 2021_05_26_084712) do
|
|
34
38
|
|
35
39
|
create_table "products", force: :cascade do |t|
|
36
40
|
t.string "uri"
|
41
|
+
t.string "name"
|
42
|
+
t.integer "manufacturer_id"
|
43
|
+
t.integer "driver_id"
|
44
|
+
t.index ["driver_id"], name: "index_products_on_driver_id"
|
45
|
+
t.index ["manufacturer_id"], name: "index_products_on_manufacturer_id"
|
37
46
|
end
|
38
47
|
|
39
48
|
create_table "references", force: :cascade do |t|
|
@@ -4,9 +4,9 @@ module ForestLiana
|
|
4
4
|
let(:pageSize) { 10 }
|
5
5
|
let(:pageNumber) { 1 }
|
6
6
|
let(:sort) { 'id' }
|
7
|
-
let(:fields) {
|
8
|
-
let(:filters) {
|
9
|
-
let(:scopes) { {
|
7
|
+
let(:fields) {}
|
8
|
+
let(:filters) {}
|
9
|
+
let(:scopes) { {} }
|
10
10
|
let(:rendering_id) { 13 }
|
11
11
|
let(:user) { { 'id' => '1', 'rendering_id' => rendering_id } }
|
12
12
|
|
@@ -22,7 +22,21 @@ module ForestLiana
|
|
22
22
|
allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(scopes)
|
23
23
|
end
|
24
24
|
|
25
|
+
def clean_database
|
26
|
+
[
|
27
|
+
Driver,
|
28
|
+
Island,
|
29
|
+
Location,
|
30
|
+
Manufacturer,
|
31
|
+
Product,
|
32
|
+
Tree,
|
33
|
+
User,
|
34
|
+
].each(&:destroy_all)
|
35
|
+
end
|
36
|
+
|
25
37
|
before(:each) do
|
38
|
+
clean_database
|
39
|
+
|
26
40
|
users = ['Michel', 'Robert', 'Vince', 'Sandro', 'Olesya', 'Romain', 'Valentin', 'Jason', 'Arnaud', 'Jeff', 'Steve', 'Marc', 'Xavier', 'Paul', 'Mickael', 'Mike', 'Maxime', 'Gertrude', 'Monique', 'Mia', 'Rachid', 'Edouard', 'Sacha', 'Caro', 'Amand', 'Nathan', 'Noémie', 'Robin', 'Gaelle', 'Isabelle']
|
27
41
|
.map { |name| User.create(name: name) }
|
28
42
|
|
@@ -50,15 +64,94 @@ module ForestLiana
|
|
50
64
|
{ :coordinates => '32154', :island => islands[4] }
|
51
65
|
].map { |location| Location.create(coordinates: location[:coordinates], island: location[:island]) }
|
52
66
|
|
67
|
+
manufacturers = ['Orange', 'Pear'].map { |name| Manufacturer.create!(name: 'name') }
|
68
|
+
|
69
|
+
drivers = ['Baby driver', 'Taxi driver'].map { |firstname| Driver.create!(firstname: firstname) }
|
70
|
+
|
71
|
+
products = [
|
72
|
+
{ name: 'Valencia', uri: 'https://valencia.com', manufacturer: manufacturers[0], driver: drivers[0] },
|
73
|
+
{ name: 'Blood', uri: 'https://blood.com', manufacturer: manufacturers[0], driver: drivers[1] },
|
74
|
+
{ name: 'Conference', uri: 'https://conference.com', manufacturer: manufacturers[1], driver: drivers[0] },
|
75
|
+
{ name: 'Concorde', uri: 'https://concorde.com', manufacturer: manufacturers[1], driver: drivers[1] }
|
76
|
+
].map {|attributes| Product.create!(attributes) }
|
77
|
+
|
53
78
|
reference = Reference.create()
|
54
79
|
init_scopes
|
55
80
|
end
|
56
81
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
82
|
+
describe 'records eager loading' do
|
83
|
+
let(:resource) { Product }
|
84
|
+
let(:fields) { { resource.name => 'id,name,manufacturer', 'manufacturer' => 'name' } }
|
85
|
+
|
86
|
+
shared_context 'resource current_database' do
|
87
|
+
before do
|
88
|
+
connection = resource.connection
|
89
|
+
|
90
|
+
def connection.current_database
|
91
|
+
'db/test.sqlite3'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
after do
|
96
|
+
resource.connection.singleton_class.remove_method(:current_database)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
shared_examples 'left outer join' do
|
101
|
+
it 'should perform a left outer join with the association' do
|
102
|
+
expect(getter.perform.to_sql).to match(/LEFT OUTER JOIN "manufacturers"/)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
shared_examples 'records' do
|
107
|
+
it 'should get only the expected records' do
|
108
|
+
getter.perform
|
109
|
+
|
110
|
+
records = getter.records
|
111
|
+
|
112
|
+
count = getter.count
|
113
|
+
|
114
|
+
expect(records.count).to eq 4
|
115
|
+
expect(count).to eq 4
|
116
|
+
expect(records.map(&:name)).to match_array(%w[Valencia Blood Conference Concorde])
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when the connections do not support current_database' do
|
121
|
+
include_examples 'left outer join'
|
122
|
+
include_examples 'records'
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'when the included association uses a different database connection' do
|
126
|
+
let(:fields) { { resource.name => 'id,name,driver', 'driver' => 'firstname' } }
|
127
|
+
|
128
|
+
before do
|
129
|
+
association_connection = resource.reflect_on_association(:driver).klass.connection
|
130
|
+
|
131
|
+
def association_connection.current_database
|
132
|
+
'db/different_test.sqlite3'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
after do
|
137
|
+
resource.reflect_on_association(:driver).klass.connection.singleton_class.remove_method(:current_database)
|
138
|
+
end
|
139
|
+
|
140
|
+
include_context 'resource current_database'
|
141
|
+
|
142
|
+
include_examples 'records'
|
143
|
+
|
144
|
+
it 'does not perform a left outer join with the association' do
|
145
|
+
expect(getter.perform.to_sql).not_to match(/LEFT OUTER JOIN "drivers"/)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when the included association uses the same database connection' do
|
150
|
+
include_context 'resource current_database'
|
151
|
+
|
152
|
+
include_examples 'left outer join'
|
153
|
+
include_examples 'records'
|
154
|
+
end
|
62
155
|
end
|
63
156
|
|
64
157
|
describe 'when there are more records than the page size' do
|
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: 7.6.
|
4
|
+
version: 7.6.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -334,6 +334,7 @@ files:
|
|
334
334
|
- spec/dummy/app/models/garage_record.rb
|
335
335
|
- spec/dummy/app/models/island.rb
|
336
336
|
- spec/dummy/app/models/location.rb
|
337
|
+
- spec/dummy/app/models/manufacturer.rb
|
337
338
|
- spec/dummy/app/models/owner.rb
|
338
339
|
- spec/dummy/app/models/product.rb
|
339
340
|
- spec/dummy/app/models/reference.rb
|
@@ -377,6 +378,8 @@ files:
|
|
377
378
|
- spec/dummy/db/migrate/20210526084712_create_products.rb
|
378
379
|
- spec/dummy/db/migrate/20220719094127_create_cars.rb
|
379
380
|
- spec/dummy/db/migrate/20220719094450_create_drivers.rb
|
381
|
+
- spec/dummy/db/migrate/20220727114450_create_manufacturers.rb
|
382
|
+
- spec/dummy/db/migrate/20220727114930_add_columns_to_products.rb
|
380
383
|
- spec/dummy/db/schema.rb
|
381
384
|
- spec/dummy/lib/forest_liana/collections/island.rb
|
382
385
|
- spec/dummy/lib/forest_liana/collections/location.rb
|
@@ -657,6 +660,7 @@ test_files:
|
|
657
660
|
- spec/dummy/app/models/island.rb
|
658
661
|
- spec/dummy/app/models/owner.rb
|
659
662
|
- spec/dummy/app/models/application_record.rb
|
663
|
+
- spec/dummy/app/models/manufacturer.rb
|
660
664
|
- spec/dummy/app/models/town.rb
|
661
665
|
- spec/dummy/app/models/user.rb
|
662
666
|
- spec/dummy/app/models/reference.rb
|
@@ -678,7 +682,9 @@ test_files:
|
|
678
682
|
- spec/dummy/db/migrate/20220719094127_create_cars.rb
|
679
683
|
- spec/dummy/db/migrate/20210511141752_create_owners.rb
|
680
684
|
- spec/dummy/db/migrate/20220719094450_create_drivers.rb
|
685
|
+
- spec/dummy/db/migrate/20220727114930_add_columns_to_products.rb
|
681
686
|
- spec/dummy/db/migrate/20210526084712_create_products.rb
|
687
|
+
- spec/dummy/db/migrate/20220727114450_create_manufacturers.rb
|
682
688
|
- spec/dummy/db/migrate/20190226174951_create_tree.rb
|
683
689
|
- spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb
|
684
690
|
- spec/dummy/db/migrate/20190226172951_create_user.rb
|