From 9156f1354f404c569e7fd337cff0171f6f43842e Mon Sep 17 00:00:00 2001 From: Aya Jaff Date: Wed, 12 Aug 2015 15:18:34 +0200 Subject: Added an 'invite code' to all the tests for the sign-up form so we have a valid user for the tests again --- test/support/browser_integration_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/support') diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb index 1e2aa51..48c7623 100644 --- a/test/support/browser_integration_test.rb +++ b/test/support/browser_integration_test.rb @@ -50,6 +50,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 'Password confirmation', with: password click_on 'Sign Up' return username, password -- cgit v1.2.3 From 8b5665b857edc460ef6105c3ba0f106dd99a25d5 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 13 Aug 2015 17:24:31 +0200 Subject: Fix test based on actual invite code validation --- test/support/browser_integration_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/support') 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}") -- cgit v1.2.3 From c48e921c101d49bf68fa1af489b8012517b1a105 Mon Sep 17 00:00:00 2001 From: ankonym Date: Tue, 1 Sep 2015 10:48:25 +0200 Subject: Fix several test failures by stubbing invite code validation --- test/support/browser_integration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/support') diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb index b4bc273..f20421d 100644 --- a/test/support/browser_integration_test.rb +++ b/test/support/browser_integration_test.rb @@ -60,7 +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) + 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}") -- cgit v1.2.3 From 2f7d085c5747a1a68afc0d854fa087ffbb46f8e7 Mon Sep 17 00:00:00 2001 From: ankonym Date: Wed, 2 Sep 2015 17:01:16 +0200 Subject: Fix the remaining failures/errors in our tests Handing freshly generated invite codes to Factory Girl to make the tests pass --- test/support/api_integration_test.rb | 7 ++++++- test/support/browser_integration_test.rb | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'test/support') 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 f20421d..34ec9a6 100644 --- a/test/support/browser_integration_test.rb +++ b/test/support/browser_integration_test.rb @@ -37,7 +37,8 @@ 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") + @testcode = InviteCode.new + @testcode.save! end teardown do @@ -51,7 +52,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.invite_code fill_in 'Password confirmation', with: password click_on 'Sign Up' return username, password -- cgit v1.2.3 From 9adbde13619de8b2c300056b062d12f0961cb710 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 21 Sep 2015 18:34:04 +0200 Subject: 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. --- test/support/browser_integration_test.rb | 35 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'test/support') diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb index 34ec9a6..35887cc 100644 --- a/test/support/browser_integration_test.rb +++ b/test/support/browser_integration_test.rb @@ -47,15 +47,32 @@ 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 'Invite code', with: @testcode.invite_code - 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. -- cgit v1.2.3