database_cleaner-sequel 1.8.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1253a731c343a4cfa702e0af053515520d99be4d117b67e849701034dbb622fe
4
+ data.tar.gz: 59066a7d47bc23bdcf68023247422839b0aae9a39b3bac48e1101d2d0e677765
5
+ SHA512:
6
+ metadata.gz: de0085bab712fa412e5552c229460ba3785a172bf53e70da654ee6519673b60091ca9cd1d3297633cde9cbb8f4eaff1d1bde4555e2ffcee9d077970f5538b4b0
7
+ data.tar.gz: 06690a46bb8ad0945b86706f9195e298afa61a9b2cff2c63dc387b690ed28848729251fa526a05e2a171c45cbe9584cdf1ff56442c8a738019f3e9a7e3e711cb
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/support/config.yml
9
+ /tmp/
10
+ !/tmp/.keep
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.9
5
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in database_cleaner-sequel.gemspec
6
+ gemspec
7
+
8
+ gem "database_cleaner", path: "../.."
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ database_cleaner (1.8.0.beta)
5
+
6
+ PATH
7
+ remote: .
8
+ specs:
9
+ database_cleaner-sequel (1.8.0.beta)
10
+ database_cleaner (~> 1.8.0.beta)
11
+ sequel
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ diff-lcs (1.3)
17
+ mysql (2.9.1)
18
+ mysql2 (0.3.18)
19
+ pg (0.18.2)
20
+ rake (10.4.2)
21
+ rspec (3.7.0)
22
+ rspec-core (~> 3.7.0)
23
+ rspec-expectations (~> 3.7.0)
24
+ rspec-mocks (~> 3.7.0)
25
+ rspec-core (3.7.1)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-expectations (3.7.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-mocks (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-support (3.7.1)
34
+ sequel (5.28.0)
35
+ sqlite3 (1.3.10)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.16)
42
+ database_cleaner!
43
+ database_cleaner-sequel!
44
+ mysql (~> 2.9.1)
45
+ mysql2
46
+ pg
47
+ rake (~> 10.0)
48
+ rspec (~> 3.0)
49
+ sqlite3
50
+
51
+ BUNDLED WITH
52
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009 Ben Mabey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # Database Cleaner Adapter for Sequel
2
+
3
+ [![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner-sequel.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner-sequel)
4
+ [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-sequel/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-sequel)
5
+
6
+ Clean your Sequel databases with Database Cleaner.
7
+
8
+ See https://github.com/DatabaseCleaner/database_cleaner for more information.
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ # Gemfile
14
+ group :test do
15
+ gem 'database_cleaner-sequel'
16
+ end
17
+ ```
18
+
19
+ ## Supported Strategies
20
+
21
+ Here is an overview of the supported strategies:
22
+
23
+ <table>
24
+ <tbody>
25
+ <tr>
26
+ <th>Truncation</th>
27
+ <th>Transaction</th>
28
+ <th>Deletion</th>
29
+ </tr>
30
+ <tr>
31
+ <td> Yes</td>
32
+ <td> <b>Yes</b></td>
33
+ <td> Yes</td>
34
+ </tr>
35
+ </tbody>
36
+ </table>
37
+
38
+ (Default strategy is denoted in bold)
39
+
40
+ ## Configuration options
41
+
42
+ <table>
43
+ <tbody>
44
+ <tr>
45
+ <th>ORM</th>
46
+ <th>How to access</th>
47
+ <th>Notes</th>
48
+ </tr>
49
+ <tr>
50
+ <td> Sequel</td>
51
+ <td> <code>DatabaseCleaner[:sequel]</code></td>
52
+ <td> Multiple databases supported; specify <code>DatabaseCleaner[:sequel, {:connection =&gt; Sequel.connect(uri)}]</code></td>
53
+ </tr>
54
+ </tbody>
55
+ </table>
56
+
57
+ ## Common Errors
58
+
59
+ ### Nothing happens in JRuby with Sequel using transactions
60
+
61
+ Due to an inconsistency in JRuby's implementation of Fibers, Sequel gives a different connection to `DatabaseCleaner.start` than is used for tests run between `.start` and `.clean`. This can be worked around by running your tests in a block like `DatabaseCleaner.cleaning { run_my_tests }` instead, which does not use Fibers.
62
+
63
+ ## COPYRIGHT
64
+
65
+ See [LICENSE] for details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "database_cleaner/sequel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle check || bundle install
7
+ cp spec/support/sample.config.yml spec/support/config.yml
8
+
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "database_cleaner/sequel/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "database_cleaner-sequel"
8
+ spec.version = DatabaseCleaner::Sequel::VERSION
9
+ spec.authors = ["Ernesto Tagwerker"]
10
+ spec.email = ["ernesto@ombulabs.com"]
11
+
12
+ spec.summary = "Strategies for cleaning databases using Sequel. Can be used to ensure a clean state for testing."
13
+ spec.description = "Strategies for cleaning databases using Sequel. Can be used to ensure a clean state for testing."
14
+ spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-sequel"
15
+ spec.license = "MIT"
16
+
17
+ spec.add_dependency "database_cleaner", "~> 1.8.0.beta"
18
+ spec.add_dependency "sequel"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+
31
+ spec.add_development_dependency 'mysql', '~> 2.9.1'
32
+ spec.add_development_dependency 'mysql2'
33
+ spec.add_development_dependency 'pg'
34
+ spec.add_development_dependency "sqlite3"
35
+ end
@@ -0,0 +1 @@
1
+ require "database_cleaner/sequel"
@@ -0,0 +1,6 @@
1
+ require "database_cleaner/sequel/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/sequel/truncation"
4
+ require "database_cleaner/sequel/transaction"
5
+ require "database_cleaner/sequel/deletion"
6
+
@@ -0,0 +1,26 @@
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
+ def self.default_strategy
9
+ :transaction
10
+ end
11
+
12
+ module Base
13
+ include ::DatabaseCleaner::Generic::Base
14
+
15
+ def db=(desired_db)
16
+ @db = desired_db
17
+ end
18
+
19
+ def db
20
+ return @db if @db && @db != :default
21
+ raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1
22
+ ::Sequel::DATABASES.first || :default
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,79 @@
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
+ tables = tables_to_truncate(db)
18
+
19
+ # Count rows before truncating
20
+ if pre_count?
21
+ tables = pre_count_tables(tables)
22
+ end
23
+
24
+ case db.database_type
25
+ when :postgres
26
+ # PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
27
+ # appended. Bulk truncation without CASCADE is:
28
+ # * Safer. Tables outside of tables_to_truncate won't be affected.
29
+ # * Faster. Less roundtrips to the db.
30
+ unless tables.empty?
31
+ tables_sql = tables.map { |t| %("#{t}") }.join(',')
32
+ db.run "TRUNCATE TABLE #{tables_sql} RESTART IDENTITY;"
33
+ end
34
+ else
35
+ truncate_tables(db, tables)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def pre_count_tables tables
42
+ tables.reject { |table| db[table.to_sym].count == 0 }
43
+ end
44
+
45
+ def truncate_tables(db, tables)
46
+ tables.each do |table|
47
+ db[table.to_sym].truncate
48
+ if db.database_type == :sqlite && db.table_exists?(:sqlite_sequence)
49
+ db[:sqlite_sequence].where(name: table).delete
50
+ end
51
+ end
52
+ end
53
+
54
+ def dirty?
55
+ @last_txid != txid || @last_txid.nil?
56
+ end
57
+
58
+ def txid
59
+ case db.database_type
60
+ when :postgres
61
+ db.fetch('SELECT txid_snapshot_xmax(txid_current_snapshot()) AS txid').first[:txid]
62
+ end
63
+ end
64
+
65
+ def tables_to_truncate(db)
66
+ (@only || db.tables.map(&:to_s)) - @tables_to_exclude
67
+ end
68
+
69
+ # overwritten
70
+ def migration_storage_names
71
+ %w(schema_info schema_migrations)
72
+ end
73
+
74
+ def pre_count?
75
+ @pre_count == true
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Sequel
3
+ VERSION = "1.8.0.beta"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: database_cleaner-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Ernesto Tagwerker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: database_cleaner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0.beta
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0.beta
27
+ - !ruby/object:Gem::Dependency
28
+ name: sequel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.9.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.9.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: mysql2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Strategies for cleaning databases using Sequel. Can be used to ensure
140
+ a clean state for testing.
141
+ email:
142
+ - ernesto@ombulabs.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - database_cleaner-sequel.gemspec
158
+ - lib/database_cleaner-sequel.rb
159
+ - lib/database_cleaner/sequel.rb
160
+ - lib/database_cleaner/sequel/base.rb
161
+ - lib/database_cleaner/sequel/deletion.rb
162
+ - lib/database_cleaner/sequel/transaction.rb
163
+ - lib/database_cleaner/sequel/truncation.rb
164
+ - lib/database_cleaner/sequel/version.rb
165
+ - tmp/.keep
166
+ homepage: https://github.com/DatabaseCleaner/database_cleaner-sequel
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">"
182
+ - !ruby/object:Gem::Version
183
+ version: 1.3.1
184
+ requirements: []
185
+ rubygems_version: 3.0.4
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Strategies for cleaning databases using Sequel. Can be used to ensure a clean
189
+ state for testing.
190
+ test_files: []