lookup_by 0.6.0 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 741a85349dfd3272380b485113086dffec0339da
4
- data.tar.gz: 4468ad178cf1b092dfe06d5d2812ab068d87edf6
3
+ metadata.gz: 03729b904ce688e312634ce27fc0378510189a06
4
+ data.tar.gz: 1da87c9243ce001671e57a92084f82a01c0ccba7
5
5
  SHA512:
6
- metadata.gz: 457ebe5fbc8ac341869c91d4fe7cf5faa03e69ffed4c98ad0a3b229c1c71b8a6f127f8ebc712618662a199a101fd96db02a389aa90e21ba8c83e3df6d99eeadf
7
- data.tar.gz: c3df0d6bf016ca2dd5ff05b5a7e67e4c478dd222ec62f3c9ffad75a94f21c4aaf0375c2bdf32d84a11a9b7eca70f73f235508b034984d68d32d32bbf63395a5f
6
+ metadata.gz: 940795913611bb0a21b97c15a79b847fbb1bf62c79447765991aa8d5d389bc763f242510c03a3cb9548b8db3fec36d877df60b71c6b3901a03d2323800da0939
7
+ data.tar.gz: e00e0708e39fe04352ea4e1f19799643e1efc9946467d3d63e86fde83225f8cff5e7ed2cef980da84b8db3450ae49a7596f28a9a7e63923be771b14c408bcd24
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
 
8
8
  group :development, :test do
9
9
  gem 'rspec'
10
+ gem 'rspec-its'
10
11
  gem 'database_cleaner'
11
12
 
12
13
  gem "pg", platform: :ruby
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -59,7 +59,9 @@ describe ::ActiveRecord::Base do
59
59
  it { should_not respond_to(:with_postal_codes) }
60
60
  end
61
61
 
62
- its(:lookups) { should include(:city) }
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
 
@@ -67,6 +67,8 @@ module LookupBy::Caching
67
67
  cache.should eq(1 => "change", 2 => "two", 3 => "three")
68
68
  end
69
69
 
70
- its(:to_h) { should eq(1 => "one", 2 => "two") }
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
@@ -0,0 +1,3 @@
1
+ class Uncacheable < ActiveRecord::Base
2
+ lookup_by :uncacheable, cache: true, find_or_create: true
3
+ end
@@ -0,0 +1,3 @@
1
+ class Unfindable < ActiveRecord::Base
2
+ lookup_by :unfindable, cache: 10, find: false
3
+ end
@@ -10,6 +10,9 @@ class CreateTables < ActiveRecord::Migration
10
10
 
11
11
  create_lookup_table :ip_addresses, lookup_type: :inet
12
12
 
13
+ create_lookup_table :uncacheables
14
+ create_lookup_table :unfindables
15
+
13
16
  enable_extension 'uuid-ossp'
14
17
 
15
18
  execute 'CREATE SCHEMA traffic;'
@@ -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
  --
@@ -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 be_false
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 be_true
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
- its(:is_a_lookup?) { should be_true }
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.6.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-05-08 00:00:00.000000000 Z
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