phony_rails 0.1.0 → 0.1.1

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.
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ phony_rails (0.1.0)
5
+ activerecord (~> 3.0)
6
+ phony (~> 1.7.4)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.6)
12
+ activesupport (= 3.2.6)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.6)
15
+ activemodel (= 3.2.6)
16
+ activesupport (= 3.2.6)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.6)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ arel (3.0.2)
23
+ builder (3.0.0)
24
+ diff-lcs (1.1.3)
25
+ i18n (0.6.0)
26
+ multi_json (1.3.6)
27
+ phony (1.7.4)
28
+ rspec (2.10.0)
29
+ rspec-core (~> 2.10.0)
30
+ rspec-expectations (~> 2.10.0)
31
+ rspec-mocks (~> 2.10.0)
32
+ rspec-core (2.10.1)
33
+ rspec-expectations (2.10.0)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.10.1)
36
+ sqlite3 (1.3.6)
37
+ tzinfo (0.3.33)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ phony_rails!
44
+ rspec
45
+ sqlite3
data/README.md CHANGED
@@ -42,6 +42,9 @@ In your views use:
42
42
 
43
43
  ## Changelog
44
44
 
45
+ 0.1.0
46
+ * Added specs.
47
+
45
48
  0.0.10
46
49
  * Same fix as 0.0.9 but for phony_formatted method.
47
50
 
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = PhonyRails::VERSION
17
17
 
18
- gem.add_dependency "phony", "~> 1.6.7"
18
+ gem.add_dependency "phony", "~> 1.7.4"
19
19
  gem.add_dependency "activerecord", "~> 3.0"
20
20
  end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+ describe PhonyRails do
3
+
4
+ describe 'String extensions' do
5
+ it "should phony_format a String" do
6
+ "31101234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-1234123')
7
+ end
8
+ end
9
+
10
+ describe 'PhonyRails#normalize_number' do
11
+ it "should normalize a number with a default_country_code" do
12
+ PhonyRails.normalize_number('010-1234123', :default_country_code => 'NL').should eql('31101234123')
13
+ end
14
+
15
+ it "should normalize a number with a country_code" do
16
+ PhonyRails.normalize_number('010-1234123', :country_code => 'NL', :default_country_code => 'DE').should eql('31101234123')
17
+ PhonyRails.normalize_number('010-1234123', :country_code => 'NL').should eql('31101234123')
18
+ end
19
+
20
+ it "should handle different countries" do
21
+ PhonyRails.normalize_number('(030) 8 61 29 06', :country_code => 'DE').should eql('49308612906')
22
+ PhonyRails.normalize_number('+43 664 3830412', :country_code => 'AT').should eql('436643830412')
23
+ PhonyRails.normalize_number('0203 330 8897', :country_code => 'GB').should eql('442033308897')
24
+ end
25
+
26
+ it "should handle some edge cases" do
27
+ PhonyRails.normalize_number('some nasty stuff in this +31 number 10-1234123 string', :country_code => 'NL').should eql('31101234123')
28
+ PhonyRails.normalize_number('070-4157134', :country_code => 'NL').should eql('31704157134')
29
+ PhonyRails.normalize_number('0031-70-4157134', :country_code => 'NL').should eql('31704157134')
30
+ PhonyRails.normalize_number('+31-70-4157134', :country_code => 'NL').should eql('31704157134')
31
+ PhonyRails.normalize_number('0323-2269497', :country_code => 'BE').should eql('323232269497')
32
+ end
33
+ end
34
+
35
+ describe 'defining ActiveRecord#phony_normalized_method' do
36
+ it "should add a normalized_phone_attribute method" do
37
+ Home.new.should respond_to(:normalized_phone_attribute)
38
+ end
39
+
40
+ it "should add a normalized_phone_method method" do
41
+ Home.new.should respond_to(:normalized_phone_method)
42
+ end
43
+
44
+ it "should raise error on existing methods" do
45
+ lambda {
46
+ Home.phony_normalized_method(:phone_method)
47
+ }.should raise_error(StandardError)
48
+ end
49
+
50
+ it "should raise error on not existing attribute" do
51
+ Home.phony_normalized_method(:phone_non_existing_method)
52
+ lambda {
53
+ Home.new.normalized_phone_non_existing_method
54
+ }.should raise_error(ArgumentError)
55
+ end
56
+ end
57
+
58
+ describe 'using ActiveRecord#phony_normalized_method' do
59
+ # Following examples have complete number (with country code!)
60
+ it "should return a normalized version of an attribute" do
61
+ home = Home.new(:phone_attribute => "+31-(0)10-1234123")
62
+ home.normalized_phone_attribute.should eql('31101234123')
63
+ end
64
+
65
+ it "should return a normalized version of a method" do
66
+ home = Home.new(:phone_method => "+31-(0)10-1234123")
67
+ home.normalized_phone_method.should eql('31101234123')
68
+ end
69
+
70
+ # Following examples have incomplete number
71
+ it "should return nil if no country_code is known" do
72
+ home = Home.new(:phone_attribute => "(0)10-1234123")
73
+ home.normalized_phone_attribute.should eql('11234123') # This actually is an incorrect number! (FIXME?)
74
+ end
75
+
76
+ it "should use country_code option" do
77
+ home = Home.new(:phone_attribute => "(0)10-1234123")
78
+ home.normalized_phone_attribute(:country_code => 'NL').should eql('31101234123')
79
+ end
80
+
81
+ it "should use country_code object method" do
82
+ home = Home.new(:phone_attribute => "(0)10-1234123", :country_code => 'NL')
83
+ home.normalized_phone_attribute.should eql('31101234123')
84
+ end
85
+
86
+ it "should fallback to default_country_code option" do
87
+ home = Home.new(:phone1_method => "(030) 8 61 29 06")
88
+ home.normalized_phone1_method.should eql('49308612906')
89
+ end
90
+
91
+ it "should overwrite default_country_code option with object method" do
92
+ home = Home.new(:phone1_method => "(030) 8 61 29 06", :country_code => 'NL')
93
+ home.normalized_phone1_method.should eql('31308612906')
94
+ end
95
+
96
+ it "should overwrite default_country_code option with option" do
97
+ home = Home.new(:phone1_method => "(030) 8 61 29 06")
98
+ home.normalized_phone1_method(:country_code => 'NL').should eql('31308612906')
99
+ end
100
+
101
+ it "should use last passed options" do
102
+ home = Home.new(:phone1_method => "(030) 8 61 29 06")
103
+ home.normalized_phone1_method(:country_code => 'NL').should eql('31308612906')
104
+ home.normalized_phone1_method(:country_code => 'DE').should eql('49308612906')
105
+ home.normalized_phone1_method(:country_code => nil).should eql('49308612906')
106
+ end
107
+
108
+ it "should use last object method" do
109
+ home = Home.new(:phone1_method => "(030) 8 61 29 06")
110
+ home.country_code = 'NL'
111
+ home.normalized_phone1_method.should eql('31308612906')
112
+ home.country_code = 'DE'
113
+ home.normalized_phone1_method.should eql('49308612906')
114
+ home.country_code = nil
115
+ home.normalized_phone1_method(:country_code => nil).should eql('49308612906')
116
+ end
117
+ end
118
+
119
+ describe 'using ActiveRecord#phony_normalize' do
120
+ it "should set a normalized version of an attribute" do
121
+ home = Home.new(:phone_number => "+31-(0)10-1234123")
122
+ home.valid?
123
+ home.phone_number.should eql('31101234123')
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+
5
+ require 'active_record'
6
+ require 'phony_rails'
7
+
8
+ ActiveRecord::Base.establish_connection(
9
+ :adapter => "sqlite3",
10
+ :database => ":memory:"
11
+ )
12
+
13
+ ActiveRecord::Schema.define do
14
+ create_table :homes do |table|
15
+ table.column :phone_attribute, :string
16
+ table.column :phone_number, :string
17
+ end
18
+ end
19
+
20
+ class Home < ActiveRecord::Base
21
+ attr_accessor :phone_method, :phone1_method, :country_code
22
+ phony_normalized_method :phone_attribute # adds normalized_phone_attribute method
23
+ phony_normalized_method :phone_method # adds normalized_phone_method method
24
+ phony_normalized_method :phone1_method, :default_country_code => 'DE' # adds normalized_phone_method method
25
+ phony_normalize :phone_number # normalized on validation
26
+ end
27
+
28
+ RSpec.configure do |config|
29
+ # some (optional) config here
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-07 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: phony
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.6.7
21
+ version: 1.7.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.6.7
29
+ version: 1.7.4
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activerecord
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - Gemfile
55
+ - Gemfile.lock
55
56
  - LICENSE
56
57
  - README.md
57
58
  - Rakefile
@@ -60,6 +61,8 @@ files:
60
61
  - lib/phony_rails/version.rb
61
62
  - lib/validators/phony_validator.rb
62
63
  - phony_rails.gemspec
64
+ - spec/lib/phony_rails_spec.rb
65
+ - spec/spec_helper.rb
63
66
  homepage: ''
64
67
  licenses: []
65
68
  post_install_message:
@@ -85,4 +88,7 @@ signing_key:
85
88
  specification_version: 3
86
89
  summary: This Gem adds useful methods to your Rails app to validate, display and save
87
90
  phone numbers.
88
- test_files: []
91
+ test_files:
92
+ - spec/lib/phony_rails_spec.rb
93
+ - spec/spec_helper.rb
94
+ has_rdoc: