direct_address 0.0.2

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.
@@ -0,0 +1,105 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'yaml'
4
+ require 'rubygems'
5
+ require 'hpricot'
6
+ require File.dirname(__FILE__) + '/extend_string.rb'
7
+
8
+ class Geoname
9
+ URL = 'http://www.geonames.org'
10
+ COUNTRIES_PATH = '/countries/'
11
+ REGION_PATH = '/{ALPHA2}/administrative-division-{country}.html'
12
+
13
+ class InvalidModelError < StandardError; end
14
+
15
+ def self.retrieve_to_db
16
+ raise(InvalidModelError, 'Country and Region models must be generated before populating the database. Please make sure the gem is installed into a rails project then try running: script/generate direct_address') if !gem_integrated?
17
+ countries = Geoname.retrieve_countries
18
+ countries.each do |country|
19
+ c = Country.find_by_abbreviation(country[0]) || Country.create(:abbreviation => country[0], :name => country[1])
20
+ regions = Geoname.retrieve_regions(country[0], country[1])
21
+ puts "Successfully retrieved #{country[1]} :: found #{regions.size} regions"
22
+ for region in regions
23
+ if c.regions.count(:conditions => ['lower(name) = ?', region]) == 0
24
+ c.regions.create(:name => region)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.retrieve_all(path)
31
+ countries = Geoname.retrieve_countries(path)
32
+ countries.each do |country|
33
+ regions = Geoname.retrieve_regions(country[0], country[1], path)
34
+ puts "Successfully retrieved #{country[1]} :: found #{regions.size} regions"
35
+ end
36
+ end
37
+
38
+
39
+ def self.retrieve_countries(filepath = nil)
40
+ response = Geoname.get_body("#{Geoname::URL}#{Geoname::COUNTRIES_PATH}")
41
+ countries = Geoname.parse_countries response
42
+ if filepath
43
+ Geoname.export("#{filepath}/countries.yml", countries )
44
+ end
45
+ countries
46
+ end
47
+
48
+ def self.retrieve_regions(alpha2, country, filepath = nil)
49
+ path = Geoname::REGION_PATH.gsub('{ALPHA2}', alpha2).gsub('{country}', Geoname.url_format(country))
50
+ response = Geoname.get_body("#{Geoname::URL}#{path}")
51
+ regions = Geoname.parse_regions response
52
+ if filepath
53
+ Geoname.export("#{filepath}/regions/#{alpha2}.yml", regions)
54
+ end
55
+ regions
56
+ end
57
+
58
+ private
59
+
60
+ def self.parse_countries(body)
61
+ doc = Hpricot(body)
62
+ (doc/"#countries td > a[@href]").collect do |elem|
63
+ href = elem.attributes['href']
64
+ fips = nil
65
+ if (href =~ /countries\/(.+)\//)
66
+ fips = $1
67
+ end
68
+ [fips, elem.innerHTML]
69
+ end
70
+ end
71
+
72
+ def self.parse_regions(body)
73
+ doc = Hpricot(body)
74
+ (doc/"#subdivtable td > a[@href]").collect {|elem| elem.innerHTML}
75
+ end
76
+
77
+ def self.url_format(string)
78
+ string.downcase.gsub(' ', '-').removeaccents
79
+ end
80
+
81
+ def self.get_body(url)
82
+ url = URI.parse(url)
83
+ request = Net::HTTP::Get.new(url.path)
84
+ response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
85
+ response.body
86
+ end
87
+
88
+ def self.export(path, content)
89
+ FileUtils.mkdir_p(File.dirname(path))
90
+ File.open(path, 'w+' ) do |out|
91
+ YAML.dump(content,out)
92
+ end
93
+ end
94
+
95
+ def self.gem_integrated?
96
+ begin
97
+ c = Country.new(:name => 'test', :abbreviation => 't')
98
+ r = Region.new(:name => 'test', :country_id => -1)
99
+ true
100
+ rescue
101
+ false
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,5 @@
1
+ [:form_builder, :form_helper, :acts_as_addressable].each do |file|
2
+ require File.dirname(__FILE__) + '/direct_address/' + file.to_s
3
+ end
4
+
5
+ require File.dirname(__FILE__) + '/direct_address/harvester/geoname.rb'
data/spec/database.yml ADDED
@@ -0,0 +1,7 @@
1
+ mysql:
2
+ adapter: mysql
3
+ encoding: utf8
4
+ database: gem_test
5
+ username: root
6
+ password:
7
+ pool: 5
data/spec/debug.log ADDED
@@ -0,0 +1,412 @@
1
+ # Logfile created on Sun Feb 07 08:08:51 -0500 2010 by /
2
+ SQL (0.2ms) SET NAMES 'utf8'
3
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
4
+ SQL (31.8ms) SHOW TABLES
5
+ SQL (91.9ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
6
+ SQL (0.7ms) SHOW TABLES
7
+ SQL (433.0ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
8
+ SQL (0.9ms) SHOW TABLES
9
+ SQL (102.4ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10
+ SQL (1.7ms) SHOW TABLES
11
+ SQL (0.4ms) SELECT version FROM `schema_migrations`
12
+ SQL (0.1ms) SET NAMES 'utf8'
13
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
14
+ SQL (0.7ms) SHOW TABLES
15
+ SQL (2.2ms) DROP TABLE `addresses`
16
+ SQL (78.8ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
17
+ SQL (1.1ms) SHOW TABLES
18
+ SQL (1.9ms) DROP TABLE `countries`
19
+ SQL (160.2ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
20
+ SQL (1.0ms) SHOW TABLES
21
+ SQL (34.2ms) DROP TABLE `regions`
22
+ SQL (119.9ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
23
+ SQL (1.0ms) SHOW TABLES
24
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
25
+ Country Columns (1.6ms) SHOW FIELDS FROM `countries`
26
+ SQL (0.2ms) SET NAMES 'utf8'
27
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
28
+ SQL (0.6ms) SHOW TABLES
29
+ SQL (1.7ms) DROP TABLE `addresses`
30
+ SQL (73.0ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
31
+ SQL (4.1ms) SHOW TABLES
32
+ SQL (1.8ms) DROP TABLE `countries`
33
+ SQL (191.9ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
34
+ SQL (1.0ms) SHOW TABLES
35
+ SQL (1.4ms) DROP TABLE `regions`
36
+ SQL (105.8ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
37
+ SQL (0.8ms) SHOW TABLES
38
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
39
+ Country Columns (1.7ms) SHOW FIELDS FROM `countries`
40
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
41
+ SQL (0.2ms) SET NAMES 'utf8'
42
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
43
+ SQL (0.7ms) SHOW TABLES
44
+ SQL (1.8ms) DROP TABLE `addresses`
45
+ SQL (136.0ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
46
+ SQL (1.8ms) SHOW TABLES
47
+ SQL (1.8ms) DROP TABLE `countries`
48
+ SQL (206.3ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
49
+ SQL (1.0ms) SHOW TABLES
50
+ SQL (2.4ms) DROP TABLE `regions`
51
+ SQL (128.6ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
52
+ SQL (1.1ms) SHOW TABLES
53
+ SQL (2.2ms) DROP TABLE `users`
54
+ SQL (130.8ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
55
+ SQL (0.9ms) SHOW TABLES
56
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
57
+ Country Columns (1.6ms) SHOW FIELDS FROM `countries`
58
+ SQL (0.3ms) BEGIN
59
+ Country Create (0.4ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:17:19', '2010-02-07 08:17:19', 'US')
60
+ SQL (0.7ms) COMMIT
61
+ Region Columns (1.6ms) SHOW FIELDS FROM `regions`
62
+ SQL (0.2ms) BEGIN
63
+ Region Create (0.3ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:17:19', '2010-02-07 08:17:19', 1)
64
+ SQL (0.5ms) COMMIT
65
+ User Columns (1.4ms) SHOW FIELDS FROM `users`
66
+ SQL (0.1ms) BEGIN
67
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:17:19', '2010-02-07 08:17:19')
68
+ SQL (0.6ms) COMMIT
69
+ SQL (0.2ms) SET NAMES 'utf8'
70
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
71
+ SQL (0.7ms) SHOW TABLES
72
+ SQL (1.7ms) DROP TABLE `addresses`
73
+ SQL (146.2ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
74
+ SQL (1.1ms) SHOW TABLES
75
+ SQL (2.2ms) DROP TABLE `countries`
76
+ SQL (366.8ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
77
+ SQL (1.0ms) SHOW TABLES
78
+ SQL (2.5ms) DROP TABLE `regions`
79
+ SQL (119.6ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
80
+ SQL (1.5ms) SHOW TABLES
81
+ SQL (3.1ms) DROP TABLE `users`
82
+ SQL (139.9ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
83
+ SQL (2.1ms) SHOW TABLES
84
+ SQL (0.4ms) SELECT version FROM `schema_migrations`
85
+ Country Columns (1.6ms) SHOW FIELDS FROM `countries`
86
+ SQL (0.1ms) BEGIN
87
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:27:09', '2010-02-07 08:27:09', 'US')
88
+ SQL (0.5ms) COMMIT
89
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
90
+ SQL (0.1ms) BEGIN
91
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:27:09', '2010-02-07 08:27:09', 1)
92
+ SQL (0.6ms) COMMIT
93
+ User Columns (1.4ms) SHOW FIELDS FROM `users`
94
+ SQL (0.1ms) BEGIN
95
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:27:09', '2010-02-07 08:27:09')
96
+ SQL (0.6ms) COMMIT
97
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
98
+ WARNING: Can't mass-assign these protected attributes: region, country, addressable
99
+ SQL (0.1ms) BEGIN
100
+ Address Create (0.0ms) Mysql::Error: Column 'addressable_type' cannot be null: INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:27:09', '04330', '54 Parkins Way', '2010-02-07 08:27:09', NULL, NULL, NULL, NULL, NULL)
101
+ SQL (0.1ms) ROLLBACK
102
+ SQL (0.1ms) SET NAMES 'utf8'
103
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
104
+ SQL (0.6ms) SHOW TABLES
105
+ SQL (21.6ms) DROP TABLE `addresses`
106
+ SQL (53.1ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
107
+ SQL (2.1ms) SHOW TABLES
108
+ SQL (2.2ms) DROP TABLE `countries`
109
+ SQL (160.8ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
110
+ SQL (2.2ms) SHOW TABLES
111
+ SQL (1.9ms) DROP TABLE `regions`
112
+ SQL (118.0ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
113
+ SQL (1.4ms) SHOW TABLES
114
+ SQL (1.9ms) DROP TABLE `users`
115
+ SQL (118.5ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
116
+ SQL (1.1ms) SHOW TABLES
117
+ SQL (0.8ms) SELECT version FROM `schema_migrations`
118
+ Country Columns (1.5ms) SHOW FIELDS FROM `countries`
119
+ SQL (0.1ms) BEGIN
120
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:29:12', '2010-02-07 08:29:12', 'US')
121
+ SQL (0.7ms) COMMIT
122
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
123
+ SQL (0.1ms) BEGIN
124
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:29:12', '2010-02-07 08:29:12', 1)
125
+ SQL (0.6ms) COMMIT
126
+ User Columns (1.6ms) SHOW FIELDS FROM `users`
127
+ SQL (0.1ms) BEGIN
128
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:29:12', '2010-02-07 08:29:12')
129
+ SQL (0.5ms) COMMIT
130
+ Address Columns (1.9ms) SHOW FIELDS FROM `addresses`
131
+ WARNING: Can't mass-assign these protected attributes: region, country, addressable
132
+ SQL (0.4ms) BEGIN
133
+ Address Create (0.0ms) Mysql::Error: Column 'addressable_type' cannot be null: INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:29:12', '04330', '54 Parkins Way', '2010-02-07 08:29:12', NULL, NULL, NULL, NULL, NULL)
134
+ SQL (0.1ms) ROLLBACK
135
+ SQL (0.2ms) SET NAMES 'utf8'
136
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
137
+ SQL (0.6ms) SHOW TABLES
138
+ SQL (18.9ms) DROP TABLE `addresses`
139
+ SQL (51.3ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
140
+ SQL (1.4ms) SHOW TABLES
141
+ SQL (3.5ms) DROP TABLE `countries`
142
+ SQL (140.3ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
143
+ SQL (1.2ms) SHOW TABLES
144
+ SQL (2.2ms) DROP TABLE `regions`
145
+ SQL (107.2ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
146
+ SQL (2.4ms) SHOW TABLES
147
+ SQL (1.7ms) DROP TABLE `users`
148
+ SQL (106.3ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
149
+ SQL (1.4ms) SHOW TABLES
150
+ SQL (0.4ms) SELECT version FROM `schema_migrations`
151
+ Country Columns (1.5ms) SHOW FIELDS FROM `countries`
152
+ SQL (0.1ms) BEGIN
153
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:30:28', '2010-02-07 08:30:28', 'US')
154
+ SQL (0.7ms) COMMIT
155
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
156
+ SQL (0.2ms) BEGIN
157
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:30:28', '2010-02-07 08:30:28', 1)
158
+ SQL (0.6ms) COMMIT
159
+ User Columns (1.5ms) SHOW FIELDS FROM `users`
160
+ SQL (0.1ms) BEGIN
161
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:30:28', '2010-02-07 08:30:28')
162
+ SQL (0.7ms) COMMIT
163
+ Address Columns (2.7ms) SHOW FIELDS FROM `addresses`
164
+ SQL (0.2ms) BEGIN
165
+ Address Create (0.3ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:30:28', '04330', '54 Parkins Way', '2010-02-07 08:30:28', 'User', 1, NULL, 1, 1)
166
+ SQL (0.7ms) COMMIT
167
+ SQL (0.2ms) SET NAMES 'utf8'
168
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
169
+ SQL (0.6ms) SHOW TABLES
170
+ SQL (1.8ms) DROP TABLE `addresses`
171
+ SQL (89.8ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
172
+ SQL (1.7ms) SHOW TABLES
173
+ SQL (1.9ms) DROP TABLE `countries`
174
+ SQL (201.3ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
175
+ SQL (1.2ms) SHOW TABLES
176
+ SQL (1.8ms) DROP TABLE `regions`
177
+ SQL (107.1ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
178
+ SQL (1.0ms) SHOW TABLES
179
+ SQL (2.4ms) DROP TABLE `users`
180
+ SQL (106.3ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
181
+ SQL (0.9ms) SHOW TABLES
182
+ SQL (0.8ms) SELECT version FROM `schema_migrations`
183
+ Country Columns (1.5ms) SHOW FIELDS FROM `countries`
184
+ SQL (0.1ms) BEGIN
185
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:30:52', '2010-02-07 08:30:52', 'US')
186
+ SQL (0.7ms) COMMIT
187
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
188
+ SQL (0.2ms) BEGIN
189
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:30:52', '2010-02-07 08:30:52', 1)
190
+ SQL (0.8ms) COMMIT
191
+ User Columns (1.5ms) SHOW FIELDS FROM `users`
192
+ SQL (0.1ms) BEGIN
193
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:30:52', '2010-02-07 08:30:52')
194
+ SQL (0.7ms) COMMIT
195
+ Address Columns (2.3ms) SHOW FIELDS FROM `addresses`
196
+ SQL (0.1ms) BEGIN
197
+ Address Create (0.4ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:30:52', '04330', '54 Parkins Way', '2010-02-07 08:30:52', 'User', 1, NULL, 1, 1)
198
+ SQL (0.6ms) COMMIT
199
+ SQL (0.2ms) SET NAMES 'utf8'
200
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
201
+ SQL (0.6ms) SHOW TABLES
202
+ SQL (24.7ms) DROP TABLE `addresses`
203
+ SQL (58.6ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
204
+ SQL (0.7ms) SHOW TABLES
205
+ SQL (2.1ms) DROP TABLE `countries`
206
+ SQL (161.4ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
207
+ SQL (1.2ms) SHOW TABLES
208
+ SQL (1.9ms) DROP TABLE `regions`
209
+ SQL (118.0ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
210
+ SQL (1.0ms) SHOW TABLES
211
+ SQL (1.9ms) DROP TABLE `users`
212
+ SQL (118.9ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
213
+ SQL (1.1ms) SHOW TABLES
214
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
215
+ Country Columns (1.7ms) SHOW FIELDS FROM `countries`
216
+ SQL (0.1ms) BEGIN
217
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:31:00', '2010-02-07 08:31:00', 'US')
218
+ SQL (0.6ms) COMMIT
219
+ Region Columns (1.4ms) SHOW FIELDS FROM `regions`
220
+ SQL (0.1ms) BEGIN
221
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:31:00', '2010-02-07 08:31:00', 1)
222
+ SQL (0.6ms) COMMIT
223
+ User Columns (1.3ms) SHOW FIELDS FROM `users`
224
+ SQL (0.1ms) BEGIN
225
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:31:00', '2010-02-07 08:31:00')
226
+ SQL (0.6ms) COMMIT
227
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
228
+ SQL (0.1ms) BEGIN
229
+ Address Create (0.2ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:31:00', '04330', '54 Parkins Way', '2010-02-07 08:31:00', 'User', 1, NULL, 1, 1)
230
+ SQL (0.6ms) COMMIT
231
+ SQL (0.3ms) SET NAMES 'utf8'
232
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
233
+ SQL (0.6ms) SHOW TABLES
234
+ SQL (1.9ms) DROP TABLE `addresses`
235
+ SQL (68.8ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
236
+ SQL (0.9ms) SHOW TABLES
237
+ SQL (3.2ms) DROP TABLE `countries`
238
+ SQL (168.6ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
239
+ SQL (1.9ms) SHOW TABLES
240
+ SQL (2.4ms) DROP TABLE `regions`
241
+ SQL (140.1ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
242
+ SQL (1.4ms) SHOW TABLES
243
+ SQL (2.5ms) DROP TABLE `users`
244
+ SQL (108.2ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
245
+ SQL (1.2ms) SHOW TABLES
246
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
247
+ Country Columns (1.5ms) SHOW FIELDS FROM `countries`
248
+ SQL (0.1ms) BEGIN
249
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-07 08:31:35', '2010-02-07 08:31:35', 'US')
250
+ SQL (0.8ms) COMMIT
251
+ Region Columns (1.4ms) SHOW FIELDS FROM `regions`
252
+ SQL (0.2ms) BEGIN
253
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-07 08:31:35', '2010-02-07 08:31:35', 1)
254
+ SQL (0.7ms) COMMIT
255
+ User Columns (1.5ms) SHOW FIELDS FROM `users`
256
+ SQL (0.1ms) BEGIN
257
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-07 08:31:35', '2010-02-07 08:31:35')
258
+ SQL (0.7ms) COMMIT
259
+ Address Columns (1.4ms) SHOW FIELDS FROM `addresses`
260
+ SQL (0.1ms) BEGIN
261
+ Address Create (0.2ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-07 08:31:35', '04330', '54 Parkins Way', '2010-02-07 08:31:35', 'User', 1, NULL, 1, 1)
262
+ SQL (0.7ms) COMMIT
263
+ SQL (0.2ms) SET NAMES 'utf8'
264
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
265
+ SQL (101.1ms) SHOW TABLES
266
+ SQL (32.7ms) DROP TABLE `addresses`
267
+ SQL (58.4ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
268
+ SQL (1.0ms) SHOW TABLES
269
+ SQL (22.5ms) DROP TABLE `countries`
270
+ SQL (176.3ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
271
+ SQL (1.6ms) SHOW TABLES
272
+ SQL (23.8ms) DROP TABLE `regions`
273
+ SQL (131.7ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
274
+ SQL (3.0ms) SHOW TABLES
275
+ SQL (3.3ms) DROP TABLE `users`
276
+ SQL (158.9ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
277
+ SQL (0.8ms) SHOW TABLES
278
+ SQL (41.0ms) SELECT version FROM `schema_migrations`
279
+ SQL (0.2ms) SET NAMES 'utf8'
280
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
281
+ SQL (0.6ms) SHOW TABLES
282
+ SQL (2.4ms) DROP TABLE `addresses`
283
+ SQL (80.7ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
284
+ SQL (0.8ms) SHOW TABLES
285
+ SQL (2.3ms) DROP TABLE `countries`
286
+ SQL (170.6ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
287
+ SQL (0.7ms) SHOW TABLES
288
+ SQL (1.8ms) DROP TABLE `regions`
289
+ SQL (120.3ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
290
+ SQL (0.8ms) SHOW TABLES
291
+ SQL (1.8ms) DROP TABLE `users`
292
+ SQL (119.1ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
293
+ SQL (1.1ms) SHOW TABLES
294
+ SQL (0.8ms) SELECT version FROM `schema_migrations`
295
+ Country Columns (2.3ms) SHOW FIELDS FROM `countries`
296
+ SQL (0.1ms) BEGIN
297
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-17 17:53:50', '2010-02-17 17:53:50', 'US')
298
+ SQL (0.7ms) COMMIT
299
+ Region Columns (1.5ms) SHOW FIELDS FROM `regions`
300
+ SQL (0.2ms) BEGIN
301
+ Region Create (0.4ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-17 17:53:50', '2010-02-17 17:53:50', 1)
302
+ SQL (0.6ms) COMMIT
303
+ User Columns (1.7ms) SHOW FIELDS FROM `users`
304
+ SQL (0.1ms) BEGIN
305
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-17 17:53:50', '2010-02-17 17:53:50')
306
+ SQL (0.6ms) COMMIT
307
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
308
+ SQL (0.1ms) BEGIN
309
+ Address Create (0.3ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-17 17:53:50', '04330', '54 Parkins Way', '2010-02-17 17:53:50', 'User', 1, NULL, 1, 1)
310
+ SQL (0.6ms) COMMIT
311
+ SQL (0.4ms) SET NAMES 'utf8'
312
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
313
+ SQL (0.6ms) SHOW TABLES
314
+ SQL (1.9ms) DROP TABLE `addresses`
315
+ SQL (146.7ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
316
+ SQL (1.1ms) SHOW TABLES
317
+ SQL (2.4ms) DROP TABLE `countries`
318
+ SQL (404.9ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
319
+ SQL (3.3ms) SHOW TABLES
320
+ SQL (1.4ms) DROP TABLE `regions`
321
+ SQL (118.1ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
322
+ SQL (0.8ms) SHOW TABLES
323
+ SQL (1.6ms) DROP TABLE `users`
324
+ SQL (130.1ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
325
+ SQL (1.2ms) SHOW TABLES
326
+ SQL (0.8ms) SELECT version FROM `schema_migrations`
327
+ Country Columns (2.1ms) SHOW FIELDS FROM `countries`
328
+ SQL (0.1ms) BEGIN
329
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-17 17:56:56', '2010-02-17 17:56:56', 'US')
330
+ SQL (0.7ms) COMMIT
331
+ Region Columns (1.5ms) SHOW FIELDS FROM `regions`
332
+ SQL (0.1ms) BEGIN
333
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-17 17:56:56', '2010-02-17 17:56:56', 1)
334
+ SQL (0.6ms) COMMIT
335
+ User Columns (1.3ms) SHOW FIELDS FROM `users`
336
+ SQL (0.1ms) BEGIN
337
+ User Create (0.3ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-17 17:56:56', '2010-02-17 17:56:56')
338
+ SQL (0.6ms) COMMIT
339
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
340
+ SQL (0.1ms) BEGIN
341
+ Address Create (0.2ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-17 17:56:56', '04330', '54 Parkins Way', '2010-02-17 17:56:56', 'User', 1, NULL, 1, 1)
342
+ SQL (1.1ms) COMMIT
343
+ SQL (0.2ms) SET NAMES 'utf8'
344
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
345
+ SQL (0.6ms) SHOW TABLES
346
+ SQL (1.9ms) DROP TABLE `addresses`
347
+ SQL (125.8ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
348
+ SQL (2.5ms) SHOW TABLES
349
+ SQL (2.3ms) DROP TABLE `countries`
350
+ SQL (235.5ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
351
+ SQL (1.3ms) SHOW TABLES
352
+ SQL (2.2ms) DROP TABLE `regions`
353
+ SQL (107.0ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
354
+ SQL (0.8ms) SHOW TABLES
355
+ SQL (1.8ms) DROP TABLE `users`
356
+ SQL (121.0ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
357
+ SQL (0.7ms) SHOW TABLES
358
+ SQL (0.7ms) SELECT version FROM `schema_migrations`
359
+ Country Columns (1.6ms) SHOW FIELDS FROM `countries`
360
+ SQL (0.1ms) BEGIN
361
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-17 17:58:44', '2010-02-17 17:58:44', 'US')
362
+ SQL (0.6ms) COMMIT
363
+ Region Columns (1.4ms) SHOW FIELDS FROM `regions`
364
+ SQL (0.1ms) BEGIN
365
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-17 17:58:44', '2010-02-17 17:58:44', 1)
366
+ SQL (0.6ms) COMMIT
367
+ User Columns (1.3ms) SHOW FIELDS FROM `users`
368
+ SQL (0.1ms) BEGIN
369
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-17 17:58:44', '2010-02-17 17:58:44')
370
+ SQL (0.6ms) COMMIT
371
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
372
+ SQL (0.3ms) BEGIN
373
+ Address Create (0.3ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-17 17:58:44', '04330', '54 Parkins Way', '2010-02-17 17:58:44', 'User', 1, NULL, 1, 1)
374
+ SQL (0.7ms) COMMIT
375
+ SQL (0.1ms) BEGIN
376
+ Country Create (0.2ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('All Americas', '2010-02-17 17:58:44', '2010-02-17 17:58:44', 'AA')
377
+ SQL (0.6ms) COMMIT
378
+ SQL (0.3ms) SET NAMES 'utf8'
379
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
380
+ SQL (0.7ms) SHOW TABLES
381
+ SQL (2.1ms) DROP TABLE `addresses`
382
+ SQL (347.6ms) CREATE TABLE `addresses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `addressable_id` int(11) NOT NULL, `addressable_type` varchar(255) NOT NULL, `country_id` int(11), `region_id` int(11), `street1` varchar(255), `street2` varchar(255), `city` varchar(255), `postal` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
383
+ SQL (0.8ms) SHOW TABLES
384
+ SQL (2.3ms) DROP TABLE `countries`
385
+ SQL (82.2ms) CREATE TABLE `countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `abbreviation` varchar(255), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
386
+ SQL (0.7ms) SHOW TABLES
387
+ SQL (2.8ms) DROP TABLE `regions`
388
+ SQL (113.3ms) CREATE TABLE `regions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `country_id` int(11), `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
389
+ SQL (1.8ms) SHOW TABLES
390
+ SQL (1.8ms) DROP TABLE `users`
391
+ SQL (117.2ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
392
+ SQL (0.8ms) SHOW TABLES
393
+ SQL (0.3ms) SELECT version FROM `schema_migrations`
394
+ Country Columns (2.2ms) SHOW FIELDS FROM `countries`
395
+ SQL (0.1ms) BEGIN
396
+ Country Create (0.3ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('United States', '2010-02-17 17:59:03', '2010-02-17 17:59:03', 'US')
397
+ SQL (0.7ms) COMMIT
398
+ Region Columns (1.3ms) SHOW FIELDS FROM `regions`
399
+ SQL (0.2ms) BEGIN
400
+ Region Create (0.2ms) INSERT INTO `regions` (`name`, `created_at`, `updated_at`, `country_id`) VALUES('Kansas', '2010-02-17 17:59:03', '2010-02-17 17:59:03', 1)
401
+ SQL (0.7ms) COMMIT
402
+ User Columns (1.3ms) SHOW FIELDS FROM `users`
403
+ SQL (0.1ms) BEGIN
404
+ User Create (0.3ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-17 17:59:03', '2010-02-17 17:59:03')
405
+ SQL (0.6ms) COMMIT
406
+ Address Columns (1.5ms) SHOW FIELDS FROM `addresses`
407
+ SQL (0.2ms) BEGIN
408
+ Address Create (0.2ms) INSERT INTO `addresses` (`city`, `created_at`, `postal`, `street1`, `updated_at`, `addressable_type`, `country_id`, `street2`, `addressable_id`, `region_id`) VALUES('Whitmore', '2010-02-17 17:59:03', '04330', '54 Parkins Way', '2010-02-17 17:59:03', 'User', 1, NULL, 1, 1)
409
+ SQL (0.6ms) COMMIT
410
+ SQL (0.1ms) BEGIN
411
+ Country Create (0.2ms) INSERT INTO `countries` (`name`, `created_at`, `updated_at`, `abbreviation`) VALUES('All Americas', '2010-02-17 17:59:03', '2010-02-17 17:59:03', 'AA')
412
+ SQL (0.7ms) COMMIT
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "DirectAddress" do
4
+ before(:all) do
5
+ @country = Country.create(:abbrev => 'US', :name => 'United States')
6
+ @region = Region.create(:name => 'Kansas', :country => @country)
7
+ @user = User.create(:name => 'Mike')
8
+ @address = Address.create(:addressable => @user, :country => @country, :region => @region, :street1 => '54 Parkins Way', :city => 'Whitmore', :postal => '04330')
9
+ end
10
+ it "should validate countries properly" do
11
+ c = Country.new
12
+ c.valid?.should be_false
13
+ c.abbreviation = @country.abbrev
14
+ c.valid?.should be_false
15
+ c.name = @country.name
16
+ c.valid?.should be_true
17
+ end
18
+
19
+ it "should validate regions properly" do
20
+ r = Region.new
21
+ r.valid?.should be_false
22
+ r.name = @region.name
23
+ r.valid?.should be_false
24
+ r.country = @country
25
+ r.valid?.should be_true
26
+ end
27
+
28
+ it "should output addresses properly" do
29
+ @address.multiline.should eql([@address.street1, "#{@address.city} #{@address.region_name} #{@address.postal}", @address.country_abbrev])
30
+ @address.single_line.should eql([@address.street1, "#{@address.city} #{@address.region_name} #{@address.postal}", @address.country_abbrev].join(', '))
31
+ end
32
+
33
+ it "should validate length of abbreviation" do
34
+ c = Country.new(:abbrev => 'a', :name => 'america')
35
+ c.valid?.should be_false
36
+ end
37
+
38
+ it "should format the abbreviation" do
39
+ c = Country.create(:abbrev => 'aa', :name => 'All Americas')
40
+ c.abbrev.should eql('AA')
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_one :address, :as => :addressable
4
+
5
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,31 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+
3
+ create_table :addresses, :force => true do |t|
4
+ t.references :addressable, :polymorphic => true, :null => false
5
+ t.references :country
6
+ t.references :region
7
+ t.string :street1
8
+ t.string :street2
9
+ t.string :city
10
+ t.string :postal
11
+ t.timestamps
12
+ end
13
+
14
+ create_table :countries, :force => true do |t|
15
+ t.string :abbreviation
16
+ t.string :name
17
+ t.timestamps
18
+ end
19
+
20
+ create_table :regions, :force => true do |t|
21
+ t.references :country
22
+ t.string :name
23
+ t.timestamps
24
+ end
25
+
26
+ create_table :users, :force => true do |t|
27
+ t.string :name
28
+ t.timestamps
29
+ end
30
+
31
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime