database_cleaner-core 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ require "database_cleaner/spec/database_helper"
2
+ require "database_cleaner/spec/shared_examples"
@@ -0,0 +1,82 @@
1
+ require 'yaml'
2
+
3
+ module DatabaseCleaner
4
+ module Spec
5
+ class DatabaseHelper < Struct.new(:db)
6
+ def self.with_all_dbs &block
7
+ %w[mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
8
+ yield new(db)
9
+ end
10
+ end
11
+
12
+ def setup
13
+ create_db
14
+ establish_connection
15
+ load_schema
16
+ end
17
+
18
+ attr_reader :connection
19
+
20
+ def teardown
21
+ drop_db
22
+ end
23
+
24
+ private
25
+
26
+ def establish_connection(config = default_config)
27
+ raise NotImplementedError
28
+ end
29
+
30
+ def create_db
31
+ if db == :sqlite3
32
+ # NO-OP
33
+ elsif db == :postgres
34
+ establish_connection default_config.merge('database' => 'postgres')
35
+ connection.execute "CREATE DATABASE #{default_config['database']}" rescue nil
36
+ else
37
+ establish_connection default_config.merge("database" => nil)
38
+ connection.execute "CREATE DATABASE IF NOT EXISTS #{default_config['database']}"
39
+ end
40
+ end
41
+
42
+ def load_schema
43
+ connection.execute <<-SQL
44
+ CREATE TABLE IF NOT EXISTS users (
45
+ id SERIAL PRIMARY KEY,
46
+ name INTEGER
47
+ );
48
+ SQL
49
+
50
+ connection.execute <<-SQL
51
+ CREATE TABLE IF NOT EXISTS agents (
52
+ name INTEGER
53
+ );
54
+ SQL
55
+ end
56
+
57
+ def drop_db
58
+ if db == :sqlite3
59
+ begin
60
+ File.unlink(db_config['sqlite3']['database'])
61
+ rescue Errno::ENOENT
62
+ end
63
+ elsif db == :postgres
64
+ # FIXME
65
+ connection.execute "DROP TABLE IF EXISTS users"
66
+ connection.execute "DROP TABLE IF EXISTS agents"
67
+ else
68
+ connection.execute "DROP DATABASE IF EXISTS #{default_config['database']}"
69
+ end
70
+ end
71
+
72
+ def db_config
73
+ config_path = 'spec/support/config.yml'
74
+ @db_config ||= YAML.load(IO.read(config_path))
75
+ end
76
+
77
+ def default_config
78
+ db_config[db.to_s]
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,24 @@
1
+ RSpec.shared_examples_for "a database_cleaner strategy" do
2
+ it { is_expected.to respond_to(:db) }
3
+ it { is_expected.to respond_to(:db=) }
4
+ it { is_expected.to respond_to(:start) }
5
+ it { is_expected.to respond_to(:clean) }
6
+ it { is_expected.to respond_to(:cleaning) }
7
+ end
8
+
9
+ RSpec.shared_examples_for "a database_cleaner adapter" do
10
+ it { expect(described_class).to respond_to(:available_strategies) }
11
+ it { expect(described_class).to respond_to(:default_strategy) }
12
+
13
+ it 'default_strategy should be part of available_strategies' do
14
+ expect(described_class.available_strategies).to include(described_class.default_strategy)
15
+ end
16
+
17
+ describe 'all strategies should adhere to a database_cleaner strategy interface' do
18
+ described_class.available_strategies.each do |strategy|
19
+ subject { described_class.const_get(strategy.to_s.capitalize).new }
20
+
21
+ it_behaves_like 'a database_cleaner strategy'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module DatabaseCleaner
2
+ VERSION = "2.0.0.beta"
3
+ end
data/tmp/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: database_cleaner-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Ben Mabey
8
+ - Ernesto Tagwerker
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: guard-rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: listen
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: cucumber
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Strategies for cleaning databases. Can be used to ensure a clean slate
99
+ for testing.
100
+ email:
101
+ - ernesto@ombulabs.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".ruby-version.sample"
109
+ - ".travis.yml"
110
+ - CONTRIBUTE.markdown
111
+ - Gemfile
112
+ - Guardfile
113
+ - History.rdoc
114
+ - LICENSE
115
+ - README.markdown
116
+ - Rakefile
117
+ - bin/setup
118
+ - cucumber.yml
119
+ - database_cleaner-core.gemspec
120
+ - database_cleaner.gemspec
121
+ - lib/database_cleaner-core.rb
122
+ - lib/database_cleaner/base.rb
123
+ - lib/database_cleaner/configuration.rb
124
+ - lib/database_cleaner/core.rb
125
+ - lib/database_cleaner/cucumber.rb
126
+ - lib/database_cleaner/deprecation.rb
127
+ - lib/database_cleaner/generic/base.rb
128
+ - lib/database_cleaner/generic/transaction.rb
129
+ - lib/database_cleaner/generic/truncation.rb
130
+ - lib/database_cleaner/null_strategy.rb
131
+ - lib/database_cleaner/safeguard.rb
132
+ - lib/database_cleaner/spec.rb
133
+ - lib/database_cleaner/spec/database_helper.rb
134
+ - lib/database_cleaner/spec/shared_examples.rb
135
+ - lib/database_cleaner/version.rb
136
+ - tmp/.keep
137
+ homepage: https://github.com/DatabaseCleaner/database_cleaner
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">"
153
+ - !ruby/object:Gem::Version
154
+ version: 1.3.1
155
+ requirements: []
156
+ rubygems_version: 3.0.3
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Strategies for cleaning databases. Can be used to ensure a clean slate for
160
+ testing.
161
+ test_files: []