phony_rails 0.1.4 → 0.1.5
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/README.md +1 -1
- data/lib/phony_rails/version.rb +1 -1
- data/lib/validators/phony_validator.rb +13 -1
- data/spec/lib/phony_validator_spec.rb +60 -0
- metadata +4 -2
data/README.md
CHANGED
data/lib/phony_rails/version.rb
CHANGED
@@ -9,4 +9,16 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
|
|
9
9
|
record.errors[attribute] << (options[:message] || "is an invalid number") if not Phony.plausible?(value)
|
10
10
|
end
|
11
11
|
|
12
|
-
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ActiveModel
|
15
|
+
module Validations
|
16
|
+
module HelperMethods
|
17
|
+
|
18
|
+
def validates_plausible_phone(*attr_names)
|
19
|
+
validates_with PhonyPlausibleValidator, _merge_attributes(attr_names)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
create_table :validating_homes do |table|
|
5
|
+
table.column :phone_number, :string
|
6
|
+
table.column :fax_number, :string
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ValidatingHome < ActiveRecord::Base
|
11
|
+
attr_accessor :phone_method, :fax_number
|
12
|
+
validates :phone_number, :phony_plausible => true
|
13
|
+
validates_plausible_phone :fax_number
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
describe PhonyPlausibleValidator do
|
19
|
+
|
20
|
+
describe 'validates' do
|
21
|
+
before(:each) do
|
22
|
+
@home = ValidatingHome.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should validate an empty number" do
|
26
|
+
@home.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should validate a valid number" do
|
30
|
+
@home.phone_number = '123456789'
|
31
|
+
@home.should be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should invalidate an invalid number" do
|
35
|
+
@home.phone_number = '123456789 123456789 123456789 123456789'
|
36
|
+
@home.should_not be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'validates_plausible_phone' do
|
41
|
+
before(:each) do
|
42
|
+
@home = ValidatingHome.new
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should validate an empty number" do
|
46
|
+
@home.should be_valid
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should validate a valid number" do
|
50
|
+
@home.fax_number = '123456789'
|
51
|
+
@home.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should invalidate an invalid number" do
|
55
|
+
@home.fax_number = '123456789 123456789 123456789 123456789'
|
56
|
+
@home.should_not be_valid
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joost Hietbrink
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/validators/phony_validator.rb
|
80
80
|
- phony_rails.gemspec
|
81
81
|
- spec/lib/phony_rails_spec.rb
|
82
|
+
- spec/lib/phony_validator_spec.rb
|
82
83
|
- spec/spec_helper.rb
|
83
84
|
has_rdoc: true
|
84
85
|
homepage: https://github.com/joost/phony_rails
|
@@ -112,4 +113,5 @@ specification_version: 3
|
|
112
113
|
summary: This Gem adds useful methods to your Rails app to validate, display and save phone numbers.
|
113
114
|
test_files:
|
114
115
|
- spec/lib/phony_rails_spec.rb
|
116
|
+
- spec/lib/phony_validator_spec.rb
|
115
117
|
- spec/spec_helper.rb
|