summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-29 11:19:21 +0200
committerAzul <azul@leap.se>2014-05-29 11:19:21 +0200
commitbbe7b3b7deb2b44d34f7c39dda2c3db284e2bf10 (patch)
tree1b921c5243e51d6aaa413ed71455d51f86f94353 /test/unit
parent85e066920568c19b788b8789c4659092224bb517 (diff)
clearify identity validations
Identity.new.valid? should not crash. So validate presence where needed and skip the other validations if the value is absent.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/identity_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/unit/identity_test.rb b/test/unit/identity_test.rb
index 54c0657..49b2075 100644
--- a/test/unit/identity_test.rb
+++ b/test/unit/identity_test.rb
@@ -7,6 +7,22 @@ class IdentityTest < ActiveSupport::TestCase
@user = find_record :user
end
+ test "blank identity does not crash on valid?" do
+ id = Identity.new
+ assert !id.valid?
+ end
+
+ test "enabled identity requires destination" do
+ id = Identity.new user: @user, address: @user.email_address
+ assert !id.valid?
+ assert_equal ["can't be blank"], id.errors[:destination]
+ end
+
+ test "disabled identity requires no destination" do
+ id = Identity.new address: @user.email_address
+ assert id.valid?
+ end
+
test "initial identity for a user" do
id = Identity.for(@user)
assert_equal @user.email_address, id.address