lookup_by 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -0
- data/Rakefile +0 -1
- data/lib/lookup_by.rb +3 -0
- data/lib/lookup_by/association.rb +9 -4
- data/lib/lookup_by/cache.rb +30 -15
- data/lib/lookup_by/lookup.rb +42 -13
- data/lib/lookup_by/version.rb +1 -1
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/models/account.rb +0 -2
- data/spec/dummy/app/models/city.rb +0 -2
- data/spec/dummy/app/models/email_address.rb +0 -2
- data/spec/dummy/app/models/ip_address.rb +0 -2
- data/spec/dummy/app/models/path.rb +5 -0
- data/spec/dummy/app/models/postal_code.rb +0 -2
- data/spec/dummy/app/models/state.rb +0 -2
- data/spec/dummy/app/models/status.rb +0 -2
- data/spec/dummy/app/models/street.rb +0 -2
- data/spec/dummy/app/models/user_agent.rb +3 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +18 -10
- data/spec/dummy/config/boot.rb +4 -8
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/development.rb +19 -5
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +25 -5
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/migrate/20121019040009_create_tables.rb +9 -6
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/dummy/db/structure.sql +616 -0
- data/spec/lookup_by_spec.rb +29 -2
- data/spec/spec_helper.rb +14 -1
- data/spec/support/shared_examples_for_a_lookup.rb +10 -8
- metadata +35 -3
- data/spec/dummy/db/schema.rb +0 -71
data/spec/lookup_by_spec.rb
CHANGED
@@ -85,8 +85,8 @@ describe LookupBy::Lookup do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
context "
|
89
|
-
subject {
|
88
|
+
context "UserAgent.lookup_by :column, cache: N, find_or_create: true" do
|
89
|
+
subject { UserAgent }
|
90
90
|
|
91
91
|
it_behaves_like "a lookup"
|
92
92
|
it_behaves_like "a cache"
|
@@ -97,4 +97,31 @@ describe LookupBy::Lookup do
|
|
97
97
|
subject.lookup.testing.should be_true
|
98
98
|
end
|
99
99
|
end
|
100
|
+
|
101
|
+
context "IpAddress.lookup_by :column, cache: N, find_or_create: true" do
|
102
|
+
subject { IpAddress }
|
103
|
+
|
104
|
+
it "allows lookup by IPAddr" do
|
105
|
+
ip = subject['127.0.0.1']
|
106
|
+
|
107
|
+
subject[IPAddr.new('127.0.0.1')].should == ip
|
108
|
+
subject[ip.id].should == ip
|
109
|
+
subject['127.0.0.1'].should == ip
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "Path.lookup_by :column, cache: true, find_or_create: true (UUID primary key)" do
|
114
|
+
subject { Path }
|
115
|
+
|
116
|
+
it_behaves_like "a lookup"
|
117
|
+
it_behaves_like "a cache"
|
118
|
+
it_behaves_like "a read-through cache"
|
119
|
+
it_behaves_like "a write-through cache"
|
120
|
+
|
121
|
+
it 'treats UUIDs as the primary key' do
|
122
|
+
path = subject['/']
|
123
|
+
path.id.should match(LookupBy::UUID_REGEX)
|
124
|
+
subject[path.id].should == path
|
125
|
+
end
|
126
|
+
end
|
100
127
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,7 @@ rescue LoadError
|
|
14
14
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
15
15
|
end
|
16
16
|
|
17
|
+
require 'database_cleaner'
|
17
18
|
require 'rspec/rails'
|
18
19
|
require 'rspec/autorun'
|
19
20
|
|
@@ -33,11 +34,23 @@ RSpec.configure do |config|
|
|
33
34
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
34
35
|
# examples within a transaction, remove the following line or assign false
|
35
36
|
# instead of true.
|
36
|
-
config.use_transactional_fixtures =
|
37
|
+
config.use_transactional_fixtures = false
|
37
38
|
|
38
39
|
# Run specs in random order to surface order dependencies. If you find an
|
39
40
|
# order dependency and want to debug it, you can fix the order by providing
|
40
41
|
# the seed, which is printed after each run.
|
41
42
|
# --seed 1234
|
42
43
|
config.order = "random"
|
44
|
+
|
45
|
+
config.before(:suite) do
|
46
|
+
DatabaseCleaner.strategy = :transaction
|
47
|
+
end
|
48
|
+
|
49
|
+
config.before(:each) do
|
50
|
+
DatabaseCleaner.start
|
51
|
+
end
|
52
|
+
|
53
|
+
config.after(:each) do
|
54
|
+
DatabaseCleaner.clean
|
55
|
+
end
|
43
56
|
end
|
@@ -51,7 +51,7 @@ shared_examples "a proxy" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "allows .destroy_all" do
|
54
|
-
subject.destroy_all.
|
54
|
+
expect { subject.destroy_all }.to_not raise_error
|
55
55
|
end
|
56
56
|
|
57
57
|
it "allows .destroy" do
|
@@ -60,7 +60,7 @@ shared_examples "a proxy" do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "allows .delete_all" do
|
63
|
-
subject.delete_all.
|
63
|
+
expect { subject.delete_all }.to_not raise_error
|
64
64
|
end
|
65
65
|
|
66
66
|
it "allows .delete" do
|
@@ -106,14 +106,15 @@ shared_examples "a strict cache" do
|
|
106
106
|
expect { subject.create(name: "new") }.to_not change(subject, :count)
|
107
107
|
end
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
xit "does cache .all" do
|
110
|
+
new = subject.create(name: 'add')
|
111
|
+
subject.all.to_a.should_not include(new)
|
111
112
|
end
|
112
113
|
|
113
|
-
|
114
|
+
xit "reloads .all when called with args" do
|
114
115
|
new = subject.create(name: "new")
|
115
|
-
subject.all.should_not include(new)
|
116
|
-
subject.all({}).should include(new)
|
116
|
+
subject.all.to_a.should_not include(new)
|
117
|
+
subject.all({}).to_a.should include(new)
|
117
118
|
end
|
118
119
|
|
119
120
|
it "caches .pluck" do
|
@@ -138,7 +139,8 @@ shared_examples "a read-through proxy" do
|
|
138
139
|
end
|
139
140
|
|
140
141
|
it "reloads .all" do
|
141
|
-
|
142
|
+
new = subject.create(name: 'add')
|
143
|
+
subject.all.to_a.should include (new)
|
142
144
|
end
|
143
145
|
|
144
146
|
it "reloads .pluck" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lookup_by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Peterson
|
@@ -63,19 +63,35 @@ files:
|
|
63
63
|
- spec/dummy/app/models/city.rb
|
64
64
|
- spec/dummy/app/models/email_address.rb
|
65
65
|
- spec/dummy/app/models/ip_address.rb
|
66
|
+
- spec/dummy/app/models/path.rb
|
66
67
|
- spec/dummy/app/models/postal_code.rb
|
67
68
|
- spec/dummy/app/models/state.rb
|
68
69
|
- spec/dummy/app/models/status.rb
|
69
70
|
- spec/dummy/app/models/street.rb
|
71
|
+
- spec/dummy/app/models/user_agent.rb
|
72
|
+
- spec/dummy/bin/bundle
|
73
|
+
- spec/dummy/bin/rails
|
74
|
+
- spec/dummy/bin/rake
|
70
75
|
- spec/dummy/config.ru
|
71
76
|
- spec/dummy/config/application.rb
|
72
77
|
- spec/dummy/config/boot.rb
|
73
78
|
- spec/dummy/config/database.yml
|
74
79
|
- spec/dummy/config/environment.rb
|
75
80
|
- spec/dummy/config/environments/development.rb
|
81
|
+
- spec/dummy/config/environments/production.rb
|
76
82
|
- spec/dummy/config/environments/test.rb
|
83
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
84
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
85
|
+
- spec/dummy/config/initializers/inflections.rb
|
86
|
+
- spec/dummy/config/initializers/mime_types.rb
|
87
|
+
- spec/dummy/config/initializers/secret_token.rb
|
88
|
+
- spec/dummy/config/initializers/session_store.rb
|
89
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
90
|
+
- spec/dummy/config/locales/en.yml
|
91
|
+
- spec/dummy/config/routes.rb
|
77
92
|
- spec/dummy/db/migrate/20121019040009_create_tables.rb
|
78
|
-
- spec/dummy/db/
|
93
|
+
- spec/dummy/db/seeds.rb
|
94
|
+
- spec/dummy/db/structure.sql
|
79
95
|
- spec/dummy/lib/missing.rb
|
80
96
|
- spec/dummy/log/.gitkeep
|
81
97
|
- spec/dummy/script/rails
|
@@ -116,19 +132,35 @@ test_files:
|
|
116
132
|
- spec/dummy/app/models/city.rb
|
117
133
|
- spec/dummy/app/models/email_address.rb
|
118
134
|
- spec/dummy/app/models/ip_address.rb
|
135
|
+
- spec/dummy/app/models/path.rb
|
119
136
|
- spec/dummy/app/models/postal_code.rb
|
120
137
|
- spec/dummy/app/models/state.rb
|
121
138
|
- spec/dummy/app/models/status.rb
|
122
139
|
- spec/dummy/app/models/street.rb
|
140
|
+
- spec/dummy/app/models/user_agent.rb
|
141
|
+
- spec/dummy/bin/bundle
|
142
|
+
- spec/dummy/bin/rails
|
143
|
+
- spec/dummy/bin/rake
|
123
144
|
- spec/dummy/config.ru
|
124
145
|
- spec/dummy/config/application.rb
|
125
146
|
- spec/dummy/config/boot.rb
|
126
147
|
- spec/dummy/config/database.yml
|
127
148
|
- spec/dummy/config/environment.rb
|
128
149
|
- spec/dummy/config/environments/development.rb
|
150
|
+
- spec/dummy/config/environments/production.rb
|
129
151
|
- spec/dummy/config/environments/test.rb
|
152
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
153
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
154
|
+
- spec/dummy/config/initializers/inflections.rb
|
155
|
+
- spec/dummy/config/initializers/mime_types.rb
|
156
|
+
- spec/dummy/config/initializers/secret_token.rb
|
157
|
+
- spec/dummy/config/initializers/session_store.rb
|
158
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
159
|
+
- spec/dummy/config/locales/en.yml
|
160
|
+
- spec/dummy/config/routes.rb
|
130
161
|
- spec/dummy/db/migrate/20121019040009_create_tables.rb
|
131
|
-
- spec/dummy/db/
|
162
|
+
- spec/dummy/db/seeds.rb
|
163
|
+
- spec/dummy/db/structure.sql
|
132
164
|
- spec/dummy/lib/missing.rb
|
133
165
|
- spec/dummy/log/.gitkeep
|
134
166
|
- spec/dummy/script/rails
|
data/spec/dummy/db/schema.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended to check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(:version => 20121019040009) do
|
15
|
-
|
16
|
-
create_table "accounts", :primary_key => "account_id", :force => true do |t|
|
17
|
-
t.text "account", :null => false
|
18
|
-
end
|
19
|
-
|
20
|
-
add_index "accounts", ["account"], :name => "index_accounts_on_account", :unique => true
|
21
|
-
|
22
|
-
create_table "addresses", :primary_key => "address_id", :force => true do |t|
|
23
|
-
t.integer "city_id"
|
24
|
-
t.integer "state_id"
|
25
|
-
t.integer "postal_code_id"
|
26
|
-
t.integer "street_id"
|
27
|
-
end
|
28
|
-
|
29
|
-
create_table "cities", :primary_key => "city_id", :force => true do |t|
|
30
|
-
t.text "city", :null => false
|
31
|
-
end
|
32
|
-
|
33
|
-
add_index "cities", ["city"], :name => "index_cities_on_city", :unique => true
|
34
|
-
|
35
|
-
create_table "email_addresses", :primary_key => "email_address_id", :force => true do |t|
|
36
|
-
t.text "email_address", :null => false
|
37
|
-
end
|
38
|
-
|
39
|
-
add_index "email_addresses", ["email_address"], :name => "index_email_addresses_on_email_address", :unique => true
|
40
|
-
|
41
|
-
create_table "ip_addresses", :primary_key => "ip_address_id", :force => true do |t|
|
42
|
-
t.text "ip_address", :null => false
|
43
|
-
end
|
44
|
-
|
45
|
-
add_index "ip_addresses", ["ip_address"], :name => "index_ip_addresses_on_ip_address", :unique => true
|
46
|
-
|
47
|
-
create_table "postal_codes", :primary_key => "postal_code_id", :force => true do |t|
|
48
|
-
t.text "postal_code", :null => false
|
49
|
-
end
|
50
|
-
|
51
|
-
add_index "postal_codes", ["postal_code"], :name => "index_postal_codes_on_postal_code", :unique => true
|
52
|
-
|
53
|
-
create_table "states", :primary_key => "state_id", :force => true do |t|
|
54
|
-
t.text "state", :null => false
|
55
|
-
end
|
56
|
-
|
57
|
-
add_index "states", ["state"], :name => "index_states_on_state", :unique => true
|
58
|
-
|
59
|
-
create_table "statuses", :primary_key => "status_id", :force => true do |t|
|
60
|
-
t.text "status", :null => false
|
61
|
-
end
|
62
|
-
|
63
|
-
add_index "statuses", ["status"], :name => "index_statuses_on_status", :unique => true
|
64
|
-
|
65
|
-
create_table "streets", :primary_key => "street_id", :force => true do |t|
|
66
|
-
t.text "street", :null => false
|
67
|
-
end
|
68
|
-
|
69
|
-
add_index "streets", ["street"], :name => "index_streets_on_street", :unique => true
|
70
|
-
|
71
|
-
end
|