record-cache 0.1.3 → 0.1.4
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 +8 -8
- data/lib/record_cache/base.rb +4 -4
- data/lib/record_cache/datastore/active_record_30.rb +1 -1
- data/lib/record_cache/datastore/active_record_31.rb +1 -1
- data/lib/record_cache/datastore/active_record_32.rb +2 -2
- data/lib/record_cache/datastore/active_record_40.rb +445 -0
- data/lib/record_cache/datastore/active_record_41.rb +446 -0
- data/lib/record_cache/strategy/full_table_cache.rb +1 -1
- data/lib/record_cache/strategy/util.rb +20 -3
- data/lib/record_cache/version.rb +1 -1
- data/spec/db/create-record-cache-db_and_user.sql +5 -0
- data/spec/db/database.yml +7 -0
- data/spec/db/schema.rb +9 -15
- data/spec/initializers/backward_compatibility.rb +32 -0
- data/spec/lib/active_record/visitor_spec.rb +1 -1
- data/spec/lib/base_spec.rb +2 -2
- data/spec/lib/dispatcher_spec.rb +1 -1
- data/spec/lib/multi_read_spec.rb +1 -1
- data/spec/lib/query_spec.rb +1 -1
- data/spec/lib/statistics_spec.rb +1 -1
- data/spec/lib/strategy/base_spec.rb +39 -39
- data/spec/lib/strategy/full_table_cache_spec.rb +18 -18
- data/spec/lib/strategy/index_cache_spec.rb +58 -52
- data/spec/lib/strategy/query_cache_spec.rb +1 -1
- data/spec/lib/strategy/unique_index_on_id_cache_spec.rb +57 -45
- data/spec/lib/strategy/unique_index_on_string_cache_spec.rb +47 -45
- data/spec/lib/strategy/util_spec.rb +49 -43
- data/spec/lib/version_store_spec.rb +1 -1
- data/spec/models/apple.rb +1 -2
- data/spec/spec_helper.rb +16 -7
- data/spec/support/matchers/hit_cache_matcher.rb +1 -1
- data/spec/support/matchers/miss_cache_matcher.rb +1 -1
- data/spec/support/matchers/use_cache_matcher.rb +1 -1
- metadata +63 -17
- data/spec/support/after_commit.rb +0 -73
data/spec/models/apple.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
ENV["RAILS_ENV"]="test"
|
2
|
+
|
1
3
|
dir = File.dirname(__FILE__)
|
2
4
|
$LOAD_PATH.unshift dir + "/../lib"
|
3
5
|
$LOAD_PATH.unshift dir
|
@@ -7,12 +9,14 @@ SimpleCov.start do
|
|
7
9
|
add_filter '/spec/'
|
8
10
|
end
|
9
11
|
|
10
|
-
require
|
11
|
-
require
|
12
|
+
require 'rubygems'
|
13
|
+
require 'rspec'
|
12
14
|
require 'database_cleaner'
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
15
|
+
require 'logger'
|
16
|
+
require 'record_cache'
|
17
|
+
require 'record_cache/test/resettable_version_store'
|
18
|
+
|
19
|
+
require 'test_after_commit'
|
16
20
|
|
17
21
|
# spec support files
|
18
22
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
@@ -24,7 +28,7 @@ ActiveRecord::Base.logger = Logger.new(dir + "/log/debug.log")
|
|
24
28
|
|
25
29
|
# SQL Lite
|
26
30
|
ActiveRecord::Base.configurations = YAML::load(IO.read(dir + "/db/database.yml"))
|
27
|
-
ActiveRecord::Base.establish_connection("sqlite3")
|
31
|
+
ActiveRecord::Base.establish_connection(ENV["DATABASE_ADAPTER"] || "sqlite3")
|
28
32
|
|
29
33
|
# Initializers + Model + Data
|
30
34
|
load(dir + "/initializers/record_cache.rb")
|
@@ -32,14 +36,19 @@ load(dir + "/db/schema.rb")
|
|
32
36
|
Dir["#{dir}/models/*.rb"].each {|f| load(f) }
|
33
37
|
load(dir + "/db/seeds.rb")
|
34
38
|
|
39
|
+
# backwards compatibility for previous versions of rails
|
40
|
+
load(dir + "/initializers/backward_compatibility.rb")
|
41
|
+
|
35
42
|
# Clear cache after each test
|
36
43
|
RSpec.configure do |config|
|
44
|
+
config.disable_monkey_patching!
|
45
|
+
config.color = true
|
37
46
|
|
38
47
|
config.before(:each) do
|
39
48
|
RecordCache::Base.enable
|
40
49
|
DatabaseCleaner.start
|
41
50
|
end
|
42
|
-
|
51
|
+
|
43
52
|
config.after(:each) do
|
44
53
|
DatabaseCleaner.clean
|
45
54
|
RecordCache::Base.version_store.reset!
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orslumen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ! '
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ! '
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - <
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - <
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mysql2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rake
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +164,20 @@ dependencies:
|
|
136
164
|
- - ! '>='
|
137
165
|
- !ruby/object:Gem::Version
|
138
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: test_after_commit
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
139
181
|
description: Record Cache for Rails 3
|
140
182
|
email: orslumen@gmail.com
|
141
183
|
executables: []
|
@@ -149,6 +191,8 @@ files:
|
|
149
191
|
- lib/record_cache/datastore/active_record_30.rb
|
150
192
|
- lib/record_cache/datastore/active_record_31.rb
|
151
193
|
- lib/record_cache/datastore/active_record_32.rb
|
194
|
+
- lib/record_cache/datastore/active_record_40.rb
|
195
|
+
- lib/record_cache/datastore/active_record_41.rb
|
152
196
|
- lib/record_cache/dispatcher.rb
|
153
197
|
- lib/record_cache/multi_read.rb
|
154
198
|
- lib/record_cache/query.rb
|
@@ -161,9 +205,11 @@ files:
|
|
161
205
|
- lib/record_cache/test/resettable_version_store.rb
|
162
206
|
- lib/record_cache/version.rb
|
163
207
|
- lib/record_cache/version_store.rb
|
208
|
+
- spec/db/create-record-cache-db_and_user.sql
|
164
209
|
- spec/db/database.yml
|
165
210
|
- spec/db/schema.rb
|
166
211
|
- spec/db/seeds.rb
|
212
|
+
- spec/initializers/backward_compatibility.rb
|
167
213
|
- spec/initializers/record_cache.rb
|
168
214
|
- spec/lib/active_record/visitor_spec.rb
|
169
215
|
- spec/lib/base_spec.rb
|
@@ -187,7 +233,6 @@ files:
|
|
187
233
|
- spec/models/person.rb
|
188
234
|
- spec/models/store.rb
|
189
235
|
- spec/spec_helper.rb
|
190
|
-
- spec/support/after_commit.rb
|
191
236
|
- spec/support/matchers/hit_cache_matcher.rb
|
192
237
|
- spec/support/matchers/log.rb
|
193
238
|
- spec/support/matchers/miss_cache_matcher.rb
|
@@ -215,12 +260,14 @@ rubyforge_project:
|
|
215
260
|
rubygems_version: 2.1.11
|
216
261
|
signing_key:
|
217
262
|
specification_version: 4
|
218
|
-
summary: Record Cache v0.1.
|
263
|
+
summary: Record Cache v0.1.4 transparantly stores Records in a Cache Store and retrieve
|
219
264
|
those Records from the store when queried using Active Model.
|
220
265
|
test_files:
|
266
|
+
- spec/db/create-record-cache-db_and_user.sql
|
221
267
|
- spec/db/database.yml
|
222
268
|
- spec/db/schema.rb
|
223
269
|
- spec/db/seeds.rb
|
270
|
+
- spec/initializers/backward_compatibility.rb
|
224
271
|
- spec/initializers/record_cache.rb
|
225
272
|
- spec/lib/active_record/visitor_spec.rb
|
226
273
|
- spec/lib/base_spec.rb
|
@@ -244,7 +291,6 @@ test_files:
|
|
244
291
|
- spec/models/person.rb
|
245
292
|
- spec/models/store.rb
|
246
293
|
- spec/spec_helper.rb
|
247
|
-
- spec/support/after_commit.rb
|
248
294
|
- spec/support/matchers/hit_cache_matcher.rb
|
249
295
|
- spec/support/matchers/log.rb
|
250
296
|
- spec/support/matchers/miss_cache_matcher.rb
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# @see http://outofti.me/post/4777884779/test-after-commit-hooks-with-transactional-fixtures
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module DatabaseStatements
|
5
|
-
#
|
6
|
-
# Run the normal transaction method; when it's done, check to see if there
|
7
|
-
# is exactly one open transaction. If so, that's the transactional
|
8
|
-
# fixtures transaction; from the model's standpoint, the completed
|
9
|
-
# transaction is the real deal. Send commit callbacks to models.
|
10
|
-
#
|
11
|
-
# If the transaction block raises a Rollback, we need to know, so we don't
|
12
|
-
# call the commit hooks. Other exceptions don't need to be explicitly
|
13
|
-
# accounted for since they will raise uncaught through this method and
|
14
|
-
# prevent the code after the hook from running.
|
15
|
-
#
|
16
|
-
def transaction_with_transactional_fixtures(options = {}, &block)
|
17
|
-
rolled_back = false
|
18
|
-
|
19
|
-
transaction_without_transactional_fixtures do
|
20
|
-
begin
|
21
|
-
yield
|
22
|
-
rescue Exception => exception
|
23
|
-
if exception.is_a?(ActiveRecord::Rollback)
|
24
|
-
rolled_back = true
|
25
|
-
else
|
26
|
-
puts "Exception in aftercommit: #{exception}"
|
27
|
-
puts exception.backtrace
|
28
|
-
end
|
29
|
-
raise exception
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
if !rolled_back && open_transactions == 1
|
34
|
-
commit_transaction_records(false)
|
35
|
-
end
|
36
|
-
true
|
37
|
-
end
|
38
|
-
alias_method_chain :transaction, :transactional_fixtures
|
39
|
-
|
40
|
-
#
|
41
|
-
# The @_current_transaction_records is an stack of arrays, each one
|
42
|
-
# containing the records associated with the corresponding transaction
|
43
|
-
# in the transaction stack. This is used by the
|
44
|
-
# `rollback_transaction_records` method (to only send a rollback hook to
|
45
|
-
# models attached to the transaction being rolled back) but is usually
|
46
|
-
# ignored by the `commit_transaction_records` method. Here we
|
47
|
-
# monkey-patch it to temporarily replace the array with only the records
|
48
|
-
# for the top-of-stack transaction, so the real
|
49
|
-
# `commit_transaction_records` method only sends callbacks to those.
|
50
|
-
#
|
51
|
-
def commit_transaction_records_with_transactional_fixtures(commit = true)
|
52
|
-
unless commit
|
53
|
-
real_current_transaction_records = @_current_transaction_records
|
54
|
-
@_current_transaction_records = @_current_transaction_records.pop
|
55
|
-
end
|
56
|
-
|
57
|
-
begin
|
58
|
-
@_current_transaction_records ||= []
|
59
|
-
commit_transaction_records_without_transactional_fixtures
|
60
|
-
rescue Exception => exception
|
61
|
-
puts "Error in aftercommit: #{exception}"
|
62
|
-
puts exception.backtrace
|
63
|
-
ensure
|
64
|
-
unless commit
|
65
|
-
@_current_transaction_records = real_current_transaction_records
|
66
|
-
end
|
67
|
-
end
|
68
|
-
true
|
69
|
-
end
|
70
|
-
alias_method_chain :commit_transaction_records, :transactional_fixtures
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|