diff options
author | azul <azul@leap.se> | 2015-09-30 10:51:21 +0200 |
---|---|---|
committer | azul <azul@leap.se> | 2015-09-30 10:51:21 +0200 |
commit | d45f6c61f6a13be06f1977b857e0cb31e79c5317 (patch) | |
tree | d3089b334c2663ea2fd76cf62dea853bdd57b047 /test/support | |
parent | a894966e425f27c31e7da196658c6ddee3fc3714 (diff) | |
parent | d4f10a8d47572bcab4c44878b952146732d64d2e (diff) |
Merge pull request #194 from Alster-Hamburgers/feature/invite_code
Request for feedback on invite code feature
Diffstat (limited to 'test/support')
-rw-r--r-- | test/support/api_integration_test.rb | 7 | ||||
-rw-r--r-- | test/support/browser_integration_test.rb | 37 |
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}") |