lib/customer_fwd.rb 🔗
@@ -61,6 +61,11 @@ class CustomerFwd
true
end
+ def initialize(values)
+ super
+ raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/)
+ end
+
def to
uri.sub(/^tel:/, "")
end
Stephen Paul Weber created
Otherwise people can specify things that won't (or shouldn't) work.
lib/customer_fwd.rb | 5 +++++
test/test_customer_fwd.rb | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
@@ -61,6 +61,11 @@ class CustomerFwd
true
end
+ def initialize(values)
+ super
+ raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/)
+ end
+
def to
uri.sub(/^tel:/, "")
end
@@ -33,13 +33,19 @@ class CustomerFwdTest < Minitest::Test
assert_equal sip, fwd.to
end
- property(:for_tel) { "+#{string(:digit)}" }
+ property(:for_tel) { sized(10) { "+1#{string(:digit)}" } }
def for_tel(tel)
fwd = CustomerFwd.for(uri: "tel:#{tel}", timeout: 10)
assert_kind_of CustomerFwd::Tel, fwd
assert_equal tel, fwd.to
end
+ def test_for_bad_tel
+ assert_raises do
+ CustomerFwd.for(uri: "tel:2261234567", timeout: 10)
+ end
+ end
+
property(:for_sip) { "#{string(:alnum)}@#{string(:alnum)}.example.com" }
def for_sip(sip)
fwd = CustomerFwd.for(uri: "sip:#{sip}", timeout: 10)