From e6e1187fdc44766aa4336e05aa12d4e74db65d1d Mon Sep 17 00:00:00 2001 From: ankonym Date: Wed, 5 Aug 2015 16:55:39 +0200 Subject: Adding invite code field to signup with validation for hardcoded invite code --- test/unit/user_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/unit/user_test.rb') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index c301923..cd290d5 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -70,6 +70,11 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end + test "user should have an invite token" do + user = User.new + assert_nil(user.invite_code) + end + # ## Regression tests # -- cgit v1.2.3 From 8b5665b857edc460ef6105c3ba0f106dd99a25d5 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 13 Aug 2015 17:24:31 +0200 Subject: Fix test based on actual invite code validation --- test/unit/user_test.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'test/unit/user_test.rb') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index cd290d5..e28bef6 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -4,6 +4,7 @@ class UserTest < ActiveSupport::TestCase include SRP::Util setup do + InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false) @user = FactoryGirl.build(:user) end @@ -70,9 +71,25 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end - test "user should have an invite token" do - user = User.new - assert_nil(user.invite_code) + test "user should not be created with invalid invite code" do + InviteCodeValidator.any_instance.stubs(:not_existent?).returns(true) + invalid_user = FactoryGirl.build(:user) + + assert !invalid_user.valid? + end + + test "user should be created with valid invite code" do + assert @user.valid? + end + + test "trying to create a user with invalid invite code should add error" do + InviteCodeValidator.any_instance.stubs(:not_existent?).returns(true) + invalid_user = FactoryGirl.build(:user) + + invalid_user.valid? + + errors = {invite_code: ["This is not a valid code"]} + assert_equal errors, invalid_user.errors.messages end # -- cgit v1.2.3 From 06ebc254bc4537e81c1336627ba8a54c881a1765 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 31 Aug 2015 17:49:47 +0200 Subject: Separate user and invite code validator tests --- test/unit/user_test.rb | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'test/unit/user_test.rb') diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index e28bef6..9501d34 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -4,7 +4,7 @@ class UserTest < ActiveSupport::TestCase include SRP::Util setup do - InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false) + InviteCodeValidator.any_instance.stubs(:validate) @user = FactoryGirl.build(:user) end @@ -71,26 +71,7 @@ class UserTest < ActiveSupport::TestCase assert_equal key, @user.public_key end - test "user should not be created with invalid invite code" do - InviteCodeValidator.any_instance.stubs(:not_existent?).returns(true) - invalid_user = FactoryGirl.build(:user) - assert !invalid_user.valid? - end - - test "user should be created with valid invite code" do - assert @user.valid? - end - - test "trying to create a user with invalid invite code should add error" do - InviteCodeValidator.any_instance.stubs(:not_existent?).returns(true) - invalid_user = FactoryGirl.build(:user) - - invalid_user.valid? - - errors = {invite_code: ["This is not a valid code"]} - assert_equal errors, invalid_user.errors.messages - end # ## Regression tests -- cgit v1.2.3