ros-apartment 2.3.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.pryrc +5 -3
  3. data/.rubocop.yml +22 -0
  4. data/.rubocop_todo.yml +29 -0
  5. data/.story_branch.yml +5 -0
  6. data/.travis.yml +20 -36
  7. data/Appraisals +16 -29
  8. data/Gemfile +5 -2
  9. data/Guardfile +3 -1
  10. data/HISTORY.md +57 -0
  11. data/README.md +64 -21
  12. data/Rakefile +36 -22
  13. data/TODO.md +0 -1
  14. data/apartment.gemspec +17 -10
  15. data/gemfiles/rails_4_2.gemfile +12 -10
  16. data/gemfiles/rails_5_0.gemfile +2 -1
  17. data/gemfiles/rails_5_1.gemfile +2 -1
  18. data/gemfiles/rails_5_2.gemfile +2 -1
  19. data/gemfiles/rails_6_0.gemfile +6 -5
  20. data/gemfiles/rails_master.gemfile +2 -1
  21. data/lib/apartment.rb +38 -14
  22. data/lib/apartment/active_record/connection_handling.rb +17 -0
  23. data/lib/apartment/active_record/internal_metadata.rb +11 -0
  24. data/lib/apartment/active_record/log_subscriber.rb +41 -0
  25. data/lib/apartment/active_record/schema_migration.rb +13 -0
  26. data/lib/apartment/adapters/abstract_adapter.rb +49 -45
  27. data/lib/apartment/adapters/abstract_jdbc_adapter.rb +4 -3
  28. data/lib/apartment/adapters/jdbc_mysql_adapter.rb +3 -3
  29. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +20 -13
  30. data/lib/apartment/adapters/mysql2_adapter.rb +12 -9
  31. data/lib/apartment/adapters/postgis_adapter.rb +3 -2
  32. data/lib/apartment/adapters/postgresql_adapter.rb +59 -27
  33. data/lib/apartment/adapters/sqlite3_adapter.rb +18 -8
  34. data/lib/apartment/console.rb +35 -3
  35. data/lib/apartment/custom_console.rb +42 -0
  36. data/lib/apartment/deprecation.rb +2 -1
  37. data/lib/apartment/elevators/domain.rb +4 -3
  38. data/lib/apartment/elevators/first_subdomain.rb +3 -2
  39. data/lib/apartment/elevators/generic.rb +4 -3
  40. data/lib/apartment/elevators/host.rb +6 -1
  41. data/lib/apartment/elevators/host_hash.rb +6 -2
  42. data/lib/apartment/elevators/subdomain.rb +9 -5
  43. data/lib/apartment/migrator.rb +4 -3
  44. data/lib/apartment/model.rb +27 -0
  45. data/lib/apartment/railtie.rb +27 -15
  46. data/lib/apartment/reloader.rb +2 -1
  47. data/lib/apartment/tasks/enhancements.rb +4 -6
  48. data/lib/apartment/tasks/task_helper.rb +35 -0
  49. data/lib/apartment/tenant.rb +19 -9
  50. data/lib/apartment/version.rb +3 -1
  51. data/lib/generators/apartment/install/install_generator.rb +4 -3
  52. data/lib/generators/apartment/install/templates/apartment.rb +8 -2
  53. data/lib/tasks/apartment.rake +22 -44
  54. metadata +51 -230
  55. data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -19
  56. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -41
  57. data/spec/adapters/mysql2_adapter_spec.rb +0 -59
  58. data/spec/adapters/postgresql_adapter_spec.rb +0 -61
  59. data/spec/adapters/sqlite3_adapter_spec.rb +0 -83
  60. data/spec/apartment_spec.rb +0 -11
  61. data/spec/config/database.yml.sample +0 -49
  62. data/spec/dummy/Rakefile +0 -7
  63. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  64. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  65. data/spec/dummy/app/models/company.rb +0 -3
  66. data/spec/dummy/app/models/user.rb +0 -3
  67. data/spec/dummy/app/views/application/index.html.erb +0 -1
  68. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  69. data/spec/dummy/config.ru +0 -4
  70. data/spec/dummy/config/application.rb +0 -49
  71. data/spec/dummy/config/boot.rb +0 -11
  72. data/spec/dummy/config/database.yml.sample +0 -44
  73. data/spec/dummy/config/environment.rb +0 -5
  74. data/spec/dummy/config/environments/development.rb +0 -28
  75. data/spec/dummy/config/environments/production.rb +0 -51
  76. data/spec/dummy/config/environments/test.rb +0 -34
  77. data/spec/dummy/config/initializers/apartment.rb +0 -4
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  79. data/spec/dummy/config/initializers/inflections.rb +0 -10
  80. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  81. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  82. data/spec/dummy/config/initializers/session_store.rb +0 -8
  83. data/spec/dummy/config/locales/en.yml +0 -5
  84. data/spec/dummy/config/routes.rb +0 -3
  85. data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
  86. data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
  87. data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
  88. data/spec/dummy/db/schema.rb +0 -55
  89. data/spec/dummy/db/seeds.rb +0 -5
  90. data/spec/dummy/db/seeds/import.rb +0 -5
  91. data/spec/dummy/public/404.html +0 -26
  92. data/spec/dummy/public/422.html +0 -26
  93. data/spec/dummy/public/500.html +0 -26
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  96. data/spec/dummy/script/rails +0 -6
  97. data/spec/dummy_engine/.gitignore +0 -8
  98. data/spec/dummy_engine/Gemfile +0 -15
  99. data/spec/dummy_engine/Rakefile +0 -34
  100. data/spec/dummy_engine/bin/rails +0 -12
  101. data/spec/dummy_engine/config/initializers/apartment.rb +0 -51
  102. data/spec/dummy_engine/dummy_engine.gemspec +0 -24
  103. data/spec/dummy_engine/lib/dummy_engine.rb +0 -4
  104. data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -4
  105. data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -3
  106. data/spec/dummy_engine/test/dummy/Rakefile +0 -6
  107. data/spec/dummy_engine/test/dummy/config.ru +0 -4
  108. data/spec/dummy_engine/test/dummy/config/application.rb +0 -22
  109. data/spec/dummy_engine/test/dummy/config/boot.rb +0 -5
  110. data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
  111. data/spec/dummy_engine/test/dummy/config/environment.rb +0 -5
  112. data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -37
  113. data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -78
  114. data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -39
  115. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -8
  116. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  117. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  118. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  119. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -16
  120. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -4
  121. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -3
  122. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  123. data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
  124. data/spec/dummy_engine/test/dummy/config/routes.rb +0 -56
  125. data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
  126. data/spec/examples/connection_adapter_examples.rb +0 -42
  127. data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -95
  128. data/spec/examples/generic_adapter_examples.rb +0 -163
  129. data/spec/examples/schema_adapter_examples.rb +0 -234
  130. data/spec/integration/apartment_rake_integration_spec.rb +0 -107
  131. data/spec/integration/query_caching_spec.rb +0 -81
  132. data/spec/integration/use_within_an_engine_spec.rb +0 -28
  133. data/spec/schemas/v1.rb +0 -16
  134. data/spec/schemas/v2.rb +0 -43
  135. data/spec/schemas/v3.rb +0 -49
  136. data/spec/spec_helper.rb +0 -61
  137. data/spec/support/apartment_helpers.rb +0 -43
  138. data/spec/support/capybara_sessions.rb +0 -15
  139. data/spec/support/config.rb +0 -10
  140. data/spec/support/contexts.rb +0 -52
  141. data/spec/support/requirements.rb +0 -35
  142. data/spec/support/setup.rb +0 -46
  143. data/spec/tasks/apartment_rake_spec.rb +0 -129
  144. data/spec/tenant_spec.rb +0 -190
  145. data/spec/unit/config_spec.rb +0 -112
  146. data/spec/unit/elevators/domain_spec.rb +0 -32
  147. data/spec/unit/elevators/first_subdomain_spec.rb +0 -24
  148. data/spec/unit/elevators/generic_spec.rb +0 -54
  149. data/spec/unit/elevators/host_hash_spec.rb +0 -32
  150. data/spec/unit/elevators/host_spec.rb +0 -89
  151. data/spec/unit/elevators/subdomain_spec.rb +0 -76
  152. data/spec/unit/migrator_spec.rb +0 -77
  153. data/spec/unit/reloader_spec.rb +0 -24
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
- require 'rake'
3
-
4
- describe "apartment rake tasks", database: :postgresql do
5
-
6
- before do
7
- @rake = Rake::Application.new
8
- Rake.application = @rake
9
- Dummy::Application.load_tasks
10
-
11
- # rails tasks running F up the schema...
12
- Rake::Task.define_task('db:migrate')
13
- Rake::Task.define_task('db:seed')
14
- Rake::Task.define_task('db:rollback')
15
- Rake::Task.define_task('db:migrate:up')
16
- Rake::Task.define_task('db:migrate:down')
17
- Rake::Task.define_task('db:migrate:redo')
18
-
19
- Apartment.configure do |config|
20
- config.use_schemas = true
21
- config.excluded_models = ["Company"]
22
- config.tenant_names = lambda{ Company.pluck(:database) }
23
- end
24
- Apartment::Tenant.reload!(config)
25
-
26
- # fix up table name of shared/excluded models
27
- Company.table_name = 'public.companies'
28
- end
29
-
30
- after { Rake.application = nil }
31
-
32
- context "with x number of databases" do
33
-
34
- let(:x){ 1 + rand(5) } # random number of dbs to create
35
- let(:db_names){ x.times.map{ Apartment::Test.next_db } }
36
- let!(:company_count){ db_names.length }
37
-
38
- before do
39
- db_names.collect do |db_name|
40
- Apartment::Tenant.create(db_name)
41
- Company.create :database => db_name
42
- end
43
- end
44
-
45
- after do
46
- db_names.each{ |db| Apartment::Tenant.drop(db) }
47
- Company.delete_all
48
- end
49
-
50
- context "with ActiveRecord below 5.2.0" do
51
- before do
52
- allow(ActiveRecord::Migrator).to receive(:migrations_paths) { %w(spec/dummy/db/migrate) }
53
- allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { true }
54
- end
55
-
56
- describe "#migrate" do
57
- it "should migrate all databases" do
58
- expect(ActiveRecord::Migrator).to receive(:migrate).exactly(company_count).times
59
-
60
- @rake['apartment:migrate'].invoke
61
- end
62
- end
63
-
64
- describe "#rollback" do
65
- it "should rollback all dbs" do
66
- expect(ActiveRecord::Migrator).to receive(:rollback).exactly(company_count).times
67
-
68
- @rake['apartment:rollback'].invoke
69
- end
70
- end
71
- end
72
-
73
- context "with ActiveRecord above or equal to 5.2.0" do
74
- let(:migration_context_double) { double(:migration_context) }
75
-
76
- before do
77
- allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { false }
78
- end
79
-
80
- describe "#migrate" do
81
- it "should migrate all databases" do
82
- allow(ActiveRecord::Base.connection).to receive(:migration_context) { migration_context_double }
83
- expect(migration_context_double).to receive(:migrate).exactly(company_count).times
84
-
85
- @rake['apartment:migrate'].invoke
86
- end
87
- end
88
-
89
- describe "#rollback" do
90
- it "should rollback all dbs" do
91
- allow(ActiveRecord::Base.connection).to receive(:migration_context) { migration_context_double }
92
- expect(migration_context_double).to receive(:rollback).exactly(company_count).times
93
-
94
- @rake['apartment:rollback'].invoke
95
- end
96
- end
97
- end
98
-
99
- describe "apartment:seed" do
100
- it "should seed all databases" do
101
- expect(Apartment::Tenant).to receive(:seed).exactly(company_count).times
102
-
103
- @rake['apartment:seed'].invoke
104
- end
105
- end
106
- end
107
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'query caching' do
4
- describe 'when use_schemas = true' do
5
- let(:db_names) { [db1, db2] }
6
-
7
- before do
8
- Apartment.configure do |config|
9
- config.excluded_models = ["Company"]
10
- config.tenant_names = lambda{ Company.pluck(:database) }
11
- config.use_schemas = true
12
- end
13
-
14
- Apartment::Tenant.reload!(config)
15
-
16
- db_names.each do |db_name|
17
- Apartment::Tenant.create(db_name)
18
- Company.create database: db_name
19
- end
20
- end
21
-
22
- after do
23
- db_names.each{ |db| Apartment::Tenant.drop(db) }
24
- Apartment::Tenant.reset
25
- Company.delete_all
26
- end
27
-
28
- it 'clears the ActiveRecord::QueryCache after switching databases' do
29
- db_names.each do |db_name|
30
- Apartment::Tenant.switch! db_name
31
- User.create! name: db_name
32
- end
33
-
34
- ActiveRecord::Base.connection.enable_query_cache!
35
-
36
- Apartment::Tenant.switch! db_names.first
37
- expect(User.find_by_name(db_names.first).name).to eq(db_names.first)
38
-
39
- Apartment::Tenant.switch! db_names.last
40
- expect(User.find_by_name(db_names.first)).to be_nil
41
- end
42
- end
43
-
44
- describe 'when use_schemas = false' do
45
- let(:db_name) { db1 }
46
-
47
- before do
48
- Apartment.configure do |config|
49
- config.excluded_models = ["Company"]
50
- config.tenant_names = lambda{ Company.pluck(:database) }
51
- config.use_schemas = false
52
- end
53
-
54
- Apartment::Tenant.reload!(config)
55
-
56
- Apartment::Tenant.create(db_name)
57
- Company.create database: db_name
58
- end
59
-
60
- after do
61
- # Avoid cannot drop the currently open database. Maybe there is a better way to handle this.
62
- Apartment::Tenant.switch! 'template1'
63
-
64
- Apartment::Tenant.drop(db_name)
65
- Apartment::Tenant.reset
66
- Company.delete_all
67
- end
68
-
69
- it "configuration value is kept after switching databases" do
70
- ActiveRecord::Base.connection.enable_query_cache!
71
-
72
- Apartment::Tenant.switch! db_name
73
- expect(Apartment.connection.query_cache_enabled).to be true
74
-
75
- ActiveRecord::Base.connection.disable_query_cache!
76
-
77
- Apartment::Tenant.switch! db_name
78
- expect(Apartment.connection.query_cache_enabled).to be false
79
- end
80
- end
81
- end
@@ -1,28 +0,0 @@
1
- describe 'using apartment within an engine' do
2
-
3
- before do
4
- engine_path = Pathname.new(File.expand_path('../../dummy_engine', __FILE__))
5
- require engine_path.join('test/dummy/config/application')
6
- @rake = Rake::Application.new
7
- Rake.application = @rake
8
- stub_const 'APP_RAKEFILE', engine_path.join('test/dummy/Rakefile')
9
- load 'rails/tasks/engine.rake'
10
- end
11
-
12
- it 'sucessfully runs rake db:migrate in the engine root' do
13
- expect{ Rake::Task['db:migrate'].invoke }.to_not raise_error
14
- end
15
-
16
- it 'sucessfully runs rake app:db:migrate in the engine root' do
17
- expect{ Rake::Task['app:db:migrate'].invoke }.to_not raise_error
18
- end
19
-
20
- context 'when Apartment.db_migrate_tenants is false' do
21
- it 'should not enhance tasks' do
22
- Apartment.db_migrate_tenants = false
23
- expect(Apartment::RakeTaskEnhancer).to_not receive(:enhance_task).with('db:migrate')
24
- Rake::Task['db:migrate'].invoke
25
- end
26
- end
27
-
28
- end
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 0) do
15
-
16
- end
@@ -1,43 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20110613152810) do
15
-
16
- create_table "companies", :force => true do |t|
17
- t.boolean "dummy"
18
- t.string "database"
19
- end
20
-
21
- create_table "delayed_jobs", :force => true do |t|
22
- t.integer "priority", :default => 0
23
- t.integer "attempts", :default => 0
24
- t.text "handler"
25
- t.text "last_error"
26
- t.datetime "run_at"
27
- t.datetime "locked_at"
28
- t.datetime "failed_at"
29
- t.string "locked_by"
30
- t.datetime "created_at"
31
- t.datetime "updated_at"
32
- t.string "queue"
33
- end
34
-
35
- add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
36
-
37
- create_table "users", :force => true do |t|
38
- t.string "name"
39
- t.datetime "birthdate"
40
- t.string "sex"
41
- end
42
-
43
- end
@@ -1,49 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20111202022214) do
15
-
16
- create_table "books", :force => true do |t|
17
- t.string "name"
18
- t.integer "pages"
19
- t.datetime "published"
20
- end
21
-
22
- create_table "companies", :force => true do |t|
23
- t.boolean "dummy"
24
- t.string "database"
25
- end
26
-
27
- create_table "delayed_jobs", :force => true do |t|
28
- t.integer "priority", :default => 0
29
- t.integer "attempts", :default => 0
30
- t.text "handler"
31
- t.text "last_error"
32
- t.datetime "run_at"
33
- t.datetime "locked_at"
34
- t.datetime "failed_at"
35
- t.string "locked_by"
36
- t.datetime "created_at"
37
- t.datetime "updated_at"
38
- t.string "queue"
39
- end
40
-
41
- add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
42
-
43
- create_table "users", :force => true do |t|
44
- t.string "name"
45
- t.datetime "birthdate"
46
- t.string "sex"
47
- end
48
-
49
- end
@@ -1,61 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
-
3
- # Configure Rails Environment
4
- ENV["RAILS_ENV"] = "test"
5
-
6
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
-
8
- # Loading dummy applications affects table_name of each excluded models
9
- # defined in `spec/dummy/config/initializers/apartment.rb`.
10
- # To make them pristine, we need to execute below lines.
11
- Apartment.excluded_models.each do |model|
12
- klass = model.constantize
13
-
14
- Apartment.connection_class.remove_connection(klass)
15
- klass.clear_all_connections!
16
- klass.reset_table_name
17
- end
18
-
19
- require "rspec/rails"
20
- require 'capybara/rspec'
21
- require 'capybara/rails'
22
-
23
- begin
24
- require 'pry'
25
- silence_warnings{ IRB = Pry }
26
- rescue LoadError
27
- end
28
-
29
- ActionMailer::Base.delivery_method = :test
30
- ActionMailer::Base.perform_deliveries = true
31
- ActionMailer::Base.default_url_options[:host] = "test.com"
32
-
33
- Rails.backtrace_cleaner.remove_silencers!
34
-
35
- # Load support files
36
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
37
-
38
- RSpec.configure do |config|
39
-
40
- config.include RSpec::Integration::CapybaraSessions, type: :request
41
- config.include Apartment::Spec::Setup
42
-
43
- # Somewhat brutal hack so that rails 4 postgres extensions don't modify this file
44
- config.after(:all) do
45
- `git checkout -- spec/dummy/db/schema.rb`
46
- end
47
-
48
- # rspec-rails 3 will no longer automatically infer an example group's spec type
49
- # from the file location. You can explicitly opt-in to the feature using this
50
- # config option.
51
- # To explicitly tag specs without using automatic inference, set the `:type`
52
- # metadata manually:
53
- #
54
- # describe ThingsController, :type => :controller do
55
- # # Equivalent to being in spec/controllers
56
- # end
57
- config.infer_spec_type_from_file_location!
58
- end
59
-
60
- # Load shared examples, must happen after configure for RSpec 3
61
- Dir["#{File.dirname(__FILE__)}/examples/**/*.rb"].each { |f| require f }
@@ -1,43 +0,0 @@
1
- module Apartment
2
- module Test
3
-
4
- extend self
5
-
6
- def reset
7
- Apartment.excluded_models = nil
8
- Apartment.use_schemas = nil
9
- Apartment.seed_after_create = nil
10
- Apartment.default_schema = nil
11
- end
12
-
13
- def next_db
14
- @x ||= 0
15
- "db%d" % @x += 1
16
- end
17
-
18
- def drop_schema(schema)
19
- ActiveRecord::Base.connection.execute("DROP SCHEMA IF EXISTS #{schema} CASCADE") rescue true
20
- end
21
-
22
- # Use this if you don't want to import schema.rb etc... but need the postgres schema to exist
23
- # basically for speed purposes
24
- def create_schema(schema)
25
- ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}")
26
- end
27
-
28
- def load_schema(version = 3)
29
- file = File.expand_path("../../schemas/v#{version}.rb", __FILE__)
30
-
31
- silence_warnings{ load(file) }
32
- end
33
-
34
- def migrate
35
- ActiveRecord::Migrator.migrate(Rails.root + ActiveRecord::Migrator.migrations_path)
36
- end
37
-
38
- def rollback
39
- ActiveRecord::Migrator.rollback(Rails.root + ActiveRecord::Migrator.migrations_path)
40
- end
41
-
42
- end
43
- end
@@ -1,15 +0,0 @@
1
- module RSpec
2
- module Integration
3
- module CapybaraSessions
4
-
5
- def in_new_session(&block)
6
- yield new_session
7
- end
8
-
9
- def new_session
10
- Capybara::Session.new(Capybara.current_driver, Capybara.app)
11
- end
12
-
13
- end
14
- end
15
- end