has_phone_numbers 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +23 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/{README → README.rdoc} +9 -9
- data/Rakefile +44 -36
- data/app/models/phone_number.rb +17 -3
- data/lib/has_phone_numbers.rb +1 -7
- data/test/app_root/app/models/person.rb +1 -7
- data/test/factory.rb +31 -21
- data/test/functional/has_phone_numbers_test.rb +22 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/phone_number_test.rb +22 -4
- metadata +11 -10
- data/CHANGELOG +0 -19
- data/test/app_root/db/migrate/003_add_phone_number_kinds.rb +0 -9
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
== master
|
2
|
+
|
3
|
+
== 0.0.5 / 2008-10-26
|
4
|
+
|
5
|
+
* Change how the base module is included to prevent namespacing conflicts
|
6
|
+
* Change PhoneNumber#to_s to PhoneNumber#display_value
|
7
|
+
|
8
|
+
== 0.0.4 / 2008-06-22
|
9
|
+
|
10
|
+
* Remove log files from gems
|
11
|
+
|
12
|
+
== 0.0.3 / 2008-05-05
|
13
|
+
|
14
|
+
* Updated documentation
|
15
|
+
|
16
|
+
== 0.0.2 / 2007-09-26
|
17
|
+
|
18
|
+
* Move test fixtures out of the test application root directory
|
19
|
+
|
20
|
+
== 0.0.1 / 2007-08-21
|
21
|
+
|
22
|
+
* Added documentation
|
23
|
+
* Removed dependency on has_association_helper
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/{README → README.rdoc}
RENAMED
@@ -4,21 +4,21 @@
|
|
4
4
|
|
5
5
|
== Resources
|
6
6
|
|
7
|
-
Wiki
|
8
|
-
|
9
|
-
* http://wiki.pluginaweek.org/Has_phone_numbers
|
10
|
-
|
11
7
|
API
|
12
8
|
|
13
9
|
* http://api.pluginaweek.org/has_phone_numbers
|
14
10
|
|
11
|
+
Bugs
|
12
|
+
|
13
|
+
* http://pluginaweek.lighthouseapp.com/projects/13275-has_phone_numbers
|
14
|
+
|
15
15
|
Development
|
16
16
|
|
17
|
-
* http://
|
17
|
+
* http://github.com/pluginaweek/has_phone_numbers
|
18
18
|
|
19
19
|
Source
|
20
20
|
|
21
|
-
*
|
21
|
+
* git://github.com/pluginaweek/has_phone_numbers.git
|
22
22
|
|
23
23
|
== Description
|
24
24
|
|
@@ -39,12 +39,12 @@ modified for your own usage.
|
|
39
39
|
:number => '1234567890',
|
40
40
|
:extension => '123'
|
41
41
|
)
|
42
|
-
phone_number.
|
42
|
+
phone_number.display_value # => 1- 1234567890 ext. 123
|
43
43
|
|
44
44
|
== Testing
|
45
45
|
|
46
46
|
Before you can run any tests, the following gem must be installed:
|
47
|
-
* plugin_test_helper[http://
|
47
|
+
* plugin_test_helper[http://github.com/pluginaweek/plugin_test_helper]
|
48
48
|
|
49
49
|
To run against a specific version of Rails:
|
50
50
|
|
@@ -53,4 +53,4 @@ To run against a specific version of Rails:
|
|
53
53
|
== Dependencies
|
54
54
|
|
55
55
|
* Rails 2.1 or later
|
56
|
-
* plugins_plus[http://
|
56
|
+
* plugins_plus[http://github.com/pluginaweek/plugins_plugins] (optional if app files are copied to your project tree)
|
data/Rakefile
CHANGED
@@ -3,46 +3,54 @@ require 'rake/rdoctask'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
spec = Gem::Specification.new do |s|
|
7
|
+
s.name = 'has_phone_numbers'
|
8
|
+
s.version = '0.0.5'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'Demonstrates a reference implementation for handling phone numbers.'
|
11
|
+
|
12
|
+
s.files = FileList['{app,db,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
|
+
s.require_path = 'lib'
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.test_files = Dir['test/**/*_test.rb']
|
16
|
+
|
17
|
+
s.author = 'Aaron Pfeifer'
|
18
|
+
s.email = 'aaron@pluginaweek.org'
|
19
|
+
s.homepage = 'http://www.pluginaweek.org'
|
20
|
+
s.rubyforge_project = 'pluginaweek'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Default: run all tests.'
|
12
24
|
task :default => :test
|
13
25
|
|
14
|
-
desc
|
26
|
+
desc "Test the #{spec.name} plugin."
|
15
27
|
Rake::TestTask.new(:test) do |t|
|
16
28
|
t.libs << 'lib'
|
17
|
-
t.
|
29
|
+
t.test_files = spec.test_files
|
18
30
|
t.verbose = true
|
19
31
|
end
|
20
32
|
|
21
|
-
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
namespace :test do
|
36
|
+
desc "Test the #{spec.name} plugin with Rcov."
|
37
|
+
Rcov::RcovTask.new(:rcov) do |t|
|
38
|
+
t.libs << 'lib'
|
39
|
+
t.test_files = spec.test_files
|
40
|
+
t.rcov_opts << '--exclude="^(?!lib/|app/)"'
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Generate documentation for the #{spec.name} plugin."
|
22
48
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
49
|
rdoc.rdoc_dir = 'rdoc'
|
24
|
-
rdoc.title =
|
50
|
+
rdoc.title = spec.name
|
25
51
|
rdoc.template = '../rdoc_template.rb'
|
26
52
|
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
-
rdoc.rdoc_files.include('README')
|
28
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
-
end
|
30
|
-
|
31
|
-
spec = Gem::Specification.new do |s|
|
32
|
-
s.name = PKG_NAME
|
33
|
-
s.version = PKG_VERSION
|
34
|
-
s.platform = Gem::Platform::RUBY
|
35
|
-
s.summary = 'Demonstrates a reference implementation for handling phone numbers.'
|
36
|
-
|
37
|
-
s.files = FileList['{app,db,lib,test}/**/*'].to_a - FileList['test/app_root/log/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
38
|
-
s.require_path = 'lib'
|
39
|
-
s.autorequire = 'has_phone_numbers'
|
40
|
-
s.has_rdoc = true
|
41
|
-
s.test_files = Dir['test/**/*_test.rb']
|
42
|
-
|
43
|
-
s.author = 'Aaron Pfeifer'
|
44
|
-
s.email = 'aaron@pluginaweek.org'
|
45
|
-
s.homepage = 'http://www.pluginaweek.org'
|
53
|
+
rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb', 'app/**/*.rb')
|
46
54
|
end
|
47
55
|
|
48
56
|
Rake::GemPackageTask.new(spec) do |p|
|
@@ -51,14 +59,14 @@ Rake::GemPackageTask.new(spec) do |p|
|
|
51
59
|
p.need_zip = true
|
52
60
|
end
|
53
61
|
|
54
|
-
desc 'Publish the beta gem'
|
62
|
+
desc 'Publish the beta gem.'
|
55
63
|
task :pgem => [:package] do
|
56
|
-
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{
|
64
|
+
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
|
57
65
|
end
|
58
66
|
|
59
|
-
desc 'Publish the API documentation'
|
67
|
+
desc 'Publish the API documentation.'
|
60
68
|
task :pdoc => [:rdoc] do
|
61
|
-
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{
|
69
|
+
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
|
62
70
|
end
|
63
71
|
|
64
72
|
desc 'Publish the API docs and gem'
|
@@ -71,10 +79,10 @@ task :release => [:gem, :package] do
|
|
71
79
|
ruby_forge = RubyForge.new.configure
|
72
80
|
ruby_forge.login
|
73
81
|
|
74
|
-
%w(
|
75
|
-
file = "pkg/#{
|
82
|
+
%w(gem tgz zip).each do |ext|
|
83
|
+
file = "pkg/#{spec.name}-#{spec.version}.#{ext}"
|
76
84
|
puts "Releasing #{File.basename(file)}..."
|
77
85
|
|
78
|
-
ruby_forge.add_release(
|
86
|
+
ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
|
79
87
|
end
|
80
88
|
end
|
data/app/models/phone_number.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# Represents a phone number
|
1
|
+
# Represents a phone number split into multiple parts:
|
2
|
+
# * +country_code+ - Uniquely identifiers the country to which the number belongs. This value is based on the E.164 standard (http://en.wikipedia.org/wiki/E.164)
|
3
|
+
# * +number+ - The subscriber number (10 digits in length)
|
4
|
+
# * +extension+ - A number that can route to different phones at a location
|
5
|
+
#
|
6
|
+
# This phone number format is biased towards those types found in the United
|
7
|
+
# States and may need to be adjusted for international support.
|
2
8
|
class PhoneNumber < ActiveRecord::Base
|
3
9
|
belongs_to :phoneable,
|
4
10
|
:polymorphic => true
|
@@ -19,10 +25,18 @@ class PhoneNumber < ActiveRecord::Base
|
|
19
25
|
:maximum => 10,
|
20
26
|
:allow_nil => true
|
21
27
|
|
22
|
-
|
28
|
+
# Generates a human-readable version of the phone number, based on all of the
|
29
|
+
# various parts of the number.
|
30
|
+
#
|
31
|
+
# For example,
|
32
|
+
#
|
33
|
+
# phone = PhoneNumber.new(:country_code => '1', :number => '123-456-7890')
|
34
|
+
# phone.display_value # => "1- 123-456-7890"
|
35
|
+
# phone.extension = "123"
|
36
|
+
# phone.display_value # => "1- 123-456-7890 ext. 123"
|
37
|
+
def display_value
|
23
38
|
human_number = "#{country_code}- #{number}"
|
24
39
|
human_number << " ext. #{extension}" if extension
|
25
|
-
|
26
40
|
human_number
|
27
41
|
end
|
28
42
|
end
|
data/lib/has_phone_numbers.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
module PluginAWeek #:nodoc:
|
2
2
|
# Adds a generic implementation for dealing with phone numbers
|
3
3
|
module HasPhoneNumbers
|
4
|
-
def self.included(base) #:nodoc:
|
5
|
-
base.class_eval do
|
6
|
-
extend PluginAWeek::HasPhoneNumbers::MacroMethods
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
module MacroMethods
|
11
5
|
# Creates the following association:
|
12
6
|
# * +phone_number+ - All phone numbers associated with the current record.
|
@@ -19,5 +13,5 @@ module PluginAWeek #:nodoc:
|
|
19
13
|
end
|
20
14
|
|
21
15
|
ActiveRecord::Base.class_eval do
|
22
|
-
|
16
|
+
extend PluginAWeek::HasPhoneNumbers::MacroMethods
|
23
17
|
end
|
@@ -1,9 +1,3 @@
|
|
1
1
|
class Person < ActiveRecord::Base
|
2
|
-
|
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
|
2
|
+
has_phone_numbers
|
9
3
|
end
|
data/test/factory.rb
CHANGED
@@ -1,26 +1,36 @@
|
|
1
1
|
module Factory
|
2
|
-
# Build actions for the
|
3
|
-
def self.build(
|
4
|
-
name =
|
5
|
-
define_method("#{name}_attributes", block)
|
2
|
+
# Build actions for the model
|
3
|
+
def self.build(model, &block)
|
4
|
+
name = model.to_s.underscore
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
define_method("#{name}_attributes", block)
|
7
|
+
define_method("valid_#{name}_attributes") {|*args| valid_attributes_for(model, *args)}
|
8
|
+
define_method("new_#{name}") {|*args| new_record(model, *args)}
|
9
|
+
define_method("create_#{name}") {|*args| create_record(model, *args)}
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get valid attributes for the model
|
13
|
+
def valid_attributes_for(model, attributes = {})
|
14
|
+
name = model.to_s.underscore
|
15
|
+
send("#{name}_attributes", attributes)
|
16
|
+
attributes.stringify_keys!
|
17
|
+
attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
# Build an unsaved record
|
21
|
+
def new_record(model, *args)
|
22
|
+
attributes = valid_attributes_for(model, *args)
|
23
|
+
record = model.new(attributes)
|
24
|
+
attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
|
25
|
+
record
|
26
|
+
end
|
27
|
+
|
28
|
+
# Build and save/reload a record
|
29
|
+
def create_record(model, *args)
|
30
|
+
record = new_record(model, *args)
|
31
|
+
record.save!
|
32
|
+
record.reload
|
33
|
+
record
|
24
34
|
end
|
25
35
|
|
26
36
|
build Person do |attributes|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class PersonByDefaultTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@person = create_person
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_not_have_any_phone_numbers
|
9
|
+
assert @person.phone_numbers.empty?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class PersonWithPhoneNumbersTest < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@person = create_person
|
16
|
+
@phone_number = create_phone_number(:phoneable => @person)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_have_phone_numbers
|
20
|
+
assert_equal [@phone_number], @person.phone_numbers
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -113,6 +113,24 @@ class PhoneNumberTest < Test::Unit::TestCase
|
|
113
113
|
assert !phone_number.valid?
|
114
114
|
assert_equal 1, Array(phone_number.errors.on(:extension)).size
|
115
115
|
end
|
116
|
+
|
117
|
+
def test_should_protect_attributes_from_mass_assignment
|
118
|
+
phone_number = PhoneNumber.new(
|
119
|
+
:id => 1,
|
120
|
+
:phoneable_id => 1,
|
121
|
+
:phoneable_type => 'User',
|
122
|
+
:country_code => '123',
|
123
|
+
:number => '8675309',
|
124
|
+
:extension => '999'
|
125
|
+
)
|
126
|
+
|
127
|
+
assert_nil phone_number.id
|
128
|
+
assert_equal 1, phone_number.phoneable_id
|
129
|
+
assert_equal 'User', phone_number.phoneable_type
|
130
|
+
assert_equal '123', phone_number.country_code
|
131
|
+
assert_equal '8675309', phone_number.number
|
132
|
+
assert_equal '999', phone_number.extension
|
133
|
+
end
|
116
134
|
end
|
117
135
|
|
118
136
|
class PhoneNumberAfterBeingCreatedTest < Test::Unit::TestCase
|
@@ -133,8 +151,8 @@ class PhoneNumberAfterBeingCreatedTest < Test::Unit::TestCase
|
|
133
151
|
assert_equal @person, @phone_number.phoneable
|
134
152
|
end
|
135
153
|
|
136
|
-
def
|
137
|
-
assert_equal '1- 1234567890', @phone_number.
|
154
|
+
def test_should_have_a_display_value
|
155
|
+
assert_equal '1- 1234567890', @phone_number.display_value
|
138
156
|
end
|
139
157
|
end
|
140
158
|
|
@@ -143,7 +161,7 @@ class PhoneNumberWithExtensionTest < Test::Unit::TestCase
|
|
143
161
|
@phone_number = create_phone_number(:country_code => '1', :number => '1234567890', :extension => '123')
|
144
162
|
end
|
145
163
|
|
146
|
-
def
|
147
|
-
assert_equal '1- 1234567890 ext. 123', @phone_number.
|
164
|
+
def test_should_have_a_display_value
|
165
|
+
assert_equal '1- 1234567890 ext. 123', @phone_number.display_value
|
148
166
|
end
|
149
167
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_phone_numbers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,17 +37,17 @@ files:
|
|
37
37
|
- test/app_root/db/migrate
|
38
38
|
- test/app_root/db/migrate/001_create_people.rb
|
39
39
|
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
40
|
-
- test/
|
41
|
-
- test/
|
40
|
+
- test/functional
|
41
|
+
- test/functional/has_phone_numbers_test.rb
|
42
42
|
- test/test_helper.rb
|
43
43
|
- test/factory.rb
|
44
44
|
- test/unit
|
45
45
|
- test/unit/phone_number_test.rb
|
46
|
-
- CHANGELOG
|
46
|
+
- CHANGELOG.rdoc
|
47
47
|
- init.rb
|
48
|
-
-
|
48
|
+
- LICENSE
|
49
49
|
- Rakefile
|
50
|
-
- README
|
50
|
+
- README.rdoc
|
51
51
|
has_rdoc: true
|
52
52
|
homepage: http://www.pluginaweek.org
|
53
53
|
post_install_message:
|
@@ -69,10 +69,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version:
|
70
70
|
requirements: []
|
71
71
|
|
72
|
-
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
72
|
+
rubyforge_project: pluginaweek
|
73
|
+
rubygems_version: 1.2.0
|
74
74
|
signing_key:
|
75
75
|
specification_version: 2
|
76
76
|
summary: Demonstrates a reference implementation for handling phone numbers.
|
77
77
|
test_files:
|
78
|
+
- test/functional/has_phone_numbers_test.rb
|
78
79
|
- test/unit/phone_number_test.rb
|
data/CHANGELOG
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
*SVN*
|
2
|
-
|
3
|
-
*0.0.4* (June 22nd, 2008)
|
4
|
-
|
5
|
-
* Remove log files from gems
|
6
|
-
|
7
|
-
*0.0.3* (May 5th, 2008)
|
8
|
-
|
9
|
-
* Updated documentation
|
10
|
-
|
11
|
-
*0.0.2* (September 26th, 2007)
|
12
|
-
|
13
|
-
* Move test fixtures out of the test application root directory
|
14
|
-
|
15
|
-
*0.0.1* (August 21st, 2007)
|
16
|
-
|
17
|
-
* Added documentation
|
18
|
-
|
19
|
-
* Removed dependency on has_association_helper
|