lookup_by 0.10.9 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +17 -9
  4. data/Appraisals +4 -4
  5. data/Gemfile +3 -1
  6. data/README.md +11 -15
  7. data/Rakefile +20 -2
  8. data/circle.yml +4 -2
  9. data/gemfiles/rails_4.1.gemfile +1 -1
  10. data/gemfiles/rails_4.2.gemfile +1 -1
  11. data/gemfiles/{rails_4.0.gemfile → rails_5.0.gemfile} +2 -2
  12. data/lib/lookup_by.rb +2 -0
  13. data/lib/lookup_by/cache.rb +15 -20
  14. data/lib/lookup_by/caching/safe_lru.rb +1 -1
  15. data/lib/lookup_by/lookup.rb +26 -12
  16. data/lib/lookup_by/version.rb +1 -1
  17. data/lookup_by.gemspec +1 -1
  18. data/spec/association_spec.rb +1 -0
  19. data/spec/{dummy → internal}/app/models/account.rb +0 -0
  20. data/spec/{dummy → internal}/app/models/address.rb +0 -0
  21. data/spec/{dummy → internal}/app/models/city.rb +0 -0
  22. data/spec/{dummy → internal}/app/models/country.rb +0 -0
  23. data/spec/{dummy → internal}/app/models/email_address.rb +0 -0
  24. data/spec/{dummy → internal}/app/models/ip_address.rb +0 -0
  25. data/spec/{dummy → internal}/app/models/path.rb +0 -0
  26. data/spec/{dummy → internal}/app/models/phone_number.rb +0 -0
  27. data/spec/{dummy → internal}/app/models/postal_code.rb +0 -0
  28. data/spec/{dummy → internal}/app/models/raisin.rb +0 -0
  29. data/spec/{dummy → internal}/app/models/read_through_raisin.rb +0 -0
  30. data/spec/{dummy → internal}/app/models/state.rb +0 -0
  31. data/spec/{dummy → internal}/app/models/status.rb +0 -0
  32. data/spec/{dummy → internal}/app/models/street.rb +0 -0
  33. data/spec/{dummy → internal}/app/models/uncacheable.rb +0 -0
  34. data/spec/{dummy → internal}/app/models/unfindable.rb +0 -0
  35. data/spec/{dummy → internal}/app/models/unsynchronizable.rb +0 -0
  36. data/spec/{dummy → internal}/app/models/user_agent.rb +0 -0
  37. data/spec/internal/config/database.yml +8 -0
  38. data/spec/internal/db/schema.rb +48 -0
  39. data/spec/{dummy → internal}/lib/missing.rb +0 -0
  40. data/spec/internal/log/.gitignore +1 -0
  41. data/spec/lookup_by_spec.rb +19 -5
  42. data/spec/rails_helper.rb +5 -6
  43. data/spec/support/shared_examples_for_a_lookup.rb +28 -7
  44. metadata +50 -86
  45. data/spec/dummy/Rakefile +0 -22
  46. data/spec/dummy/app/models/.gitkeep +0 -0
  47. data/spec/dummy/bin/bundle +0 -3
  48. data/spec/dummy/bin/rails +0 -4
  49. data/spec/dummy/bin/rake +0 -4
  50. data/spec/dummy/config.ru +0 -4
  51. data/spec/dummy/config/application.rb +0 -28
  52. data/spec/dummy/config/boot.rb +0 -6
  53. data/spec/dummy/config/database.yml +0 -44
  54. data/spec/dummy/config/environment.rb +0 -5
  55. data/spec/dummy/config/environments/development.rb +0 -20
  56. data/spec/dummy/config/environments/test.rb +0 -19
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  59. data/spec/dummy/config/initializers/inflections.rb +0 -16
  60. data/spec/dummy/config/locales/en.yml +0 -23
  61. data/spec/dummy/db/migrate/20121019040009_create_tables.rb +0 -41
  62. data/spec/dummy/db/seeds.rb +0 -1
  63. data/spec/dummy/db/structure.sql +0 -1053
  64. data/spec/dummy/log/.gitkeep +0 -0
  65. data/spec/dummy/script/rails +0 -6
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: lookup_by_development
4
+
5
+ # Combustion uses the "test" config even when Rails.env.development?
6
+ test:
7
+ adapter: postgresql
8
+ database: lookup_by_<%= Rails.env %>
@@ -0,0 +1,48 @@
1
+ ActiveRecord::Schema.define do
2
+ enable_extension "plpgsql"
3
+ enable_extension "uuid-ossp"
4
+
5
+ create_lookup_tables :cities, :states, :postal_codes, :streets, :countries
6
+
7
+ create_lookup_table :user_agents
8
+ create_lookup_table :email_addresses
9
+
10
+
11
+ create_lookup_table :statuses, small: true
12
+
13
+ create_lookup_table :ip_addresses, lookup_type: :inet
14
+
15
+ create_lookup_table :phone_numbers
16
+
17
+ create_lookup_table :uncacheables
18
+ create_lookup_table :unfindables
19
+
20
+ create_lookup_table :raisins
21
+ create_lookup_table :read_through_raisins
22
+
23
+ create_lookup_table :unsynchronizables
24
+
25
+ enable_extension 'uuid-ossp'
26
+
27
+ execute 'CREATE SCHEMA traffic;'
28
+
29
+ create_lookup_table :paths, schema: 'traffic', id: :uuid
30
+
31
+ create_lookup_table :accounts do |t|
32
+ t.belongs_to :phone_number
33
+ end
34
+
35
+ create_lookup_table :addresses do |t|
36
+ t.belongs_to :city
37
+ t.belongs_to :state
38
+ t.belongs_to :postal_code
39
+ t.belongs_to :street
40
+ t.belongs_to :country
41
+ end
42
+ end
43
+
44
+ print 'Seeding db...'
45
+
46
+ State.lookup.create(name: 'AL')
47
+
48
+ puts 'done'
File without changes
@@ -0,0 +1 @@
1
+ *.log
@@ -22,6 +22,7 @@ describe LookupBy do
22
22
  describe ".clear" do
23
23
  it "clears all lookup caches" do
24
24
  Path.lookup.cache[1] = "remove-this"
25
+
25
26
  expect { LookupBy.clear }.to change { Path.lookup.cache.size }
26
27
  end
27
28
  end
@@ -75,16 +76,29 @@ describe LookupBy::Lookup::ClassMethods do
75
76
  it "accepts duplicates" do
76
77
  expect { City.seed 'Chicago', 'Chicago' }.not_to raise_error
77
78
 
78
- if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR == 0
79
- expect(City.pluck(:city)).to eq(['Chicago'])
80
- else
81
- expect(City.pluck(:name)).to eq(['Chicago'])
82
- end
79
+ expect(City.pluck(:city)).to eq(['Chicago'])
83
80
  end
84
81
  end
85
82
  end
86
83
 
87
84
  describe LookupBy::Lookup do
85
+ describe "#clear" do
86
+ it "clears the cache" do
87
+ expect(State.lookup.cache).to be_present
88
+ State.lookup.clear
89
+ expect(State.lookup.cache).to be_empty
90
+ end
91
+ end
92
+
93
+ describe "#load" do
94
+ it "populates the cache" do
95
+ State.lookup.clear
96
+ expect(State.lookup.cache).to be_empty
97
+ State.lookup.load
98
+ expect(State.lookup.cache).to be_present
99
+ end
100
+ end
101
+
88
102
  context "Uncacheable.lookup_by :column, cache: true, find_or_create: true" do
89
103
  it "fails when trying to cache and write-through" do
90
104
  expect { Uncacheable }.to raise_error(ArgumentError)
data/spec/rails_helper.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
+
4
+ require 'combustion'
5
+
6
+ Combustion.initialize! :active_record
7
+
3
8
  require 'spec_helper'
4
9
 
5
10
  if ENV["COVERAGE"]
@@ -14,12 +19,6 @@ if ENV["COVERAGE"]
14
19
  SimpleCov.start
15
20
  end
16
21
 
17
- begin
18
- require File.expand_path("../../config/environment", __FILE__)
19
- rescue LoadError
20
- require File.expand_path("../dummy/config/environment", __FILE__)
21
- end
22
-
23
22
  require 'pry'
24
23
  require 'rspec/its'
25
24
  require 'rspec/rails'
@@ -8,6 +8,25 @@ shared_examples "a lookup" do
8
8
  expect(subject.is_a_lookup?).to be true
9
9
  end
10
10
 
11
+ it "seeds a single value" do
12
+ subject.seed "Missing"
13
+
14
+ expect(subject.pluck(subject.lookup.field)).to include('Missing')
15
+ end
16
+
17
+ it "seeds multiple values" do
18
+ subject.seed "New 1", "New 2"
19
+
20
+ expect(subject.pluck(subject.lookup.field)).to include('New 1', 'New 2')
21
+ end
22
+
23
+ it "seeds without duplicates" do
24
+ subject.seed "Missing", "Missing"
25
+ subject.seed "Missing"
26
+
27
+ expect(subject.pluck(subject.lookup.field)).to include('Missing')
28
+ end
29
+
11
30
  it "raises with no args" do
12
31
  expect { subject[] }.to raise_error ArgumentError
13
32
  end
@@ -39,6 +58,14 @@ shared_examples "a lookup" do
39
58
  it "proxies create!" do
40
59
  expect { subject.lookup.create!(name: "add to cache") }.to change(subject, :count).by(1)
41
60
  end
61
+
62
+ it "doesn't break first_or_create! called on a scope" do
63
+ subject.where(subject.lookup.field => "Missing").first_or_create!
64
+
65
+ subject.lookup.reload
66
+
67
+ expect(subject.pluck(subject.lookup.field)).to include("Missing")
68
+ end
42
69
  end
43
70
 
44
71
  shared_examples "a proxy" do
@@ -108,17 +135,11 @@ shared_examples "a strict cache" do
108
135
  expect { subject.create(name: "new") }.to_not change(subject, :count)
109
136
  end
110
137
 
111
- xit "does cache .all" do
138
+ it "caches .all" do
112
139
  new = subject.create(name: 'add')
113
140
  expect(subject.all.to_a).not_to include(new)
114
141
  end
115
142
 
116
- xit "reloads .all when called with args" do
117
- new = subject.create(name: "new")
118
- expect(subject.all.to_a).not_to include(new)
119
- expect(subject.all({}).to_a).to include(new)
120
- end
121
-
122
143
  it "caches .pluck" do
123
144
  subject.create(name: "pluck this")
124
145
  expect(subject.pluck(:name)).not_to include("pluck this")
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.9
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Peterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 4.1.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: 4.0.0
26
+ version: 4.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,9 +70,9 @@ files:
70
70
  - Rakefile
71
71
  - TODO.md
72
72
  - circle.yml
73
- - gemfiles/rails_4.0.gemfile
74
73
  - gemfiles/rails_4.1.gemfile
75
74
  - gemfiles/rails_4.2.gemfile
75
+ - gemfiles/rails_5.0.gemfile
76
76
  - lib/lookup_by.rb
77
77
  - lib/lookup_by/association.rb
78
78
  - lib/lookup_by/cache.rb
@@ -90,46 +90,28 @@ files:
90
90
  - spec/association_spec.rb
91
91
  - spec/cache_spec.rb
92
92
  - spec/caching/lru_spec.rb
93
- - spec/dummy/Rakefile
94
- - spec/dummy/app/models/.gitkeep
95
- - spec/dummy/app/models/account.rb
96
- - spec/dummy/app/models/address.rb
97
- - spec/dummy/app/models/city.rb
98
- - spec/dummy/app/models/country.rb
99
- - spec/dummy/app/models/email_address.rb
100
- - spec/dummy/app/models/ip_address.rb
101
- - spec/dummy/app/models/path.rb
102
- - spec/dummy/app/models/phone_number.rb
103
- - spec/dummy/app/models/postal_code.rb
104
- - spec/dummy/app/models/raisin.rb
105
- - spec/dummy/app/models/read_through_raisin.rb
106
- - spec/dummy/app/models/state.rb
107
- - spec/dummy/app/models/status.rb
108
- - spec/dummy/app/models/street.rb
109
- - spec/dummy/app/models/uncacheable.rb
110
- - spec/dummy/app/models/unfindable.rb
111
- - spec/dummy/app/models/unsynchronizable.rb
112
- - spec/dummy/app/models/user_agent.rb
113
- - spec/dummy/bin/bundle
114
- - spec/dummy/bin/rails
115
- - spec/dummy/bin/rake
116
- - spec/dummy/config.ru
117
- - spec/dummy/config/application.rb
118
- - spec/dummy/config/boot.rb
119
- - spec/dummy/config/database.yml
120
- - spec/dummy/config/environment.rb
121
- - spec/dummy/config/environments/development.rb
122
- - spec/dummy/config/environments/test.rb
123
- - spec/dummy/config/initializers/backtrace_silencers.rb
124
- - spec/dummy/config/initializers/filter_parameter_logging.rb
125
- - spec/dummy/config/initializers/inflections.rb
126
- - spec/dummy/config/locales/en.yml
127
- - spec/dummy/db/migrate/20121019040009_create_tables.rb
128
- - spec/dummy/db/seeds.rb
129
- - spec/dummy/db/structure.sql
130
- - spec/dummy/lib/missing.rb
131
- - spec/dummy/log/.gitkeep
132
- - spec/dummy/script/rails
93
+ - spec/internal/app/models/account.rb
94
+ - spec/internal/app/models/address.rb
95
+ - spec/internal/app/models/city.rb
96
+ - spec/internal/app/models/country.rb
97
+ - spec/internal/app/models/email_address.rb
98
+ - spec/internal/app/models/ip_address.rb
99
+ - spec/internal/app/models/path.rb
100
+ - spec/internal/app/models/phone_number.rb
101
+ - spec/internal/app/models/postal_code.rb
102
+ - spec/internal/app/models/raisin.rb
103
+ - spec/internal/app/models/read_through_raisin.rb
104
+ - spec/internal/app/models/state.rb
105
+ - spec/internal/app/models/status.rb
106
+ - spec/internal/app/models/street.rb
107
+ - spec/internal/app/models/uncacheable.rb
108
+ - spec/internal/app/models/unfindable.rb
109
+ - spec/internal/app/models/unsynchronizable.rb
110
+ - spec/internal/app/models/user_agent.rb
111
+ - spec/internal/config/database.yml
112
+ - spec/internal/db/schema.rb
113
+ - spec/internal/lib/missing.rb
114
+ - spec/internal/log/.gitignore
133
115
  - spec/lookup_by_spec.rb
134
116
  - spec/rails_helper.rb
135
117
  - spec/rubinius_helper.rb
@@ -155,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
137
  version: '0'
156
138
  requirements: []
157
139
  rubyforge_project:
158
- rubygems_version: 2.5.2
140
+ rubygems_version: 2.6.10
159
141
  signing_key:
160
142
  specification_version: 4
161
143
  summary: A thread-safe lookup table cache for ActiveRecord
@@ -163,46 +145,28 @@ test_files:
163
145
  - spec/association_spec.rb
164
146
  - spec/cache_spec.rb
165
147
  - spec/caching/lru_spec.rb
166
- - spec/dummy/Rakefile
167
- - spec/dummy/app/models/.gitkeep
168
- - spec/dummy/app/models/account.rb
169
- - spec/dummy/app/models/address.rb
170
- - spec/dummy/app/models/city.rb
171
- - spec/dummy/app/models/country.rb
172
- - spec/dummy/app/models/email_address.rb
173
- - spec/dummy/app/models/ip_address.rb
174
- - spec/dummy/app/models/path.rb
175
- - spec/dummy/app/models/phone_number.rb
176
- - spec/dummy/app/models/postal_code.rb
177
- - spec/dummy/app/models/raisin.rb
178
- - spec/dummy/app/models/read_through_raisin.rb
179
- - spec/dummy/app/models/state.rb
180
- - spec/dummy/app/models/status.rb
181
- - spec/dummy/app/models/street.rb
182
- - spec/dummy/app/models/uncacheable.rb
183
- - spec/dummy/app/models/unfindable.rb
184
- - spec/dummy/app/models/unsynchronizable.rb
185
- - spec/dummy/app/models/user_agent.rb
186
- - spec/dummy/bin/bundle
187
- - spec/dummy/bin/rails
188
- - spec/dummy/bin/rake
189
- - spec/dummy/config.ru
190
- - spec/dummy/config/application.rb
191
- - spec/dummy/config/boot.rb
192
- - spec/dummy/config/database.yml
193
- - spec/dummy/config/environment.rb
194
- - spec/dummy/config/environments/development.rb
195
- - spec/dummy/config/environments/test.rb
196
- - spec/dummy/config/initializers/backtrace_silencers.rb
197
- - spec/dummy/config/initializers/filter_parameter_logging.rb
198
- - spec/dummy/config/initializers/inflections.rb
199
- - spec/dummy/config/locales/en.yml
200
- - spec/dummy/db/migrate/20121019040009_create_tables.rb
201
- - spec/dummy/db/seeds.rb
202
- - spec/dummy/db/structure.sql
203
- - spec/dummy/lib/missing.rb
204
- - spec/dummy/log/.gitkeep
205
- - spec/dummy/script/rails
148
+ - spec/internal/app/models/account.rb
149
+ - spec/internal/app/models/address.rb
150
+ - spec/internal/app/models/city.rb
151
+ - spec/internal/app/models/country.rb
152
+ - spec/internal/app/models/email_address.rb
153
+ - spec/internal/app/models/ip_address.rb
154
+ - spec/internal/app/models/path.rb
155
+ - spec/internal/app/models/phone_number.rb
156
+ - spec/internal/app/models/postal_code.rb
157
+ - spec/internal/app/models/raisin.rb
158
+ - spec/internal/app/models/read_through_raisin.rb
159
+ - spec/internal/app/models/state.rb
160
+ - spec/internal/app/models/status.rb
161
+ - spec/internal/app/models/street.rb
162
+ - spec/internal/app/models/uncacheable.rb
163
+ - spec/internal/app/models/unfindable.rb
164
+ - spec/internal/app/models/unsynchronizable.rb
165
+ - spec/internal/app/models/user_agent.rb
166
+ - spec/internal/config/database.yml
167
+ - spec/internal/db/schema.rb
168
+ - spec/internal/lib/missing.rb
169
+ - spec/internal/log/.gitignore
206
170
  - spec/lookup_by_spec.rb
207
171
  - spec/rails_helper.rb
208
172
  - spec/rubinius_helper.rb
data/spec/dummy/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
-
5
- require File.expand_path('../config/application', __FILE__)
6
-
7
- Dummy::Application.load_tasks
8
-
9
- require "rspec/core/rake_task"
10
- RSpec::Core::RakeTask.new(:spec) do |config|
11
- config.pattern = FileList["../**/*_spec.rb"]
12
- end
13
-
14
- task :default => :spec
15
-
16
- namespace :db do
17
- namespace :test do
18
- task :load_structure => :environment do
19
- Rake::Task["db:seed"].invoke
20
- end
21
- end
22
- end
File without changes
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
data/spec/dummy/bin/rails DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'