fixpoints 0.2.5 → 0.2.6

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: 4fc86155d7a0255ba0b6001e2d9a848820a88679faf80a009523ce169d87bb47
4
- data.tar.gz: b05dff89ee223f26b9aaaddbe8b076b11b07d941dda4c6b25de770e833066700
3
+ metadata.gz: 4a12beeaa3e9a600b6bafeb91a4ed10e769dd24c5e179634e71044f8b91cff4f
4
+ data.tar.gz: 7156873029ee1e27e9e5487c43fccdd929078eb83de1b67e87abc11e73cc4d08
5
5
  SHA512:
6
- metadata.gz: 5d93cbb9284a2012294e880b1a4a1a2f65d5fbae6acb7a333e19de1f141ba492ecbace36e7123c78a293c0d19d018f6715f90733e9d8b98d1d56fdfde28a2643
7
- data.tar.gz: 8564d92f6540959ff166ea5cbbd1f82a6ab4cffe839141fbf65152e6cb53a71ddfee08cc583243842120c3b6f7167523b024179015a9c6996bcf4c9640cf3fbb
6
+ metadata.gz: eaa831ed5ad889e9b1d18071ccf721dfc7973efe1a86f7fc9aea02f5aab13616c68eddff8a50d8a6e07c1ff8ad59a386b7d5f8cdf0ac4f67470ec918d7293ca6
7
+ data.tar.gz: ab9cfcca94232a87eb09d02a158756eaef69edf92468af02abea478638ad9134523ce4e564c9940f4c62fa5ab8d1b2855725970dd54b527856c3ee3bf06a95ba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fixpoints (0.2.3)
4
+ fixpoints (0.2.6)
5
5
  activerecord (>= 5.0.0)
6
6
  rspec
7
7
 
data/README.md CHANGED
@@ -123,6 +123,16 @@ to specify the database connection to use.
123
123
  end
124
124
  ```
125
125
 
126
+ **Exclude Tables** If a database contains tables that are irrelevant to your tests, you can use the optional `exclude_tables` parameter
127
+ to specify a set of tables to exclude from the fixpoint.
128
+
129
+ ```ruby
130
+ it 'excludes versions' do
131
+ store_fixpoint_unless_present :registered_user, exclude_tables: ['versions']
132
+ # ...
133
+ end
134
+ ```
135
+
126
136
  ## Limitations & Known issues
127
137
 
128
138
  - The records in tables are ordered by their id.
data/lib/fixpoint.rb CHANGED
@@ -45,8 +45,8 @@ class Fixpoint
45
45
  end
46
46
 
47
47
  # Creates a Fixpoint from the database contents. Empty tables are skipped.
48
- def from_database(conn)
49
- new(read_database_records(conn))
48
+ def from_database(conn, exclude_tables: [])
49
+ new(read_database_records(conn, exclude_tables: exclude_tables))
50
50
  end
51
51
 
52
52
  def remove(fixname)
@@ -81,11 +81,11 @@ class Fixpoint
81
81
  File.join(spec_path, FIXPOINT_FOLDER)
82
82
  end
83
83
 
84
- def read_database_records(conn)
84
+ def read_database_records(conn, exclude_tables: [])
85
85
  # adapted from: https://yizeng.me/2017/07/16/generate-rails-test-fixtures-yaml-from-database-dump/
86
86
  tables = conn.tables
87
- tables.reject! { |table_name| TABLES_TO_SKIP.include?(table_name) }
88
-
87
+ excluded_tables = TABLES_TO_SKIP + exclude_tables
88
+ tables.reject! { |table_name| excluded_tables.include?(table_name) }
89
89
  tables.each_with_object({}) do |table_name, acc|
90
90
  result = conn.select_all("SELECT * FROM #{conn.quote_table_name(table_name)}")
91
91
  next if result.count.zero?
@@ -10,16 +10,17 @@ module FixpointTestHelpers
10
10
  # The latter is useful if the fixpoint was deleted to accommodate changes to it (see example in class description).
11
11
  #
12
12
  # +tables_to_compare+ can either be +:all+ or a list of table names (e.g. ['users', 'posts'])
13
+ # +exclude_tables+ a list of tables which should be ignored when storing a fixpoint (e.g. ['versions'])
13
14
  # +ignored_columns+ see Fixnum#records_for_table
14
15
  # +store_fixpoint_and_fail+ when given and the fixpoint does not already exist, a new fixpoint is created an the test will be marked pending/failed
15
16
  # +parent_fixname+ when storing a new fixpoint, use this as parent fixpoint (you can specify `:last_restored` then the last given to restore_fixpoint is used; not thread safe)
16
17
  # ---
17
18
  # If we refactor this to a gem, we should rely on rspec (e.g. use minitest or move comparison logic to Fixpoint class).
18
19
  # Anyhow, we keep it like this for now, because the expectations give much nicer output than the minitest assertions.
19
- def compare_fixpoint(fixname, ignored_columns=[:updated_at, :created_at], tables_to_compare: :all, store_fixpoint_and_fail: false, parent_fixname: nil, connection: default_connection)
20
+ def compare_fixpoint(fixname, ignored_columns=[:updated_at, :created_at], tables_to_compare: :all, exclude_tables: [], store_fixpoint_and_fail: false, parent_fixname: nil, connection: default_connection)
20
21
  if !IncrementalFixpoint.exists?(fixname)
21
22
  if store_fixpoint_and_fail
22
- store_fixpoint(fixname, parent_fixname, connection: connection)
23
+ store_fixpoint(fixname, parent_fixname, connection: connection, exclude_tables: exclude_tables)
23
24
  pending("Fixpoint \"#{fixname}\" did not exist yet. Skipping comparison, but created fixpoint from database. Try re-running the test.")
24
25
  fail
25
26
  else
@@ -27,7 +28,7 @@ module FixpointTestHelpers
27
28
  end
28
29
  end
29
30
 
30
- database_fp = IncrementalFixpoint.from_database(nil, connection)
31
+ database_fp = IncrementalFixpoint.from_database(nil, connection, exclude_tables: exclude_tables)
31
32
  fixpoint_fp = IncrementalFixpoint.from_file(fixname)
32
33
 
33
34
  tables_to_compare = (database_fp.table_names + fixpoint_fp.table_names).uniq if tables_to_compare == :all
@@ -42,15 +43,15 @@ module FixpointTestHelpers
42
43
 
43
44
  # it is not a good idea to overwrite the fixpoint each time because timestamps may change (which then shows up in version control).
44
45
  # Hence we only provide a method to write to it if it does not exist.
45
- def store_fixpoint_unless_present(fixname, parent_fixname = nil, connection: default_connection)
46
- store_fixpoint(fixname, parent_fixname, connection: connection) unless IncrementalFixpoint.exists?(fixname)
46
+ def store_fixpoint_unless_present(fixname, parent_fixname = nil, connection: default_connection, exclude_tables: [])
47
+ store_fixpoint(fixname, parent_fixname, connection: connection, exclude_tables: exclude_tables) unless IncrementalFixpoint.exists?(fixname)
47
48
  end
48
49
 
49
50
  # +parent_fixname+ when given, only the (incremental) changes to the parent are saved
50
51
  # please see store_fixpoint_unless_present for note on why not to use this method
51
- def store_fixpoint(fixname, parent_fixname = nil, connection: default_connection)
52
+ def store_fixpoint(fixname, parent_fixname = nil, connection: default_connection, exclude_tables: [])
52
53
  parent_fixname = @last_restored if parent_fixname == :last_restored
53
- IncrementalFixpoint.from_database(parent_fixname, connection).save_to_file(fixname)
54
+ IncrementalFixpoint.from_database(parent_fixname, connection, exclude_tables: exclude_tables).save_to_file(fixname)
54
55
  end
55
56
 
56
57
  private def default_connection
@@ -1,3 +1,3 @@
1
1
  module Fixpoints
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -33,11 +33,11 @@ class IncrementalFixpoint < Fixpoint
33
33
  end
34
34
 
35
35
  # Creates a Fixpoint from the database contents. Empty tables are skipped.
36
- def self.from_database(parent_fixname=nil, conn)
37
- return super(conn) if parent_fixname.nil?
36
+ def self.from_database(parent_fixname=nil, conn, exclude_tables: [])
37
+ return super(conn, exclude_tables: exclude_tables) if parent_fixname.nil?
38
38
 
39
39
  parent = from_file(parent_fixname)
40
- changes_in_tables = FixpointDiff.extract_changes(parent.records_in_tables, read_database_records(conn))
40
+ changes_in_tables = FixpointDiff.extract_changes(parent.records_in_tables, read_database_records(conn, exclude_tables: exclude_tables))
41
41
  new(changes_in_tables, parent_fixname)
42
42
  end
43
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixpoints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Rothe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.1.2
83
+ rubygems_version: 3.1.6
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Don't discard the database state at the end of your test. Use it!