database_cleaner 1.6.2 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTE.markdown +1 -2
  3. data/Gemfile.lock +132 -93
  4. data/History.rdoc +67 -0
  5. data/README.markdown +88 -217
  6. data/Rakefile +12 -8
  7. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/base.rb +14 -5
  8. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/deletion.rb +19 -17
  9. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/truncation.rb +25 -20
  10. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +5 -0
  11. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +6 -0
  12. data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +1 -0
  13. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +5 -0
  14. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +11 -0
  15. data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +1 -0
  16. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/base.rb +4 -0
  17. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/truncation.rb +4 -3
  18. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +5 -0
  19. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +4 -0
  20. data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +1 -0
  21. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation.rb +2 -0
  22. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +5 -0
  23. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +10 -0
  24. data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +1 -0
  25. data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/base.rb +4 -0
  26. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +35 -0
  27. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +5 -0
  28. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +4 -0
  29. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +1 -0
  30. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +26 -0
  31. data/{lib/database_cleaner/mongo2/truncation_mixin.rb → adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb} +3 -4
  32. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +65 -0
  33. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/truncation.rb +6 -6
  34. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +5 -0
  35. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +10 -0
  36. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +1 -0
  37. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/base.rb +1 -1
  38. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation_base.rb +4 -0
  39. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +5 -0
  40. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +10 -0
  41. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +1 -0
  42. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/base.rb +4 -0
  43. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +5 -0
  44. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +6 -0
  45. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +1 -0
  46. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +24 -0
  47. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +5 -0
  48. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +12 -0
  49. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +1 -0
  50. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/base.rb +4 -0
  51. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +5 -0
  52. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +4 -0
  53. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +1 -0
  54. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/base.rb +4 -0
  55. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/truncation.rb +16 -15
  56. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +5 -0
  57. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +6 -0
  58. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +1 -0
  59. data/lib/database_cleaner/base.rb +94 -105
  60. data/lib/database_cleaner/configuration.rb +87 -83
  61. data/lib/database_cleaner/deprecation.rb +26 -0
  62. data/lib/database_cleaner/null_strategy.rb +6 -6
  63. data/lib/database_cleaner/orm_autodetector.rb +41 -0
  64. data/lib/database_cleaner/safeguard.rb +107 -0
  65. data/lib/database_cleaner/spec/database_helper.rb +82 -0
  66. data/lib/database_cleaner/spec/shared_examples.rb +15 -0
  67. data/lib/database_cleaner/spec.rb +2 -0
  68. data/lib/database_cleaner/version.rb +3 -0
  69. data/lib/database_cleaner.rb +41 -2
  70. metadata +113 -126
  71. data/VERSION.yml +0 -4
  72. data/examples/Gemfile +0 -1
  73. data/examples/Gemfile.lock +0 -1
  74. data/examples/config/database.yml.example +0 -8
  75. data/examples/config/redis.yml +0 -8
  76. data/examples/db/sqlite_databases_go_here +0 -0
  77. data/examples/features/example.feature +0 -11
  78. data/examples/features/example_multiple_db.feature +0 -23
  79. data/examples/features/example_multiple_orm.feature +0 -22
  80. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  81. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  82. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  83. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  84. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  85. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  86. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  87. data/examples/features/step_definitions/redis_steps.rb +0 -31
  88. data/examples/features/step_definitions/translation_steps.rb +0 -55
  89. data/examples/features/support/env.rb +0 -61
  90. data/examples/lib/activerecord_models.rb +0 -41
  91. data/examples/lib/couchpotato_models.rb +0 -61
  92. data/examples/lib/datamapper_models.rb +0 -50
  93. data/examples/lib/mongoid_models.rb +0 -44
  94. data/examples/lib/mongomapper_models.rb +0 -51
  95. data/examples/lib/neo4j_models.rb +0 -17
  96. data/examples/lib/ohm_models.rb +0 -43
  97. data/examples/lib/redis_models.rb +0 -65
  98. data/examples/lib/sequel_models.rb +0 -9
  99. data/features/cleaning.feature +0 -30
  100. data/features/cleaning_default_strategy.feature +0 -23
  101. data/features/cleaning_multiple_dbs.feature +0 -22
  102. data/features/cleaning_multiple_orms.feature +0 -67
  103. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  104. data/features/support/env.rb +0 -4
  105. data/features/support/feature_runner.rb +0 -39
  106. data/lib/database_cleaner/mongo2/base.rb +0 -16
  107. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  108. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  109. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  110. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  111. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  112. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  113. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  114. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  115. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  116. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  117. data/spec/database_cleaner/base_spec.rb +0 -617
  118. data/spec/database_cleaner/configuration_spec.rb +0 -345
  119. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  120. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  121. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  122. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  123. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  124. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  125. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  126. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  127. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  128. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  129. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  130. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  131. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  132. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  133. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  134. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  135. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  136. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  137. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  138. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  139. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  140. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  141. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  142. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  143. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  144. data/spec/database_cleaner/shared_strategy.rb +0 -15
  145. data/spec/rcov.opts +0 -1
  146. data/spec/spec_helper.rb +0 -21
  147. data/spec/support/active_record/database_setup.rb +0 -6
  148. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  149. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  150. data/spec/support/active_record/mysql2_setup.rb +0 -39
  151. data/spec/support/active_record/mysql_setup.rb +0 -38
  152. data/spec/support/active_record/postgresql_setup.rb +0 -48
  153. data/spec/support/active_record/schema_setup.rb +0 -17
  154. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  155. data/spec/support/data_mapper/schema_setup.rb +0 -15
  156. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
  157. /data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/transaction.rb +0 -0
  158. /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/base.rb +0 -0
  159. /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/truncation.rb +0 -0
  160. /data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/transaction.rb +0 -0
  161. /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/base.rb +0 -0
  162. /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation_mixin.rb +0 -0
  163. /data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/base.rb +0 -0
  164. /data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation.rb +0 -0
  165. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/deletion.rb +0 -0
  166. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/transaction.rb +0 -0
  167. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/truncation.rb +0 -0
  168. /data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/truncation.rb +0 -0
  169. /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/deletion.rb +0 -0
  170. /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/transaction.rb +0 -0
@@ -1,182 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/sequel/truncation'
3
- require 'database_cleaner/shared_strategy'
4
- require 'sequel'
5
-
6
- # XXX: use ActiveRecord's db_config (`db/config.yml`) for CI/dev convenience
7
- require 'support/active_record/database_setup'
8
-
9
- module DatabaseCleaner
10
- module Sequel
11
- describe Truncation do
12
- it_should_behave_like "a generic strategy"
13
- it_should_behave_like "a generic truncation strategy"
14
- end
15
-
16
- shared_examples 'a Sequel truncation strategy' do
17
-
18
- # XXX: it'd be really nice if Truncation accepted db: constructor parameter
19
- let(:truncation) do
20
- t = Truncation.new
21
- t.db = db
22
- t
23
- end
24
-
25
- context 'when several tables have data' do
26
- before(:each) do
27
- db.create_table!(:precious_stones) { primary_key :id }
28
- db.create_table!(:replaceable_trifles) { primary_key :id }
29
- db.create_table!(:worthless_junk) { primary_key :id }
30
-
31
- db[:precious_stones].insert
32
- db[:replaceable_trifles].insert
33
- db[:worthless_junk].insert
34
- end
35
- context 'by default' do
36
- it 'truncates all the tables' do
37
- t = Truncation.new
38
- t.db = db
39
- t.clean
40
-
41
- expect(db[:replaceable_trifles]).to have(0).rows
42
- expect(db[:worthless_junk]).to have(0).rows
43
- expect(db[:precious_stones]).to have(0).rows
44
- end
45
- end
46
- context 'when the Truncation is restricted to "only: [...]" some tables' do
47
- it 'truncates only the mentioned tables (and leaves the rest alone)' do
48
- t = Truncation.new(only: ['worthless_junk', 'replaceable_trifles'])
49
- t.db = db
50
- t.clean
51
-
52
- expect(db[:replaceable_trifles]).to have(0).rows
53
- expect(db[:worthless_junk]).to have(0).rows
54
- expect(db[:precious_stones]).to have(1).rows
55
- end
56
- end
57
- context 'when the Truncation is restricted to "except: [...]" some tables' do
58
- it 'leaves the mentioned tables alone (and truncates the rest)' do
59
- t = Truncation.new(except: ['precious_stones']) # XXX: Strings only, symbols are ignored
60
- t.db = db
61
- t.clean
62
-
63
- expect(db[:replaceable_trifles]).to be_empty
64
- expect(db[:worthless_junk]).to be_empty
65
- expect(db[:precious_stones]).to have(1).item
66
- end
67
- end
68
- end
69
- end
70
-
71
- shared_examples_for 'a truncation strategy without autoincrement resets' do
72
- it "leaves AUTO_INCREMENT index alone by default (BUG: it should be reset instead)" do
73
- # Jordan Hollinger made everything reset auto increment IDs
74
- # in commit 6a0104382647e5c06578aeac586c0333c8944492 so I'm pretty sure
75
- # everything is meant to reset by default.
76
- #
77
- # For Postgres, db[:mytable].truncate(restart: true) should work.
78
- # For SQLite, db[:sqlite_sequence].where(name: 'mytable').delete
79
-
80
- db.create_table!(:replaceable_trifles) { primary_key :id }
81
- table = db[:replaceable_trifles]
82
- 2.times { table.insert }
83
-
84
- truncation.clean
85
-
86
- id_after_clean = table.insert
87
- pending('the bug being fixed') do
88
- expect(id_after_clean).to eq 1
89
- end
90
- end
91
- # XXX: it'd be really nice if Truncation accepted db: constructor parameter
92
- let(:truncation) do
93
- t = Truncation.new
94
- t.db = db
95
- t
96
- end
97
- end
98
-
99
- shared_examples_for 'a truncation strategy that resets autoincrement keys by default' do
100
- it "resets AUTO_INCREMENT primary keys" do
101
- db.create_table!(:replaceable_trifles) { primary_key :id }
102
- table = db[:replaceable_trifles]
103
- 2.times { table.insert }
104
-
105
- truncation.clean
106
-
107
- id_after_clean = table.insert
108
- expect(id_after_clean).to eq 1
109
- end
110
-
111
- # XXX: it'd be really nice if Truncation accepted db: constructor parameter
112
- let(:truncation) do
113
- t = Truncation.new
114
- t.db = db
115
- t
116
- end
117
- end
118
-
119
- half_supported_configurations = [
120
- {url: 'sqlite:///', connection_options: db_config['sqlite3']},
121
- {url: 'postgres:///', connection_options: db_config['postgres']},
122
- ]
123
- supported_configurations = [
124
- {url: 'mysql:///', connection_options: db_config['mysql']},
125
- {url: 'mysql2:///', connection_options: db_config['mysql2']}
126
- ]
127
- supported_configurations.each do |config|
128
- describe "Sequel truncation (using a #{config[:url]} connection)" do
129
- let(:db) { ::Sequel.connect(config[:url], config[:connection_options]) }
130
-
131
- it_behaves_like 'a Sequel truncation strategy'
132
- it_behaves_like 'a truncation strategy that resets autoincrement keys by default'
133
-
134
- describe '#pre_count?' do
135
- subject { Truncation.new.tap { |t| t.db = db } }
136
-
137
- its(:pre_count?) { should eq false }
138
-
139
- it 'should return true if @reset_id is set and non false or nil' do
140
- subject.instance_variable_set(:"@pre_count", true)
141
- subject.send(:pre_count?).should eq true
142
- end
143
-
144
- it 'should return false if @reset_id is set to false' do
145
- subject.instance_variable_set(:"@pre_count", false)
146
- subject.send(:pre_count?).should eq false
147
- end
148
- end
149
-
150
- describe "relying on #pre_count_truncate_tables if asked to" do
151
- subject { Truncation.new.tap { |t| t.db = db } }
152
-
153
- it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do
154
- subject.instance_variable_set(:"@pre_count", true)
155
-
156
- subject.should_not_receive(:truncate_tables)
157
- subject.should_receive(:pre_count_truncate_tables)
158
-
159
- subject.clean
160
- end
161
-
162
- it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do
163
- subject.instance_variable_set(:"@pre_count", false)
164
-
165
- subject.should_not_receive(:pre_count_truncate_tables)
166
- subject.should_receive(:truncate_tables)
167
-
168
- subject.clean
169
- end
170
- end
171
- end
172
- end
173
- half_supported_configurations.each do |config|
174
- describe "Sequel truncation (using a #{config[:url]} connection)" do
175
- let(:db) { ::Sequel.connect(config[:url], config[:connection_options]) }
176
-
177
- it_behaves_like 'a Sequel truncation strategy'
178
- it_behaves_like 'a truncation strategy without autoincrement resets'
179
- end
180
- end
181
- end
182
- end
@@ -1,15 +0,0 @@
1
- shared_examples_for "a generic strategy" do
2
- it { should respond_to(:db) }
3
- end
4
-
5
- shared_examples_for "a generic truncation strategy" do
6
- it { should respond_to(:start) }
7
- it { should respond_to(:clean) }
8
- it { should respond_to(:cleaning) }
9
- end
10
-
11
- shared_examples_for "a generic transaction strategy" do
12
- it { should respond_to(:start) }
13
- it { should respond_to(:clean) }
14
- it { should respond_to(:cleaning) }
15
- end
data/spec/rcov.opts DELETED
@@ -1 +0,0 @@
1
- --exclude "spec/*,vendor/*,examples/*,features/*,Users/*/.rvm/gems/*/gems/*"
data/spec/spec_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- require "rubygems"
2
-
3
- require "bundler"
4
- Bundler.setup
5
-
6
- require 'rspec/core'
7
- require 'rspec/mocks'
8
-
9
- #require 'active_record'
10
- #require 'mongo_mapper'
11
-
12
- $:.unshift(File.dirname(__FILE__))
13
- $:.unshift(File.dirname(__FILE__) + '/../lib')
14
-
15
- require 'database_cleaner'
16
-
17
- RSpec.configure do |config|
18
-
19
- end
20
-
21
- alias running lambda
@@ -1,6 +0,0 @@
1
- require 'yaml'
2
-
3
- def db_config
4
- config_path = 'db/config.yml'
5
- @db_config ||= YAML.load(IO.read(config_path))
6
- end
@@ -1,14 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
- def self.up
3
- create_table :users do |t|
4
- t.string :name
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :users
10
- end
11
- end
12
-
13
- class ::User < ActiveRecord::Base
14
- end
@@ -1,14 +0,0 @@
1
- class CreateAgents < ActiveRecord::Migration
2
- def self.up
3
- create_table :agents do |t|
4
- t.string :name
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :agents
10
- end
11
- end
12
-
13
- class ::Agent < ActiveRecord::Base
14
- end
@@ -1,39 +0,0 @@
1
- require 'support/active_record/database_setup'
2
- require 'support/active_record/schema_setup'
3
-
4
-
5
- module MySQL2Helper
6
- puts "Active Record #{ActiveRecord::VERSION::STRING}, mysql2"
7
-
8
- # require 'logger'
9
- # ActiveRecord::Base.logger = Logger.new(STDERR)
10
-
11
- def default_config
12
- db_config['mysql2']
13
- end
14
-
15
- def create_db
16
- establish_connection(default_config.merge(:database => nil))
17
-
18
- ActiveRecord::Base.connection.drop_database default_config['database'] rescue nil
19
- ActiveRecord::Base.connection.create_database default_config['database']
20
- end
21
-
22
- def establish_connection(config = default_config)
23
- ActiveRecord::Base.establish_connection config
24
- end
25
-
26
- def active_record_mysql2_setup
27
- create_db
28
- establish_connection
29
- active_record_load_schema
30
- end
31
-
32
- def active_record_mysql2_connection
33
- ActiveRecord::Base.connection
34
- end
35
- end
36
-
37
- RSpec.configure do |c|
38
- c.include MySQL2Helper
39
- end
@@ -1,38 +0,0 @@
1
- require 'support/active_record/database_setup'
2
- require 'support/active_record/schema_setup'
3
-
4
- module MySQLHelper
5
- puts "Active Record #{ActiveRecord::VERSION::STRING}, mysql"
6
-
7
- # require 'logger'
8
- # ActiveRecord::Base.logger = Logger.new(STDERR)
9
-
10
- def default_config
11
- db_config['mysql']
12
- end
13
-
14
- def create_db
15
- establish_connection(default_config.merge(:database => nil))
16
-
17
- ActiveRecord::Base.connection.drop_database default_config['database'] rescue nil
18
- ActiveRecord::Base.connection.create_database default_config['database']
19
- end
20
-
21
- def establish_connection(config = default_config)
22
- ActiveRecord::Base.establish_connection config
23
- end
24
-
25
- def active_record_mysql_setup
26
- create_db
27
- establish_connection
28
- active_record_load_schema
29
- end
30
-
31
- def active_record_mysql_connection
32
- ActiveRecord::Base.connection
33
- end
34
- end
35
-
36
- RSpec.configure do |c|
37
- c.include MySQLHelper
38
- end
@@ -1,48 +0,0 @@
1
- require 'support/active_record/database_setup'
2
- require 'support/active_record/schema_setup'
3
-
4
- module PostgreSQLHelper
5
- puts "Active Record #{ActiveRecord::VERSION::STRING}, pg"
6
-
7
- # ActiveRecord::Base.logger = Logger.new(STDERR)
8
-
9
- def default_config
10
- db_config['postgres']
11
- end
12
-
13
- def create_db
14
- @encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
15
- begin
16
- establish_connection(default_config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
17
- ActiveRecord::Base.connection.drop_database(default_config['database']) rescue nil
18
- ActiveRecord::Base.connection.create_database(default_config['database'], default_config.merge('encoding' => @encoding))
19
- rescue Exception => e
20
- $stderr.puts e, *(e.backtrace)
21
- $stderr.puts "Couldn't create database for #{default_config.inspect}"
22
- end
23
- end
24
-
25
- def establish_connection(config = default_config)
26
- ActiveRecord::Base.establish_connection(config)
27
- end
28
-
29
- def active_record_pg_setup
30
- create_db
31
- establish_connection
32
- active_record_load_schema
33
- end
34
-
35
- def active_record_pg_migrate
36
- create_db
37
- establish_connection
38
- ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
39
- end
40
-
41
- def active_record_pg_connection
42
- ActiveRecord::Base.connection
43
- end
44
- end
45
-
46
- RSpec.configure do |c|
47
- c.include PostgreSQLHelper
48
- end
@@ -1,17 +0,0 @@
1
- def active_record_load_schema
2
- ActiveRecord::Schema.define do
3
- create_table :users, :force => true do |t|
4
- t.integer :name
5
- end
6
-
7
- create_table :agents, :id => false, :force => true do |t|
8
- t.integer :name
9
- end
10
- end
11
- end
12
-
13
- class ::User < ActiveRecord::Base
14
- end
15
-
16
- class ::Agent < ActiveRecord::Base
17
- end
@@ -1,40 +0,0 @@
1
- require 'support/active_record/database_setup'
2
- require 'support/active_record/schema_setup'
3
-
4
- module SQLite3Helper
5
- puts "Active Record #{ActiveRecord::VERSION::STRING}, sqlite3"
6
-
7
- # ActiveRecord::Base.logger = Logger.new(STDERR)
8
-
9
- def default_config
10
- db_config['sqlite3']
11
- end
12
-
13
- def create_db
14
- @encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
15
- begin
16
- establish_connection(default_config.merge('database' => 'sqlite3', 'schema_search_path' => 'public'))
17
- rescue Exception => e
18
- $stderr.puts e, *(e.backtrace)
19
- $stderr.puts "Couldn't create database for #{default_config.inspect}"
20
- end
21
- end
22
-
23
- def establish_connection(config = default_config)
24
- ActiveRecord::Base.establish_connection(config)
25
- end
26
-
27
- def active_record_sqlite3_setup
28
- create_db
29
- establish_connection
30
- active_record_load_schema
31
- end
32
-
33
- def active_record_sqlite3_connection
34
- ActiveRecord::Base.connection
35
- end
36
- end
37
-
38
- RSpec.configure do |c|
39
- c.include SQLite3Helper
40
- end
@@ -1,15 +0,0 @@
1
- def data_mapper_load_schema
2
- require 'dm-migrations'
3
-
4
- DataMapper.auto_migrate!
5
- end
6
-
7
- class ::DmUser
8
- include DataMapper::Resource
9
-
10
- self.storage_names[:default] = 'users'
11
-
12
- property :id, Serial
13
- property :name, String
14
-
15
- end
@@ -1,39 +0,0 @@
1
- require 'support/active_record/database_setup'
2
- require 'support/data_mapper/schema_setup'
3
-
4
- module DataMapperSQLite3Helper
5
-
6
- puts "DataMapper #{DataMapper::VERSION}, sqlite3"
7
-
8
- def default_config
9
- db_config['sqlite3']
10
- end
11
-
12
- def create_db
13
- @encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
14
- begin
15
- establish_connection(default_config.merge('database' => 'sqlite3', 'schema_search_path' => 'public'))
16
- rescue Exception => e
17
- $stderr.puts e, *(e.backtrace)
18
- $stderr.puts "Couldn't create database for #{default_config.inspect}"
19
- end
20
- end
21
-
22
- def establish_connection(config = default_config)
23
- DataMapper.setup(:default, config)
24
- end
25
-
26
- def data_mapper_sqlite3_setup
27
- create_db
28
- establish_connection
29
- data_mapper_load_schema
30
- end
31
-
32
- def data_mapper_sqlite3_connection
33
- DataMapper.repository.adapter
34
- end
35
- end
36
-
37
- RSpec.configure do |c|
38
- c.include(DataMapperSQLite3Helper)
39
- end