summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/billing/test/functional/customers_controller_test.rb1
-rw-r--r--engines/support/test/unit/account_extension_test.rb4
-rw-r--r--engines/support/test/unit/ticket_test.rb4
-rw-r--r--test/factories.rb1
-rw-r--r--test/functional/identities_controller_test.rb4
-rw-r--r--test/functional/v1/messages_controller_test.rb1
-rw-r--r--test/support/browser_integration_test.rb4
-rw-r--r--test/unit/tmp_user_test.rb8
-rw-r--r--test/unit/token_test.rb1
-rw-r--r--test/unit/user_test.rb23
10 files changed, 44 insertions, 7 deletions
diff --git a/engines/billing/test/functional/customers_controller_test.rb b/engines/billing/test/functional/customers_controller_test.rb
index cc82fc1..0dafe72 100644
--- a/engines/billing/test/functional/customers_controller_test.rb
+++ b/engines/billing/test/functional/customers_controller_test.rb
@@ -5,6 +5,7 @@ class CustomersControllerTest < ActionController::TestCase
tests CustomerController
setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
@user = FactoryGirl.create :user
@other_user = FactoryGirl.create :user
#FakeBraintree.clear!
diff --git a/engines/support/test/unit/account_extension_test.rb b/engines/support/test/unit/account_extension_test.rb
index aba162c..dd7e77d 100644
--- a/engines/support/test/unit/account_extension_test.rb
+++ b/engines/support/test/unit/account_extension_test.rb
@@ -2,6 +2,10 @@ require 'test_helper'
class AccountExtensionTest < ActiveSupport::TestCase
+ setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
+ end
+
test "destroying an account triggers ticket destruction" do
t = FactoryGirl.create :ticket_with_creator
u = t.created_by_user
diff --git a/engines/support/test/unit/ticket_test.rb b/engines/support/test/unit/ticket_test.rb
index c64e8f4..7727650 100644
--- a/engines/support/test/unit/ticket_test.rb
+++ b/engines/support/test/unit/ticket_test.rb
@@ -2,6 +2,10 @@ require 'test_helper'
class TicketTest < ActiveSupport::TestCase
+ setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
+ end
+
test "ticket with default attribs is valid" do
t = FactoryGirl.build :ticket
assert t.valid?
diff --git a/test/factories.rb b/test/factories.rb
index 1a778ff..b6e1475 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -13,7 +13,6 @@ FactoryGirl.define do
password_salt "4321AB"
invite_code "testcode"
-
factory :user_with_settings do
email_forward { Faker::Internet.email }
email_aliases_attributes do
diff --git a/test/functional/identities_controller_test.rb b/test/functional/identities_controller_test.rb
index fcdeaa2..c900178 100644
--- a/test/functional/identities_controller_test.rb
+++ b/test/functional/identities_controller_test.rb
@@ -2,6 +2,10 @@ require 'test_helper'
class IdentitiesControllerTest < ActionController::TestCase
+ setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
+ end
+
test "admin can list active and blocked ids" do
login :is_admin? => true
get :index
diff --git a/test/functional/v1/messages_controller_test.rb b/test/functional/v1/messages_controller_test.rb
index 6f7ea5d..455eebd 100644
--- a/test/functional/v1/messages_controller_test.rb
+++ b/test/functional/v1/messages_controller_test.rb
@@ -3,6 +3,7 @@ require 'test_helper'
class V1::MessagesControllerTest < ActionController::TestCase
setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
@user = FactoryGirl.build(:user)
@user.save
@message = Message.new(:text => 'a test message')
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index 48c7623..b4bc273 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -37,6 +37,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
setup do
Capybara.current_driver = Capybara.javascript_driver
page.driver.add_headers 'ACCEPT-LANGUAGE' => 'en-EN'
+ @invite_code = InviteCode.create(invite_code: "testcode")
end
teardown do
@@ -50,7 +51,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
visit '/users/new'
fill_in 'Username', with: username
fill_in 'Password', with: password
- fill_in 'Invite code', with: 'testcode'
+ fill_in 'Invite code', with: "testcode"
fill_in 'Password confirmation', with: password
click_on 'Sign Up'
return username, password
@@ -59,6 +60,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
# currently this only works for tests with poltergeist.
# ApiIntegrationTest has a working implementation for RackTest
def login(user = nil)
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
@user ||= user ||= FactoryGirl.create(:user)
token = Token.create user_id: user.id
page.driver.add_header "Authorization", %Q(Token token="#{token}")
diff --git a/test/unit/tmp_user_test.rb b/test/unit/tmp_user_test.rb
index af2218e..0a9ad68 100644
--- a/test/unit/tmp_user_test.rb
+++ b/test/unit/tmp_user_test.rb
@@ -2,19 +2,23 @@ require 'test_helper'
class TmpUserTest < ActiveSupport::TestCase
+ setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
+ end
+
test "test_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', :invite_code => 'testcode')
+ :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 => 'test_user_'+SecureRandom.hex(5).downcase,
- :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF', :invite_code => 'testcode')
+ :password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF')
assert tmp_user.database.to_s.include?('tmp')
end
ensure
diff --git a/test/unit/token_test.rb b/test/unit/token_test.rb
index 5468650..dcf3fc4 100644
--- a/test/unit/token_test.rb
+++ b/test/unit/token_test.rb
@@ -4,6 +4,7 @@ class TokenTest < ActiveSupport::TestCase
include StubRecordHelper
setup do
+ InviteCodeValidator.any_instance.stubs(:not_existent?).returns(false)
@user = find_record :user
end
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
#