has_addresses 0.0.2 → 0.5.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.
- data/CHANGELOG.rdoc +50 -0
- data/{MIT-LICENSE → LICENSE} +2 -2
- data/README.rdoc +63 -0
- data/Rakefile +48 -41
- data/app/models/address.rb +92 -50
- data/app/models/country.rb +287 -101
- data/app/models/region.rb +5378 -106
- data/db/migrate/001_create_countries.rb +7 -7
- data/db/migrate/002_create_regions.rb +7 -5
- data/db/migrate/003_create_addresses.rb +10 -12
- data/lib/has_addresses.rb +9 -68
- data/test/app_root/app/models/company.rb +1 -5
- data/test/app_root/config/environment.rb +6 -19
- data/test/app_root/db/migrate/001_create_companies.rb +1 -1
- data/test/app_root/db/migrate/002_migrate_has_addresses_to_version_3.rb +13 -0
- data/test/factory.rb +68 -0
- data/test/functional/has_addresses_test.rb +22 -0
- data/test/test_helper.rb +11 -5
- data/test/unit/address_test.rb +210 -79
- data/test/unit/country_test.rb +101 -72
- data/test/unit/region_test.rb +104 -61
- metadata +70 -61
- data/CHANGELOG +0 -23
- data/README +0 -122
- data/tasks/has_addresses_tasks.rake +0 -23
- data/test/app_root/db/migrate/002_add_address_kinds.rb +0 -9
- data/test/files/iso_3166.xml +0 -1719
- data/test/files/iso_3166_2.xml +0 -8617
- data/test/fixtures/addresses.yml +0 -47
- data/test/fixtures/companies.yml +0 -7
- data/test/fixtures/countries.yml +0 -12
- data/test/fixtures/regions.yml +0 -5
- data/test/unit/has_addresses_test.rb +0 -15
data/test/unit/region_test.rb
CHANGED
@@ -1,101 +1,144 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class RegionTest < Test::Unit::TestCase
|
8
|
-
fixtures :countries, :regions, :addresses
|
9
|
-
|
10
|
-
def test_should_download_and_parse_regions_from_iso_standard
|
11
|
-
regions = Region.download_all
|
12
|
-
assert_instance_of Array, regions
|
13
|
-
assert !regions.empty?
|
3
|
+
class RegionByDefaultTest < ActiveRecord::TestCase
|
4
|
+
def setup
|
5
|
+
@region = Region.new
|
14
6
|
end
|
15
7
|
|
16
|
-
def
|
17
|
-
region
|
18
|
-
assert !region.new_record?
|
19
|
-
Region.bootstrap
|
20
|
-
assert_nil Region.find_by_name('Test')
|
8
|
+
def test_should_not_have_a_country
|
9
|
+
assert_nil @region.country_id
|
21
10
|
end
|
22
11
|
|
23
|
-
def
|
24
|
-
|
25
|
-
assert Region.count > 1
|
12
|
+
def test_should_not_have_a_group
|
13
|
+
assert_nil @region.group
|
26
14
|
end
|
27
15
|
|
28
|
-
def
|
29
|
-
|
16
|
+
def test_should_not_have_a_name
|
17
|
+
assert_nil @region.name
|
30
18
|
end
|
31
19
|
|
32
|
-
def
|
33
|
-
|
34
|
-
assert File.exists?("#{RAILS_ROOT}/db/bootstrap/regions.yml")
|
20
|
+
def test_should_not_have_an_abbreviation
|
21
|
+
assert_nil @region.abbreviation
|
35
22
|
end
|
36
23
|
|
37
|
-
def
|
38
|
-
Region.
|
39
|
-
|
24
|
+
def test_should_use_id_for_abbreviation_if_not_specified
|
25
|
+
region = Region.new(:id => 1005)
|
26
|
+
assert_equal '005', region.abbreviation
|
27
|
+
|
28
|
+
region = Region.new(:id => 1052)
|
29
|
+
assert_equal '052', region.abbreviation
|
30
|
+
|
31
|
+
region = Region.new(:id => 1523)
|
32
|
+
assert_equal '523', region.abbreviation
|
33
|
+
|
34
|
+
region = Region.new(:id => 15234)
|
35
|
+
assert_equal '234', region.abbreviation
|
40
36
|
end
|
41
37
|
|
42
|
-
def
|
43
|
-
Region.
|
44
|
-
|
45
|
-
assert Region.count > 1
|
38
|
+
def test_should_not_use_id_for_abbreviation_if_specified
|
39
|
+
region = Region.new(:id => 1005, :abbreviation => 'CA')
|
40
|
+
assert_equal 'CA', region.abbreviation
|
46
41
|
end
|
47
42
|
|
48
|
-
def
|
49
|
-
|
43
|
+
def test_should_use_country_and_abbreviation_for_code_if_not_specified
|
44
|
+
region = Region.new(:country => create_country(:alpha_2_code => 'US'), :abbreviation => 'CA')
|
45
|
+
assert_equal 'US-CA', region.code
|
50
46
|
end
|
51
47
|
|
52
|
-
def
|
53
|
-
|
48
|
+
def test_should_use_country_and_abbreviation_for_code_if_specified
|
49
|
+
region = Region.new(:country => create_country(:alpha_2_code => 'US'), :abbreviation => 'CA', :code => 'US--CA')
|
50
|
+
assert_equal 'US-CA', region.code
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class RegionTest < ActiveRecord::TestCase
|
55
|
+
def test_should_be_valid_with_a_set_of_valid_attributes
|
56
|
+
region = new_region
|
57
|
+
assert region.valid?
|
54
58
|
end
|
55
59
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
60
|
+
def test_should_require_a_code
|
61
|
+
region = new_region
|
62
|
+
region.code = nil
|
63
|
+
assert !region.valid?
|
64
|
+
assert region.errors.invalid?(:code)
|
59
65
|
end
|
60
66
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
67
|
+
def test_should_require_a_unique_code
|
68
|
+
country = create_country
|
69
|
+
|
70
|
+
region = new_region(:country => country)
|
71
|
+
region.code = 'US-CA'
|
72
|
+
region.save!
|
64
73
|
|
65
|
-
region
|
66
|
-
|
74
|
+
region = new_region(:country => country)
|
75
|
+
region.code = 'US-CA'
|
76
|
+
assert !region.valid?
|
77
|
+
assert region.errors.invalid?(:code)
|
67
78
|
end
|
68
79
|
|
69
|
-
def
|
70
|
-
|
80
|
+
def test_should_require_a_name
|
81
|
+
region = new_region(:name => nil)
|
82
|
+
assert !region.valid?
|
83
|
+
assert region.errors.invalid?(:name)
|
71
84
|
end
|
72
85
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
86
|
+
def test_should_require_a_country
|
87
|
+
region = new_region(:country => nil)
|
88
|
+
assert !region.valid?
|
89
|
+
assert region.errors.invalid?(:country_id)
|
76
90
|
end
|
77
91
|
|
78
|
-
def
|
79
|
-
region =
|
80
|
-
|
92
|
+
def test_should_require_an_abbreviation
|
93
|
+
region = new_region(:abbreviation => nil)
|
94
|
+
assert !region.valid?
|
95
|
+
assert region.errors.invalid?(:abbreviation)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_should_not_allow_abbrevations_shorter_than_1_or_longer_than_5_characters
|
99
|
+
region = new_region(:abbreviation => '')
|
100
|
+
assert !region.valid?
|
101
|
+
assert region.errors.invalid?(:abbreviation)
|
102
|
+
|
103
|
+
region.abbreviation += 'a'
|
104
|
+
assert region.valid?
|
81
105
|
|
82
|
-
region.
|
83
|
-
|
106
|
+
region.abbreviation += 'aaaa'
|
107
|
+
assert region.valid?
|
108
|
+
|
109
|
+
region.abbreviation += 'a'
|
110
|
+
assert !region.valid?
|
111
|
+
assert region.errors.invalid?(:abbreviation)
|
84
112
|
end
|
85
113
|
|
86
|
-
def
|
87
|
-
|
114
|
+
def test_should_not_require_a_group
|
115
|
+
region = new_region(:group => nil)
|
116
|
+
assert region.valid?
|
88
117
|
end
|
89
118
|
|
90
|
-
def
|
91
|
-
|
119
|
+
def test_should_use_code_for_stringification
|
120
|
+
region = new_region(:country => create_country(:alpha_2_code => 'US'), :abbreviation => 'CA')
|
121
|
+
assert_equal 'US-CA', region.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class RegionAfterBeingCreatedTest < ActiveRecord::TestCase
|
126
|
+
def setup
|
127
|
+
@region = create_region
|
92
128
|
end
|
93
129
|
|
94
|
-
def
|
95
|
-
assert_equal
|
130
|
+
def test_should_not_have_any_addresses
|
131
|
+
assert_equal 0, @region.addresses.size
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class RegionWithAddressesTest < ActiveRecord::TestCase
|
136
|
+
def setup
|
137
|
+
@region = create_region
|
138
|
+
@address = create_address(:region => @region)
|
96
139
|
end
|
97
140
|
|
98
|
-
def
|
99
|
-
|
141
|
+
def test_should_have_addresses
|
142
|
+
assert_equal [@address], @region.addresses
|
100
143
|
end
|
101
144
|
end
|
metadata
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: has_addresses
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-09-26 00:00:00 -04:00
|
8
|
-
summary: Adds a base skeleton for handling countries, regions, and addresses.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: info@pluginaweek.org
|
12
|
-
homepage: http://www.pluginaweek.org
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: has_addresses
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.5.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
|
-
- Aaron Pfeifer
|
7
|
+
- Aaron Pfeifer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-30 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: enumerate_by
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: aaron@pluginaweek.org
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
31
33
|
files:
|
32
34
|
- app/models
|
33
35
|
- app/models/country.rb
|
@@ -35,53 +37,60 @@ files:
|
|
35
37
|
- app/models/address.rb
|
36
38
|
- db/migrate
|
37
39
|
- db/migrate/001_create_countries.rb
|
38
|
-
- db/migrate/003_create_addresses.rb
|
39
40
|
- db/migrate/002_create_regions.rb
|
41
|
+
- db/migrate/003_create_addresses.rb
|
40
42
|
- lib/has_addresses.rb
|
41
|
-
-
|
43
|
+
- test/factory.rb
|
42
44
|
- test/test_helper.rb
|
43
|
-
- test/
|
44
|
-
- test/
|
45
|
+
- test/functional
|
46
|
+
- test/functional/has_addresses_test.rb
|
45
47
|
- test/unit
|
46
|
-
- test/
|
47
|
-
- test/
|
48
|
-
- test/
|
49
|
-
- test/
|
50
|
-
- test/fixtures/countries.yml
|
51
|
-
- test/app_root/config
|
52
|
-
- test/app_root/app
|
48
|
+
- test/unit/address_test.rb
|
49
|
+
- test/unit/region_test.rb
|
50
|
+
- test/unit/country_test.rb
|
51
|
+
- test/app_root
|
53
52
|
- test/app_root/db
|
53
|
+
- test/app_root/db/migrate
|
54
|
+
- test/app_root/db/migrate/002_migrate_has_addresses_to_version_3.rb
|
55
|
+
- test/app_root/db/migrate/001_create_companies.rb
|
56
|
+
- test/app_root/config
|
54
57
|
- test/app_root/config/environment.rb
|
58
|
+
- test/app_root/app
|
55
59
|
- test/app_root/app/models
|
56
60
|
- test/app_root/app/models/company.rb
|
57
|
-
-
|
58
|
-
- test/app_root/db/migrate/001_create_companies.rb
|
59
|
-
- test/app_root/db/migrate/002_add_address_kinds.rb
|
60
|
-
- test/unit/country_test.rb
|
61
|
-
- test/unit/region_test.rb
|
62
|
-
- test/unit/has_addresses_test.rb
|
63
|
-
- test/unit/address_test.rb
|
64
|
-
- test/files/iso_3166.xml
|
65
|
-
- test/files/iso_3166_2.xml
|
66
|
-
- CHANGELOG
|
61
|
+
- CHANGELOG.rdoc
|
67
62
|
- init.rb
|
68
|
-
-
|
63
|
+
- LICENSE
|
69
64
|
- Rakefile
|
70
|
-
- README
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
- test/unit/has_addresses_test.rb
|
75
|
-
- test/unit/address_test.rb
|
65
|
+
- README.rdoc
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://www.pluginaweek.org
|
68
|
+
post_install_message:
|
76
69
|
rdoc_options: []
|
77
70
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
84
85
|
requirements: []
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
rubyforge_project: pluginaweek
|
88
|
+
rubygems_version: 1.3.1
|
89
|
+
signing_key:
|
90
|
+
specification_version: 2
|
91
|
+
summary: Demonstrates a reference implementation for handling countries, regions, and addresses.
|
92
|
+
test_files:
|
93
|
+
- test/functional/has_addresses_test.rb
|
94
|
+
- test/unit/address_test.rb
|
95
|
+
- test/unit/region_test.rb
|
96
|
+
- test/unit/country_test.rb
|
data/CHANGELOG
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
*SVN*
|
2
|
-
|
3
|
-
*0.0.2* (September 26th, 2007)
|
4
|
-
|
5
|
-
* Move test fixtures out of the test application root directory
|
6
|
-
|
7
|
-
*0.0.1* (August 21st, 2007)
|
8
|
-
|
9
|
-
* Add documentation
|
10
|
-
|
11
|
-
* Add descriptive output for rake tasks
|
12
|
-
|
13
|
-
* Remove dependency on has_association_helper
|
14
|
-
|
15
|
-
* Remove default bootstrap files in favor of creating new ones through the bootstrap tasks
|
16
|
-
|
17
|
-
* Add tests for rake tests
|
18
|
-
|
19
|
-
* Fix not allowing single character abbreviations for regions
|
20
|
-
|
21
|
-
* Add countries:create_fixtures, countries:bootstrap, regions:create_fixtures, and regions:bootstrap files
|
22
|
-
|
23
|
-
* Refactor Rake code into Country/Region classes
|
data/README
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
= has_addresses
|
2
|
-
|
3
|
-
+has_addresses+ adds a base skeleton for handling countries, regions, and
|
4
|
-
addresses.
|
5
|
-
|
6
|
-
== Resources
|
7
|
-
|
8
|
-
API
|
9
|
-
|
10
|
-
* http://api.pluginaweek.org/has_addresses
|
11
|
-
|
12
|
-
Wiki
|
13
|
-
|
14
|
-
* http://wiki.pluginaweek.org/Has_addresses
|
15
|
-
|
16
|
-
Announcement
|
17
|
-
|
18
|
-
* http://www.pluginaweek.org
|
19
|
-
|
20
|
-
Source
|
21
|
-
|
22
|
-
* http://svn.pluginaweek.org/trunk/plugins/active_record/has/has_addresses
|
23
|
-
|
24
|
-
Development
|
25
|
-
|
26
|
-
* http://dev.pluginaweek.org/browser/trunk/plugins/active_record/has/has_addresses
|
27
|
-
|
28
|
-
== Description
|
29
|
-
|
30
|
-
Countries, regions, and addresses are all simple models whose data and
|
31
|
-
functionality should be able to be standardized across multiple applications.
|
32
|
-
has_addresses adds support for countries and regions based on the ISO 3166 and
|
33
|
-
ISO 3166-2 standard. The data for these standards is obtained through the
|
34
|
-
open-source Debian package, iso-codes.
|
35
|
-
|
36
|
-
Along with the simple Country and Region models, addresses can be defined and
|
37
|
-
integrated based on the data in these models. Addresses are minimalistic in
|
38
|
-
terms of the type of data required and follows the standard U.S. format.
|
39
|
-
|
40
|
-
== Usage
|
41
|
-
|
42
|
-
=== Running migrations
|
43
|
-
|
44
|
-
To migrate the tables required for this plugin, you can either run the
|
45
|
-
migration from the command line like so:
|
46
|
-
|
47
|
-
rake db:migrate:plugins PLUGIN=has_addresses
|
48
|
-
|
49
|
-
or (more ideally) generate a migration file that will integrate into your main
|
50
|
-
application's migration path:
|
51
|
-
|
52
|
-
ruby script/generate plugin_migration has_addresses
|
53
|
-
|
54
|
-
=== Bootstrapping the database
|
55
|
-
|
56
|
-
+has_addresses+ comes bundled with tasks for bootstrapping the countries and
|
57
|
-
regions table based on the ISO 3166 and ISO 3166-2 standard. You can bootstrap
|
58
|
-
the database using built-in rake tasks or by creating fixtures which contain the
|
59
|
-
bootstrap data.
|
60
|
-
|
61
|
-
To bootstrap country/region data into the current database schema:
|
62
|
-
|
63
|
-
$ rake countries:bootstrap
|
64
|
-
(in /my/project)
|
65
|
-
Downloading ISO 3166 data...
|
66
|
-
Parsing countries...
|
67
|
-
Loading countries into database...
|
68
|
-
Done!
|
69
|
-
|
70
|
-
$ rake regions:bootstrap
|
71
|
-
Downloading ISO 3166 data...
|
72
|
-
Parsing countries...
|
73
|
-
Downloading ISO 3166-2 data...
|
74
|
-
Parsing regions...
|
75
|
-
Loading regions into database...
|
76
|
-
Done!
|
77
|
-
|
78
|
-
To create fixtures for the country/region bootstrap data:
|
79
|
-
|
80
|
-
$ rake countries:create_fixtures
|
81
|
-
(in /my/project)
|
82
|
-
Downloading ISO 3166 data...
|
83
|
-
Parsing countries...
|
84
|
-
Saving countries to /my/project/config/../db/bootstrap/countries.yml...
|
85
|
-
Done!
|
86
|
-
|
87
|
-
$ rake regions:create_fixtures
|
88
|
-
(in /my/project)
|
89
|
-
Downloading ISO 3166 data...
|
90
|
-
Parsing countries...
|
91
|
-
Downloading ISO 3166-2 data...
|
92
|
-
Parsing regions...
|
93
|
-
Saving regions to /my/project/config/../db/bootstrap/regions.yml...
|
94
|
-
Done!
|
95
|
-
|
96
|
-
== Testing
|
97
|
-
|
98
|
-
Before you can run any tests, the following gems must be installed:
|
99
|
-
* plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
|
100
|
-
* dry_validity_assertions[http://wiki.pluginaweek.org/Dry_validity_assertions]
|
101
|
-
|
102
|
-
Since the rake tasks for installing TinyMCE and updating the configuration
|
103
|
-
options are part of the unit tests, already-downloaded files are included with
|
104
|
-
the plugin. If you want to perform a "live" test which actually downloads the
|
105
|
-
files off the Internet (rather than using the local versions), you must set
|
106
|
-
the LIVE environment variable to true. For example,
|
107
|
-
|
108
|
-
rake test LIVE=true
|
109
|
-
|
110
|
-
== Dependencies
|
111
|
-
|
112
|
-
This plugin is a plugin+. That means that it contains a slice of an
|
113
|
-
application, such as models and migrations. To test or use a plugin+, you
|
114
|
-
must have the following plugins/gems installed:
|
115
|
-
* plugin_dependencies[http://wiki.pluginaweek.org/Plugin_dependencies]
|
116
|
-
* loaded_plugins[http://wiki.pluginaweek.org/Loaded_plugins]
|
117
|
-
* appable_plugins[http://wiki.pluginaweek.org/Appable_plugins]
|
118
|
-
* plugin_migrations[http://wiki.pluginaweek.org/Plugin_migrations]
|
119
|
-
|
120
|
-
Instead of installing each individual plugin+ feature, you can install them all
|
121
|
-
at once using the plugins+[http://wiki.pluginaweek.org/Plugins_plus] meta package,
|
122
|
-
which contains all additional features.
|
@@ -1,23 +0,0 @@
|
|
1
|
-
namespace :countries do
|
2
|
-
desc 'Generates a new fixtures file for the countries table'
|
3
|
-
task :create_fixtures => :environment do
|
4
|
-
Country.create_fixtures(ENV['OUTPUT'])
|
5
|
-
end
|
6
|
-
|
7
|
-
desc 'Bootstraps the countries table with the latest ISO 3166 standard'
|
8
|
-
task :bootstrap => :environment do
|
9
|
-
Country.bootstrap
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
namespace :regions do
|
14
|
-
desc 'Generates a new fixtures file for the regions table'
|
15
|
-
task :create_fixtures => :environment do
|
16
|
-
Region.create_fixtures(ENV['OUTPUT'])
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Bootstraps the regions table with the latest ISO 3166-2 standard'
|
20
|
-
task :bootstrap => :environment do
|
21
|
-
Region.bootstrap
|
22
|
-
end
|
23
|
-
end
|