has_phone_numbers 0.0.2 → 0.0.3
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 +4 -0
- data/MIT-LICENSE +2 -2
- data/README +18 -33
- data/Rakefile +6 -6
- data/app/models/phone_number.rb +15 -16
- data/db/migrate/001_create_phone_numbers.rb +5 -8
- data/init.rb +1 -1
- data/lib/has_phone_numbers.rb +13 -60
- data/test/app_root/app/models/person.rb +8 -6
- data/test/app_root/config/environment.rb +3 -19
- data/test/app_root/db/migrate/001_create_people.rb +1 -1
- data/test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb +9 -0
- data/test/factory.rb +39 -0
- data/test/test_helper.rb +7 -3
- data/test/unit/phone_number_test.rb +116 -30
- metadata +51 -47
- data/test/fixtures/people.yml +0 -3
- data/test/fixtures/phone_numbers.yml +0 -20
- data/test/unit/has_phone_numbers_test.rb +0 -15
- /data/test/app_root/db/migrate/{002_add_phone_number_kinds.rb → 003_add_phone_number_kinds.rb} +0 -0
data/CHANGELOG
CHANGED
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2006-
|
1
|
+
Copyright (c) 2006-2008 Aaron Pfeifer
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
CHANGED
@@ -1,28 +1,24 @@
|
|
1
1
|
= has_phone_numbers
|
2
2
|
|
3
|
-
+has_phone_numbers+
|
3
|
+
+has_phone_numbers+ demonstrates a reference implementation for handling phone numbers.
|
4
4
|
|
5
5
|
== Resources
|
6
6
|
|
7
|
-
API
|
8
|
-
|
9
|
-
* http://api.pluginaweek.org/has_phone_numbers
|
10
|
-
|
11
7
|
Wiki
|
12
8
|
|
13
9
|
* http://wiki.pluginaweek.org/Has_phone_numbers
|
14
10
|
|
15
|
-
|
11
|
+
API
|
16
12
|
|
17
|
-
* http://
|
13
|
+
* http://api.pluginaweek.org/has_phone_numbers
|
18
14
|
|
19
|
-
|
15
|
+
Development
|
20
16
|
|
21
|
-
* http://
|
17
|
+
* http://dev.pluginaweek.org/browser/trunk/has_phone_numbers
|
22
18
|
|
23
|
-
|
19
|
+
Source
|
24
20
|
|
25
|
-
* http://
|
21
|
+
* http://svn.pluginaweek.org/trunk/has_phone_numbers
|
26
22
|
|
27
23
|
== Description
|
28
24
|
|
@@ -33,34 +29,23 @@ Support for international formats may be added in the future.
|
|
33
29
|
|
34
30
|
== Usage
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
To migrate the tables required for this plugin, you can either run the
|
39
|
-
migration from the command line like so:
|
40
|
-
|
41
|
-
rake db:migrate:plugins PLUGIN=has_phone_numbers
|
32
|
+
Note that this is a reference implementation and, most likely, should be
|
33
|
+
modified for your own usage.
|
42
34
|
|
43
|
-
|
44
|
-
application's migration path:
|
35
|
+
=== Example
|
45
36
|
|
46
|
-
|
37
|
+
phone_number = Phone_number.new(
|
38
|
+
:country_code => '1',
|
39
|
+
:number => '1234567890',
|
40
|
+
:extension => '123'
|
41
|
+
)
|
42
|
+
phone_number.to_s # => 1- 1234567890 ext. 123
|
47
43
|
|
48
44
|
== Testing
|
49
45
|
|
50
|
-
Before you can run any tests, the following
|
46
|
+
Before you can run any tests, the following gem must be installed:
|
51
47
|
* plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
|
52
|
-
* dry_validity_assertions[http://wiki.pluginaweek.org/Dry_validity_assertions]
|
53
48
|
|
54
49
|
== Dependencies
|
55
50
|
|
56
|
-
|
57
|
-
application, such as models and migrations. To test or use a plugin+, you
|
58
|
-
must have the following plugins/gems installed:
|
59
|
-
* plugin_dependencies[http://wiki.pluginaweek.org/Plugin_dependencies]
|
60
|
-
* loaded_plugins[http://wiki.pluginaweek.org/Loaded_plugins]
|
61
|
-
* appable_plugins[http://wiki.pluginaweek.org/Appable_plugins]
|
62
|
-
* plugin_migrations[http://wiki.pluginaweek.org/Plugin_migrations]
|
63
|
-
|
64
|
-
Instead of installing each individual plugin+ feature, you can install them all
|
65
|
-
at once using the plugins+[http://wiki.pluginaweek.org/Plugins_plus] meta package,
|
66
|
-
which contains all additional features.
|
51
|
+
* plugins_plus[http://wiki.pluginaweek.org/Plugins_plus]
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
|
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
6
|
PKG_NAME = 'has_phone_numbers'
|
7
|
-
PKG_VERSION = '0.0.
|
7
|
+
PKG_VERSION = '0.0.3'
|
8
8
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
9
9
|
RUBY_FORGE_PROJECT = 'pluginaweek'
|
10
10
|
|
@@ -31,7 +31,7 @@ spec = Gem::Specification.new do |s|
|
|
31
31
|
s.name = PKG_NAME
|
32
32
|
s.version = PKG_VERSION
|
33
33
|
s.platform = Gem::Platform::RUBY
|
34
|
-
s.summary = '
|
34
|
+
s.summary = 'Demonstrates a reference implementation for handling phone numbers.'
|
35
35
|
|
36
36
|
s.files = FileList['{app,db,lib,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
37
37
|
s.require_path = 'lib'
|
@@ -39,8 +39,8 @@ spec = Gem::Specification.new do |s|
|
|
39
39
|
s.has_rdoc = true
|
40
40
|
s.test_files = Dir['test/**/*_test.rb']
|
41
41
|
|
42
|
-
s.author = 'Aaron Pfeifer
|
43
|
-
s.email = '
|
42
|
+
s.author = 'Aaron Pfeifer'
|
43
|
+
s.email = 'aaron@pluginaweek.org'
|
44
44
|
s.homepage = 'http://www.pluginaweek.org'
|
45
45
|
end
|
46
46
|
|
@@ -52,12 +52,12 @@ end
|
|
52
52
|
|
53
53
|
desc 'Publish the beta gem'
|
54
54
|
task :pgem => [:package] do
|
55
|
-
Rake::SshFilePublisher.new('
|
55
|
+
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
|
56
56
|
end
|
57
57
|
|
58
58
|
desc 'Publish the API documentation'
|
59
59
|
task :pdoc => [:rdoc] do
|
60
|
-
Rake::SshDirPublisher.new('
|
60
|
+
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{PKG_NAME}", 'rdoc').upload
|
61
61
|
end
|
62
62
|
|
63
63
|
desc 'Publish the API docs and gem'
|
data/app/models/phone_number.rb
CHANGED
@@ -3,22 +3,21 @@ class PhoneNumber < ActiveRecord::Base
|
|
3
3
|
belongs_to :phoneable,
|
4
4
|
:polymorphic => true
|
5
5
|
|
6
|
-
validates_presence_of
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
6
|
+
validates_presence_of :phoneable_id,
|
7
|
+
:phoneable_type,
|
8
|
+
:country_code,
|
9
|
+
:number
|
10
|
+
validates_numericality_of :country_code,
|
11
|
+
:number
|
12
|
+
validates_numericality_of :extension,
|
13
|
+
:allow_nil => true
|
14
|
+
validates_length_of :country_code,
|
15
|
+
:in => 1..3
|
16
|
+
validates_length_of :number,
|
17
|
+
:is => 10
|
18
|
+
validates_length_of :extension,
|
19
|
+
:maximum => 10,
|
20
|
+
:allow_nil => true
|
22
21
|
|
23
22
|
def to_s #:nodoc
|
24
23
|
human_number = "#{country_code}- #{number}"
|
@@ -1,14 +1,11 @@
|
|
1
1
|
class CreatePhoneNumbers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :phone_numbers do |t|
|
4
|
-
t.
|
5
|
-
t.
|
6
|
-
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
t.column :extension, :string, :limit => 10
|
10
|
-
t.column :created_at, :timestamp, :null => false
|
11
|
-
t.column :updated_at, :datetime, :null => false
|
4
|
+
t.references :phoneable, :polymorphic => true, :null => false
|
5
|
+
t.string :country_code, :null => false, :limit => 3, :default => 1 # Default is the United States
|
6
|
+
t.string :number, :null => false, :limit => 12
|
7
|
+
t.string :extension, :limit => 10
|
8
|
+
t.timestamps
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'has_phone_numbers'
|
1
|
+
require 'has_phone_numbers'
|
data/lib/has_phone_numbers.rb
CHANGED
@@ -1,69 +1,22 @@
|
|
1
1
|
module PluginAWeek #:nodoc:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
base.extend(MacroMethods)
|
2
|
+
# Adds a generic implementation for dealing with phone numbers
|
3
|
+
module HasPhoneNumbers
|
4
|
+
def self.included(base) #:nodoc:
|
5
|
+
base.class_eval do
|
6
|
+
extend PluginAWeek::HasPhoneNumbers::MacroMethods
|
8
7
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# has_phone_number
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# and
|
20
|
-
#
|
21
|
-
# class Person < ActiveRecord::Base
|
22
|
-
# has_one :phone_number,
|
23
|
-
# :class_name => 'PhoneNumber',
|
24
|
-
# :as => :phoneable,
|
25
|
-
# :dependent => :destroy
|
26
|
-
# end
|
27
|
-
def has_phone_number(*args, &extension)
|
28
|
-
create_phone_number_association(:one, :phone_number, *args, &extension)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Creates a new association for having a multiple phone numbers. This
|
32
|
-
# takes the same parameters as +has_many+. By default, the following
|
33
|
-
# associations are the same:
|
34
|
-
#
|
35
|
-
# class Person < ActiveRecord::Base
|
36
|
-
# has_phone_numbers
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# and
|
40
|
-
#
|
41
|
-
# class Person < ActiveRecord::Base
|
42
|
-
# has_many :phone_numbers,
|
43
|
-
# :class_name => 'PhoneNumber',
|
44
|
-
# :as => :phoneable,
|
45
|
-
# :dependent => :destroy
|
46
|
-
# end
|
47
|
-
def has_phone_numbers(*args, &extension)
|
48
|
-
create_phone_number_association(:many, :phone_numbers, *args, &extension)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def create_phone_number_association(cardinality, association_id, *args, &extension)
|
53
|
-
options = extract_options_from_args!(args)
|
54
|
-
options.symbolize_keys!.reverse_merge!(
|
55
|
-
:class_name => 'PhoneNumber',
|
56
|
-
:as => :phoneable,
|
57
|
-
:dependent => :destroy
|
58
|
-
)
|
59
|
-
|
60
|
-
send("has_#{cardinality}", args.first || association_id, options, &extension)
|
61
|
-
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module MacroMethods
|
11
|
+
# Creates the following association:
|
12
|
+
# * +phone_number+ - All phone numbers associated with the current record.
|
13
|
+
def has_addresses
|
14
|
+
has_many :phone_numbers
|
62
15
|
end
|
63
16
|
end
|
64
17
|
end
|
65
18
|
end
|
66
19
|
|
67
20
|
ActiveRecord::Base.class_eval do
|
68
|
-
include PluginAWeek::
|
21
|
+
include PluginAWeek::HasPhoneNumbers
|
69
22
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class Person < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
has_one :cell_phone,
|
3
|
+
:class_name => 'PhoneNumber',
|
4
|
+
:conditions => {:kind => 'cell'}
|
5
|
+
has_one :work_phone,
|
6
|
+
:class_name => 'PhoneNumber',
|
7
|
+
:conditions => {:kind => 'work'}
|
8
|
+
has_many :phone_numbers
|
9
|
+
end
|
@@ -1,25 +1,9 @@
|
|
1
1
|
require 'config/boot'
|
2
|
-
|
3
|
-
$:.unshift("#{RAILS_ROOT}/../../../../../rails/plugin_dependencies/lib")
|
4
|
-
begin
|
5
|
-
require 'plugin_dependencies'
|
6
|
-
rescue Exception => e
|
7
|
-
end
|
2
|
+
require "#{File.dirname(__FILE__)}/../../../../plugins_plus/boot"
|
8
3
|
|
9
4
|
Rails::Initializer.run do |config|
|
10
|
-
config.plugin_paths
|
11
|
-
|
12
|
-
"#{RAILS_ROOT}/../../../../migrations",
|
13
|
-
"#{RAILS_ROOT}/../../../../../rails",
|
14
|
-
"#{RAILS_ROOT}/../../../../../test"
|
15
|
-
])
|
16
|
-
config.plugins = [
|
17
|
-
'loaded_plugins',
|
18
|
-
'appable_plugins',
|
19
|
-
'plugin_migrations',
|
20
|
-
File.basename(File.expand_path("#{RAILS_ROOT}/../..")),
|
21
|
-
'dry_validity_assertions'
|
22
|
-
]
|
5
|
+
config.plugin_paths << '..'
|
6
|
+
config.plugins = %w(plugins_plus has_phone_numbers)
|
23
7
|
config.cache_classes = false
|
24
8
|
config.whiny_nils = true
|
25
9
|
end
|
data/test/factory.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Factory
|
2
|
+
# Build actions for the class
|
3
|
+
def self.build(klass, &block)
|
4
|
+
name = klass.to_s.underscore
|
5
|
+
define_method("#{name}_attributes", block)
|
6
|
+
|
7
|
+
module_eval <<-end_eval
|
8
|
+
def valid_#{name}_attributes(attributes = {})
|
9
|
+
#{name}_attributes(attributes)
|
10
|
+
attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_#{name}(attributes = {})
|
14
|
+
#{klass}.new(valid_#{name}_attributes(attributes))
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_#{name}(*args)
|
18
|
+
record = new_#{name}(*args)
|
19
|
+
record.save!
|
20
|
+
record.reload
|
21
|
+
record
|
22
|
+
end
|
23
|
+
end_eval
|
24
|
+
end
|
25
|
+
|
26
|
+
build Person do |attributes|
|
27
|
+
attributes.reverse_merge!(
|
28
|
+
:name => 'John Doe'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
build PhoneNumber do |attributes|
|
33
|
+
attributes[:phoneable] = create_person unless attributes.include?(:phoneable)
|
34
|
+
attributes.reverse_merge!(
|
35
|
+
:country_code => '1',
|
36
|
+
:number => '1234567890'
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# Load the plugin testing framework
|
2
|
-
$:.unshift("#{File.dirname(__FILE__)}
|
2
|
+
$:.unshift("#{File.dirname(__FILE__)}/../../plugin_test_helper/lib")
|
3
3
|
require 'rubygems'
|
4
4
|
require 'plugin_test_helper'
|
5
5
|
|
6
|
-
PluginAWeek::PluginMigrations.migrate('has_phone_numbers')
|
7
|
-
|
8
6
|
# Run the migrations
|
9
7
|
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
8
|
+
|
9
|
+
# Mixin the factory helper
|
10
|
+
require File.expand_path("#{File.dirname(__FILE__)}/factory")
|
11
|
+
class Test::Unit::TestCase #:nodoc:
|
12
|
+
include Factory
|
13
|
+
end
|
@@ -1,63 +1,149 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class PhoneNumberByDefaultTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@phone_number = PhoneNumber.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_not_have_a_phoneable_id
|
9
|
+
assert_nil @phone_number.phoneable_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_not_have_a_phoneable_type
|
13
|
+
assert @phone_number.phoneable_type.blank?
|
14
|
+
end
|
5
15
|
|
6
|
-
def
|
7
|
-
|
16
|
+
def test_should_a_united_states_country_code
|
17
|
+
assert_equal '1', @phone_number.country_code
|
8
18
|
end
|
9
19
|
|
10
|
-
def
|
11
|
-
|
20
|
+
def test_should_not_have_a_number
|
21
|
+
assert @phone_number.number.blank?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_not_have_an_extension
|
25
|
+
assert @phone_number.extension.blank?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class PhoneNumberTest < Test::Unit::TestCase
|
30
|
+
def test_should_be_valid_with_a_set_of_valid_attributes
|
31
|
+
phone_number = new_phone_number
|
32
|
+
assert phone_number.valid?
|
12
33
|
end
|
13
34
|
|
14
|
-
def
|
15
|
-
|
35
|
+
def test_should_require_a_phoneable_id
|
36
|
+
phone_number = new_phone_number(:phoneable_id => nil)
|
37
|
+
assert !phone_number.valid?
|
38
|
+
assert_equal 1, Array(phone_number.errors.on(:phoneable_id)).size
|
16
39
|
end
|
17
40
|
|
18
|
-
def
|
19
|
-
|
41
|
+
def test_should_require_a_phoneable_type
|
42
|
+
phone_number = new_phone_number(:phoneable_type => nil)
|
43
|
+
assert !phone_number.valid?
|
44
|
+
assert_equal 1, Array(phone_number.errors.on(:phoneable_type)).size
|
20
45
|
end
|
21
46
|
|
22
|
-
def
|
23
|
-
|
47
|
+
def test_should_require_a_country_code
|
48
|
+
phone_number = new_phone_number(:country_code => nil)
|
49
|
+
assert !phone_number.valid?
|
50
|
+
assert_equal 3, Array(phone_number.errors.on(:country_code)).size
|
24
51
|
end
|
25
52
|
|
26
53
|
def test_should_require_country_code_be_a_number
|
27
|
-
|
54
|
+
phone_number = new_phone_number(:country_code => 'a')
|
55
|
+
assert !phone_number.valid?
|
56
|
+
assert_equal 1, Array(phone_number.errors.on(:country_code)).size
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_should_require_country_codes_be_between_1_and_3_numbers
|
60
|
+
phone_number = new_phone_number(:country_code => '')
|
61
|
+
assert !phone_number.valid?
|
62
|
+
assert_equal 3, Array(phone_number.errors.on(:country_code)).size
|
63
|
+
|
64
|
+
phone_number.country_code += '1'
|
65
|
+
assert phone_number.valid?
|
66
|
+
|
67
|
+
phone_number.country_code += '11'
|
68
|
+
assert phone_number.valid?
|
69
|
+
|
70
|
+
phone_number.country_code += '1'
|
71
|
+
assert !phone_number.valid?
|
72
|
+
assert_equal 1, Array(phone_number.errors.on(:country_code)).size
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_require_a_number
|
76
|
+
phone_number = new_phone_number(:number => nil)
|
77
|
+
assert !phone_number.valid?
|
78
|
+
assert_equal 3, Array(phone_number.errors.on(:number)).size
|
28
79
|
end
|
29
80
|
|
30
81
|
def test_should_require_number_be_a_number
|
31
|
-
|
82
|
+
phone_number = new_phone_number(:number => 'a' * 10)
|
83
|
+
assert !phone_number.valid?
|
84
|
+
assert_equal 1, Array(phone_number.errors.on(:number)).size
|
32
85
|
end
|
33
86
|
|
34
|
-
def
|
35
|
-
|
87
|
+
def test_should_require_number_be_exactly_10_numbers
|
88
|
+
phone_number = new_phone_number(:number => '1' * 9)
|
89
|
+
assert !phone_number.valid?
|
90
|
+
assert_equal 1, Array(phone_number.errors.on(:number)).size
|
91
|
+
|
92
|
+
phone_number.number += '1'
|
93
|
+
assert phone_number.valid?
|
94
|
+
|
95
|
+
phone_number.number += '1'
|
96
|
+
assert !phone_number.valid?
|
97
|
+
assert_equal 1, Array(phone_number.errors.on(:number)).size
|
36
98
|
end
|
37
99
|
|
38
|
-
def
|
39
|
-
|
100
|
+
def test_should_not_require_an_extension
|
101
|
+
phone_number = new_phone_number(:extension => nil)
|
102
|
+
assert phone_number.valid?
|
40
103
|
end
|
41
104
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
105
|
+
def test_should_require_extension_be_at_most_10_numbers
|
106
|
+
phone_number = new_phone_number(:extension => '1' * 9)
|
107
|
+
assert phone_number.valid?
|
108
|
+
|
109
|
+
phone_number.extension += '1'
|
110
|
+
assert phone_number.valid?
|
111
|
+
|
112
|
+
phone_number.extension += '1'
|
113
|
+
assert !phone_number.valid?
|
114
|
+
assert_equal 1, Array(phone_number.errors.on(:extension)).size
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class PhoneNumberAfterBeingCreatedTest < Test::Unit::TestCase
|
119
|
+
def setup
|
120
|
+
@person = create_person
|
121
|
+
@phone_number = create_phone_number(:phoneable => @person, :country_code => '1', :number => '1234567890')
|
45
122
|
end
|
46
123
|
|
47
|
-
def
|
48
|
-
|
49
|
-
assert_valid phone_numbers(:cell), 'extension', '1', '123', '1234567890'
|
124
|
+
def test_should_record_when_it_was_created
|
125
|
+
assert_not_nil @phone_number.created_at
|
50
126
|
end
|
51
127
|
|
52
|
-
def
|
53
|
-
|
128
|
+
def test_should_record_when_it_was_updated
|
129
|
+
assert_not_nil @phone_number.updated_at
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_should_have_a_phoneable_association
|
133
|
+
assert_equal @person, @phone_number.phoneable
|
54
134
|
end
|
55
135
|
|
56
136
|
def test_should_generate_stringified_version_of_phone_number
|
57
|
-
assert_equal '1- 1234567890',
|
137
|
+
assert_equal '1- 1234567890', @phone_number.to_s
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class PhoneNumberWithExtensionTest < Test::Unit::TestCase
|
142
|
+
def setup
|
143
|
+
@phone_number = create_phone_number(:country_code => '1', :number => '1234567890', :extension => '123')
|
58
144
|
end
|
59
145
|
|
60
|
-
def
|
61
|
-
assert_equal '1-
|
146
|
+
def test_should_generate_stringified_version_of_phone_number
|
147
|
+
assert_equal '1- 1234567890 ext. 123', @phone_number.to_s
|
62
148
|
end
|
63
|
-
end
|
149
|
+
end
|
metadata
CHANGED
@@ -1,73 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: has_phone_numbers
|
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 phone numbers.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: info@pluginaweek.org
|
12
|
-
homepage: http://www.pluginaweek.org
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: has_phone_numbers
|
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.0.3
|
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: has_phone_numbers
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-05 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: aaron@pluginaweek.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
31
24
|
files:
|
32
25
|
- app/models
|
33
26
|
- app/models/phone_number.rb
|
34
27
|
- db/migrate
|
35
28
|
- db/migrate/001_create_phone_numbers.rb
|
36
29
|
- lib/has_phone_numbers.rb
|
37
|
-
- test/
|
38
|
-
- test/fixtures
|
30
|
+
- test/factory.rb
|
39
31
|
- test/app_root
|
40
|
-
- test/unit
|
41
|
-
- test/fixtures/phone_numbers.yml
|
42
|
-
- test/fixtures/people.yml
|
43
|
-
- test/app_root/config
|
44
|
-
- test/app_root/app
|
45
32
|
- test/app_root/db
|
33
|
+
- test/app_root/db/migrate
|
34
|
+
- test/app_root/db/migrate/003_add_phone_number_kinds.rb
|
35
|
+
- test/app_root/db/migrate/001_create_people.rb
|
36
|
+
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
37
|
+
- test/app_root/config
|
46
38
|
- test/app_root/config/environment.rb
|
39
|
+
- test/app_root/app
|
47
40
|
- test/app_root/app/models
|
48
41
|
- test/app_root/app/models/person.rb
|
49
|
-
- test/
|
50
|
-
- test/
|
51
|
-
- test/app_root/db/migrate/002_add_phone_number_kinds.rb
|
42
|
+
- test/test_helper.rb
|
43
|
+
- test/unit
|
52
44
|
- test/unit/phone_number_test.rb
|
53
|
-
- test/unit/has_phone_numbers_test.rb
|
54
45
|
- CHANGELOG
|
55
46
|
- init.rb
|
56
47
|
- MIT-LICENSE
|
57
48
|
- Rakefile
|
58
49
|
- README
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://www.pluginaweek.org
|
52
|
+
post_install_message:
|
62
53
|
rdoc_options: []
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
70
69
|
requirements: []
|
71
70
|
|
72
|
-
|
73
|
-
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.1.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 2
|
75
|
+
summary: Demonstrates a reference implementation for handling phone numbers.
|
76
|
+
test_files:
|
77
|
+
- test/unit/phone_number_test.rb
|
data/test/fixtures/people.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
cell:
|
2
|
-
id: 1
|
3
|
-
phoneable_id: 1
|
4
|
-
phoneable_type: Person
|
5
|
-
country_code: 1
|
6
|
-
number: 1234567890
|
7
|
-
created_at: <%= Time.now.to_s(:db) %>
|
8
|
-
updated_at: <%= Time.now.to_s(:db) %>
|
9
|
-
kind: cell
|
10
|
-
|
11
|
-
work:
|
12
|
-
id: 2
|
13
|
-
phoneable_id: 1
|
14
|
-
phoneable_type: Person
|
15
|
-
country_code: 1
|
16
|
-
number: 1234567891
|
17
|
-
extension: 123
|
18
|
-
created_at: <%= Time.now.to_s(:db) %>
|
19
|
-
updated_at: <%= Time.now.to_s(:db) %>
|
20
|
-
kind: work
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
|
3
|
-
class HasPhoneNumbersTest < Test::Unit::TestCase
|
4
|
-
fixtures :phone_numbers, :people
|
5
|
-
|
6
|
-
def test_should_create_one_association
|
7
|
-
assert_equal phone_numbers(:cell), people(:john_doe).cell_phone
|
8
|
-
assert_equal phone_numbers(:work), people(:john_doe).work_phone
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_create_many_association
|
12
|
-
assert_equal 2, people(:john_doe).phone_numbers.size
|
13
|
-
assert_equal [], [phone_numbers(:cell), phone_numbers(:work)] - people(:john_doe).phone_numbers
|
14
|
-
end
|
15
|
-
end
|
/data/test/app_root/db/migrate/{002_add_phone_number_kinds.rb → 003_add_phone_number_kinds.rb}
RENAMED
File without changes
|