summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-09-21 18:34:04 +0200
committerankonym <ankonym@gmail.com>2015-09-28 15:12:46 +0200
commit9adbde13619de8b2c300056b062d12f0961cb710 (patch)
treef9161d0a39b497cca05887a0e4fc48acde5aa650 /test/unit
parentca591b482870c93674aaf454e90f56796da7d87d (diff)
Make invite code configurable
Through the config param 'invite_required', providers can decide whether users need to provide an invite code upon signup. The default setting is false.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/account_test.rb27
-rw-r--r--test/unit/invite_code_validator_test.rb4
2 files changed, 23 insertions, 8 deletions
diff --git a/test/unit/account_test.rb b/test/unit/account_test.rb
index 0882c43..6b814b6 100644
--- a/test/unit/account_test.rb
+++ b/test/unit/account_test.rb
@@ -11,7 +11,7 @@ class AccountTest < ActiveSupport::TestCase
Identity.destroy_all_disabled
end
- test "create a new account" do
+ test "create a new account when invited" do
user = Account.create(FactoryGirl.attributes_for(:user, :invite_code => @testcode.invite_code))
assert user.valid?, "unexpected errors: #{user.errors.inspect}"
assert user.persisted?
@@ -21,6 +21,16 @@ class AccountTest < ActiveSupport::TestCase
user.account.destroy
end
+ test "create a new account" do
+ with_config invite_required: false do
+ user = Account.create(FactoryGirl.attributes_for(:user))
+ assert user.valid?, "unexpected errors: #{user.errors.inspect}"
+ assert user.persisted?
+ user.account.destroy
+ end
+ end
+
+
test "create and remove a user account" do
# We keep an identity that will block the handle from being reused.
assert_difference "Identity.count" do
@@ -50,13 +60,14 @@ class AccountTest < ActiveSupport::TestCase
end
test "Invite code count goes up by 1 when the invite code is entered" do
-
- user = Account.create(FactoryGirl.attributes_for(:user, :invite_code => @testcode.invite_code))
- user_code = InviteCode.find_by_invite_code user.invite_code
- user_code.save
- user.save
- assert user.persisted?
- assert_equal 1, user_code.invite_count
+ with_config invite_required: true do
+ user = Account.create(FactoryGirl.attributes_for(:user, :invite_code => @testcode.invite_code))
+ user_code = InviteCode.find_by_invite_code user.invite_code
+ user_code.save
+ user.save
+ assert user.persisted?
+ assert_equal 1, user_code.invite_count
+ end
end
diff --git a/test/unit/invite_code_validator_test.rb b/test/unit/invite_code_validator_test.rb
index 75e691d..ee8f1b3 100644
--- a/test/unit/invite_code_validator_test.rb
+++ b/test/unit/invite_code_validator_test.rb
@@ -2,9 +2,11 @@ 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)
assert !invalid_user.valid?
+ end
end
test "user should be created with valid invite code" do
@@ -16,11 +18,13 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
end
test "trying to create a user with invalid invite code should add error" do
+ with_config invite_required: true do
invalid_user = FactoryGirl.build(:user, :invite_code => "a non-existent code")
invalid_user.valid?
errors = {invite_code: ["This is not a valid code"]}
assert_equal errors, invalid_user.errors.messages
+ end
end
end \ No newline at end of file