Permalink
Browse files

Add some validation for originator.

  • Loading branch information...
1 parent e5dd443 commit 6ea2c5848681a20c802e2c5b00641928748a4ecb @alloy alloy committed Aug 2, 2010
Showing with 36 additions and 0 deletions.
  1. +14 −0 lib/mollie/sms.rb
  2. +22 −0 spec/sms_spec.rb
View
@@ -19,7 +19,10 @@ class SMS
'landline' => '8'
}
+ class StandardError < ::StandardError; end
+ class ValidationError < StandardError; end
class MissingRequiredParam < StandardError; end
+
REQUIRED_PARAMS = %w{ username md5_password originator gateway charset type recipients message }
class << self
@@ -29,6 +32,17 @@ def password=(password)
@password = Digest::MD5.hexdigest(password)
end
+ def originator=(originator)
+ if originator =~ /^\d+$/
+ if originator.size > 14
+ raise ValidationError, "Originator may have a maximimun of 14 numerical characters."
+ end
+ elsif originator.size > 11
+ raise ValidationError, "Originator may have a maximimun of 11 alphanumerical characters."
+ end
+ @originator = originator
+ end
+
def default_params
{
'username' => @username,
View
@@ -206,3 +206,25 @@
@response.message.should == "[HTTP: 400] Bad request"
end
end
+
+describe "Mollie::SMS, concerning validation" do
+ it "accepts an originator of upto 14 numbers" do
+ lambda { Mollie::SMS.originator = "00000000001111" }.should.not.raise
+ end
+
+ it "does not accept an originator string with more than 14 numbers" do
+ lambda do
+ Mollie::SMS.originator = "000000000011112"
+ end.should.raise(Mollie::SMS::ValidationError, "Originator may have a maximimun of 14 numerical characters.")
+ end
+
+ it "accepts an originator of upto 11 alphanumerical characters" do
+ lambda { Mollie::SMS.originator = "0123456789A" }.should.not.raise
+ end
+
+ it "does not accept an originator string with more than 11 alphanumerical characters" do
+ lambda do
+ Mollie::SMS.originator = "0123456789AB"
+ end.should.raise(Mollie::SMS::ValidationError, "Originator may have a maximimun of 11 alphanumerical characters.")
+ end
+end

0 comments on commit 6ea2c58

Please sign in to comment.