summaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/api_integration_test.rb7
-rw-r--r--test/support/browser_integration_test.rb37
2 files changed, 35 insertions, 9 deletions
diff --git a/test/support/api_integration_test.rb b/test/support/api_integration_test.rb
index bd10f11..4077920 100644
--- a/test/support/api_integration_test.rb
+++ b/test/support/api_integration_test.rb
@@ -3,8 +3,13 @@ class ApiIntegrationTest < ActionDispatch::IntegrationTest
DUMMY_TOKEN = Token.new
RACK_ENV = {'HTTP_AUTHORIZATION' => %Q(Token token="#{DUMMY_TOKEN.to_s}")}
+ setup do
+ @testcode = InviteCode.new
+ @testcode.save!
+ end
+
def login(user = nil)
- @user ||= user ||= FactoryGirl.create(:user)
+ @user ||= user ||= FactoryGirl.create(:user, :invite_code => @testcode.invite_code)
# DUMMY_TOKEN will be frozen. So let's use a dup
@token ||= DUMMY_TOKEN.dup
# make sure @token is up to date if it already exists
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index 1e2aa51..35887cc 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -37,6 +37,8 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
setup do
Capybara.current_driver = Capybara.javascript_driver
page.driver.add_headers 'ACCEPT-LANGUAGE' => 'en-EN'
+ @testcode = InviteCode.new
+ @testcode.save!
end
teardown do
@@ -45,19 +47,38 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
end
def submit_signup(username = nil, password = nil)
- username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
- password ||= SecureRandom.base64
- visit '/users/new'
- fill_in 'Username', with: username
- fill_in 'Password', with: password
- fill_in 'Password confirmation', with: password
- click_on 'Sign Up'
- return username, password
+
+ with_config invite_required: true do
+
+ username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
+ password ||= SecureRandom.base64
+ visit '/users/new'
+ fill_in 'Username', with: username
+ fill_in 'Password', with: password
+ fill_in 'Invite code', with: @testcode.invite_code
+ fill_in 'Password confirmation', with: password
+ click_on 'Sign Up'
+ return username, password
+ end
+
+ with_config invite_required: false do
+
+ username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
+ password ||= SecureRandom.base64
+ visit '/users/new'
+ fill_in 'Username', with: username
+ fill_in 'Password', with: password
+ fill_in 'Password confirmation', with: password
+ click_on 'Sign Up'
+ return username, password
+ end
+
end
# currently this only works for tests with poltergeist.
# ApiIntegrationTest has a working implementation for RackTest
def login(user = nil)
+ InviteCodeValidator.any_instance.stubs(:validate)
@user ||= user ||= FactoryGirl.create(:user)
token = Token.create user_id: user.id
page.driver.add_header "Authorization", %Q(Token token="#{token}")