fixpoints 0.2.3 → 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: 3ef08ea7ece7fead58adea51cc099a9fdf2b54db15af1b54406a4123bafd9f58
4
- data.tar.gz: 3adb38547c45cc8bcaf2c105ba22a60c5eceb1caeeb1de423c4a27524cf42e20
3
+ metadata.gz: 4a12beeaa3e9a600b6bafeb91a4ed10e769dd24c5e179634e71044f8b91cff4f
4
+ data.tar.gz: 7156873029ee1e27e9e5487c43fccdd929078eb83de1b67e87abc11e73cc4d08
5
5
  SHA512:
6
- metadata.gz: b2de749871dc8108723bb6ff7187526ed30b4a4d920fa8562bb611e34373a2666f2053ab247d3f6280a6968b161e4057fb4dfae6732989a8feb215838b15774f
7
- data.tar.gz: 9e6c9dd9d176073a3a930e3228ec10dd0f38a5ab811c9aba1fa03642401ee1a8c6ad47a117f0c649288af71acff1028c2f14007b1929ccc3bc88bbf20c4610bb
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,15 +28,14 @@ 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
34
35
  tables_to_compare.each do |table_name|
35
- db_records = database_fp.records_for_table(table_name, ignored_columns)
36
- fp_records = fixpoint_fp.records_for_table(table_name, ignored_columns)
36
+ db_records = database_fp.records_for_table(table_name, ignored_columns) || []
37
+ fp_records = fixpoint_fp.records_for_table(table_name, ignored_columns) || []
37
38
 
38
- expect(fp_records).not_to be_empty, "#{table_name} not in fixpoint, but in database"
39
39
  # we assume that the order of records returned by SELECT is stable (so we do not do any sorting)
40
40
  expect(db_records).to eq(fp_records), "Database records for table \"#{table_name}\" did not match fixpoint \"#{fixname}\". Consider removing the fixpoint and re-running the test if the change is intended."
41
41
  end
@@ -43,15 +43,15 @@ module FixpointTestHelpers
43
43
 
44
44
  # it is not a good idea to overwrite the fixpoint each time because timestamps may change (which then shows up in version control).
45
45
  # Hence we only provide a method to write to it if it does not exist.
46
- def store_fixpoint_unless_present(fixname, parent_fixname = nil, connection: default_connection)
47
- 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)
48
48
  end
49
49
 
50
50
  # +parent_fixname+ when given, only the (incremental) changes to the parent are saved
51
51
  # please see store_fixpoint_unless_present for note on why not to use this method
52
- def store_fixpoint(fixname, parent_fixname = nil, connection: default_connection)
52
+ def store_fixpoint(fixname, parent_fixname = nil, connection: default_connection, exclude_tables: [])
53
53
  parent_fixname = @last_restored if parent_fixname == :last_restored
54
- 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)
55
55
  end
56
56
 
57
57
  private def default_connection
@@ -1,3 +1,3 @@
1
1
  module Fixpoints
2
- VERSION = "0.2.3"
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.3
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!