forest_liana 9.20.2 → 9.20.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be12c6b12347b9f674f52eb7f52b41294717436fae76926129d02b6194d6a116
|
|
4
|
+
data.tar.gz: 3a2d7c0a34e7cadbfc40d70b4385d23ffe703de619f9c28b49a10af86a23a8f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c32654d08132350f85a8313b7ef296838782d72e367509c4283990fb7fda261e453629e0b44f268ece649ae2889ec67dea07c31a6b4b3f2f799178367c016d4
|
|
7
|
+
data.tar.gz: 205dad627f2752573f9f8e9c9a17e8e5a1ec3ad2260bad68a041b38d783060ee5f399950928a8b7f6ea8bf3b450d23878ec5fac7247d7c5e067b323348b4acf0
|
|
@@ -51,10 +51,8 @@ module ForestLiana
|
|
|
51
51
|
def separate_database?(resource, association)
|
|
52
52
|
return false if SchemaUtils.polymorphic?(association)
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
resource_connection = resource.connection
|
|
57
|
-
resource_database = resource_connection.current_database if resource_connection.respond_to? :current_database
|
|
54
|
+
target_model_database = association.klass.connection.pool.db_config.database
|
|
55
|
+
resource_database = resource.connection.pool.db_config.database
|
|
58
56
|
|
|
59
57
|
target_model_database != resource_database
|
|
60
58
|
end
|
data/lib/forest_liana/version.rb
CHANGED
|
@@ -83,26 +83,6 @@ module ForestLiana
|
|
|
83
83
|
let(:resource) { Product }
|
|
84
84
|
let(:fields) { { resource.name => 'id,name,manufacturer', 'manufacturer' => 'name' } }
|
|
85
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
86
|
shared_examples 'records' do
|
|
107
87
|
it 'should get only the expected records' do
|
|
108
88
|
getter.perform
|
|
@@ -117,40 +97,38 @@ module ForestLiana
|
|
|
117
97
|
end
|
|
118
98
|
end
|
|
119
99
|
|
|
120
|
-
context 'when the
|
|
121
|
-
|
|
100
|
+
context 'when the included association is in the same database' do
|
|
101
|
+
it 'performs a left outer join with the association' do
|
|
102
|
+
expect(getter.perform.to_sql).to match(/LEFT OUTER JOIN "manufacturers"/)
|
|
103
|
+
end
|
|
104
|
+
|
|
122
105
|
include_examples 'records'
|
|
123
106
|
end
|
|
124
107
|
|
|
125
|
-
context 'when the included association
|
|
108
|
+
context 'when the included association is in a different database' do
|
|
126
109
|
let(:fields) { { resource.name => 'id,name,driver', 'driver' => 'firstname' } }
|
|
127
110
|
|
|
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
111
|
it 'does not perform a left outer join with the association' do
|
|
145
112
|
expect(getter.perform.to_sql).not_to match(/LEFT OUTER JOIN "drivers"/)
|
|
146
113
|
end
|
|
114
|
+
|
|
115
|
+
include_examples 'records'
|
|
147
116
|
end
|
|
148
117
|
|
|
149
|
-
|
|
150
|
-
|
|
118
|
+
it 'resolves the database without issuing a SQL query' do
|
|
119
|
+
getter
|
|
151
120
|
|
|
152
|
-
|
|
153
|
-
|
|
121
|
+
queries = []
|
|
122
|
+
subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*, payload|
|
|
123
|
+
queries << payload[:sql] unless payload[:name] == 'SCHEMA' || payload[:cached]
|
|
124
|
+
end
|
|
125
|
+
begin
|
|
126
|
+
getter.send(:separate_database?, Product, Product.reflect_on_association(:manufacturer))
|
|
127
|
+
ensure
|
|
128
|
+
ActiveSupport::Notifications.unsubscribe(subscriber)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
expect(queries).to be_empty
|
|
154
132
|
end
|
|
155
133
|
end
|
|
156
134
|
|