diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/email_test.rb | 1 | ||||
-rw-r--r-- | test/unit/identity_test.rb | 9 | ||||
-rw-r--r-- | test/unit/invite_code_validator_test.rb | 14 | ||||
-rw-r--r-- | test/unit/temporary_user_test.rb (renamed from test/unit/tmp_user_test.rb) | 30 | ||||
-rw-r--r-- | test/unit/user_test.rb | 7 |
5 files changed, 45 insertions, 16 deletions
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 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 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 diff --git a/test/unit/tmp_user_test.rb b/test/unit/temporary_user_test.rb index 1dea5f9..2c9e70f 100644 --- a/test/unit/tmp_user_test.rb +++ b/test/unit/temporary_user_test.rb @@ -1,21 +1,42 @@ require 'test_helper' -class TmpUserTest < ActiveSupport::TestCase +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) + 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 TmpUserTest < ActiveSupport::TestCase end ensure begin - normal_user.destroy tmp_user.destroy rescue end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 9501d34..02e94df 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -71,6 +71,13 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end + 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 # |