noncommittal 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -1
- data/lib/noncommittal.rb +21 -7
- data/lib/noncommittal/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 879fc0c2093963716f47cc6b6cce6a061af562276863e1e82ecf877f138cc967
|
4
|
+
data.tar.gz: deef82a615dac6ee22b4ac9c6fc5172721981fd02c50afbf2d2e3f3d8bc79be1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5028466829afe2049492b285d50eec77cdea8cea8e76aefaa57510557af7a94a7a3a0c89de018c7a097927b5651dffd663be9cea48e991563d3e1923702368
|
7
|
+
data.tar.gz: b92d7569ca458fa6f36cf6c245d8638f5c86535f8f29ab1bb6dea20241f2b9f7347c25ff5907e0184957ca9ffed45070003b1f7260066dba15eb5748bc05e3e9
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Then, in your `test_helper.rb` (or similar), after you require your Rails
|
|
17
17
|
environment, just drop this in:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
Noncommittal.start!
|
20
|
+
Noncommittal.start!
|
21
21
|
```
|
22
22
|
|
23
23
|
This will create an empty table called `noncommittal_no_rows_allowed` and, for
|
@@ -81,6 +81,12 @@ keyword argument:
|
|
81
81
|
Noncommittal.start!(exclude_tables: [:system_configurations])
|
82
82
|
```
|
83
83
|
|
84
|
+
## What if I want to stop disallowing committed inserts?
|
85
|
+
|
86
|
+
Just call `Noncommittal.stop!`, which takes the same arguments as `start!` for
|
87
|
+
specifying tables and exclusions, and will simply remove all the constraints
|
88
|
+
and the reference table.
|
89
|
+
|
84
90
|
## Limitations
|
85
91
|
|
86
92
|
This only works with Postgres currently. PRs welcome if you can accomplish the
|
data/lib/noncommittal.rb
CHANGED
@@ -4,13 +4,7 @@ module Noncommittal
|
|
4
4
|
def self.start!(tables: nil, exclude_tables: [])
|
5
5
|
raise "noncommittal is only designed to be run in your test environment!" unless Rails.env.test?
|
6
6
|
|
7
|
-
tables ||=
|
8
|
-
ActiveRecord::Base.connection.select_values(
|
9
|
-
"select table_name from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' and table_catalog = $1",
|
10
|
-
"SQL",
|
11
|
-
[ActiveRecord::Relation::QueryAttribute.new("table_name", ActiveRecord::Base.connection.current_database, ActiveRecord::Type::String.new)]
|
12
|
-
) - ["ar_internal_metadata", "schema_migrations"]
|
13
|
-
end
|
7
|
+
tables ||= __gather_default_tables
|
14
8
|
tables = tables.map(&:to_s) - exclude_tables.map(&:to_s)
|
15
9
|
|
16
10
|
ActiveRecord::Base.connection.execute <<~SQL
|
@@ -24,4 +18,24 @@ module Noncommittal
|
|
24
18
|
}.join("\n")}
|
25
19
|
SQL
|
26
20
|
end
|
21
|
+
|
22
|
+
def self.stop!(tables: nil, exclude_tables: [])
|
23
|
+
tables ||= __gather_default_tables
|
24
|
+
tables = tables.map(&:to_s) - exclude_tables.map(&:to_s)
|
25
|
+
|
26
|
+
ActiveRecord::Base.connection.execute <<~SQL
|
27
|
+
#{tables.map { |table_name|
|
28
|
+
"alter table #{table_name} drop constraint if exists noncommittal_#{table_name};"
|
29
|
+
}.join("\n")}
|
30
|
+
drop table if exists noncommittal_no_rows_allowed;
|
31
|
+
SQL
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.__gather_default_tables
|
35
|
+
ActiveRecord::Base.connection.select_values(
|
36
|
+
"select table_name from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' and table_catalog = $1",
|
37
|
+
"SQL",
|
38
|
+
[ActiveRecord::Relation::QueryAttribute.new("catalog_name", ActiveRecord::Base.connection.current_database, ActiveRecord::Type::String.new)]
|
39
|
+
) - ["ar_internal_metadata", "schema_migrations"]
|
40
|
+
end
|
27
41
|
end
|
data/lib/noncommittal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noncommittal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.1.
|
53
|
+
rubygems_version: 3.1.4
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: Ensures test isolation by preventing your Rails tests from committing to
|