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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd0a0f0466a9358d62172e153ae85c8a88a0e9a9
4
- data.tar.gz: b6d62a665e5a4b179101924c320e3ca2dd773e35
3
+ metadata.gz: 952a6f9f15aa9905df69f3dcb279391f55a5abde
4
+ data.tar.gz: ac94f3acbf0e194aad02e91fb4c45ed16f2594d3
5
5
  SHA512:
6
- metadata.gz: 350eef086260e755159c68fa837515eff1c50f79b90a6044fb3ecdc806b78955faa9ba5716e73ad0b92827e7bad2c3e11666a0914a872e7df086a195c9f7b205
7
- data.tar.gz: 0d9a1eed230c95df417727e8693da32e9168b8dd428a49aee3cbf6d08e73e650824c9d453878d01a7de2461e31ad4b40792c142bf3a6267b0bd3c548de3ad4c9
6
+ metadata.gz: 278138ada54ee955e1a29b58505959e772e4db8468d4835393502912e8d91ecd7766cc1347f40afcfece79892b3419ce93580a15f2a3f6ff57a177a7a42e6dcf
7
+ data.tar.gz: 6367660c3f7a614fa90357558fa93f8ced9a3a1b3a26a9486a48c05c496a96ff8a6acf661aac9990d8914220d17d835d3adf8dddf02be15a7601a0b3f3776982
data/Gemfile CHANGED
@@ -10,6 +10,4 @@ gemspec
10
10
  # Git. Remember to move these dependencies to your gemspec before releasing
11
11
  # your gem to rubygems.org.
12
12
 
13
- # To use debugger
14
- # gem 'ruby-debug19', :require => 'ruby-debug'
15
- # gem 'ruby-debug'
13
+ gem 'rails', ENV['RAILS_VERSION']
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Will Bryant, Sekuda Ltd
1
+ Copyright (c) 2010-2018 Will Bryant, Sekuda Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.0beta2) and 5.0 (up to 5.0.2) and 4.2 (up to 4.2.7), on Ruby 2.3.4.
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
- Copyright (c) 2010-2017 Will Bryant, Sekuda Ltd, released under the MIT license
85
+ Thanks
86
+ ======
87
+
88
+ * Marc Shaw (@marcshaw)
89
+
90
+ Copyright (c) 2010-2018 Will Bryant, Sekuda Ltd, released under the MIT license
@@ -33,5 +33,8 @@ EOF
33
33
 
34
34
  gem.add_dependency "activerecord"
35
35
  gem.add_development_dependency "rake"
36
+ gem.add_development_dependency "mysql2"
37
+ gem.add_development_dependency "pg"
36
38
  gem.add_development_dependency "sqlite3"
39
+ gem.add_development_dependency "byebug"
37
40
  end
@@ -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 => all.to_sql,
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 => all.to_sql,
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,
@@ -1,3 +1,3 @@
1
1
  module ConstantTableSaver
2
- VERSION = '5.1.1'
2
+ VERSION = '5.1.2'
3
3
  end
@@ -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
@@ -1,10 +1,6 @@
1
1
  sqlite3:
2
2
  adapter: sqlite3
3
3
  database: test/constant_table_saver.db
4
- mysql:
5
- adapter: mysql
6
- database: constant_table_saver_test
7
- username: root
8
4
  mysql2:
9
5
  adapter: mysql2
10
6
  database: constant_table_saver_test
data/test/test_helper.rb CHANGED
@@ -11,7 +11,7 @@ require 'active_support'
11
11
  require 'active_support/test_case'
12
12
  require 'active_record'
13
13
  require 'active_record/fixtures'
14
- require 'byebug' rescue nil
14
+ require 'byebug'
15
15
 
16
16
  RAILS_ENV = ENV['RAILS_ENV'] ||= 'sqlite3'
17
17
 
data/test_all.rb CHANGED
@@ -2,12 +2,15 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- rails_versions = ["4.2.0".."4.2.3", "4.1.07".."4.1.12", "4.0.13", "3.2.18"].flat_map {|spec| Array(spec).collect {|v| v.gsub /.0(\d)/, '.\\1'}}
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
- rails_envs.each do |env|
9
- rails_versions.each do |version|
10
- puts "*"*40
11
- system "RAILS_ENV=#{env} RAILS_VERSION=#{version} rake" or exit(1)
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.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: 2017-04-07 00:00:00.000000000 Z
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