postspec 0.2.4 → 0.3.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: 0a37e17b3250ab5a8ea9553c1c332d946f7bb642eb25c1dad8ebc9c6210ec9d3
4
- data.tar.gz: 7e9042c7fd716f3222b6bc9b7d7409048ea35531da880e96e80f961fb50b76d5
3
+ metadata.gz: ca6e04e0de0967bafaba5c3eb7072f56e72574e4344f65ced4f3b87f1330f6ca
4
+ data.tar.gz: e71ade1a64158703302b6ee982b1861e6a936010adb9d354c74a2994fe151f3c
5
5
  SHA512:
6
- metadata.gz: 5c12cdecb6a05d0e0086d59cf2045f0f7b5d969f3df6759d3d5343f089c371657a546b3347f26799dd469ecd88516b106fbc8f5289244371b86ba98fa7230068
7
- data.tar.gz: d4e07f0c8a8cfda85c27586088e95e6a77701fe478e643c612603dbb14df3151caafcbccbdddb17a4e3ae8938f4555f0369339702d8592cc43463c0739388142
6
+ metadata.gz: b20845560ebfdacb2ebd7b4e087e7f65ff78802f04c6e68a1339e74ec3a6b52bd9f022cbf2539a56eb3ac4ca06e0abbe62576e81bba08b843aa4d356b7edfe6c
7
+ data.tar.gz: c6d458fb0e0c71cd55d0641057b1ccfb96b5202bef248b6e772e1b74e88b8ee5c36f44fe679d6fc61889b2f362a790b13a85fe84f25e42fba870e10c6b7ffb2a
@@ -47,14 +47,17 @@ module Postspec
47
47
  when :create; create_seed_triggers(uids)
48
48
  when :drop; drop_seed_triggers
49
49
  else
50
- raise ArgumentError
50
+ raise ArgumentError, state.inspect
51
51
  end
52
52
  end
53
53
 
54
54
  def drop_seed_triggers
55
+ p "DROP"
55
56
  postspec.tables.map { |uid|
57
+ p "BING"
56
58
  [SEED_BUD_TRIGGER_NAME, SEED_BT_TRIGGER_NAME].map { |trigger|
57
59
  trigger_uid = "#{uid}.#{trigger}()"
60
+ p trigger_uid
58
61
  postspec.meta.exist?(trigger_uid) ? "drop trigger #{trigger} on #{uid}" : nil
59
62
  }.compact
60
63
  }.flatten
@@ -77,11 +80,15 @@ module Postspec
77
80
  execute function postspec.readonly_failure('#{uid}')
78
81
  EOS1
79
82
  bt_sql = <<~EOS2
80
- create trigger postspec_readonly_trigger_bt
83
+ create trigger postspec_readonly_bt_trg
81
84
  before truncate on #{uid}
82
85
  execute function postspec.readonly_failure('#{uid}')
83
86
  EOS2
84
- [bud_sql, bt_sql, "insert into postspec.seeds (table_uid, record_id) values ('#{uid}', #{id})"]
87
+ [
88
+ bud_sql.chomp,
89
+ bt_sql.chomp,
90
+ "insert into postspec.seeds (table_uid, record_id) values ('#{uid}', #{id})"
91
+ ]
85
92
  }.flatten
86
93
  end
87
94
 
@@ -1,3 +1,3 @@
1
1
  module Postspec
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/postspec.rb CHANGED
@@ -68,16 +68,17 @@ module Postspec
68
68
  # TODO: PgMeta object
69
69
  #
70
70
  # +mode+ can be one of :seed, :empty (TODO :reseed, :keep)
71
- def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true, ignore: [])
71
+ def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true, ignore: [], cache: nil)
72
72
  constrain conn, PgConn
73
73
  constrain reflector, NilClass, String, PgGraph::Reflector
74
74
  constrain mode, lambda { |m| [:empty, :seed].include?(m) }
75
75
  constrain anchors, [Hash], NilClass
76
76
  constrain fail, TrueClass, FalseClass
77
77
  constrain ignore, [String]
78
+ constrain cache, String, nil
78
79
 
79
80
  @conn = conn
80
- @meta = PgMeta.new(@conn)
81
+ @meta = cache ? PgMeta.cache(@conn, yaml: cache) : PgMeta.new(@conn)
81
82
 
82
83
  # Make sure the postspec schema is not included in the type model. TODO:
83
84
  # Consolidate this into the :ignore option of PgGraph::Type.new as is
@@ -85,7 +86,8 @@ module Postspec
85
86
  has_postspec = @meta.schemas.key?("postspec")
86
87
  !has_postspec or (@meta.schemas["postspec"].hidden = true)
87
88
 
88
- @type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"] + ignore)
89
+ @type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"] + ignore)
90
+
89
91
  @render = Render.new(self)
90
92
  @tables = type.schemas.map(&:tables).flatten
91
93
  @ignore = ignore
@@ -32,30 +32,27 @@ RSpec.configure do |config|
32
32
  end
33
33
 
34
34
  config.around(:example) do |example|
35
- # puts "postspec_helper around example"
36
35
  if postspec.failed?
37
36
  example.skip
38
37
  else
39
38
  postspec.conn.push_transaction
40
39
  begin
41
- # puts ">> TRYING"
42
40
  result = example.run
43
- # puts ">> RESULT: #{result.inspect} (#{result.class})"
44
- # puts ">> EXAMPLE: #{example.exception.inspect} (#{example.exception.class})"
45
- # puts ">> EXECUTION_RESULT: #{example.execution_result}"
46
- if result.is_a?(PG::Error)
47
- postspec.fail!
48
- postspec.conn.cancel_transaction
49
- elsif result.is_a?(Exception)
50
- postspec.fail!
51
- postspec.conn.pop_transaction(commit: postspec.failed?)
41
+
42
+ case example.execution_result.exception
43
+ when PG::Error
44
+ # Collapse whole transaction stack
45
+ postspec.fail!
46
+ postspec.conn.cancel_transaction
47
+ when Exception
48
+ # Pops only last transaction
49
+ postspec.fail!
50
+ postspec.conn.pop_transaction(commit: postspec.failed?)
52
51
  else
53
- postspec.conn.pop_transaction(commit: postspec.failed?)
52
+ # Success - pop last transaction
53
+ postspec.conn.pop_transaction(commit: postspec.failed?, fail: false)
54
54
  end
55
- rescue
56
- puts ">> OTHER EXCEPTIONS"
57
- puts ">> OTHER EXCEPTIONS"
58
- puts ">> OTHER EXCEPTIONS"
55
+ rescue => ex # Happens when rspec itself fails
59
56
  postspec.conn.cancel_transaction
60
57
  postspec.fail!
61
58
  raise
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-18 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  requirements: []
233
- rubygems_version: 3.3.18
233
+ rubygems_version: 3.3.7
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: postspec gem