has_addresses 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +22 -11
- data/Rakefile +1 -1
- data/app/models/address.rb +6 -6
- data/lib/has_addresses.rb +4 -4
- data/test/app_root/config/environment.rb +5 -10
- data/test/{app_root/test/fixtures → fixtures}/addresses.yml +0 -0
- data/test/{app_root/test/fixtures → fixtures}/companies.yml +0 -0
- data/test/{app_root/test/fixtures → fixtures}/countries.yml +0 -0
- data/test/{app_root/test/fixtures → fixtures}/regions.yml +0 -0
- data/test/unit/country_test.rb +1 -1
- metadata +8 -9
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= has_addresses
|
2
2
|
|
3
|
-
has_addresses adds a base skeleton for handling countries, regions, and
|
3
|
+
+has_addresses+ adds a base skeleton for handling countries, regions, and
|
4
4
|
addresses.
|
5
5
|
|
6
6
|
== Resources
|
@@ -15,7 +15,7 @@ Wiki
|
|
15
15
|
|
16
16
|
Announcement
|
17
17
|
|
18
|
-
* http://www.pluginaweek.org
|
18
|
+
* http://www.pluginaweek.org
|
19
19
|
|
20
20
|
Source
|
21
21
|
|
@@ -37,9 +37,11 @@ Along with the simple Country and Region models, addresses can be defined and
|
|
37
37
|
integrated based on the data in these models. Addresses are minimalistic in
|
38
38
|
terms of the type of data required and follows the standard U.S. format.
|
39
39
|
|
40
|
+
== Usage
|
41
|
+
|
40
42
|
=== Running migrations
|
41
43
|
|
42
|
-
To migrate the tables required for
|
44
|
+
To migrate the tables required for this plugin, you can either run the
|
43
45
|
migration from the command line like so:
|
44
46
|
|
45
47
|
rake db:migrate:plugins PLUGIN=has_addresses
|
@@ -47,11 +49,11 @@ migration from the command line like so:
|
|
47
49
|
or (more ideally) generate a migration file that will integrate into your main
|
48
50
|
application's migration path:
|
49
51
|
|
50
|
-
ruby script/generate plugin_migration
|
52
|
+
ruby script/generate plugin_migration has_addresses
|
51
53
|
|
52
54
|
=== Bootstrapping the database
|
53
55
|
|
54
|
-
has_addresses comes bundled with tasks for bootstrapping the countries and
|
56
|
+
+has_addresses+ comes bundled with tasks for bootstrapping the countries and
|
55
57
|
regions table based on the ISO 3166 and ISO 3166-2 standard. You can bootstrap
|
56
58
|
the database using built-in rake tasks or by creating fixtures which contain the
|
57
59
|
bootstrap data.
|
@@ -93,6 +95,10 @@ To create fixtures for the country/region bootstrap data:
|
|
93
95
|
|
94
96
|
== Testing
|
95
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
|
+
|
96
102
|
Since the rake tasks for installing TinyMCE and updating the configuration
|
97
103
|
options are part of the unit tests, already-downloaded files are included with
|
98
104
|
the plugin. If you want to perform a "live" test which actually downloads the
|
@@ -101,11 +107,16 @@ the LIVE environment variable to true. For example,
|
|
101
107
|
|
102
108
|
rake test LIVE=true
|
103
109
|
|
104
|
-
The following plugins/gems must be installed before any tests can be run:
|
105
|
-
* plugin_dependencies - http://wiki.pluginaweekk.org/Plugin_dependencies
|
106
|
-
* loaded_plugins - http://wiki.pluginaweek.org/Loaded_plugins
|
107
|
-
* appable_plugins - http://wiki.pluginaweek.org/Appable_plugins
|
108
|
-
|
109
110
|
== Dependencies
|
110
111
|
|
111
|
-
This plugin
|
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.
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'rake/contrib/sshpublisher'
|
|
7
7
|
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each {|ext| load ext}
|
8
8
|
|
9
9
|
PKG_NAME = 'has_addresses'
|
10
|
-
PKG_VERSION = '0.0.
|
10
|
+
PKG_VERSION = '0.0.2'
|
11
11
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
12
12
|
RUBY_FORGE_PROJECT = 'pluginaweek'
|
13
13
|
|
data/app/models/address.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Represents a mailing address
|
2
2
|
class Address < ActiveRecord::Base
|
3
|
-
belongs_to
|
4
|
-
|
5
|
-
belongs_to
|
6
|
-
belongs_to
|
3
|
+
belongs_to :addressable,
|
4
|
+
:polymorphic => true
|
5
|
+
belongs_to :region
|
6
|
+
belongs_to :country
|
7
7
|
|
8
8
|
validates_presence_of :addressable_id,
|
9
9
|
:addressable_type,
|
@@ -18,7 +18,7 @@ class Address < ActiveRecord::Base
|
|
18
18
|
:with => /^[0-9]{5}$/,
|
19
19
|
:allow_nil => true
|
20
20
|
|
21
|
-
before_save
|
21
|
+
before_save :ensure_exclusive_references
|
22
22
|
|
23
23
|
# Returns the region's country if the region is specified
|
24
24
|
def country_with_region_check
|
@@ -81,4 +81,4 @@ class Address < ActiveRecord::Base
|
|
81
81
|
|
82
82
|
true
|
83
83
|
end
|
84
|
-
end
|
84
|
+
end
|
data/lib/has_addresses.rb
CHANGED
@@ -14,8 +14,8 @@ module PluginAWeek #:nodoc:
|
|
14
14
|
|
15
15
|
module MacroMethods
|
16
16
|
# Creates a new association for having a single address. This takes
|
17
|
-
# the same parameters as
|
18
|
-
#
|
17
|
+
# the same parameters as +has_one+. By default, the following associations
|
18
|
+
# are the same:
|
19
19
|
#
|
20
20
|
# class Person < ActiveRecord::Base
|
21
21
|
# has_address
|
@@ -34,8 +34,8 @@ module PluginAWeek #:nodoc:
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Creates a new association for having a multiple addresses. This takes
|
37
|
-
# the same parameters as
|
38
|
-
#
|
37
|
+
# the same parameters as +has_many+. By default, the following associations
|
38
|
+
# are the same:
|
39
39
|
#
|
40
40
|
# class Person < ActiveRecord::Base
|
41
41
|
# has_addresses
|
@@ -3,16 +3,10 @@ require 'config/boot'
|
|
3
3
|
$:.unshift("#{RAILS_ROOT}/../../../../../rails/plugin_dependencies/lib")
|
4
4
|
begin
|
5
5
|
require 'plugin_dependencies'
|
6
|
-
rescue
|
6
|
+
rescue Exception => e
|
7
7
|
end
|
8
8
|
|
9
9
|
Rails::Initializer.run do |config|
|
10
|
-
config.log_level = :debug
|
11
|
-
config.cache_classes = false
|
12
|
-
config.whiny_nils = true
|
13
|
-
config.breakpoint_server = true
|
14
|
-
config.load_paths << "#{RAILS_ROOT}/../../lib"
|
15
|
-
|
16
10
|
config.plugin_paths.concat([
|
17
11
|
"#{RAILS_ROOT}/../../..",
|
18
12
|
"#{RAILS_ROOT}/../../../../migrations",
|
@@ -20,11 +14,12 @@ Rails::Initializer.run do |config|
|
|
20
14
|
"#{RAILS_ROOT}/../../../../../test"
|
21
15
|
])
|
22
16
|
config.plugins = [
|
23
|
-
|
17
|
+
'loaded_plugins',
|
24
18
|
'appable_plugins',
|
25
19
|
'plugin_migrations',
|
20
|
+
File.basename(File.expand_path("#{RAILS_ROOT}/../..")),
|
26
21
|
'dry_validity_assertions'
|
27
22
|
]
|
23
|
+
config.cache_classes = false
|
24
|
+
config.whiny_nils = true
|
28
25
|
end
|
29
|
-
|
30
|
-
Dependencies.log_activity = true
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/unit/country_test.rb
CHANGED
@@ -92,7 +92,7 @@ class CountryTest < Test::Unit::TestCase
|
|
92
92
|
assert_equal 'US', countries(:united_states).abbreviation_2
|
93
93
|
end
|
94
94
|
|
95
|
-
def
|
95
|
+
def test_abbreviation_3_should_be_same_as_alpha_3_code
|
96
96
|
assert_equal 'USA', countries(:united_states).abbreviation_3
|
97
97
|
end
|
98
98
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: has_addresses
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-09-26 00:00:00 -04:00
|
8
8
|
summary: Adds a base skeleton for handling countries, regions, and addresses.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,18 +40,17 @@ files:
|
|
40
40
|
- lib/has_addresses.rb
|
41
41
|
- tasks/has_addresses_tasks.rake
|
42
42
|
- test/test_helper.rb
|
43
|
+
- test/fixtures
|
43
44
|
- test/app_root
|
44
45
|
- test/unit
|
45
46
|
- test/files
|
46
|
-
- test/
|
47
|
+
- test/fixtures/regions.yml
|
48
|
+
- test/fixtures/companies.yml
|
49
|
+
- test/fixtures/addresses.yml
|
50
|
+
- test/fixtures/countries.yml
|
47
51
|
- test/app_root/config
|
48
52
|
- test/app_root/app
|
49
53
|
- test/app_root/db
|
50
|
-
- test/app_root/test/fixtures
|
51
|
-
- test/app_root/test/fixtures/regions.yml
|
52
|
-
- test/app_root/test/fixtures/companies.yml
|
53
|
-
- test/app_root/test/fixtures/addresses.yml
|
54
|
-
- test/app_root/test/fixtures/countries.yml
|
55
54
|
- test/app_root/config/environment.rb
|
56
55
|
- test/app_root/app/models
|
57
56
|
- test/app_root/app/models/company.rb
|