From c6e3c29a579f3e268cbf25340ccc37e4ec10feff Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Jan 2013 23:47:21 +0100 Subject: [PATCH] Load the data for integration tests upfront We can do it, because we use :transaction strategy with DatabaseCleaner, which starts transaction before each test and rollbacks after it. That way data before each test is consistent. The big advantage of such approach is that tests are fast now - we need to only load Scenario data once. One of the drawbacks, on the other hand, is that we need to always load this data, even if no integration tests need running. We can try to be smart about it and check if any integration tests are loaded. --- spec/integration/v1/branches_spec.rb | 2 -- spec/integration/v1/builds_spec.rb | 2 -- spec/integration/v1/hooks_spec.rb | 1 - spec/integration/v1/repositories_spec.rb | 2 -- spec/integration/v2/branches_spec.rb | 2 -- spec/integration/v2/builds_spec.rb | 2 -- spec/integration/v2/hooks_spec.rb | 1 - spec/integration/v2/repositories_spec.rb | 2 -- spec/integration/v2/users_spec.rb | 2 +- spec/spec_helper.rb | 3 ++- spec/unit/endpoint/accounts_spec.rb | 2 +- 11 files changed, 4 insertions(+), 17 deletions(-) diff --git a/spec/integration/v1/branches_spec.rb b/spec/integration/v1/branches_spec.rb index 07beef62..6e5c8735 100644 --- a/spec/integration/v1/branches_spec.rb +++ b/spec/integration/v1/branches_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Branches' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v1/builds_spec.rb b/spec/integration/v1/builds_spec.rb index 3c1bca96..73d2fe85 100644 --- a/spec/integration/v1/builds_spec.rb +++ b/spec/integration/v1/builds_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Builds' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:build) { repo.builds.first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v1/hooks_spec.rb b/spec/integration/v1/hooks_spec.rb index 35160330..ccf76a00 100644 --- a/spec/integration/v1/hooks_spec.rb +++ b/spec/integration/v1/hooks_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe 'Hooks' do before(:each) do - Scenario.default user.permissions.create repository: repo, admin: true end diff --git a/spec/integration/v1/repositories_spec.rb b/spec/integration/v1/repositories_spec.rb index 9d4da90b..aea3fd4c 100644 --- a/spec/integration/v1/repositories_spec.rb +++ b/spec/integration/v1/repositories_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'v1 repos' do - before(:each) { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v2/branches_spec.rb b/spec/integration/v2/branches_spec.rb index 6f52bbf7..3e54ecc8 100644 --- a/spec/integration/v2/branches_spec.rb +++ b/spec/integration/v2/branches_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Branches' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 1f948fb8..4366a558 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Builds' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:build) { repo.builds.first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/hooks_spec.rb b/spec/integration/v2/hooks_spec.rb index 37f1a931..c0a685de 100644 --- a/spec/integration/v2/hooks_spec.rb +++ b/spec/integration/v2/hooks_spec.rb @@ -3,7 +3,6 @@ require 'travis/testing/payloads' describe 'Hooks' do before(:each) do - Scenario.default user.permissions.create repository: repo, admin: true end diff --git a/spec/integration/v2/repositories_spec.rb b/spec/integration/v2/repositories_spec.rb index fba8035d..9de7ad63 100644 --- a/spec/integration/v2/repositories_spec.rb +++ b/spec/integration/v2/repositories_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Repos' do - before(:each) { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/users_spec.rb b/spec/integration/v2/users_spec.rb index 945afa57..739ebc43 100644 --- a/spec/integration/v2/users_spec.rb +++ b/spec/integration/v2/users_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'Users' do - let(:user) { Factory(:user, locale: 'en') } + let(:user) { User.first } let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af4563da..33a828a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,7 +41,8 @@ RSpec.configure do |c| c.before :suite do DatabaseCleaner.strategy = :transaction - DatabaseCleaner.clean_with :transaction + DatabaseCleaner.clean_with :truncation + Scenario.default end c.before :each do diff --git a/spec/unit/endpoint/accounts_spec.rb b/spec/unit/endpoint/accounts_spec.rb index 2277ea8d..ecae3c03 100644 --- a/spec/unit/endpoint/accounts_spec.rb +++ b/spec/unit/endpoint/accounts_spec.rb @@ -18,7 +18,7 @@ describe Travis::Api::App::Endpoint::Accounts do 'login' => user.login, 'name' => user.name, 'type' => 'user', - 'repos_count' => nil + 'repos_count' => 1 }] end end