summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-15 11:04:56 +0200
committerAzul <azul@leap.se>2014-05-19 14:24:47 +0200
commit5dd6c1529f8f4fc5089c71b0a44e360acaea900d (patch)
treed5e6ecf304ff6d862be05b64e4ee6ac42693c25e
parent1241cb8f13e6d0752b67521e8385b62d7fbcc882 (diff)
fix Email so User.new.valid? does not crash
Email.new(nil) now returns an invalid email rather than crashing.
-rw-r--r--app/models/email.rb5
-rw-r--r--test/unit/user_test.rb7
2 files changed, 12 insertions, 0 deletions
diff --git a/app/models/email.rb b/app/models/email.rb
index a9a503f..4090275 100644
--- a/app/models/email.rb
+++ b/app/models/email.rb
@@ -7,6 +7,11 @@ class Email < String
:message => "needs to be a valid email address"
}
+ # Make sure we can call Email.new(nil) and get an invalid email address
+ def initialize(s)
+ super(s.to_s)
+ end
+
def to_partial_path
"emails/email"
end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index ffbb7d8..b3c831b 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -65,4 +65,11 @@ class UserTest < ActiveSupport::TestCase
assert_equal key, @user.public_key
end
+ #
+ ## Regression tests
+ #
+ test "make sure valid does not crash" do
+ assert !User.new.valid?
+ end
+
end