noncommittal 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7557b627c1362e8ee9b04006e3c6d2e9663764fb4315714e600531f22907643
4
- data.tar.gz: f7f88e955fdc0367083a8d6e403595ec4fc07302f06c8238e443c60c2de8491b
3
+ metadata.gz: 879fc0c2093963716f47cc6b6cce6a061af562276863e1e82ecf877f138cc967
4
+ data.tar.gz: deef82a615dac6ee22b4ac9c6fc5172721981fd02c50afbf2d2e3f3d8bc79be1
5
5
  SHA512:
6
- metadata.gz: cdcbc2d52e274631bb2a6df662745619247d5fcc6e590679c78772b13c39a1ee0fc4562b289ae783a5b0ff4b7e5849272771c2434bf481a7ea3b9d35086983da
7
- data.tar.gz: 35390d884f70ce8c61fb207fd2ffbf21e1f2a97d21669cfebe524673de8cb43d5b611d35cc3eaac895566e09aab631cde3c300e140908f0ac5439b48734c0bed
6
+ metadata.gz: fd5028466829afe2049492b285d50eec77cdea8cea8e76aefaa57510557af7a94a7a3a0c89de018c7a097927b5651dffd663be9cea48e991563d3e1923702368
7
+ data.tar.gz: b92d7569ca458fa6f36cf6c245d8638f5c86535f8f29ab1bb6dea20241f2b9f7347c25ff5907e0184957ca9ffed45070003b1f7260066dba15eb5748bc05e3e9
@@ -1,3 +1,7 @@
1
+ ## 0.2.0
2
+
3
+ * Added `stop!` (#1)
4
+
1
5
  ## 0.1.1
2
6
 
3
7
  * Locks down all tables by querying postgres as opposed to looking for
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- noncommittal (0.1.1)
4
+ noncommittal (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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!(tables: [:users, :posts])
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
@@ -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 ||= begin
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
@@ -1,3 +1,3 @@
1
1
  module Noncommittal
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.1
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: 2020-12-10 00:00:00.000000000 Z
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.2
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