From 6d9bd6b966ec2370b7f8659b0810b03c5d1568aa Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 24 Mar 2016 09:08:46 +0100 Subject: upgrade: unique test names Rails 4.2 runs all tests mixed together. So unit tests and integration tests may not have conflicting names. --- test/unit/temporary_user_test.rb | 33 +++++++++++++++++++++++++++++++++ test/unit/tmp_user_test.rb | 33 --------------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 test/unit/temporary_user_test.rb delete mode 100644 test/unit/tmp_user_test.rb (limited to 'test/unit') diff --git a/test/unit/temporary_user_test.rb b/test/unit/temporary_user_test.rb new file mode 100644 index 0000000..38ccd67 --- /dev/null +++ b/test/unit/temporary_user_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' + +class TemporaryUserTest < ActiveSupport::TestCase + + setup do + InviteCodeValidator.any_instance.stubs(:validate) + end + + test "tmp_user saved to tmp_users" do + begin + assert User.ancestors.include?(TemporaryUser) + + assert_difference('User.database.info["doc_count"]') do + normal_user = User.create!(:login => 'a'+SecureRandom.hex(5).downcase, + :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') + refute normal_user.database.to_s.include?('tmp') + end + + assert_difference('User.tmp_database.info["doc_count"]') do + tmp_user = User.create!(:login => 'tmp_user_'+SecureRandom.hex(5).downcase, + :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') + assert tmp_user.database.to_s.include?('tmp') + end + ensure + begin + normal_user.destroy + tmp_user.destroy + rescue + end + end + end + +end diff --git a/test/unit/tmp_user_test.rb b/test/unit/tmp_user_test.rb deleted file mode 100644 index 1dea5f9..0000000 --- a/test/unit/tmp_user_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'test_helper' - -class TmpUserTest < ActiveSupport::TestCase - - setup do - InviteCodeValidator.any_instance.stubs(:validate) - end - - test "tmp_user saved to tmp_users" do - begin - assert User.ancestors.include?(TemporaryUser) - - assert_difference('User.database.info["doc_count"]') do - normal_user = User.create!(:login => 'a'+SecureRandom.hex(5).downcase, - :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') - refute normal_user.database.to_s.include?('tmp') - end - - assert_difference('User.tmp_database.info["doc_count"]') do - tmp_user = User.create!(:login => 'tmp_user_'+SecureRandom.hex(5).downcase, - :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF') - assert tmp_user.database.to_s.include?('tmp') - end - ensure - begin - normal_user.destroy - tmp_user.destroy - rescue - end - end - end - -end -- cgit v1.2.3 From 2d75afb15e005e97a57b68abae0a34f1a2c4a30b Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 25 Mar 2016 11:21:37 +0100 Subject: tests: Validator.new has optional options hash but you may not hand it a nil --- test/unit/invite_code_validator_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/unit') diff --git a/test/unit/invite_code_validator_test.rb b/test/unit/invite_code_validator_test.rb index 62eeae6..934ba2e 100644 --- a/test/unit/invite_code_validator_test.rb +++ b/test/unit/invite_code_validator_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class InviteCodeValidatorTest < ActiveSupport::TestCase test "user should not be created with invalid invite code" do with_config invite_required: true do - invalid_user = FactoryGirl.build(:user) + invalid_user = FactoryGirl.build(:user) - assert !invalid_user.valid? + assert !invalid_user.valid? end end @@ -30,7 +30,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase test "Invite count >= invite max uses is not accepted for new account signup" do - validator = InviteCodeValidator.new nil + validator = InviteCodeValidator.new user_code = InviteCode.new user_code.invite_count = 1 @@ -46,7 +46,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase end test "Invite count < invite max uses is accepted for new account signup" do - validator = InviteCodeValidator.new nil + validator = InviteCodeValidator.new user_code = InviteCode.create user_code.save @@ -60,7 +60,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase end test "Invite count 0 is accepted for new account signup" do - validator = InviteCodeValidator.new nil + validator = InviteCodeValidator.new user_code = InviteCode.create @@ -73,7 +73,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase end test "There is an error message if the invite code does not exist" do - validator = InviteCodeValidator.new nil + validator = InviteCodeValidator.new user = FactoryGirl.build :user user.invite_code = "wrongcode" @@ -83,4 +83,4 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase assert_equal ["This is not a valid code"], user.errors[:invite_code] end -end \ No newline at end of file +end -- cgit v1.2.3 From 90e2145e33913ff59b99b81a660cb730e3c7efd8 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 9 May 2016 08:54:57 +0200 Subject: 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. --- test/unit/identity_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/unit') 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 -- cgit v1.2.3 From bf77b0b1f53753ba239ef8c2668bc76603cd96e5 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 5 Jul 2016 09:18:43 +0200 Subject: fix email unit test - need to require now --- test/unit/email_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/email_test.rb b/test/unit/email_test.rb index e858bd5..739b43e 100644 --- a/test/unit/email_test.rb +++ b/test/unit/email_test.rb @@ -1,4 +1,5 @@ require 'test_helper' +require 'email' class EmailTest < ActiveSupport::TestCase -- cgit v1.2.3