lookup_by 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/lookup_by/cache.rb +2 -0
- data/lib/lookup_by/version.rb +1 -1
- data/spec/association_spec.rb +3 -1
- data/spec/caching/lru_spec.rb +3 -1
- data/spec/dummy/app/models/uncacheable.rb +3 -0
- data/spec/dummy/app/models/unfindable.rb +3 -0
- data/spec/dummy/db/migrate/20121019040009_create_tables.rb +3 -0
- data/spec/dummy/db/structure.sql +102 -0
- data/spec/lookup_by_spec.rb +8 -2
- data/spec/spec_helper.rb +4 -0
- data/spec/support/shared_examples_for_a_lookup.rb +3 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03729b904ce688e312634ce27fc0378510189a06
|
4
|
+
data.tar.gz: 1da87c9243ce001671e57a92084f82a01c0ccba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 940795913611bb0a21b97c15a79b847fbb1bf62c79447765991aa8d5d389bc763f242510c03a3cb9548b8db3fec36d877df60b71c6b3901a03d2323800da0939
|
7
|
+
data.tar.gz: e00e0708e39fe04352ea4e1f19799643e1efc9946467d3d63e86fde83225f8cff5e7ed2cef980da84b8db3450ae49a7596f28a9a7e63923be771b14c408bcd24
|
data/Gemfile
CHANGED
data/lib/lookup_by/cache.rb
CHANGED
@@ -25,6 +25,8 @@ module LookupBy
|
|
25
25
|
when true
|
26
26
|
@type = :all
|
27
27
|
@read ||= false
|
28
|
+
|
29
|
+
raise ArgumentError, "`#{@klass}.lookup_by :#{@field}` Should be `cache: true` or `cache: N, find_or_create: true`" if @write
|
28
30
|
when ::Integer
|
29
31
|
raise ArgumentError, "`#{@klass}.lookup_by :#{@field}` options[:find] must be true when caching N" if @read == false
|
30
32
|
|
data/lib/lookup_by/version.rb
CHANGED
data/spec/association_spec.rb
CHANGED
@@ -59,7 +59,9 @@ describe ::ActiveRecord::Base do
|
|
59
59
|
it { should_not respond_to(:with_postal_codes) }
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
it "better include the association under test in lookups" do
|
63
|
+
expect(subject.lookups).to include(:city)
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
data/spec/caching/lru_spec.rb
CHANGED
@@ -67,6 +67,8 @@ module LookupBy::Caching
|
|
67
67
|
cache.should eq(1 => "change", 2 => "two", 3 => "three")
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "better include the values under test" do
|
71
|
+
expect(subject.to_h).to eq(1 => "one", 2 => "two")
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|
data/spec/dummy/db/structure.sql
CHANGED
@@ -353,6 +353,64 @@ CREATE SEQUENCE streets_street_id_seq
|
|
353
353
|
ALTER SEQUENCE streets_street_id_seq OWNED BY streets.street_id;
|
354
354
|
|
355
355
|
|
356
|
+
--
|
357
|
+
-- Name: uncacheables; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
358
|
+
--
|
359
|
+
|
360
|
+
CREATE TABLE uncacheables (
|
361
|
+
uncacheable_id integer NOT NULL,
|
362
|
+
uncacheable text NOT NULL
|
363
|
+
);
|
364
|
+
|
365
|
+
|
366
|
+
--
|
367
|
+
-- Name: uncacheables_uncacheable_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
368
|
+
--
|
369
|
+
|
370
|
+
CREATE SEQUENCE uncacheables_uncacheable_id_seq
|
371
|
+
START WITH 1
|
372
|
+
INCREMENT BY 1
|
373
|
+
NO MINVALUE
|
374
|
+
NO MAXVALUE
|
375
|
+
CACHE 1;
|
376
|
+
|
377
|
+
|
378
|
+
--
|
379
|
+
-- Name: uncacheables_uncacheable_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
380
|
+
--
|
381
|
+
|
382
|
+
ALTER SEQUENCE uncacheables_uncacheable_id_seq OWNED BY uncacheables.uncacheable_id;
|
383
|
+
|
384
|
+
|
385
|
+
--
|
386
|
+
-- Name: unfindables; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
387
|
+
--
|
388
|
+
|
389
|
+
CREATE TABLE unfindables (
|
390
|
+
unfindable_id integer NOT NULL,
|
391
|
+
unfindable text NOT NULL
|
392
|
+
);
|
393
|
+
|
394
|
+
|
395
|
+
--
|
396
|
+
-- Name: unfindables_unfindable_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
397
|
+
--
|
398
|
+
|
399
|
+
CREATE SEQUENCE unfindables_unfindable_id_seq
|
400
|
+
START WITH 1
|
401
|
+
INCREMENT BY 1
|
402
|
+
NO MINVALUE
|
403
|
+
NO MAXVALUE
|
404
|
+
CACHE 1;
|
405
|
+
|
406
|
+
|
407
|
+
--
|
408
|
+
-- Name: unfindables_unfindable_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
409
|
+
--
|
410
|
+
|
411
|
+
ALTER SEQUENCE unfindables_unfindable_id_seq OWNED BY unfindables.unfindable_id;
|
412
|
+
|
413
|
+
|
356
414
|
--
|
357
415
|
-- Name: user_agents; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
358
416
|
--
|
@@ -466,6 +524,20 @@ ALTER TABLE ONLY statuses ALTER COLUMN status_id SET DEFAULT nextval('statuses_s
|
|
466
524
|
ALTER TABLE ONLY streets ALTER COLUMN street_id SET DEFAULT nextval('streets_street_id_seq'::regclass);
|
467
525
|
|
468
526
|
|
527
|
+
--
|
528
|
+
-- Name: uncacheable_id; Type: DEFAULT; Schema: public; Owner: -
|
529
|
+
--
|
530
|
+
|
531
|
+
ALTER TABLE ONLY uncacheables ALTER COLUMN uncacheable_id SET DEFAULT nextval('uncacheables_uncacheable_id_seq'::regclass);
|
532
|
+
|
533
|
+
|
534
|
+
--
|
535
|
+
-- Name: unfindable_id; Type: DEFAULT; Schema: public; Owner: -
|
536
|
+
--
|
537
|
+
|
538
|
+
ALTER TABLE ONLY unfindables ALTER COLUMN unfindable_id SET DEFAULT nextval('unfindables_unfindable_id_seq'::regclass);
|
539
|
+
|
540
|
+
|
469
541
|
--
|
470
542
|
-- Name: user_agent_id; Type: DEFAULT; Schema: public; Owner: -
|
471
543
|
--
|
@@ -553,6 +625,22 @@ ALTER TABLE ONLY streets
|
|
553
625
|
ADD CONSTRAINT streets_pkey PRIMARY KEY (street_id);
|
554
626
|
|
555
627
|
|
628
|
+
--
|
629
|
+
-- Name: uncacheables_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
630
|
+
--
|
631
|
+
|
632
|
+
ALTER TABLE ONLY uncacheables
|
633
|
+
ADD CONSTRAINT uncacheables_pkey PRIMARY KEY (uncacheable_id);
|
634
|
+
|
635
|
+
|
636
|
+
--
|
637
|
+
-- Name: unfindables_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
638
|
+
--
|
639
|
+
|
640
|
+
ALTER TABLE ONLY unfindables
|
641
|
+
ADD CONSTRAINT unfindables_pkey PRIMARY KEY (unfindable_id);
|
642
|
+
|
643
|
+
|
556
644
|
--
|
557
645
|
-- Name: user_agents_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
558
646
|
--
|
@@ -636,6 +724,20 @@ CREATE UNIQUE INDEX statuses__u_status ON statuses USING btree (status);
|
|
636
724
|
CREATE UNIQUE INDEX streets__u_street ON streets USING btree (street);
|
637
725
|
|
638
726
|
|
727
|
+
--
|
728
|
+
-- Name: uncacheables__u_uncacheable; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
729
|
+
--
|
730
|
+
|
731
|
+
CREATE UNIQUE INDEX uncacheables__u_uncacheable ON uncacheables USING btree (uncacheable);
|
732
|
+
|
733
|
+
|
734
|
+
--
|
735
|
+
-- Name: unfindables__u_unfindable; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
736
|
+
--
|
737
|
+
|
738
|
+
CREATE UNIQUE INDEX unfindables__u_unfindable ON unfindables USING btree (unfindable);
|
739
|
+
|
740
|
+
|
639
741
|
--
|
640
742
|
-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
641
743
|
--
|
data/spec/lookup_by_spec.rb
CHANGED
@@ -29,6 +29,12 @@ describe LookupBy::Lookup do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
context "Uncacheable.lookup_by :column, cache: true, find_or_create: true" do
|
33
|
+
it "fails when trying to cache and write-through" do
|
34
|
+
expect { Uncacheable }.to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
32
38
|
context "City.lookup_by :column" do
|
33
39
|
subject { City }
|
34
40
|
|
@@ -96,7 +102,7 @@ describe LookupBy::Lookup do
|
|
96
102
|
it_behaves_like "a read-through cache"
|
97
103
|
|
98
104
|
it "is not testing when not writing through the LRU" do
|
99
|
-
subject.lookup.testing.should
|
105
|
+
subject.lookup.testing.should be false
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
@@ -109,7 +115,7 @@ describe LookupBy::Lookup do
|
|
109
115
|
it_behaves_like "a write-through cache"
|
110
116
|
|
111
117
|
it "sets testing when RAILS_ENV=test" do
|
112
|
-
subject.lookup.testing.should
|
118
|
+
subject.lookup.testing.should be true
|
113
119
|
end
|
114
120
|
|
115
121
|
it "does not write primary keys" do
|
data/spec/spec_helper.rb
CHANGED
@@ -20,7 +20,11 @@ rescue LoadError
|
|
20
20
|
end
|
21
21
|
|
22
22
|
require 'rspec'
|
23
|
+
require 'rspec/its'
|
23
24
|
require 'database_cleaner'
|
25
|
+
require 'pry'
|
26
|
+
|
27
|
+
ActiveRecord::Migration.maintain_test_schema! if defined?(ActiveRecord::Migration)
|
24
28
|
|
25
29
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
26
30
|
# in spec/support/ and its subdirectories.
|
@@ -4,7 +4,9 @@ shared_examples "a lookup" do
|
|
4
4
|
it { should respond_to :lookup_by }
|
5
5
|
it { should respond_to :lookup_for }
|
6
6
|
|
7
|
-
|
7
|
+
it "better be a lookup" do
|
8
|
+
expect(subject.is_a_lookup?).to be true
|
9
|
+
end
|
8
10
|
|
9
11
|
it "raises with no args" do
|
10
12
|
expect { subject[] }.to raise_error ArgumentError
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Peterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -95,6 +95,8 @@ files:
|
|
95
95
|
- spec/dummy/app/models/state.rb
|
96
96
|
- spec/dummy/app/models/status.rb
|
97
97
|
- spec/dummy/app/models/street.rb
|
98
|
+
- spec/dummy/app/models/uncacheable.rb
|
99
|
+
- spec/dummy/app/models/unfindable.rb
|
98
100
|
- spec/dummy/app/models/user_agent.rb
|
99
101
|
- spec/dummy/bin/bundle
|
100
102
|
- spec/dummy/bin/rails
|
@@ -160,6 +162,8 @@ test_files:
|
|
160
162
|
- spec/dummy/app/models/state.rb
|
161
163
|
- spec/dummy/app/models/status.rb
|
162
164
|
- spec/dummy/app/models/street.rb
|
165
|
+
- spec/dummy/app/models/uncacheable.rb
|
166
|
+
- spec/dummy/app/models/unfindable.rb
|
163
167
|
- spec/dummy/app/models/user_agent.rb
|
164
168
|
- spec/dummy/bin/bundle
|
165
169
|
- spec/dummy/bin/rails
|