forest_liana 7.6.9 → 7.6.10
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/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: 529622dcf795df3fecbb514a1b707c59ba2508d5b9c09b51ebc4cd25984cc558
|
4
|
+
data.tar.gz: 31d36870440829fcad6549e452ccba2b25cde75a9bb3ce3c7370baf48248c6c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8183bd54a698c09f6831a8972bf108074cf038f983c3e9e89ab688b61dab07d9bb9e4fc75b337d0bcf54fe6d64e11eb96cfe7e3e6a05b133f9b2c3c5dd2a2724
|
7
|
+
data.tar.gz: f677de6ae48ec830dcde1f2f9acaa7b795017f4a068af72a5d2f3eacc3c826c5df6827fe5398869671ef275d86beb355736eefd64a7b1f965c3baa8dc5a760f6
|
@@ -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
|
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.10
|
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-01 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
|