lookup_by 0.10.6 → 0.10.7

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: 733db5812641f61aedee288b13938b411ca1fe8f
4
- data.tar.gz: 1ef219c1cf241bb0dbf342160f13f70c472f43b6
3
+ metadata.gz: 5f66e8cfacf984285ac5c1a39050c953e59727cf
4
+ data.tar.gz: 88e26f09abcb787959662658bd1cf941337dd1e0
5
5
  SHA512:
6
- metadata.gz: a1e2d836bdff533ff4563530c46c6d1532f610cdcf41c099faa9c4e209c14db99990dcb12617062745f35101520ff41639e0c6efa9b72ac8546c7aa80d5cdf0d
7
- data.tar.gz: 00be839049273eead6d1be21855d3753e865bf1afad15e207427a12f82043825548bfd15e56dbe2cc8ae00477ec9b063fe530d30f2b22ffd7da5e091f6e8b1b5
6
+ metadata.gz: 9b3f2d7a4ea2d2dde3d9ef4f90b72e78003d1e0c63aa60487cff6132d7042cf467de1fdd3c56f04960c2c61a132b143c2d820c07164a43d10067d838a3f95162
7
+ data.tar.gz: 63c97a2f17ac275aed7732d8419fbe626d9cb6bf884a1997336a175638c1b76d24fc4319cccb814b78db6cec6812b2cc930a289f10842488ff3c30b5ee0fe743
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  group :development, :test do
9
- gem 'appraisal', '~> 2.0.0', require: false
9
+ gem 'appraisal', '~> 2.1.0', require: false
10
10
 
11
11
  gem 'rspec'
12
12
  gem 'rspec-its'
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.0.0"
6
6
 
7
7
  group :development, :test do
8
- gem "appraisal", "~> 2.0.0", :require => false
8
+ gem "appraisal", "~> 2.1.0", :require => false
9
9
  gem "rspec"
10
10
  gem "rspec-its"
11
11
  gem "rspec-rails"
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.1.0"
6
6
 
7
7
  group :development, :test do
8
- gem "appraisal", "~> 2.0.0", :require => false
8
+ gem "appraisal", "~> 2.1.0", :require => false
9
9
  gem "rspec"
10
10
  gem "rspec-its"
11
11
  gem "rspec-rails"
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.2.0"
6
6
 
7
7
  group :development, :test do
8
- gem "appraisal", "~> 2.0.0", :require => false
8
+ gem "appraisal", "~> 2.1.0", :require => false
9
9
  gem "rspec"
10
10
  gem "rspec-its"
11
11
  gem "rspec-rails"
@@ -202,14 +202,14 @@ module LookupBy
202
202
  return unless object
203
203
 
204
204
  @mutex.synchronize do
205
- @reverse[object.send(@field)] = @cache[object.id] = object
205
+ @reverse[object.send(@field).to_s] = @cache[object.id] = object
206
206
  end
207
207
  end
208
208
  else
209
209
  def cache_write(object)
210
210
  return unless object
211
211
 
212
- @reverse[object.send(@field)] = @cache[object.id] = object
212
+ @reverse[object.send(@field).to_s] = @cache[object.id] = object
213
213
  end
214
214
  end
215
215
 
@@ -98,7 +98,7 @@ module LookupBy
98
98
  when Symbol then @lookup.fetch(arg.to_s)
99
99
  when IPAddr then @lookup.fetch(arg.to_s)
100
100
  when self then arg
101
- else raise TypeError, "#{name}[arg]: arg must be at least one String, Symbol, Integer, nil, or #{name}"
101
+ else raise TypeError, "#{name}[*args]: args must be at least one String, Symbol, Integer, IPAddr, nil, or #{name}"
102
102
  end
103
103
  else return args.map { |arg| self[arg] }
104
104
  end
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.10.6"
2
+ VERSION = "0.10.7"
3
3
  end
@@ -56,7 +56,7 @@ describe LookupBy::Caching::LRU do
56
56
  describe "#fetch" do
57
57
  specify { expect(cache.fetch(1)).to eq "one" }
58
58
  specify { expect(cache.fetch(3) { |key| key }).to eq 3 }
59
- specify { expect { cache.fetch(3) }.to raise_error }
59
+ specify { expect { cache.fetch(3) }.to raise_error(KeyError) }
60
60
 
61
61
  it "writes missing values" do
62
62
  expect(cache.fetch(3) { "missing" }).to eq "missing"
@@ -71,7 +71,7 @@ describe LookupBy::Caching::LRU do
71
71
  end
72
72
 
73
73
  describe "#max_size=" do
74
- specify { expect { cache.max_size = -1 }.to raise_error }
74
+ specify { expect { cache.max_size = -1 }.to raise_error(ArgumentError) }
75
75
  end
76
76
 
77
77
  describe "#size" do
@@ -87,7 +87,7 @@ end
87
87
  describe LookupBy::Lookup do
88
88
  context "Uncacheable.lookup_by :column, cache: true, find_or_create: true" do
89
89
  it "fails when trying to cache and write-through" do
90
- expect { Uncacheable }.to raise_error
90
+ expect { Uncacheable }.to raise_error(ArgumentError)
91
91
  end
92
92
  end
93
93
 
@@ -209,12 +209,30 @@ describe LookupBy::Lookup do
209
209
  context "IpAddress.lookup_by :column, cache: N, find_or_create: true" do
210
210
  subject { IpAddress }
211
211
 
212
- it "allows lookup by IPAddr" do
213
- ip = subject['127.0.0.1']
212
+ let(:value) { '127.0.0.1' }
213
+ let(:ip) { subject[value] }
214
214
 
215
- expect(subject[IPAddr.new('127.0.0.1')]).to eq(ip)
215
+ it "allows lookup by IPAddr" do
216
+ expect(subject[IPAddr.new(value)]).to eq(ip)
217
+ expect(subject[ip]).to eq(ip)
216
218
  expect(subject[ip.id]).to eq(ip)
217
- expect(subject['127.0.0.1']).to eq(ip)
219
+ expect(subject[value]).to eq(ip)
220
+ end
221
+
222
+ it 'caches values' do
223
+ subject.lookup.testing = false
224
+
225
+ subject[value]
226
+
227
+ id1 = subject[IPAddr.new(value)].object_id
228
+ id2 = subject[ip.id].object_id
229
+ id3 = subject[value].object_id
230
+ id4 = subject[ip].object_id
231
+
232
+ expect([id1, id2, id3, id4].uniq.size).to eq(1)
233
+
234
+ subject.lookup.testing = true
235
+ subject.lookup.clear
218
236
  end
219
237
  end
220
238
 
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.6
4
+ version: 0.10.7
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-12 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.4.8
156
+ rubygems_version: 2.4.5.1
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: A thread-safe lookup table cache for ActiveRecord