Created
January 13, 2013 23:54
-
-
Save sxross/4526913 to your computer and use it in GitHub Desktop.
Spec for core_extensions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://gist.github.com/4526905 for the code this tests | |
describe "core helpers" do | |
it "has a 'to_us_phone' method" do | |
'hello'.should.respond_to? :to_us_phone | |
end | |
describe "7-digit phone numbers" do | |
it "formats string" do | |
'1112222'.to_us_phone.should == '111-2222' | |
end | |
it "formats phone number stored as a number" do | |
1112222.to_us_phone.should == '111-2222' | |
end | |
end | |
describe "10-digit phone numbers" do | |
it "formats string" do | |
'111-222-3333'.to_us_phone.should == '(111) 222-3333' | |
end | |
it "formats phone number stored as a number" do | |
1112223333.to_us_phone.should == '(111) 222-3333' | |
end | |
end | |
describe "long distance numbers" do | |
it "formats string" do | |
'1 111-222-3333'.to_us_phone.should == '+1 (111) 222-3333' | |
end | |
it "formats phone number stored as a number" do | |
11112223333.to_us_phone.should == '+1 (111) 222-3333' | |
end | |
end | |
describe "numbers in a class" do | |
class Foo | |
attr_reader :result | |
include MotionModel::Model | |
include MotionModel::Formotion | |
include MotionModel::Validatable | |
include Comparable | |
columns :foo_phone => :string | |
def before_save(o) | |
@result = o.foo_phone.to_us_phone | |
end | |
def get_number(num) | |
num.to_us_phone | |
end | |
end | |
it "get a phone number" do | |
Foo.new.get_number(11112223333).should == '+1 (111) 222-3333' | |
end | |
it "also gets one in callback" do | |
f = Foo.new(:foo_phone => '111-222-3333') | |
f.save | |
f.result.should == '(111) 222-3333' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment