fixpoints 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -3
- data/lib/fixpoint_test_helpers.rb +58 -0
- data/lib/fixpoints/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fc801ca2cedc0a4abc0de5eda59a90ade61b99b462bff2dcad91c7f11909f7
|
4
|
+
data.tar.gz: 60267a9065b27e86f9180a3da0243267a0fcdc7aa45a8b9f35390ad3e5ac5fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e6d1e3ae14981d469135f62ca1b5f66f81e8239cbe27b7965694791ac22a79652cea2532cfc8c35f625aa870131d73cb56a9c245ed8d7e4a044d28956702b09
|
7
|
+
data.tar.gz: 94b15a4d1b186466eed68c7db66c32f1f73c8bb168a818a46a137181adacddb67756ccdb1f911c1bd6f12a7547033235682616a065829c5719fb8196ba71a379
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -85,9 +85,7 @@ A change in a fixpoint might point to an unintended change in code.
|
|
85
85
|
We need to be be careful to use `let` and `let!` with factories.
|
86
86
|
Records might be created twice when using create in there (once by the fixpoint and once by the factory).
|
87
87
|
|
88
|
-
**Ignoring columns**
|
89
|
-
|
90
|
-
Often you might want to add more columns to ignore (e.g. login time stamps):
|
88
|
+
**Ignoring columns** Often you might want to add more columns to ignore (e.g. login time stamps):
|
91
89
|
|
92
90
|
```ruby
|
93
91
|
let(:ignored_fixpoint_columns) { [:updated_at, :created_at, users: [:last_login_at] }
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Helper methods to be included into RSpec
|
2
|
+
module FixpointTestHelpers
|
3
|
+
def restore_fixpoint(fixname)
|
4
|
+
@last_restored = fixname
|
5
|
+
IncrementalFixpoint.from_file(fixname).load_into_database
|
6
|
+
end
|
7
|
+
|
8
|
+
# Compares the fixpoint with the records in the database.
|
9
|
+
# If there is no such fixpoint yet, it will write a new one to the file system.
|
10
|
+
# The latter is useful if the fixpoint was deleted to accommodate changes to it (see example in class description).
|
11
|
+
#
|
12
|
+
# +tables_to_compare+ can either be +:all+ or a list of table names (e.g. ['users', 'posts'])
|
13
|
+
# +ignored_columns+ see Fixnum#records_for_table
|
14
|
+
# +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
|
+
# +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
|
+
# If we refactor this to a gem, we should rely on rspec (e.g. use minitest or move comparison logic to Fixpoint class).
|
18
|
+
# 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)
|
20
|
+
if !IncrementalFixpoint.exists?(fixname)
|
21
|
+
if store_fixpoint_and_fail
|
22
|
+
store_fixpoint(fixname, parent_fixname)
|
23
|
+
pending("Fixpoint \"#{fixname}\" did not exist yet. Skipping comparison, but created fixpoint from database. Try re-running the test.")
|
24
|
+
fail
|
25
|
+
else
|
26
|
+
raise Fixpoint::Error, "Fixpoint #{fixname} does not exist"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
database_fp = IncrementalFixpoint.from_database
|
31
|
+
fixpoint_fp = IncrementalFixpoint.from_file(fixname)
|
32
|
+
|
33
|
+
tables_to_compare = (database_fp.table_names + fixpoint_fp.table_names).uniq if tables_to_compare == :all
|
34
|
+
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)
|
37
|
+
|
38
|
+
# if a table is present in a fixpoint, there must be records in it because empty tables are stripped from fixpoints
|
39
|
+
expect(db_records).not_to be_empty, "#{table_name} not in database, but in fixpoint"
|
40
|
+
expect(fp_records).not_to be_empty, "#{table_name} not in fixpoint, but in database"
|
41
|
+
# we assume that the order of records returned by SELECT is stable (so we do not do any sorting)
|
42
|
+
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."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# it is not a good idea to overwrite the fixpoint each time because timestamps may change (which then shows up in version control).
|
47
|
+
# Hence we only provide a method to write to it if it does not exist.
|
48
|
+
def store_fixpoint_unless_present(fixname, parent_fixname = nil)
|
49
|
+
store_fixpoint(fixname, parent_fixname) unless IncrementalFixpoint.exists?(fixname)
|
50
|
+
end
|
51
|
+
|
52
|
+
# +parent_fixname+ when given, only the (incremental) changes to the parent are saved
|
53
|
+
# please see store_fixpoint_unless_present for note on why not to use this method
|
54
|
+
def store_fixpoint(fixname, parent_fixname = nil)
|
55
|
+
parent_fixname = @last_restored if parent_fixname == :last_restored
|
56
|
+
IncrementalFixpoint.from_database(parent_fixname).save_to_file(fixname)
|
57
|
+
end
|
58
|
+
end
|
data/lib/fixpoints/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Rothe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- fixpoints.gemspec
|
56
56
|
- lib/fixpoint.rb
|
57
57
|
- lib/fixpoint_diff.rb
|
58
|
+
- lib/fixpoint_test_helpers.rb
|
58
59
|
- lib/fixpoints.rb
|
59
60
|
- lib/fixpoints/version.rb
|
60
61
|
- lib/incremental_fixpoint.rb
|