blob: d20b68ee67d3cf86b6f63fc0eac302c5e97dbc5f (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 | module ReferentialHelper
  def first_referential
    Organisation.find_by_name("first").referentials.find_by_slug("first")
  end
  def self.included(base)
    base.class_eval do
      extend ClassMethods
      alias_method :referential, :first_referential
    end
  end
  module ClassMethods
    def assign_referential
      before(:each) do
        assign :referential, referential
      end
    end
  end
end
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
  end
  config.before(:each) do
    # Start transaction for this test
    #DatabaseCleaner.start
    # Switch into the default tenant
    first_referential.switch
  end
  config.after(:each) do
    # Reset tenant back to `public`
    Apartment::Tenant.reset
    # Rollback transaction
    DatabaseCleaner.clean
  end 
end
 |