database_cleaner 1.6.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/lib/database_cleaner.rb +1 -8
  3. metadata +18 -498
  4. data/CONTRIBUTE.markdown +0 -28
  5. data/Gemfile.lock +0 -286
  6. data/History.rdoc +0 -430
  7. data/LICENSE +0 -20
  8. data/README.markdown +0 -518
  9. data/Rakefile +0 -40
  10. data/TODO +0 -3
  11. data/VERSION.yml +0 -4
  12. data/cucumber.yml +0 -1
  13. data/examples/Gemfile +0 -1
  14. data/examples/Gemfile.lock +0 -1
  15. data/examples/config/database.yml.example +0 -8
  16. data/examples/config/redis.yml +0 -8
  17. data/examples/db/sqlite_databases_go_here +0 -0
  18. data/examples/features/example.feature +0 -11
  19. data/examples/features/example_multiple_db.feature +0 -23
  20. data/examples/features/example_multiple_orm.feature +0 -22
  21. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  22. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  23. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  24. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  25. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  26. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  27. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  28. data/examples/features/step_definitions/redis_steps.rb +0 -31
  29. data/examples/features/step_definitions/translation_steps.rb +0 -55
  30. data/examples/features/support/env.rb +0 -61
  31. data/examples/lib/activerecord_models.rb +0 -41
  32. data/examples/lib/couchpotato_models.rb +0 -61
  33. data/examples/lib/datamapper_models.rb +0 -50
  34. data/examples/lib/mongoid_models.rb +0 -44
  35. data/examples/lib/mongomapper_models.rb +0 -51
  36. data/examples/lib/neo4j_models.rb +0 -17
  37. data/examples/lib/ohm_models.rb +0 -43
  38. data/examples/lib/redis_models.rb +0 -65
  39. data/examples/lib/sequel_models.rb +0 -9
  40. data/features/cleaning.feature +0 -30
  41. data/features/cleaning_default_strategy.feature +0 -23
  42. data/features/cleaning_multiple_dbs.feature +0 -22
  43. data/features/cleaning_multiple_orms.feature +0 -67
  44. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  45. data/features/support/env.rb +0 -4
  46. data/features/support/feature_runner.rb +0 -39
  47. data/lib/database_cleaner/active_record/base.rb +0 -92
  48. data/lib/database_cleaner/active_record/deletion.rb +0 -106
  49. data/lib/database_cleaner/active_record/transaction.rb +0 -59
  50. data/lib/database_cleaner/active_record/truncation.rb +0 -275
  51. data/lib/database_cleaner/base.rb +0 -164
  52. data/lib/database_cleaner/configuration.rb +0 -131
  53. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  54. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  55. data/lib/database_cleaner/cucumber.rb +0 -3
  56. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  57. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  58. data/lib/database_cleaner/data_mapper/truncation.rb +0 -172
  59. data/lib/database_cleaner/generic/base.rb +0 -29
  60. data/lib/database_cleaner/generic/transaction.rb +0 -11
  61. data/lib/database_cleaner/generic/truncation.rb +0 -40
  62. data/lib/database_cleaner/mongo/base.rb +0 -16
  63. data/lib/database_cleaner/mongo/truncation.rb +0 -62
  64. data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  65. data/lib/database_cleaner/mongo2/base.rb +0 -16
  66. data/lib/database_cleaner/mongo2/truncation_mixin.rb +0 -39
  67. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  68. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  69. data/lib/database_cleaner/mongoid/base.rb +0 -20
  70. data/lib/database_cleaner/mongoid/truncation.rb +0 -49
  71. data/lib/database_cleaner/moped/base.rb +0 -39
  72. data/lib/database_cleaner/moped/truncation.rb +0 -9
  73. data/lib/database_cleaner/moped/truncation_base.rb +0 -40
  74. data/lib/database_cleaner/neo4j/base.rb +0 -62
  75. data/lib/database_cleaner/neo4j/deletion.rb +0 -16
  76. data/lib/database_cleaner/neo4j/transaction.rb +0 -35
  77. data/lib/database_cleaner/neo4j/truncation.rb +0 -9
  78. data/lib/database_cleaner/null_strategy.rb +0 -20
  79. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  80. data/lib/database_cleaner/redis/base.rb +0 -37
  81. data/lib/database_cleaner/redis/truncation.rb +0 -26
  82. data/lib/database_cleaner/sequel/base.rb +0 -22
  83. data/lib/database_cleaner/sequel/deletion.rb +0 -47
  84. data/lib/database_cleaner/sequel/transaction.rb +0 -40
  85. data/lib/database_cleaner/sequel/truncation.rb +0 -78
  86. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  87. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  88. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  89. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  90. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  91. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  92. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  93. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  94. data/spec/database_cleaner/base_spec.rb +0 -617
  95. data/spec/database_cleaner/configuration_spec.rb +0 -345
  96. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  97. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  98. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  99. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  100. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  101. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  102. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  103. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  104. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  105. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  106. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  107. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  108. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  109. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  110. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  111. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  112. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  113. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  114. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  115. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  116. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  117. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  118. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  119. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  120. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  121. data/spec/database_cleaner/shared_strategy.rb +0 -15
  122. data/spec/rcov.opts +0 -1
  123. data/spec/spec_helper.rb +0 -21
  124. data/spec/support/active_record/database_setup.rb +0 -6
  125. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  126. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  127. data/spec/support/active_record/mysql2_setup.rb +0 -39
  128. data/spec/support/active_record/mysql_setup.rb +0 -38
  129. data/spec/support/active_record/postgresql_setup.rb +0 -48
  130. data/spec/support/active_record/schema_setup.rb +0 -17
  131. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  132. data/spec/support/data_mapper/schema_setup.rb +0 -15
  133. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -1,16 +0,0 @@
1
- require 'database_cleaner/neo4j/base'
2
- require 'neo4j-core'
3
-
4
- module DatabaseCleaner
5
- module Neo4j
6
- class Deletion
7
- include ::DatabaseCleaner::Neo4j::Base
8
-
9
- def clean
10
- ::Neo4j::Transaction.run do
11
- session._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,35 +0,0 @@
1
- require 'database_cleaner/neo4j/base'
2
- require 'database_cleaner/generic/transaction'
3
- require 'neo4j-core'
4
-
5
- module DatabaseCleaner
6
- module Neo4j
7
- class Transaction
8
- include ::DatabaseCleaner::Generic::Transaction
9
- include ::DatabaseCleaner::Neo4j::Base
10
-
11
- attr_accessor :tx
12
-
13
- def start
14
- super
15
- rollback
16
- self.tx = ::Neo4j::Transaction.new
17
- end
18
-
19
- def clean
20
- rollback
21
- end
22
-
23
- private
24
-
25
- def rollback
26
- if tx
27
- tx.failure
28
- tx.close
29
- end
30
- ensure
31
- self.tx = nil
32
- end
33
- end
34
- end
35
- end
@@ -1,9 +0,0 @@
1
- require 'database_cleaner/neo4j/base'
2
- require 'database_cleaner/neo4j/deletion'
3
-
4
- module DatabaseCleaner
5
- module Neo4j
6
- class Truncation < DatabaseCleaner::Neo4j::Deletion
7
- end
8
- end
9
- end
@@ -1,20 +0,0 @@
1
- module DatabaseCleaner
2
- class NullStrategy
3
- def self.start
4
- # no-op
5
- end
6
-
7
- def self.db=(connection)
8
- # no-op
9
- end
10
-
11
- def self.clean
12
- # no-op
13
- end
14
-
15
- def self.cleaning(&block)
16
- # no-op
17
- yield
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- require 'database_cleaner/redis/truncation'
2
-
3
- module DatabaseCleaner
4
- module Ohm
5
- class Truncation < ::DatabaseCleaner::Redis::Truncation
6
-
7
- private
8
-
9
- def default_redis
10
- ::Ohm.redis
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,37 +0,0 @@
1
- require 'database_cleaner/generic/base'
2
-
3
- module DatabaseCleaner
4
- module Redis
5
- def self.available_strategies
6
- %w{truncation}
7
- end
8
-
9
- module Base
10
- include ::DatabaseCleaner::Generic::Base
11
-
12
- def db=(desired_db)
13
- @db = desired_db
14
- end
15
-
16
- def db
17
- @db ||= :default
18
- end
19
-
20
- alias url db
21
-
22
- private
23
-
24
- def connection
25
- @connection ||= begin
26
- if url == :default
27
- ::Redis.new
28
- elsif db.is_a?(::Redis) # pass directly the connection
29
- db
30
- else
31
- ::Redis.new(:url => url)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,26 +0,0 @@
1
- require 'database_cleaner/redis/base'
2
- require 'database_cleaner/generic/truncation'
3
-
4
- module DatabaseCleaner
5
- module Redis
6
- class Truncation
7
- include ::DatabaseCleaner::Redis::Base
8
- include ::DatabaseCleaner::Generic::Truncation
9
-
10
- def clean
11
- if @only
12
- @only.each do |term|
13
- connection.keys(term).each { |k| connection.del k }
14
- end
15
- elsif @tables_to_exclude
16
- keys_except = []
17
- @tables_to_exclude.each { |term| keys_except += connection.keys(term) }
18
- connection.keys.each { |k| connection.del(k) unless keys_except.include?(k) }
19
- else
20
- connection.flushdb
21
- end
22
- connection.quit unless url == :default
23
- end
24
- end
25
- end
26
- end
@@ -1,22 +0,0 @@
1
- require 'database_cleaner/generic/base'
2
- module DatabaseCleaner
3
- module Sequel
4
- def self.available_strategies
5
- %w(truncation transaction deletion)
6
- end
7
-
8
- module Base
9
- include ::DatabaseCleaner::Generic::Base
10
-
11
- def db=(desired_db)
12
- @db = desired_db
13
- end
14
-
15
- def db
16
- return @db if @db && @db != :default
17
- raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1
18
- ::Sequel::DATABASES.first || :default
19
- end
20
- end
21
- end
22
- end
@@ -1,47 +0,0 @@
1
- require 'database_cleaner/sequel/base'
2
- require 'database_cleaner/generic/truncation'
3
- require 'database_cleaner/sequel/truncation'
4
-
5
- module DatabaseCleaner::Sequel
6
- class Deletion < Truncation
7
- def disable_referential_integrity(tables)
8
- case db.database_type
9
- when :postgres
10
- db.run('SET CONSTRAINTS ALL DEFERRED')
11
- tables_to_truncate(db).each do |table|
12
- db.run("ALTER TABLE \"#{table}\" DISABLE TRIGGER ALL")
13
- end
14
- when :mysql
15
- old = db.fetch('SELECT @@FOREIGN_KEY_CHECKS').first[:@@FOREIGN_KEY_CHECKS]
16
- db.run('SET FOREIGN_KEY_CHECKS = 0')
17
- end
18
- yield
19
- ensure
20
- case db.database_type
21
- when :postgres
22
- tables.each do |table|
23
- db.run("ALTER TABLE \"#{table}\" ENABLE TRIGGER ALL")
24
- end
25
- when :mysql
26
- db.run("SET FOREIGN_KEY_CHECKS = #{old}")
27
- end
28
- end
29
-
30
- def delete_tables(db, tables)
31
- tables.each do |table|
32
- db[table.to_sym].delete
33
- end
34
- end
35
-
36
- def clean
37
- return unless dirty?
38
-
39
- tables = tables_to_truncate(db)
40
- db.transaction do
41
- disable_referential_integrity(tables) do
42
- delete_tables(db, tables)
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,40 +0,0 @@
1
- require 'database_cleaner/sequel/base'
2
- module DatabaseCleaner
3
- module Sequel
4
- class Transaction
5
- include ::DatabaseCleaner::Sequel::Base
6
-
7
- def self.check_fiber_brokenness
8
- if !@checked_fiber_brokenness && Fiber.new { Thread.current }.resume != Thread.current
9
- raise RuntimeError, "This ruby engine's Fibers are not compatible with Sequel's connection pool. " +
10
- "To work around this, please use DatabaseCleaner.cleaning with a block instead of " +
11
- "DatabaseCleaner.start and DatabaseCleaner.clean"
12
- end
13
- @checked_fiber_brokenness = true
14
- end
15
-
16
- def start
17
- self.class.check_fiber_brokenness
18
-
19
- @fibers ||= []
20
- db = self.db
21
- f = Fiber.new do
22
- db.transaction(:rollback => :always, :savepoint => true) do
23
- Fiber.yield
24
- end
25
- end
26
- f.resume
27
- @fibers << f
28
- end
29
-
30
- def clean
31
- f = @fibers.pop
32
- f.resume
33
- end
34
-
35
- def cleaning
36
- self.db.transaction(:rollback => :always, :savepoint => true) { yield }
37
- end
38
- end
39
- end
40
- end
@@ -1,78 +0,0 @@
1
- require 'database_cleaner/generic/truncation'
2
- require 'database_cleaner/sequel/base'
3
-
4
- module DatabaseCleaner
5
- module Sequel
6
- class Truncation
7
- include ::DatabaseCleaner::Sequel::Base
8
- include ::DatabaseCleaner::Generic::Truncation
9
-
10
- def start
11
- @last_txid = txid
12
- end
13
-
14
- def clean
15
- return unless dirty?
16
-
17
- case db.database_type
18
- when :postgres
19
- # PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
20
- # appended. Bulk truncation without CASCADE is:
21
- # * Safer. Tables outside of tables_to_truncate won't be affected.
22
- # * Faster. Less roundtrips to the db.
23
- unless (tables = tables_to_truncate(db)).empty?
24
- all_tables = tables.map { |t| %("#{t}") }.join(',')
25
- db.run "TRUNCATE TABLE #{all_tables};"
26
- end
27
- else
28
- tables = tables_to_truncate(db)
29
-
30
- if pre_count?
31
- # Count rows before truncating
32
- pre_count_truncate_tables(db, tables)
33
- else
34
- # Truncate each table normally
35
- truncate_tables(db, tables)
36
- end
37
- end
38
- end
39
-
40
- private
41
-
42
- def pre_count_truncate_tables(db, tables)
43
- tables = tables.reject { |table| db[table.to_sym].count == 0 }
44
- truncate_tables(db, tables)
45
- end
46
-
47
- def truncate_tables(db, tables)
48
- tables.each do |table|
49
- db[table.to_sym].truncate
50
- end
51
- end
52
-
53
- def dirty?
54
- @last_txid != txid || @last_txid.nil?
55
- end
56
-
57
- def txid
58
- case db.database_type
59
- when :postgres
60
- db.fetch('SELECT txid_snapshot_xmax(txid_current_snapshot()) AS txid').first[:txid]
61
- end
62
- end
63
-
64
- def tables_to_truncate(db)
65
- (@only || db.tables.map(&:to_s)) - @tables_to_exclude
66
- end
67
-
68
- # overwritten
69
- def migration_storage_names
70
- %w(schema_info schema_migrations)
71
- end
72
-
73
- def pre_count?
74
- @pre_count == true
75
- end
76
- end
77
- end
78
- end
@@ -1,188 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
- require 'database_cleaner/active_record/base'
4
- require 'database_cleaner/shared_strategy'
5
-
6
- class FakeModel
7
- def self.connection
8
- :fake_connection
9
- end
10
- end
11
-
12
- module DatabaseCleaner
13
- describe ActiveRecord do
14
- it { should respond_to(:available_strategies) }
15
-
16
- describe "config_file_location" do
17
- subject { ActiveRecord.config_file_location }
18
-
19
- it "should default to DatabaseCleaner.root / config / database.yml" do
20
- ActiveRecord.config_file_location=nil
21
- DatabaseCleaner.should_receive(:app_root).and_return("/path/to")
22
- subject.should eq '/path/to/config/database.yml'
23
- end
24
- end
25
-
26
- end
27
-
28
- module ActiveRecord
29
- class ExampleStrategy
30
- include ::DatabaseCleaner::ActiveRecord::Base
31
- end
32
-
33
- describe ExampleStrategy do
34
- let :config_location do
35
- '/path/to/config/database.yml'
36
- end
37
-
38
- before { ::DatabaseCleaner::ActiveRecord.stub(:config_file_location).and_return(config_location) }
39
-
40
- it_should_behave_like "a generic strategy"
41
-
42
- describe "db" do
43
-
44
- it "should store my desired db" do
45
- subject.stub(:load_config)
46
-
47
- subject.db = :my_db
48
- subject.db.should eq :my_db
49
- end
50
-
51
- it "should default to :default" do
52
- subject.db.should eq :default
53
- end
54
-
55
- it "should load_config when I set db" do
56
- subject.should_receive(:load_config)
57
- subject.db = :my_db
58
- end
59
- end
60
-
61
- describe "load_config" do
62
-
63
- before do
64
- subject.db = :my_db
65
- yaml = <<-Y
66
- my_db:
67
- database: <%= "ONE".downcase %>
68
- Y
69
- File.stub(:file?).with(config_location).and_return(true)
70
- IO.stub(:read).with(config_location).and_return(yaml)
71
- end
72
-
73
- it "should parse the config" do
74
- YAML.should_receive(:load).and_return({ :nil => nil })
75
- subject.load_config
76
- end
77
-
78
- it "should process erb in the config" do
79
- transformed = <<-Y
80
- my_db:
81
- database: one
82
- Y
83
- YAML.should_receive(:load).with(transformed).and_return({ "my_db" => { "database" => "one" } })
84
- subject.load_config
85
- end
86
-
87
- context 'use ActiveRecord::Base.configuration' do
88
- it 'when config file different with it' do
89
- ::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "two"} })
90
- subject.load_config
91
- subject.connection_hash.should eq({ "database" => "two"})
92
- end
93
- end
94
-
95
- context 'use config file' do
96
- it 'when config file same with it' do
97
- ::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "one"} })
98
- subject.load_config
99
- subject.connection_hash.should eq({ "database" => "one"})
100
- end
101
-
102
- it 'when ::ActiveRecord::Base.configurations nil' do
103
- ::ActiveRecord::Base.stub(:configurations).and_return(nil)
104
- subject.load_config
105
- subject.connection_hash.should eq({ "database" => "one"})
106
- end
107
-
108
- it 'when ::ActiveRecord::Base.configurations empty' do
109
- ::ActiveRecord::Base.stub(:configurations).and_return({})
110
- subject.load_config
111
- subject.connection_hash.should eq({ "database" => "one"})
112
- end
113
- end
114
-
115
- it "should store the relevant config in connection_hash" do
116
- subject.load_config
117
- subject.connection_hash.should eq( "database" => "one" )
118
- end
119
-
120
- it "should skip config if config file is not available" do
121
- File.should_receive(:file?).with(config_location).and_return(false)
122
- subject.load_config
123
- subject.connection_hash.should_not be
124
- end
125
-
126
- it "skips the file when the model is set" do
127
- subject.db = FakeModel
128
- YAML.should_not_receive(:load)
129
- subject.load_config
130
- subject.connection_hash.should_not be
131
- end
132
-
133
- it "skips the file when the db is set to :default" do
134
- # to avoid https://github.com/bmabey/database_cleaner/issues/72
135
- subject.db = :default
136
- YAML.should_not_receive(:load)
137
- subject.load_config
138
- subject.connection_hash.should_not be
139
- end
140
-
141
- end
142
-
143
- describe "connection_hash" do
144
- it "should store connection_hash" do
145
- subject.connection_hash = { :key => "value" }
146
- subject.connection_hash.should eq( :key => "value" )
147
- end
148
- end
149
-
150
- describe "connection_class" do
151
- it { expect { subject.connection_class }.to_not raise_error }
152
- it "should default to ActiveRecord::Base" do
153
- subject.connection_class.should eq ::ActiveRecord::Base
154
- end
155
-
156
- context "with database models" do
157
- context "connection_hash is set" do
158
- it "allows for database models to be passed in" do
159
- subject.db = FakeModel
160
- subject.connection_hash = { }
161
- subject.load_config
162
- subject.connection_class.should eq FakeModel
163
- end
164
- end
165
-
166
- context "connection_hash is not set" do
167
- it "allows for database models to be passed in" do
168
- subject.db = FakeModel
169
- subject.connection_class.should eq FakeModel
170
- end
171
- end
172
- end
173
-
174
- context "when connection_hash is set" do
175
- let(:hash) { double("hash") }
176
- before { ::ActiveRecord::Base.stub(:respond_to?).and_return(false) }
177
- before { subject.stub(:connection_hash).and_return(hash) }
178
-
179
- it "establish a connection using ActiveRecord::Base" do
180
- ::ActiveRecord::Base.should_receive(:establish_connection).with(hash)
181
-
182
- subject.connection_class
183
- end
184
- end
185
- end
186
- end
187
- end
188
- end