diff options
| author | ankonym <ankonym@gmail.com> | 2015-08-31 17:49:47 +0200 | 
|---|---|---|
| committer | ankonym <ankonym@gmail.com> | 2015-09-28 15:12:45 +0200 | 
| commit | 06ebc254bc4537e81c1336627ba8a54c881a1765 (patch) | |
| tree | a192c3967327867231a9e2b8a8c5ade2d0c46635 | |
| parent | a8f07fb18518fd95fd701e8c0e550a3cd70520b0 (diff) | |
Separate user and invite code validator tests
| -rw-r--r-- | test/unit/invite_code_validator_test.rb | 26 | ||||
| -rw-r--r-- | test/unit/user_test.rb | 21 | 
2 files changed, 27 insertions, 20 deletions
| diff --git a/test/unit/invite_code_validator_test.rb b/test/unit/invite_code_validator_test.rb new file mode 100644 index 0000000..62768e3 --- /dev/null +++ b/test/unit/invite_code_validator_test.rb @@ -0,0 +1,26 @@ +require 'test_helper' + +class InviteCodeValidatorTest < ActiveSupport::TestCase +  test "user should not be created with invalid invite code" do +    invalid_user = FactoryGirl.build(:user) + +    assert !invalid_user.valid? +  end + +  test "user should be created with valid invite code" do +    valid_user = FactoryGirl.build(:user) +    valid_code = InviteCode.create +    valid_user.invite_code = valid_code.invite_code + +    assert valid_user.valid? +  end + +  test "trying to create a user with invalid invite code should add error" do +    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 +end
\ No newline at end of file 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 | 
