active_sanity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,7 @@ If you wish to store invalid records in your database run:
18
18
 
19
19
  Just run:
20
20
 
21
- rake db:sanity_check
21
+ rake db:check_sanity
22
22
 
23
23
  ActiveSanity will iterate over every records of all your models to check
24
24
  weither they're valid or not. It will save invalid records in the table
@@ -9,7 +9,7 @@ Feature: Check sanity
9
9
 
10
10
  Scenario: Check sanity on empty database
11
11
  When I run "rake db:check_sanity"
12
- Then I should see "Checking the following models: Category, Post, User"
12
+ Then I should see "Checking the following models: InvalidRecord, Category, Post, User"
13
13
  Then I should not see any invalid records
14
14
 
15
15
  Scenario: Check sanity on database with valid records
@@ -9,7 +9,7 @@ Feature: Check sanity with db storage
9
9
 
10
10
  Scenario: Check sanity on empty database
11
11
  When I run "rake db:check_sanity"
12
- Then I should see "Checking the following models: Category, Post, User"
12
+ Then I should see "Checking the following models: InvalidRecord, Category, Post, User"
13
13
  Then the table "invalid_records" should be empty
14
14
 
15
15
  Scenario: Check sanity on database with valid records
@@ -13,11 +13,13 @@ module ActiveSanity
13
13
  end
14
14
 
15
15
  def models
16
- @models ||= Dir["#{Rails.root}/app/models/**/*.rb"].map do |file_path|
17
- basename = File.basename(file_path, File.extname(file_path))
18
- klass = basename.camelize.constantize
19
- klass.new.is_a?(ActiveRecord::Base) ? klass : nil
20
- end.compact
16
+ # Ensure ActiveRecord::Base is aware of all models under
17
+ # app/models
18
+ Dir["#{Rails.root}/app/models/**/*.rb"].each do |file_path|
19
+ require file_path rescue nil
20
+ end
21
+
22
+ @models ||= ActiveRecord::Base.subclasses
21
23
  end
22
24
 
23
25
  protected
@@ -32,10 +34,17 @@ module ActiveSanity
32
34
 
33
35
  def check_all_records
34
36
  models.each do |model|
35
- model.find_each do |record|
36
- unless record.valid?
37
- invalid_record!(record)
37
+ begin
38
+ model.find_each do |record|
39
+ unless record.valid?
40
+ invalid_record!(record)
41
+ end
38
42
  end
43
+ rescue => e
44
+ # Rescue from exceptions (table does not exists,
45
+ # deserialization error, ...)
46
+ puts e.message
47
+ puts "Skipping validations for #{model}"
39
48
  end
40
49
  end
41
50
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveSanity
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_sanity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - VersaPay