ae_check_migrations_load_silently 0.0.0 → 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: b76540091b20bf219a815f5ee7dde9272d4f8029435a36c0b3fd7294131e671f
4
- data.tar.gz: db2f412966f0b86194aff16b74d7e678a1dd48194de28cc1480c1fc27a9e26c5
3
+ metadata.gz: 9dc4d7a9b05b8695db3c4e8b3f0c18f613118a12fa05582dbb0c1dff89930008
4
+ data.tar.gz: 68c46a66187aced0398e012a23c61344d886e9cf298b0645be794012d1163dde
5
5
  SHA512:
6
- metadata.gz: 63ed8730d210bf7a9f6666be23071767f21de6dbe0805f5d908bec64178ba0418edea1e33d0c107c7ff7aefe83f68955bd12dee6b0c236842098b3b8ab757e46
7
- data.tar.gz: b0afb5b34055d1b08ee1a19ebad5ab67214cd831037e9d57770b3611998124c1cb7b3393206002341eca3f8420c34aac86e23291954673b54f2da957d666a00c
6
+ metadata.gz: 6baba3f5190ebbe9dea450d9cc9059dd80166867e35ffc6e574e6616c201f1a71d77649fae5c8f8418a263f0f0ec57c12c52c1cb278942e528f92ca417146e0a
7
+ data.tar.gz: 26fadec1e587076366e2f01563d4f1ad348c45fc2e2a41d813de312f7aa2b57deedc200716ad5e578f315fe534055a658f1bb47573e9fa5960015ac80ba2e7ae
@@ -1,55 +1,54 @@
1
-
2
1
  require 'active_record'
3
-
4
- class AeCheckMigrationsLoadSilently
5
- class << self
6
-
7
- def run
8
- before_checksums = get_database_checksums
9
- load_all_migrations
10
- after_checksums = get_database_checksums
11
-
12
- tables_modified = (
13
- (before_checksums - after_checksums).map(&:first) +
14
- (after_checksums - before_checksums).map(&:first)
15
- ).uniq
16
-
17
- if tables_modified.present?
18
- error_message = <<~MSG
19
- The following tables were modified when the migration classes were
20
- loaded. This is not compatable with our release process. This is likely
21
- because the migration has database modifiying code on the
22
- class rather than inside a method.
23
-
24
- #{tables_modified.sort.join("\n")}
25
- MSG
26
-
27
- flunk error_message
28
- end
2
+ require 'minitest'
3
+
4
+ module AeCheckMigrationsLoadSilently
5
+ include Minitest::Assertions
6
+
7
+ def check_all_migrations_load_silently
8
+ before_checksums = get_database_checksums
9
+ load_all_migrations
10
+ after_checksums = get_database_checksums
11
+
12
+ tables_modified = (
13
+ (before_checksums - after_checksums).map(&:first) +
14
+ (after_checksums - before_checksums).map(&:first)
15
+ ).uniq
16
+
17
+ if tables_modified.present?
18
+ error_message = <<~MSG
19
+ The following tables were modified when the migration classes were
20
+ loaded. This is not compatable with our release process. This is likely
21
+ because the migration has database modifiying code on the
22
+ class rather than inside a method.
23
+ #{tables_modified.sort.join("\n")}
24
+ MSG
25
+
26
+ flunk error_message
29
27
  end
28
+ end
30
29
 
31
- private
30
+ private
32
31
 
33
- def get_database_checksums
34
- tables_sql = ActiveRecord::Base.connection.tables.sort.join(", ")
35
- checksum_sql = "CHECKSUM TABLE #{tables_sql}"
36
- ActiveRecord::Base.connection.execute(checksum_sql).to_a
37
- end
32
+ def get_database_checksums
33
+ tables_sql = ActiveRecord::Base.connection.tables.sort.join(", ")
34
+ checksum_sql = "CHECKSUM TABLE #{tables_sql}"
35
+ ActiveRecord::Base.connection.execute(checksum_sql).to_a
36
+ end
38
37
 
39
- def load_all_migrations
40
- migrations_to_process = Dir['db/migrate/20*.rb']
41
- migrations_to_process.each do |migration|
42
- begin
43
- load migration
44
- rescue StandardError => e
45
- msg = <<~MSG
46
- #{self.class.name}: #{migration} failed to load. This is likely because the migration has code that is defined
47
- on the top level class, instead of in a method.
48
- #{e.message}
49
- MSG
50
- flunk msg
51
- end
38
+ def load_all_migrations
39
+ migrations_to_process = Dir['db/migrate/20*.rb']
40
+ migrations_to_process.each do |migration|
41
+ begin
42
+ load migration
43
+ rescue StandardError => e
44
+ msg = <<~MSG
45
+ #{self.class.name}: #{migration} failed to load. This is likely because the migration has code that is defined
46
+ on the top level class, instead of in a method.
47
+ #{e.message}
48
+ MSG
49
+ flunk msg
52
50
  end
53
51
  end
54
52
  end
55
53
  end
54
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_check_migrations_load_silently
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Appfolio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord