lookup_by 0.10.7 → 0.10.8

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: 5f66e8cfacf984285ac5c1a39050c953e59727cf
4
- data.tar.gz: 88e26f09abcb787959662658bd1cf941337dd1e0
3
+ metadata.gz: 2ceed8b515acb74ee2516b39bf8c6294f47e5482
4
+ data.tar.gz: c0802d0d24eceb21274dd5c2db4bd2d0bd4b85ff
5
5
  SHA512:
6
- metadata.gz: 9b3f2d7a4ea2d2dde3d9ef4f90b72e78003d1e0c63aa60487cff6132d7042cf467de1fdd3c56f04960c2c61a132b143c2d820c07164a43d10067d838a3f95162
7
- data.tar.gz: 63c97a2f17ac275aed7732d8419fbe626d9cb6bf884a1997336a175638c1b76d24fc4319cccb814b78db6cec6812b2cc930a289f10842488ff3c30b5ee0fe743
6
+ metadata.gz: 023e3a164cc64adb1aeb5beb15a1af2eb25a3784b85bef8287fa71cfe188566674a37f3fa3b779f76f9564786b0de2eeda075fc1ca9439d507dc0dee24e653c2
7
+ data.tar.gz: c18044e3054cf75ea5fd74565f36dd8357be044be1bfdd58ebf1289abe06dd8c38a94208b32ac54e34d8b71ab2e2c0d739553a31ab62e162f5eb9ada3e909ea5
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.2.2
1
+ ruby-2.3.0
data/.travis.yml CHANGED
@@ -2,9 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3-p551
4
4
  - 2.0.0
5
- - 2.1.6
6
- - 2.2.2
7
- - rbx-2.5.2
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
8
+ - rbx-3.19
8
9
  services:
9
10
  - postgresql
10
11
  before_script:
data/README.md CHANGED
@@ -25,8 +25,8 @@ LookupBy is a thread-safe lookup table cache for ActiveRecord that reduces norma
25
25
 
26
26
  ### Dependencies
27
27
 
28
- * Rails 4.0+, _tested on Rails 4.0, 4.1, and 4.2_
29
- * Ruby 1.9.3+, _tested on Ruby 1.9.3, 2.0, 2.1, 2.2 and Rubinius 1.5.2_
28
+ * Rails 4.0+ (_tested on Rails 4.0, 4.1, and 4.2_)
29
+ * Ruby 1.9.3+ (_tested on Ruby 1.9.3, 2.0, 2.1, 2.2, 2.3 and Rubinius 3.19_)
30
30
  * PostgreSQL
31
31
 
32
32
  ### Development
data/circle.yml ADDED
@@ -0,0 +1,9 @@
1
+ dependencies:
2
+ post:
3
+ - bundle exec appraisal install
4
+
5
+ test:
6
+ pre:
7
+ - bundle exec rake app:db:test:prepare
8
+ override:
9
+ - bundle exec appraisal rake
@@ -129,15 +129,29 @@ module LookupBy
129
129
  end
130
130
 
131
131
  def enable!
132
+ return if enabled?
133
+
132
134
  @enabled = true
133
135
  reload
134
136
  end
135
137
 
136
138
  def disable!
139
+ return if disabled?
140
+
137
141
  @enabled = false
138
142
  clear
139
143
  end
140
144
 
145
+ def while_disabled
146
+ raise ArgumentError, "no block given" unless block_given?
147
+
148
+ disable!
149
+
150
+ yield
151
+
152
+ enable!
153
+ end
154
+
141
155
  private
142
156
 
143
157
  # RAILS_ENV=test will not use the SafeLRU
@@ -158,7 +172,6 @@ module LookupBy
158
172
  @klass.new(@field => value).send(@field)
159
173
  end
160
174
 
161
-
162
175
  if Rails.env.production?
163
176
  def cache_read(value)
164
177
  if primary_key?(value)
@@ -67,6 +67,7 @@ module LookupBy
67
67
  def all(*args)
68
68
  return super if Rails::VERSION::MAJOR >= 4
69
69
  return super if @lookup.read_through?
70
+ return super if @lookup.disabled?
70
71
  return super if args.any?
71
72
 
72
73
  @lookup.cache.values
@@ -74,6 +75,7 @@ module LookupBy
74
75
 
75
76
  def count(column_name = nil, options = {})
76
77
  return super if @lookup.read_through?
78
+ return super if @lookup.disabled?
77
79
  return super if column_name
78
80
 
79
81
  @lookup.cache.size
@@ -81,6 +83,7 @@ module LookupBy
81
83
 
82
84
  def pluck(*column_names)
83
85
  return super if @lookup.read_through?
86
+ return super if @lookup.disabled?
84
87
  return super if column_names.size > 1
85
88
 
86
89
  @lookup.cache.values.map { |o| o.send(column_names.first) }
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.10.7"
2
+ VERSION = "0.10.8"
3
3
  end
@@ -0,0 +1,93 @@
1
+ require "rails_helper"
2
+ require "lookup_by"
3
+
4
+ describe LookupBy::Cache do
5
+ subject { State.lookup }
6
+
7
+ describe "#clear" do
8
+ it "clears the cache" do
9
+ expect { subject.clear }.to change(subject.cache, :size).from(1).to(0)
10
+ expect { subject.clear }.not_to change(subject.cache, :size)
11
+ end
12
+ end
13
+
14
+ describe "#reload" do
15
+ before(:each) { subject.clear }
16
+
17
+ it "loads the cache" do
18
+ expect { subject.reload }.to change(subject.cache, :size).from(0).to(1)
19
+ expect { subject.reload }.not_to change(subject.cache, :size)
20
+ end
21
+ end
22
+
23
+ describe "#disable!" do
24
+ it "disables the cache" do
25
+ subject.disable!
26
+
27
+ expect(subject).to be_disabled
28
+ end
29
+
30
+ it "clears the cache once" do
31
+ expect(subject).to receive(:clear).once
32
+
33
+ subject.disable!
34
+ subject.disable!
35
+ end
36
+ end
37
+
38
+ describe "#disabled?" do
39
+ it "toggles correctly" do
40
+ expect(subject).not_to be_disabled
41
+
42
+ subject.disable!
43
+
44
+ expect(subject).to be_disabled
45
+ end
46
+ end
47
+
48
+ describe "#enable!" do
49
+ before(:each) { subject.disable! }
50
+
51
+ it "enables the cache" do
52
+ expect(subject).not_to be_enabled
53
+
54
+ subject.enable!
55
+
56
+ expect(subject).to be_enabled
57
+ end
58
+
59
+ it "does not reload if already enabled" do
60
+ expect(subject).to receive(:reload).once
61
+
62
+ subject.enable!
63
+ subject.enable!
64
+ end
65
+ end
66
+
67
+ describe "#while_disabled" do
68
+ it "raises without a block" do
69
+ expect { subject.while_disabled }.to raise_error(ArgumentError)
70
+ end
71
+
72
+ it "disables the cache while running the block" do
73
+ expect(subject).to be_enabled
74
+
75
+ subject.while_disabled do
76
+ expect(subject).to be_disabled
77
+ expect(subject.cache.size).to eq(0)
78
+ end
79
+
80
+ expect(subject).to be_enabled
81
+ end
82
+ end
83
+
84
+ # @todo Add tests
85
+ # #initialize
86
+ # #create
87
+ # #create!
88
+ # #seed
89
+ # #fetch
90
+ # #has_cache?
91
+ # #read_through?
92
+ # #allow_blank?
93
+ end
data/spec/spec_helper.rb CHANGED
@@ -76,11 +76,11 @@ RSpec.configure do |config|
76
76
  Kernel.srand config.seed
77
77
 
78
78
  config.before(:each) do
79
- LookupBy.reload
79
+ LookupBy.enable
80
80
  end
81
81
 
82
82
  config.after(:each) do
83
- LookupBy.clear
83
+ LookupBy.disable
84
84
  end
85
85
 
86
86
  if RUBY_ENGINE == 'rbx' && ENV['PROFILE']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookup_by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.7
4
+ version: 0.10.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Peterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -69,6 +69,7 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - TODO.md
72
+ - circle.yml
72
73
  - gemfiles/rails_4.0.gemfile
73
74
  - gemfiles/rails_4.1.gemfile
74
75
  - gemfiles/rails_4.2.gemfile
@@ -87,6 +88,7 @@ files:
87
88
  - lib/lookup_by/version.rb
88
89
  - lookup_by.gemspec
89
90
  - spec/association_spec.rb
91
+ - spec/cache_spec.rb
90
92
  - spec/caching/lru_spec.rb
91
93
  - spec/dummy/Rakefile
92
94
  - spec/dummy/app/models/.gitkeep
@@ -153,12 +155,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 2.4.5.1
158
+ rubygems_version: 2.6.6
157
159
  signing_key:
158
160
  specification_version: 4
159
161
  summary: A thread-safe lookup table cache for ActiveRecord
160
162
  test_files:
161
163
  - spec/association_spec.rb
164
+ - spec/cache_spec.rb
162
165
  - spec/caching/lru_spec.rb
163
166
  - spec/dummy/Rakefile
164
167
  - spec/dummy/app/models/.gitkeep