active_sanity 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ ## 0.2.0
2
+
3
+ * Add Rails ~3.1 compatibility. Pull Request [#6][] by [@skateinmars][].
4
+
5
+ ## 0.1.1
6
+
7
+ * Fix bug where records stored with STI would be duplicated in the
8
+ database. Issue [#1][]. [@vraravam][]
9
+
10
+ ## 0.1.0
11
+
12
+ Initial release.
13
+
14
+ <!--- The following link definition list is generated by PimpMyChangelog --->
15
+ [#1]: https://github.com/versapay/active_sanity/issues/1
16
+ [#6]: https://github.com/versapay/active_sanity/issues/6
17
+ [@skateinmars]: https://github.com/skateinmars
18
+ [@vraravam]: https://github.com/vraravam
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in active_sanity.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rails', '~> 3.1.0'
8
+ end
9
+
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Active Sanity
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/versapay/active_sanity.png)](http://travis-ci.org/versapay/active_sanity)
4
+
3
5
  Perform a sanity check on your database through active record
4
6
  validation.
5
7
 
8
+ ## Requirements
9
+
10
+ ActiveSanity 0.2.0 requires Rails ~ 3.1
11
+ ActiveSanity 0.1.1 requires Rails ~ 3.0
12
+
6
13
  ## Install
7
14
 
8
15
  Add the following line to your Gemfile
@@ -31,14 +38,6 @@ The output might look like the following:
31
38
  Flight | 123 | { "arrival_time" => ["can't be nil"], "departure_time" => ["is invalid"] }
32
39
  Flight | 323 | { "arrival_time" => ["can't be nil"] }
33
40
 
34
- ## Known issues
35
-
36
- There is a bug in Rails 3.0.5 with the unserialization of OrderedHash
37
- storing arrays: only the last error of a given attribute gets retrieved
38
- from the database.
39
-
40
- See https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6646-orderedhash-serialization-does-not-work-when-storing-arrays
41
-
42
41
  ## Contribute & Dev environment
43
42
 
44
43
  Usual fork & pull request.
@@ -47,7 +46,7 @@ This gem is quite simple so I experiment using features only. To run the
47
46
  acceptance test suite, just run:
48
47
 
49
48
  bundle install
50
- cucumber features
49
+ RAILS_ENV=test cucumber features
51
50
 
52
51
  Using features only was kinda handsome until I had to deal with two
53
52
  different database schema (with / without the table invalid_records) in
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ task :default => :features
5
5
 
6
6
  desc "Run features"
7
7
  task :features do
8
- raise "Failed!" unless system('bundle exec cucumber features')
8
+ raise "Failed!" unless system('export RAILS_ENV=test && bundle exec cucumber features')
9
9
  end
10
10
 
11
11
  desc "Clean test rails app"
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Performs a Sanity Check of your database by logging all invalid Active Records}
14
14
  s.homepage = "https://github.com/versapay/active_sanity"
15
15
 
16
- s.add_dependency "rails", ">=3.0.0"
16
+ s.add_dependency "rails", ">=3.1.0"
17
17
 
18
18
  s.add_development_dependency "rspec"
19
19
  s.add_development_dependency "cucumber"
@@ -22,5 +22,5 @@ Feature: Check sanity
22
22
  And the first author's username is empty and the first post category_id is nil
23
23
  When I run "rake db:check_sanity"
24
24
  Then I should see the following invalid records:
25
- | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)", "can't be blank", "can't be blank", "is too short (minimum is 3 characters)"]} |
25
+ | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
26
26
  | Post | 1 | {:category=>["can't be blank"]} |
@@ -22,7 +22,7 @@ Feature: Check sanity with db storage
22
22
  And the first author's username is empty and the first post category_id is nil
23
23
  When I run "rake db:check_sanity"
24
24
  Then the table "invalid_records" should contain:
25
- | User | 1 | {:username=>["is too short (minimum is 3 characters)"]} |
25
+ | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
26
26
  | Post | 1 | {:category=>["can't be blank"]} |
27
27
 
28
28
  Scenario: Check sanity on database with invalid records now valid
@@ -30,7 +30,7 @@ Feature: Check sanity with db storage
30
30
  And the first author's username is empty and the first post category_id is nil
31
31
  When I run "rake db:check_sanity"
32
32
  Then the table "invalid_records" should contain:
33
- | User | 1 | {:username=>["is too short (minimum is 3 characters)"]} |
33
+ | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
34
34
  | Post | 1 | {:category=>["can't be blank"]} |
35
35
 
36
36
  Given the first author's username is "Greg"
@@ -44,12 +44,12 @@ Feature: Check sanity with db storage
44
44
  And the first author's username is empty and the first post category_id is nil
45
45
  When I run "rake db:check_sanity"
46
46
  Then the table "invalid_records" should contain:
47
- | User | 1 | {:username=>["is too short (minimum is 3 characters)"]} |
47
+ | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
48
48
  | Post | 1 | {:category=>["can't be blank"]} |
49
49
 
50
50
  Given the first post category is set
51
51
  And the first post title is empty
52
52
  When I run "rake db:check_sanity"
53
53
  Then the table "invalid_records" should contain:
54
- | User | 1 | {:username=>["is too short (minimum is 3 characters)"]} |
54
+ | User | 1 | {:username=>["can't be blank", "is too short (minimum is 3 characters)"]} |
55
55
  | Post | 1 | {:title=>["can't be blank"]} |
@@ -1,7 +1,7 @@
1
1
  def setup_rails_app
2
2
  return if File.directory?("test/rails_app")
3
3
 
4
- unless system "bundle exec rails new test/rails_app -m test/rails_template.rb"
4
+ unless system "bundle exec rails new test/rails_app -m test/rails_template.rb && cd ./test/rails_app && RAILS_ENV=test rake db:migrate"
5
5
  system("rm -fr test/rails_app")
6
6
  raise "Failed to generate test/rails_app"
7
7
  end
@@ -15,18 +15,21 @@ Given /^I have a rails app using 'active_sanity'$/ do
15
15
  setup_rails_app
16
16
 
17
17
  require './test/rails_app/config/environment'
18
+
19
+ # Reset connection
20
+ ActiveRecord::Base.connection.reconnect!
18
21
  end
19
22
 
20
23
  Given /^I have a rails app using 'active_sanity' with db storage$/ do
21
24
  setup_rails_app
22
25
 
23
- raise unless system("cd ./test/rails_app && rails generate active_sanity && rake db:migrate")
26
+ raise unless system("cd ./test/rails_app && rails generate active_sanity && RAILS_ENV=test rake db:migrate")
24
27
 
25
28
  require './test/rails_app/config/environment'
26
29
 
27
30
  # Reset connection
28
31
  ActiveRecord::Base.connection.reconnect!
29
- InvalidRecord.table_exists?
32
+ InvalidRecord.table_exists? # Looks up if table exists.
30
33
  end
31
34
 
32
35
  Given /^the database contains a few valid records$/ do
@@ -57,7 +60,7 @@ end
57
60
 
58
61
 
59
62
  When /^I run "([^"]*)"$/ do |command|
60
- puts @output = `cd ./test/rails_app && #{command}; echo "RETURN:$?"`
63
+ puts @output = `cd ./test/rails_app && export RAILS_ENV=test && bundle exec #{command} --trace; echo "RETURN:$?"`
61
64
  raise unless @output['RETURN:0']
62
65
  end
63
66
 
@@ -86,21 +89,7 @@ Then /^the table "([^"]*)" should contain:$/ do |_, table|
86
89
  invalid_record.should be_an_instance_of(InvalidRecord)
87
90
  errors = eval(errors)
88
91
  errors.each do |k, v|
89
- begin
90
- invalid_record.validation_errors[k].should == v
91
- rescue RSpec::Expectations::ExpectationNotMetError => e
92
- # A bug in serialization of ordered hash get rid of the array of
93
- # errors. The following is stored in the db:
94
- # --- !omap
95
- # - :username: can't be blank
96
- # - :username: is too short (minimum is 3 characters)
97
- #
98
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6646-orderedhash-serialization-does-not-work-when-storing-arrays
99
- #
100
- # You actually get the last error on an attribute only
101
- #
102
- invalid_record.validation_errors[k].should == v.last
103
- end
92
+ invalid_record.validation_errors[k].should == v
104
93
  end
105
94
  end
106
95
  end
@@ -6,7 +6,7 @@ Bundler.setup
6
6
 
7
7
  if File.directory?("test/rails_app")
8
8
  Dir.chdir("test/rails_app") do
9
- raise unless system("rm -f db/migrate/*create_invalid_records.rb && rake db:drop db:create db:migrate")
9
+ raise unless system("rm -f db/migrate/*create_invalid_records.rb && RAILS_ENV=test rake db:drop db:create db:migrate")
10
10
  end
11
11
  end
12
12
 
@@ -26,7 +26,7 @@ module ActiveSanity
26
26
 
27
27
  protected
28
28
 
29
- # Require all files under /app/models.
29
+ # Require all files under /app/models.
30
30
  # All models under /lib are required when the rails app loads.
31
31
  def load_all_models
32
32
  Dir["#{Rails.root}/app/models/**/*.rb"].each { |file_path| require file_path rescue nil }
@@ -101,7 +101,7 @@ module ActiveSanity
101
101
  invalid_record = InvalidRecord.where(:record_type => type_of(record), :record_id => record.id).first
102
102
  invalid_record ||= InvalidRecord.new
103
103
  invalid_record.record = record
104
- invalid_record.validation_errors = record.errors
104
+ invalid_record.validation_errors = record.errors.messages
105
105
  invalid_record.save!
106
106
  end
107
107
 
@@ -110,7 +110,7 @@ module ActiveSanity
110
110
  end
111
111
 
112
112
  def pretty_errors(record)
113
- record.errors.inspect.sub(/^#<OrderedHash (.*)>$/, '\1')
113
+ record.errors.messages.inspect.sub(/^#<OrderedHash (.*)>$/, '\1')
114
114
  end
115
115
  end
116
116
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveSanity
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,93 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: active_sanity
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - VersaPay
14
9
  - Philippe Creux
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-06 00:00:00 -07:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-05-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: rails
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70154013012080 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 3
33
- - 0
34
- - 0
35
- version: 3.0.0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.0
36
23
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: rspec
40
24
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70154013012080
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &70154013011660 !ruby/object:Gem::Requirement
42
29
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
50
34
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: cucumber
54
35
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70154013011660
37
+ - !ruby/object:Gem::Dependency
38
+ name: cucumber
39
+ requirement: &70154013011180 !ruby/object:Gem::Requirement
56
40
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
64
45
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: sqlite3
68
46
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70154013011180
48
+ - !ruby/object:Gem::Dependency
49
+ name: sqlite3
50
+ requirement: &70154013010760 !ruby/object:Gem::Requirement
70
51
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
78
56
  type: :development
79
- version_requirements: *id004
80
- description: Performs a Sanity Check of your database by logging all invalid Active Records
81
- email:
57
+ prerelease: false
58
+ version_requirements: *70154013010760
59
+ description: Performs a Sanity Check of your database by logging all invalid Active
60
+ Records
61
+ email:
82
62
  - philippe.creux@versapay.com
83
63
  executables: []
84
-
85
64
  extensions: []
86
-
87
65
  extra_rdoc_files: []
88
-
89
- files:
66
+ files:
90
67
  - .gitignore
68
+ - CHANGELOG.md
91
69
  - Gemfile
92
70
  - README.md
93
71
  - Rakefile
@@ -105,43 +83,34 @@ files:
105
83
  - lib/generators/active_sanity/active_sanity_generator.rb
106
84
  - lib/generators/active_sanity/templates/create_invalid_records.rb
107
85
  - test/rails_template.rb
108
- has_rdoc: true
109
86
  homepage: https://github.com/versapay/active_sanity
110
87
  licenses: []
111
-
112
88
  post_install_message:
113
89
  rdoc_options: []
114
-
115
- require_paths:
90
+ require_paths:
116
91
  - lib
117
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
118
93
  none: false
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- hash: 3
123
- segments:
124
- - 0
125
- version: "0"
126
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
99
  none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
- version: "0"
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
135
104
  requirements: []
136
-
137
105
  rubyforge_project:
138
- rubygems_version: 1.3.7
106
+ rubygems_version: 1.8.11
139
107
  signing_key:
140
108
  specification_version: 3
141
109
  summary: Checks Sanity of Active Record records
142
- test_files:
110
+ test_files:
143
111
  - features/check_sanity.feature
144
112
  - features/check_sanity_with_db_storage.feature
145
113
  - features/step_definitions/rails_app.rb
146
114
  - features/support/env.rb
147
115
  - test/rails_template.rb
116
+ has_rdoc: