summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-05-09 08:54:57 +0200
committerAzul <azul@riseup.net>2016-05-09 08:54:57 +0200
commit90e2145e33913ff59b99b81a660cb730e3c7efd8 (patch)
treeb05cb68d6f271f73442eef2fdc4fea92f15d3d71
parent0ab4b26752c7949840f9168a7e8dc94226debd51 (diff)
test: make identity test locale independent
It somehow managed to fail for a certain test order. Seems rather rare though - have not been able to reproduce it in 5 runs. Failed with --seed 60219.
-rw-r--r--test/support/record_assertions.rb10
-rw-r--r--test/unit/identity_test.rb9
2 files changed, 15 insertions, 4 deletions
diff --git a/test/support/record_assertions.rb b/test/support/record_assertions.rb
new file mode 100644
index 0000000..30b947f
--- /dev/null
+++ b/test/support/record_assertions.rb
@@ -0,0 +1,10 @@
+module RecordAssertions
+
+ def assert_error(record, options)
+ options.each do |k, v|
+ errors = record.errors[k]
+ assert_equal I18n.t("errors.messages.#{v}"), errors.first
+ end
+ end
+
+end
diff --git a/test/unit/identity_test.rb b/test/unit/identity_test.rb
index 9d4bc90..e9173af 100644
--- a/test/unit/identity_test.rb
+++ b/test/unit/identity_test.rb
@@ -2,6 +2,7 @@ require_relative '../test_helper'
class IdentityTest < ActiveSupport::TestCase
include StubRecordHelper
+ include RecordAssertions
setup do
@user = find_record :user
@@ -22,7 +23,7 @@ class IdentityTest < ActiveSupport::TestCase
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]
+ assert_error @id, destination: :blank
end
test "disabled identity requires no destination" do
@@ -62,7 +63,7 @@ class IdentityTest < ActiveSupport::TestCase
@id = Identity.create_for @user, address: alias_name, destination: forward_address
dup = Identity.build_for @user, address: alias_name, destination: forward_address
assert !dup.valid?
- assert_equal ["has already been taken"], dup.errors[:destination]
+ assert_error dup, destination: :taken
end
test "validates availability" do
@@ -70,7 +71,7 @@ class IdentityTest < ActiveSupport::TestCase
@id = Identity.create_for @user, address: alias_name, destination: forward_address
taken = Identity.build_for other_user, address: alias_name
assert !taken.valid?
- assert_equal ["has already been taken"], taken.errors[:address]
+ assert_error taken, address: :taken
end
test "setting and getting pgp key" do
@@ -133,7 +134,7 @@ class IdentityTest < ActiveSupport::TestCase
other_user = find_record :user
taken = Identity.build_for other_user, address: @id.address
assert !taken.valid?
- assert_equal ["has already been taken"], taken.errors[:address]
+ assert_error taken, address: :taken
end
test "destroy all orphaned identities" do