constant_table_saver 5.1.1 → 5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/MIT-LICENSE +1 -1
- data/README.md +7 -2
- data/constant_table_saver.gemspec +3 -0
- data/lib/constant_table_saver.rb +2 -2
- data/lib/constant_table_saver/version.rb +1 -1
- data/test/constant_table_saver_test.rb +23 -0
- data/test/database.yml +0 -4
- data/test/test_helper.rb +1 -1
- data/test_all.rb +8 -5
- metadata +45 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952a6f9f15aa9905df69f3dcb279391f55a5abde
|
4
|
+
data.tar.gz: ac94f3acbf0e194aad02e91fb4c45ed16f2594d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278138ada54ee955e1a29b58505959e772e4db8468d4835393502912e8d91ecd7766cc1347f40afcfece79892b3419ce93580a15f2a3f6ff57a177a7a42e6dcf
|
7
|
+
data.tar.gz: 6367660c3f7a614fa90357558fa93f8ced9a3a1b3a26a9486a48c05c496a96ff8a6acf661aac9990d8914220d17d835d3adf8dddf02be15a7601a0b3f3776982
|
data/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ named after the name field you specify.
|
|
11
11
|
Compatibility
|
12
12
|
=============
|
13
13
|
|
14
|
-
Currently tested against Rails 5.1 (5.1.
|
14
|
+
Currently tested against Rails 5.1 (up to 5.1.6), 5.0 (up to 5.0.6), and 4.2 (up to 4.2.10), on Ruby 2.3.6, 2.4.3, and 2.5.0.
|
15
15
|
|
16
16
|
For earlier versions of Rails, use an older version of the gem.
|
17
17
|
|
@@ -82,4 +82,9 @@ Means you will also have methods returning those records:
|
|
82
82
|
Optionally, you can specify a `:name_prefix` and/or `:name_suffix`.
|
83
83
|
|
84
84
|
|
85
|
-
|
85
|
+
Thanks
|
86
|
+
======
|
87
|
+
|
88
|
+
* Marc Shaw (@marcshaw)
|
89
|
+
|
90
|
+
Copyright (c) 2010-2018 Will Bryant, Sekuda Ltd, released under the MIT license
|
data/lib/constant_table_saver.rb
CHANGED
@@ -80,7 +80,7 @@ module ConstantTableSaver
|
|
80
80
|
module ActiveRecord5ClassMethods
|
81
81
|
def find_by_sql(sql, binds = [], preparable: nil, &block)
|
82
82
|
@find_by_sql ||= {
|
83
|
-
:all =>
|
83
|
+
:all => relation.to_sql,
|
84
84
|
:id => relation.where(relation.table[primary_key].eq(Arel::Nodes::BindParam.new)).limit(1).arel,
|
85
85
|
:first => relation.order(relation.table[primary_key].asc).limit(1).arel,
|
86
86
|
:last => relation.order(relation.table[primary_key].desc).limit(1).arel,
|
@@ -119,7 +119,7 @@ module ConstantTableSaver
|
|
119
119
|
module ActiveRecord4ClassMethods
|
120
120
|
def find_by_sql(sql, binds = [])
|
121
121
|
@find_by_sql ||= {
|
122
|
-
:all =>
|
122
|
+
:all => relation.to_sql,
|
123
123
|
:id => relation.where(relation.table[primary_key].eq(connection.substitute_at(columns_hash[primary_key], 0))).limit(1).
|
124
124
|
tap {|r| r.bind_values += [[columns_hash[primary_key], :undefined]]}. # work around AR 4.1.9-4.1.x (but not 4.2.x) calling nil.first if there's no bind_values
|
125
125
|
arel,
|
@@ -14,6 +14,10 @@ class ConstantPie < ActiveRecord::Base
|
|
14
14
|
def self.with_unicorn_filling_scope
|
15
15
|
with_scope(:find => {:conditions => {:filling => 'unicorn'}}) { yield }
|
16
16
|
end
|
17
|
+
|
18
|
+
def self.retrieve_pies
|
19
|
+
all.map { |x| x }
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
class ConstantNamedPie < ActiveRecord::Base
|
@@ -160,6 +164,25 @@ class ConstantTableSaverTest < ActiveSupport::TestCase
|
|
160
164
|
end
|
161
165
|
end
|
162
166
|
|
167
|
+
test "it doesn't cache find queries on scoped methods, even when no binds are set, if the records have been cached" do
|
168
|
+
ConstantPie.all.to_a
|
169
|
+
assert_queries(1) do
|
170
|
+
@pies = ConstantPie.where(:filling => ["Tasty beef steak"]).retrieve_pies
|
171
|
+
end
|
172
|
+
assert_equal 1, @pies.size
|
173
|
+
end
|
174
|
+
|
175
|
+
test "it doesn't cache find queries on scoped methods, even when no binds are set, if the records have not been cached" do
|
176
|
+
# these two lines are needed to fix random test order failures when nothing has hit the ConstantPie schema before
|
177
|
+
ConstantPie.all.to_a
|
178
|
+
ConstantPie.reset_constant_record_cache!
|
179
|
+
|
180
|
+
assert_queries(1) do
|
181
|
+
@pies = ConstantPie.where(:filling => ["Tasty beef steak"]).retrieve_pies
|
182
|
+
end
|
183
|
+
assert_equal 1, @pies.size
|
184
|
+
end
|
185
|
+
|
163
186
|
test "it passes the options preventing caching to the underlying query methods" do
|
164
187
|
assert_nil ConstantPie.where(:filling => 'unicorn').first
|
165
188
|
assert_equal [], ConstantPie.where(:filling => 'unicorn').all
|
data/test/database.yml
CHANGED
data/test/test_helper.rb
CHANGED
data/test_all.rb
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
rails_versions = ["
|
5
|
+
rails_versions = ["5.1.1".."5.1.6", "5.0.2".."5.0.6", "4.2.10"].flat_map {|spec| Array(spec).collect {|v| v.gsub /.0(\d)/, '.\\1'}}
|
6
6
|
rails_envs = YAML.load(File.read("test/database.yml")).keys
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
rails_versions.each do |version|
|
9
|
+
puts "*"*40
|
10
|
+
system "RAILS_VERSION=#{version} bundle update rails" or exit(1)
|
11
|
+
|
12
|
+
rails_envs.each do |env|
|
13
|
+
puts "Rails #{version}, #{env}"
|
14
|
+
system "RAILS_ENV=#{env} bundle exec rake" or exit(2)
|
12
15
|
end
|
13
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constant_table_saver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mysql2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pg
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: sqlite3
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +80,20 @@ dependencies:
|
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
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'
|
55
97
|
description: |
|
56
98
|
Loads all records from the table on first use, and thereafter returns the
|
57
99
|
cached (and frozen) records for all find calls.
|
@@ -121,3 +163,4 @@ test_files:
|
|
121
163
|
- test/fixtures/pies.yml
|
122
164
|
- test/schema.rb
|
123
165
|
- test/test_helper.rb
|
166
|
+
has_rdoc: false
|