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 e2f19bcfb6dbce77746c2d61715340525b29a592 Mon Sep 17 00:00:00 2001 From: NavaL Date: Wed, 22 Jun 2016 19:17:15 +0200 Subject: [feature] expose is_admin in the user api So that whoever consumes the API can use this attribute to determine if admin functionalities should be made available to the current user. --- test/unit/user_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/unit') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 9501d34..55d0648 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -71,6 +71,14 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end + test "user to json includes id, login, valid, is_admin and enabled" do + json_content = JSON.parse @user.to_json + assert_equal @user.id, json_content["id"] + assert_equal @user.valid?, json_content["ok"] + assert_equal @user.login, json_content["login"] + assert_equal @user.enabled?, json_content["enabled"] + assert_equal @user.is_admin?, json_content["is_admin"] + end # -- 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 From ab1917c5fe0f03e7719863a5598ad575d9fef302 Mon Sep 17 00:00:00 2001 From: NavaL Date: Thu, 14 Jul 2016 15:06:20 +0200 Subject: [feature] restrict is_admin in the user api, to only allow querying for him/herself So that it we do not expose the is_admin property to anyone else including other admins. --- test/unit/user_test.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'test/unit') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 55d0648..02e94df 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -71,13 +71,12 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end - test "user to json includes id, login, valid, is_admin and enabled" do - json_content = JSON.parse @user.to_json - assert_equal @user.id, json_content["id"] - assert_equal @user.valid?, json_content["ok"] - assert_equal @user.login, json_content["login"] - assert_equal @user.enabled?, json_content["enabled"] - assert_equal @user.is_admin?, json_content["is_admin"] + test "user to hash includes id, login, valid and enabled" do + hash = @user.to_hash + assert_equal @user.id, hash[:id] + assert_equal @user.valid?, hash[:ok] + assert_equal @user.login, hash[:login] + assert_equal @user.enabled?, hash[:enabled] end -- cgit v1.2.3 From 8fbe70729da1d308a118c930e8f938837484a61c Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 12 Aug 2016 17:26:51 +0200 Subject: [db] def database on users instead of use_database use_database affects all uses of prepare_database - so also the one in tmp_database. In order to avoid that we do not use_database but just overwrite the database method itself. --- test/unit/temporary_user_test.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/temporary_user_test.rb b/test/unit/temporary_user_test.rb index 38ccd67..2c9e70f 100644 --- a/test/unit/temporary_user_test.rb +++ b/test/unit/temporary_user_test.rb @@ -6,16 +6,37 @@ class TemporaryUserTest < ActiveSupport::TestCase InviteCodeValidator.any_instance.stubs(:validate) end - test "tmp_user saved to tmp_users" do - begin - assert User.ancestors.include?(TemporaryUser) + test "TemporaryUser concern is applied" do + assert User.ancestors.include?(TemporaryUser) + end + + test "temporary user has tmp_users as db" do + tmp_user = User.new :login => 'tmp_user_'+SecureRandom.hex(5).downcase + assert_equal 'leap_web_tmp_users', tmp_user.database.name + end + test "normal user has users as db" do + user = User.new :login => 'a'+SecureRandom.hex(5).downcase + assert_equal 'leap_web_users', user.database.name + end + + test "user saved to users" do + begin 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 + ensure + begin + normal_user.destroy + rescue + end + end + end + test "tmp_user saved to tmp_users" do + begin 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') @@ -23,7 +44,6 @@ class TemporaryUserTest < ActiveSupport::TestCase end ensure begin - normal_user.destroy tmp_user.destroy rescue end -- cgit v1.2.3