activerecord_views 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad72d8911d4f996a5b7eb841d2a7b1f930d16aac
4
- data.tar.gz: 1891b3ee70bfa4e3737213f285b2e350c9c628ae
3
+ metadata.gz: 9eded5dc204c84d1913a10b2c73a15b80ba1aeb4
4
+ data.tar.gz: 3cc3301d035582053ebc27c447d7a0eab65da7ba
5
5
  SHA512:
6
- metadata.gz: dda606e695a85d2e07170c2337d315d72a23cab5e0c53650035168d520e8ebfd9661a8e78a1025a46f9c556fd080eb9da07c1101343d614bae12ca97ce209988
7
- data.tar.gz: b84c8e82443bf416f9c754ecba2a097ed002bf7b97c2c8a24c90049e6f4984e8f3ba7626ebef7e33cc41d968401a219b1d54bcb0755ca6c2272341c9ed9ed23d
6
+ metadata.gz: 74a57fb79e1136a4f2a00977d98221bf032a42cff691ccba96bd12a36c243754e08298fed60e4678c9e053614bd09b552e7c0bbbfa8e66bdc9428ad1a20d8e26
7
+ data.tar.gz: a5c0e4987e1925e0cad58a2024262c41249601cc4e11cd40d4266eb8db490c03a2cd0ec7f1ffd87ec814b4a9084365653d871cf5f8668faa1e779c49e210bfb9
data/README.markdown CHANGED
@@ -99,7 +99,7 @@ end
99
99
 
100
100
  ## Materialized views
101
101
 
102
- ActiveRecordViews has support [PostgreSQL's materialized views](http://www.postgresql.org/docs/9.4/static/rules-materializedviews.html).
102
+ ActiveRecordViews has support for [PostgreSQL's materialized views](http://www.postgresql.org/docs/9.4/static/rules-materializedviews.html).
103
103
  By default, views execute their query to calculate the output every time they are accessed.
104
104
  Materialized views let you cache the output of views. This is useful for views which have expensive calculations. Your application can then trigger a refresh of the cached data as required.
105
105
 
@@ -0,0 +1,13 @@
1
+ require 'database_cleaner/active_record/truncation'
2
+
3
+ module ActiveRecordViews
4
+ module DatabaseCleaner
5
+ module TruncationExtension
6
+ def migration_storage_names
7
+ super + %w[active_record_views]
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ ::DatabaseCleaner::ActiveRecord::Truncation.prepend ActiveRecordViews::DatabaseCleaner::TruncationExtension
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordViews
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -15,6 +15,7 @@ module ActiveRecordViews
15
15
  def self.init!
16
16
  require 'active_record_views/extension'
17
17
  ::ActiveRecord::Base.send :include, ActiveRecordViews::Extension
18
+ require 'active_record_views/database_cleaner/truncation_extension' if defined? ::DatabaseCleaner
18
19
  end
19
20
 
20
21
  def self.find_sql_file(name)
@@ -34,22 +35,28 @@ module ActiveRecordViews
34
35
  !connection.outside_transaction?
35
36
  end
36
37
 
37
- begin
38
- recursing = Thread.current[:active_record_views_without_transaction]
39
- Thread.current[:active_record_views_without_transaction] = true
38
+ states = Thread.current[:active_record_views_without_transaction] ||= {}
40
39
 
41
- if in_transaction && !recursing
40
+ begin
41
+ if states[connection]
42
+ yield states[connection]
43
+ elsif in_transaction
42
44
  begin
43
45
  temp_connection = connection.pool.checkout
46
+ states[temp_connection] = states[connection] = temp_connection
44
47
  yield temp_connection
45
48
  ensure
46
49
  connection.pool.checkin temp_connection
50
+ states[temp_connection] = states[connection] = nil
47
51
  end
48
52
  else
49
- yield connection
53
+ begin
54
+ states[connection] = connection
55
+ yield connection
56
+ ensure
57
+ states[connection] = nil
58
+ end
50
59
  end
51
- ensure
52
- Thread.current[:active_record_views_without_transaction] = nil
53
60
  end
54
61
  end
55
62
 
@@ -241,5 +241,37 @@ describe ActiveRecordViews do
241
241
  end
242
242
  end
243
243
  end
244
+
245
+ it 'yields same isolated connection if called recursively on original connection inside transaction' do
246
+ original_connection.transaction do
247
+ ActiveRecordViews.without_transaction original_connection do |new_connection_1|
248
+ expect(new_connection_1).to_not eq original_connection
249
+ ActiveRecordViews.without_transaction original_connection do |new_connection_2|
250
+ expect(new_connection_2).to eq new_connection_1
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ it 'yields different isolated connection if called recursively on different connections inside transcation' do
257
+ begin
258
+ original_connection_2 = original_connection.pool.checkout
259
+
260
+ original_connection.transaction do
261
+ ActiveRecordViews.without_transaction original_connection do |new_connection_1|
262
+ expect(new_connection_1).to_not eq original_connection
263
+ original_connection_2.transaction do
264
+ ActiveRecordViews.without_transaction original_connection_2 do |new_connection_2|
265
+ expect(new_connection_2).to_not eq original_connection
266
+ expect(new_connection_2).to_not eq original_connection_2
267
+ expect(new_connection_2).to_not eq new_connection_1
268
+ end
269
+ end
270
+ end
271
+ end
272
+ ensure
273
+ original_connection.pool.checkin original_connection_2
274
+ end
275
+ end
244
276
  end
245
277
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Weathered
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -107,6 +107,7 @@ files:
107
107
  - gemfiles/rails4_2.gemfile
108
108
  - lib/active_record_views.rb
109
109
  - lib/active_record_views/checksum_cache.rb
110
+ - lib/active_record_views/database_cleaner/truncation_extension.rb
110
111
  - lib/active_record_views/extension.rb
111
112
  - lib/active_record_views/railtie.rb
112
113
  - lib/active_record_views/registered_view.rb