lookup_by 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/lib/lookup_by/association.rb +4 -1
- data/lib/lookup_by/version.rb +1 -1
- data/spec/association_spec.rb +4 -0
- data/spec/dummy/app/models/country.rb +2 -0
- data/spec/dummy/db/migrate/20121019040009_create_tables.rb +2 -1
- data/spec/dummy/db/structure.sql +53 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 741a85349dfd3272380b485113086dffec0339da
|
4
|
+
data.tar.gz: 4468ad178cf1b092dfe06d5d2812ab068d87edf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 457ebe5fbc8ac341869c91d4fe7cf5faa03e69ffed4c98ad0a3b229c1c71b8a6f127f8ebc712618662a199a101fd96db02a389aa90e21ba8c83e3df6d99eeadf
|
7
|
+
data.tar.gz: c3df0d6bf016ca2dd5ff05b5a7e67e4c478dd222ec62f3c9ffad75a94f21c4aaf0375c2bdf32d84a11a9b7eca70f73f235508b034984d68d32d32bbf63395a5f
|
data/.travis.yml
CHANGED
@@ -65,7 +65,10 @@ module LookupBy
|
|
65
65
|
|
66
66
|
cast = options[:symbolize] ? ".to_sym" : ""
|
67
67
|
|
68
|
-
|
68
|
+
klass = class_name.constantize
|
69
|
+
raise Error, "class #{class_name} does not use lookup_by" unless klass.respond_to?(:lookup)
|
70
|
+
|
71
|
+
lookup_field = klass.lookup.field
|
69
72
|
lookup_object = "#{class_name}[#{foreign_key}]"
|
70
73
|
|
71
74
|
class_eval <<-METHODS, __FILE__, __LINE__.next
|
data/lib/lookup_by/version.rb
CHANGED
data/spec/association_spec.rb
CHANGED
@@ -45,6 +45,10 @@ describe ::ActiveRecord::Base do
|
|
45
45
|
expect { subject.new.city = City.new(name: "Toronto") }.to raise_error ArgumentError, /must be saved/
|
46
46
|
end
|
47
47
|
|
48
|
+
it "requires the lookup model to be using lookup_by" do
|
49
|
+
expect { subject.lookup_for :country }.to raise_error LookupBy::Error, /Country does not use lookup_by/
|
50
|
+
end
|
51
|
+
|
48
52
|
context "scope: nil" do
|
49
53
|
it { should respond_to(:with_city).with(1).arguments }
|
50
54
|
it { should respond_to(:with_cities).with(2).arguments }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class CreateTables < ActiveRecord::Migration
|
2
2
|
def up
|
3
|
-
create_lookup_tables :cities, :states, :postal_codes, :streets
|
3
|
+
create_lookup_tables :cities, :states, :postal_codes, :streets, :countries
|
4
4
|
|
5
5
|
create_lookup_table :user_agents
|
6
6
|
create_lookup_table :email_addresses
|
@@ -21,6 +21,7 @@ class CreateTables < ActiveRecord::Migration
|
|
21
21
|
t.belongs_to :state
|
22
22
|
t.belongs_to :postal_code
|
23
23
|
t.belongs_to :street
|
24
|
+
t.belongs_to :country
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/spec/dummy/db/structure.sql
CHANGED
@@ -88,7 +88,8 @@ CREATE TABLE addresses (
|
|
88
88
|
city_id integer,
|
89
89
|
state_id integer,
|
90
90
|
postal_code_id integer,
|
91
|
-
street_id integer
|
91
|
+
street_id integer,
|
92
|
+
country_id integer
|
92
93
|
);
|
93
94
|
|
94
95
|
|
@@ -140,6 +141,35 @@ CREATE SEQUENCE cities_city_id_seq
|
|
140
141
|
ALTER SEQUENCE cities_city_id_seq OWNED BY cities.city_id;
|
141
142
|
|
142
143
|
|
144
|
+
--
|
145
|
+
-- Name: countries; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
146
|
+
--
|
147
|
+
|
148
|
+
CREATE TABLE countries (
|
149
|
+
country_id integer NOT NULL,
|
150
|
+
country text NOT NULL
|
151
|
+
);
|
152
|
+
|
153
|
+
|
154
|
+
--
|
155
|
+
-- Name: countries_country_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
156
|
+
--
|
157
|
+
|
158
|
+
CREATE SEQUENCE countries_country_id_seq
|
159
|
+
START WITH 1
|
160
|
+
INCREMENT BY 1
|
161
|
+
NO MINVALUE
|
162
|
+
NO MAXVALUE
|
163
|
+
CACHE 1;
|
164
|
+
|
165
|
+
|
166
|
+
--
|
167
|
+
-- Name: countries_country_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
168
|
+
--
|
169
|
+
|
170
|
+
ALTER SEQUENCE countries_country_id_seq OWNED BY countries.country_id;
|
171
|
+
|
172
|
+
|
143
173
|
--
|
144
174
|
-- Name: email_addresses; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
145
175
|
--
|
@@ -387,6 +417,13 @@ ALTER TABLE ONLY addresses ALTER COLUMN address_id SET DEFAULT nextval('addresse
|
|
387
417
|
ALTER TABLE ONLY cities ALTER COLUMN city_id SET DEFAULT nextval('cities_city_id_seq'::regclass);
|
388
418
|
|
389
419
|
|
420
|
+
--
|
421
|
+
-- Name: country_id; Type: DEFAULT; Schema: public; Owner: -
|
422
|
+
--
|
423
|
+
|
424
|
+
ALTER TABLE ONLY countries ALTER COLUMN country_id SET DEFAULT nextval('countries_country_id_seq'::regclass);
|
425
|
+
|
426
|
+
|
390
427
|
--
|
391
428
|
-- Name: email_address_id; Type: DEFAULT; Schema: public; Owner: -
|
392
429
|
--
|
@@ -460,6 +497,14 @@ ALTER TABLE ONLY cities
|
|
460
497
|
ADD CONSTRAINT cities_pkey PRIMARY KEY (city_id);
|
461
498
|
|
462
499
|
|
500
|
+
--
|
501
|
+
-- Name: countries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
502
|
+
--
|
503
|
+
|
504
|
+
ALTER TABLE ONLY countries
|
505
|
+
ADD CONSTRAINT countries_pkey PRIMARY KEY (country_id);
|
506
|
+
|
507
|
+
|
463
508
|
--
|
464
509
|
-- Name: email_addresses_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
465
510
|
--
|
@@ -542,6 +587,13 @@ CREATE UNIQUE INDEX accounts__u_account ON accounts USING btree (account);
|
|
542
587
|
CREATE UNIQUE INDEX cities__u_city ON cities USING btree (city);
|
543
588
|
|
544
589
|
|
590
|
+
--
|
591
|
+
-- Name: countries__u_country; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
592
|
+
--
|
593
|
+
|
594
|
+
CREATE UNIQUE INDEX countries__u_country ON countries USING btree (country);
|
595
|
+
|
596
|
+
|
545
597
|
--
|
546
598
|
-- Name: email_addresses__u_email_address; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
547
599
|
--
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Peterson
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- spec/dummy/app/models/account.rb
|
88
88
|
- spec/dummy/app/models/address.rb
|
89
89
|
- spec/dummy/app/models/city.rb
|
90
|
+
- spec/dummy/app/models/country.rb
|
90
91
|
- spec/dummy/app/models/email_address.rb
|
91
92
|
- spec/dummy/app/models/ip_address.rb
|
92
93
|
- spec/dummy/app/models/path.rb
|
@@ -151,6 +152,7 @@ test_files:
|
|
151
152
|
- spec/dummy/app/models/account.rb
|
152
153
|
- spec/dummy/app/models/address.rb
|
153
154
|
- spec/dummy/app/models/city.rb
|
155
|
+
- spec/dummy/app/models/country.rb
|
154
156
|
- spec/dummy/app/models/email_address.rb
|
155
157
|
- spec/dummy/app/models/ip_address.rb
|
156
158
|
- spec/dummy/app/models/path.rb
|