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: de38bb4323a6676a9185bee03e2ba490c9b9bc2be0fcb41e213849ef9755c9f2
4
- data.tar.gz: 54e8bd60a653ecdf126480f2530b15cf52c024d9b69acd3152fd7ffa86f52c0e
3
+ metadata.gz: be12c6b12347b9f674f52eb7f52b41294717436fae76926129d02b6194d6a116
4
+ data.tar.gz: 3a2d7c0a34e7cadbfc40d70b4385d23ffe703de619f9c28b49a10af86a23a8f5
5
5
  SHA512:
6
- metadata.gz: c319db67ae5621fd89a52d86e02022b73c4a2872763ec1cc48ef5a43c0f9b47b0ae3fa4927c1d180b60d0af83dfaa6085e788f8e66b91c3213c804a9e5fc56b6
7
- data.tar.gz: 2d59d2fb65f0b2c05e189e11d25d20dcf9980fe9dc23d4c1f14c96050a7ef67bc7e162731b0fe5f6c0a717557ba9b8b12d98d4481197abc21a69b9d2a1c5b900
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
- target_model_connection = association.klass.connection
55
- target_model_database = target_model_connection.current_database if target_model_connection.respond_to? :current_database
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
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.20.2"
2
+ VERSION = "9.20.3"
3
3
  end
@@ -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 connections do not support current_database' do
121
- include_examples 'left outer join'
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 uses a different database connection' do
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
- context 'when the included association uses the same database connection' do
150
- include_context 'resource current_database'
118
+ it 'resolves the database without issuing a SQL query' do
119
+ getter
151
120
 
152
- include_examples 'left outer join'
153
- include_examples 'records'
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.20.2
4
+ version: 9.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda