aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/referential.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/referential.rb')
-rw-r--r--spec/support/referential.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index c1a043b8f..7704d8510 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -1,7 +1,7 @@
module ReferentialHelper
def first_referential
- Organisation.find_by_name("first").referentials.find_by_slug("first")
+ Referential.where(:slug => "first").take!
end
def self.included(base)
@@ -27,21 +27,33 @@ RSpec.configure do |config|
config.include ReferentialHelper
config.before(:suite) do
+ # Clean all tables to start
+ DatabaseCleaner.clean_with :truncation
+ # Use transactions for tests
+ DatabaseCleaner.strategy = :transaction
# Truncating doesn't drop schemas, ensure we're clean here, first *may not* exist
Apartment::Tenant.drop('first') rescue nil
# Create the default tenant for our tests
- organisation = Organisation.where(:name => "first").first_or_create
- Referential.where(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation).first_or_create
+ organisation = Organisation.create!(:name => "first")
+ Referential.create!(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation)
end
config.before(:each) do
+ # Start transaction for this test
+ DatabaseCleaner.start
# Switch into the default tenant
first_referential.switch
end
+ config.before(:each, :js => true) do
+ DatabaseCleaner.strategy = :truncation
+ end
+
config.after(:each) do
# Reset tenant back to `public`
Apartment::Tenant.reset
+ # Rollback transaction
+ DatabaseCleaner.clean
end
end