has_phone_numbers 0.0.5 → 0.1.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 +4 -0
- data/Rakefile +1 -1
- data/lib/has_phone_numbers.rb +9 -11
- data/test/unit/phone_number_test.rb +13 -13
- metadata +14 -14
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'has_phone_numbers'
|
8
|
-
s.version = '0.0
|
8
|
+
s.version = '0.1.0'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Demonstrates a reference implementation for handling phone numbers.'
|
11
11
|
|
data/lib/has_phone_numbers.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:as => :phoneable
|
10
|
-
end
|
1
|
+
# Adds a generic implementation for dealing with phone numbers
|
2
|
+
module HasPhoneNumbers
|
3
|
+
module MacroMethods
|
4
|
+
# Creates the following association:
|
5
|
+
# * +phone_number+ - All phone numbers associated with the current record.
|
6
|
+
def has_phone_numbers
|
7
|
+
has_many :phone_numbers,
|
8
|
+
:as => :phoneable
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
ActiveRecord::Base.class_eval do
|
16
|
-
extend
|
14
|
+
extend HasPhoneNumbers::MacroMethods
|
17
15
|
end
|
@@ -33,33 +33,33 @@ class PhoneNumberTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_should_require_a_phoneable_id
|
36
|
-
phone_number = new_phone_number(:phoneable_id => nil)
|
36
|
+
phone_number = new_phone_number(:phoneable => nil, :phoneable_id => nil)
|
37
37
|
assert !phone_number.valid?
|
38
|
-
|
38
|
+
assert phone_number.errors.invalid?(:phoneable_id)
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_require_a_phoneable_type
|
42
|
-
phone_number = new_phone_number(:phoneable_type => nil)
|
42
|
+
phone_number = new_phone_number(:phoneable => nil, :phoneable_type => nil)
|
43
43
|
assert !phone_number.valid?
|
44
|
-
|
44
|
+
assert phone_number.errors.invalid?(:phoneable_type)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_should_require_a_country_code
|
48
48
|
phone_number = new_phone_number(:country_code => nil)
|
49
49
|
assert !phone_number.valid?
|
50
|
-
|
50
|
+
assert phone_number.errors.invalid?(:country_code)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_should_require_country_code_be_a_number
|
54
54
|
phone_number = new_phone_number(:country_code => 'a')
|
55
55
|
assert !phone_number.valid?
|
56
|
-
|
56
|
+
assert phone_number.errors.invalid?(:country_code)
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_should_require_country_codes_be_between_1_and_3_numbers
|
60
60
|
phone_number = new_phone_number(:country_code => '')
|
61
61
|
assert !phone_number.valid?
|
62
|
-
|
62
|
+
assert phone_number.errors.invalid?(:country_code)
|
63
63
|
|
64
64
|
phone_number.country_code += '1'
|
65
65
|
assert phone_number.valid?
|
@@ -69,32 +69,32 @@ class PhoneNumberTest < Test::Unit::TestCase
|
|
69
69
|
|
70
70
|
phone_number.country_code += '1'
|
71
71
|
assert !phone_number.valid?
|
72
|
-
|
72
|
+
assert phone_number.errors.invalid?(:country_code)
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_should_require_a_number
|
76
76
|
phone_number = new_phone_number(:number => nil)
|
77
77
|
assert !phone_number.valid?
|
78
|
-
|
78
|
+
assert phone_number.errors.invalid?(:number)
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_should_require_number_be_a_number
|
82
82
|
phone_number = new_phone_number(:number => 'a' * 10)
|
83
83
|
assert !phone_number.valid?
|
84
|
-
|
84
|
+
assert phone_number.errors.invalid?(:number)
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_should_require_number_be_exactly_10_numbers
|
88
88
|
phone_number = new_phone_number(:number => '1' * 9)
|
89
89
|
assert !phone_number.valid?
|
90
|
-
|
90
|
+
assert phone_number.errors.invalid?(:number)
|
91
91
|
|
92
92
|
phone_number.number += '1'
|
93
93
|
assert phone_number.valid?
|
94
94
|
|
95
95
|
phone_number.number += '1'
|
96
96
|
assert !phone_number.valid?
|
97
|
-
|
97
|
+
assert phone_number.errors.invalid?(:number)
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_should_not_require_an_extension
|
@@ -111,7 +111,7 @@ class PhoneNumberTest < Test::Unit::TestCase
|
|
111
111
|
|
112
112
|
phone_number.extension += '1'
|
113
113
|
assert !phone_number.valid?
|
114
|
-
|
114
|
+
assert phone_number.errors.invalid?(:extension)
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_should_protect_attributes_from_mass_assignment
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,22 +27,22 @@ files:
|
|
27
27
|
- db/migrate
|
28
28
|
- db/migrate/001_create_phone_numbers.rb
|
29
29
|
- lib/has_phone_numbers.rb
|
30
|
-
- test/
|
31
|
-
- test/
|
32
|
-
- test/app_root/app/models
|
33
|
-
- test/app_root/app/models/person.rb
|
34
|
-
- test/app_root/config
|
35
|
-
- test/app_root/config/environment.rb
|
36
|
-
- test/app_root/db
|
37
|
-
- test/app_root/db/migrate
|
38
|
-
- test/app_root/db/migrate/001_create_people.rb
|
39
|
-
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
30
|
+
- test/factory.rb
|
31
|
+
- test/test_helper.rb
|
40
32
|
- test/functional
|
41
33
|
- test/functional/has_phone_numbers_test.rb
|
42
|
-
- test/test_helper.rb
|
43
|
-
- test/factory.rb
|
44
34
|
- test/unit
|
45
35
|
- test/unit/phone_number_test.rb
|
36
|
+
- test/app_root
|
37
|
+
- test/app_root/db
|
38
|
+
- test/app_root/db/migrate
|
39
|
+
- test/app_root/db/migrate/002_migrate_has_phone_numbers_to_version_1.rb
|
40
|
+
- test/app_root/db/migrate/001_create_people.rb
|
41
|
+
- test/app_root/config
|
42
|
+
- test/app_root/config/environment.rb
|
43
|
+
- test/app_root/app
|
44
|
+
- test/app_root/app/models
|
45
|
+
- test/app_root/app/models/person.rb
|
46
46
|
- CHANGELOG.rdoc
|
47
47
|
- init.rb
|
48
48
|
- LICENSE
|