consistency_fail 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -13
  2. data/.rspec +1 -0
  3. data/bin/consistency_fail +1 -31
  4. data/consistency_fail.gemspec +2 -1
  5. data/lib/consistency_fail.rb +38 -0
  6. data/lib/consistency_fail/index.rb +18 -0
  7. data/lib/consistency_fail/introspectors/has_one.rb +1 -1
  8. data/lib/consistency_fail/introspectors/polymorphic.rb +1 -2
  9. data/lib/consistency_fail/introspectors/validates_uniqueness_of.rb +1 -0
  10. data/lib/consistency_fail/models.rb +0 -1
  11. data/lib/consistency_fail/version.rb +1 -1
  12. data/spec/index_spec.rb +37 -18
  13. data/spec/introspectors/has_one_spec.rb +14 -89
  14. data/spec/introspectors/polymorphic_spec.rb +15 -66
  15. data/spec/introspectors/table_data_spec.rb +47 -36
  16. data/spec/introspectors/validates_uniqueness_of_spec.rb +47 -72
  17. data/spec/models_spec.rb +2 -3
  18. data/spec/reporter_spec.rb +88 -49
  19. data/spec/spec_helper.rb +11 -10
  20. data/spec/support/active_record.rb +1 -0
  21. data/spec/support/models/correct_account.rb +3 -0
  22. data/spec/support/models/correct_address.rb +3 -0
  23. data/spec/support/models/correct_attachment.rb +5 -0
  24. data/spec/support/models/correct_person.rb +3 -0
  25. data/spec/support/models/correct_post.rb +3 -0
  26. data/spec/support/models/correct_user.rb +7 -0
  27. data/spec/support/models/correct_user/credential.rb +3 -0
  28. data/spec/support/models/correct_user/phone.rb +4 -0
  29. data/spec/support/models/new_correct_person.rb +7 -0
  30. data/spec/support/models/nonexistent.rb +2 -0
  31. data/spec/support/models/wrong_account.rb +3 -0
  32. data/spec/support/models/wrong_address.rb +5 -0
  33. data/spec/support/models/wrong_attachment.rb +3 -0
  34. data/spec/support/models/wrong_business.rb +3 -0
  35. data/spec/support/models/wrong_person.rb +3 -0
  36. data/spec/support/models/wrong_post.rb +3 -0
  37. data/spec/support/models/wrong_user.rb +3 -0
  38. data/spec/support/schema.rb +121 -0
  39. metadata +68 -24
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
@@ -0,0 +1,3 @@
1
+ class CorrectAccount < ActiveRecord::Base
2
+ validates :email, uniqueness: true
3
+ end
@@ -0,0 +1,3 @@
1
+ class WrongAddress < ActiveRecord::Base
2
+ belongs_to :wrong_user
3
+ end
@@ -0,0 +1,5 @@
1
+ class CorrectAttachment < ActiveRecord::Base
2
+ belongs_to :attachable, polymorphic: true
3
+
4
+ validates :name, uniqueness: { scope: :attachable }
5
+ end
@@ -0,0 +1,3 @@
1
+ class CorrectPerson < ActiveRecord::Base
2
+ validates :email, uniqueness: { scope: [:city, :state] }
3
+ end
@@ -0,0 +1,3 @@
1
+ class CorrectPost < ActiveRecord::Base
2
+ has_one :correct_attachment, as: :attachable
3
+ end
@@ -0,0 +1,7 @@
1
+ class CorrectUser < ActiveRecord::Base
2
+ has_one :correct_address
3
+ has_one :credential
4
+ has_one :phone, as: :phoneable
5
+
6
+ validates :email, uniqueness: true
7
+ end
@@ -0,0 +1,3 @@
1
+ require_relative '../correct_user'
2
+ class CorrectUser::Credential < ActiveRecord::Base
3
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "../correct_user"
2
+ class CorrectUser::Phone < ActiveRecord::Base
3
+ belongs_to :phoneable, polymorphic: true
4
+ end
@@ -0,0 +1,7 @@
1
+ class NewCorrectPerson < CorrectPerson
2
+ self.table_name = 'new_correct_people'
3
+
4
+ def readonly?
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ class Nonexistent < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class WrongAccount < ActiveRecord::Base
2
+ validates :email, uniqueness: true
3
+ end
@@ -0,0 +1,5 @@
1
+ class CorrectAddress < ActiveRecord::Base
2
+ belongs_to :correct_user
3
+
4
+ validates :city, uniqueness: { scope: :correct_user }
5
+ end
@@ -0,0 +1,3 @@
1
+ class WrongAttachment < ActiveRecord::Base
2
+ belongs_to :attachable, polymorphic: true
3
+ end
@@ -0,0 +1,3 @@
1
+ class WrongBusiness < ActiveRecord::Base
2
+ validates :name, uniqueness: { scope: [:city, :state] }
3
+ end
@@ -0,0 +1,3 @@
1
+ class WrongPerson < ActiveRecord::Base
2
+ validates :email, :name, uniqueness: { scope: [:city, :state] }
3
+ end
@@ -0,0 +1,3 @@
1
+ class WrongPost < ActiveRecord::Base
2
+ has_one :wrong_attachment, as: :attachable
3
+ end
@@ -0,0 +1,3 @@
1
+ class WrongUser < ActiveRecord::Base
2
+ has_one :wrong_address
3
+ end
@@ -0,0 +1,121 @@
1
+ ActiveRecord::Schema.define(version: 0) do
2
+ self.verbose = false
3
+
4
+ create_table :correct_accounts do |t|
5
+ t.string :email
6
+ t.timestamps
7
+ end
8
+
9
+ add_index "correct_accounts", ["email"], name: "index_correct_accounts_on_email", unique: true, using: :btree
10
+
11
+ create_table :correct_addresses do |t|
12
+ t.string :city
13
+ t.integer :correct_user_id
14
+ t.string :state
15
+ t.timestamps
16
+ end
17
+
18
+ add_index "correct_addresses", ["correct_user_id"], name: "index_correct_addresses_on_user_id", unique: true, using: :btree
19
+ add_index "correct_addresses", ["city", "correct_user_id"], name: "index_correct_addresses_on_city_and_correct_user", unique: true, using: :btree
20
+
21
+ create_table :correct_attachments do |t|
22
+ t.integer :attachable_id
23
+ t.string :attachable_type
24
+ t.string :name
25
+ t.timestamps
26
+ end
27
+
28
+ add_index "correct_attachments", ["name", "attachable_id", "attachable_type"], name: "index_correct_attachments_on_name_attachable_id_and_type", unique: true, using: :btree
29
+ add_index "correct_attachments", ["attachable_id", "attachable_type"], name: "index_correct_attachments_on_attachable_id_and_attachable_type", unique: true, using: :btree
30
+ add_index "correct_attachments", ["name"], name: "index_correct_attachments_on_name", unique: true, using: :btree
31
+
32
+ create_table :correct_people do |t|
33
+ t.string :city
34
+ t.string :email
35
+ t.string :name
36
+ t.string :state
37
+ t.timestamps
38
+ end
39
+
40
+ add_index "correct_people", ["state", "city", "email"], name: "index_correct_people_on_city_and_state_and_email", unique: true, using: :btree
41
+
42
+ create_table :correct_posts do |t|
43
+ t.text :content
44
+ t.string :title
45
+ t.timestamps
46
+ end
47
+
48
+ create_table :correct_users do |t|
49
+ t.string :email
50
+ t.string :name
51
+ t.timestamps
52
+ end
53
+
54
+ create_table :correct_user_credentials do |t|
55
+ t.string :oauth_token
56
+ t.string :refresh_token
57
+ t.integer :correct_user_id
58
+ t.timestamps
59
+ end
60
+ add_index "correct_user_credentials", ["correct_user_id"], name: "index_correct_user_credentials_on_user_id", unique: true, using: :btree
61
+
62
+ create_table :correct_user_phones do |t|
63
+ t.string :text
64
+ t.integer :phoneable_id
65
+ t.string :phoneable_type
66
+ t.timestamps
67
+ end
68
+ add_index "correct_user_phones", ["phoneable_id", "phoneable_type"], name: "index_correct_user_phones_on_id_and_type", unique: true, using: :btree
69
+
70
+ create_table :wrong_accounts do |t|
71
+ t.string :email
72
+ t.timestamps
73
+ end
74
+
75
+ create_table :wrong_addresses do |t|
76
+ t.string :city
77
+ t.string :state
78
+ t.integer :wrong_user_id
79
+ t.timestamps
80
+ end
81
+
82
+ add_index "wrong_addresses", ["wrong_user_id"], name: "index_wrong_addresses_on_user_id", using: :btree
83
+
84
+ create_table :wrong_attachments do |t|
85
+ t.integer :attachable_id
86
+ t.string :attachable_type
87
+ t.string :name
88
+ t.timestamps
89
+ end
90
+
91
+ create_table :wrong_businesses do |t|
92
+ t.string :city
93
+ t.string :name
94
+ t.string :state
95
+ t.timestamps
96
+ end
97
+
98
+ create_table :wrong_people do |t|
99
+ t.string :city
100
+ t.string :email
101
+ t.string :name
102
+ t.string :state
103
+ t.timestamps
104
+ end
105
+
106
+ create_table :wrong_posts do |t|
107
+ t.text :content
108
+ t.string :title
109
+ t.timestamps
110
+ end
111
+
112
+ create_table :wrong_users do |t|
113
+ t.string :email
114
+ t.string :name
115
+ t.timestamps
116
+ end
117
+
118
+ execute 'CREATE VIEW new_correct_people AS '\
119
+ 'SELECT * FROM correct_people '\
120
+ 'WHERE created_at = updated_at'
121
+ end
metadata CHANGED
@@ -1,58 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consistency_fail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '3.1'
47
+ version: '3.2'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ~>
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '3.1'
41
- description: ! 'With more than one application server, validates_uniqueness_of becomes
42
- a lie.
43
-
54
+ version: '3.2'
55
+ description: |
56
+ With more than one application server, validates_uniqueness_of becomes a lie.
44
57
  Two app servers -> two requests -> two near-simultaneous uniqueness checks ->
45
-
46
58
  two processes that commit to the database independently, violating this faux
47
-
48
- constraint. You''ll need a database-level constraint for cases like these.
49
-
59
+ constraint. You'll need a database-level constraint for cases like these.
50
60
 
51
61
  consistency_fail will find your missing unique indexes, so you can add them and
52
-
53
62
  stop ignoring the C in ACID.
54
-
55
- '
56
63
  email:
57
64
  - colin@8thlight.com
58
65
  executables:
@@ -60,8 +67,8 @@ executables:
60
67
  extensions: []
61
68
  extra_rdoc_files: []
62
69
  files:
63
- - .gitignore
64
- - .rspec
70
+ - ".gitignore"
71
+ - ".rspec"
65
72
  - Gemfile
66
73
  - LICENSE
67
74
  - README.md
@@ -90,6 +97,25 @@ files:
90
97
  - spec/models_spec.rb
91
98
  - spec/reporter_spec.rb
92
99
  - spec/spec_helper.rb
100
+ - spec/support/active_record.rb
101
+ - spec/support/models/correct_account.rb
102
+ - spec/support/models/correct_address.rb
103
+ - spec/support/models/correct_attachment.rb
104
+ - spec/support/models/correct_person.rb
105
+ - spec/support/models/correct_post.rb
106
+ - spec/support/models/correct_user.rb
107
+ - spec/support/models/correct_user/credential.rb
108
+ - spec/support/models/correct_user/phone.rb
109
+ - spec/support/models/new_correct_person.rb
110
+ - spec/support/models/nonexistent.rb
111
+ - spec/support/models/wrong_account.rb
112
+ - spec/support/models/wrong_address.rb
113
+ - spec/support/models/wrong_attachment.rb
114
+ - spec/support/models/wrong_business.rb
115
+ - spec/support/models/wrong_person.rb
116
+ - spec/support/models/wrong_post.rb
117
+ - spec/support/models/wrong_user.rb
118
+ - spec/support/schema.rb
93
119
  homepage: http://github.com/trptcolin/consistency_fail
94
120
  licenses:
95
121
  - MIT
@@ -100,17 +126,17 @@ require_paths:
100
126
  - lib
101
127
  required_ruby_version: !ruby/object:Gem::Requirement
102
128
  requirements:
103
- - - ! '>='
129
+ - - ">="
104
130
  - !ruby/object:Gem::Version
105
131
  version: '0'
106
132
  required_rubygems_version: !ruby/object:Gem::Requirement
107
133
  requirements:
108
- - - ! '>='
134
+ - - ">="
109
135
  - !ruby/object:Gem::Version
110
136
  version: '0'
111
137
  requirements: []
112
138
  rubyforge_project:
113
- rubygems_version: 2.4.2
139
+ rubygems_version: 2.4.5
114
140
  signing_key:
115
141
  specification_version: 4
116
142
  summary: A tool to detect missing unique indexes
@@ -123,4 +149,22 @@ test_files:
123
149
  - spec/models_spec.rb
124
150
  - spec/reporter_spec.rb
125
151
  - spec/spec_helper.rb
126
- has_rdoc:
152
+ - spec/support/active_record.rb
153
+ - spec/support/models/correct_account.rb
154
+ - spec/support/models/correct_address.rb
155
+ - spec/support/models/correct_attachment.rb
156
+ - spec/support/models/correct_person.rb
157
+ - spec/support/models/correct_post.rb
158
+ - spec/support/models/correct_user.rb
159
+ - spec/support/models/correct_user/credential.rb
160
+ - spec/support/models/correct_user/phone.rb
161
+ - spec/support/models/new_correct_person.rb
162
+ - spec/support/models/nonexistent.rb
163
+ - spec/support/models/wrong_account.rb
164
+ - spec/support/models/wrong_address.rb
165
+ - spec/support/models/wrong_attachment.rb
166
+ - spec/support/models/wrong_business.rb
167
+ - spec/support/models/wrong_person.rb
168
+ - spec/support/models/wrong_post.rb
169
+ - spec/support/models/wrong_user.rb
170
+ - spec/support/schema.rb