consistency_fail 0.3.5 → 0.3.6

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
  SHA1:
3
- metadata.gz: c507681aa9fdff8f28a5bb8d5c1b5b5e90224865
4
- data.tar.gz: c3ca7f71bdb87dccd25411da929196fdb6d4f318
3
+ metadata.gz: 531019a9820d2e2099018388c98a966b41ecff84
4
+ data.tar.gz: 58bcc05d1259e0e7f6fcd6e80388003c15d07785
5
5
  SHA512:
6
- metadata.gz: d06468cad8ded7968fd766fb8acda9fcb8fee9e7c32a98ed54efe7696725fcf53d96a9463b59906f6ac37c0b08d8d76f6258e6940bf3fb236c3cc7622fbacf79
7
- data.tar.gz: ef0b8fe78a001d6a82126dbe482e986a2092056be2399b4a3dd37e563438b7a06a3bf0f1353ec71d362c1120643b77b7b490ea33da161096935ff8ea07bf4394
6
+ metadata.gz: a065a54f5c469dc3741d37d06e5a9de36e49cfc1193020c22ddf672b1dea7cca39b6528dca7b45120cafe36266133579bb7a996c007e5611757e3fb62e09e593
7
+ data.tar.gz: af440e0d00c9e6dd7785542ede83284c2351a89a7149b7b3d3109216242bf78c5d42b1fcb6cbd52c144c0ec971e11fa3971e58ca27623015ea437a588acbd6f4
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in consistency_fail.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry'
7
+
8
+ group :test do
9
+ gem 'activesupport', '~> 5.0'
10
+ end
data/README.md CHANGED
@@ -17,19 +17,35 @@ database-level enforcement is lacking there as well.
17
17
  For more detail, see [my blog post on the
18
18
  subject](http://blog.8thlight.com/articles/2011/6/11/winning-at-consistency).
19
19
 
20
+
20
21
  ## Installation
21
22
 
22
- I'm currently only maintaining consistency\_fail for Rails 3. If you need or
23
- want Rails 2.3 support, I'd be happy to take patches based off the 0.1.1
24
- branch.
23
+ You can install the gem directly:
25
24
 
26
25
  gem install consistency_fail
27
26
 
28
- Or, even better if you're using bundler, add it to your Gemfile, with the
29
- appropriate version number to match your Rails version.
27
+ Or if you're using Bundler (which you probably are), add it to your Gemfile.
28
+
29
+ gem 'consistency_fail'
30
+
30
31
 
31
32
  ## Limitations
32
33
 
34
+ The master branch should work for the following ActiveRecord versions:
35
+
36
+ - 5.x
37
+ - 4.x (*has a known issue around views*)
38
+ - 3.x
39
+ - 2.3 (on the `rails-2.3` branch)
40
+
41
+ The known issue with views in ActiveRecord 4.x is that in this version, the
42
+ connection adapter's `tables` method includes both tables and views. This means
43
+ that without additional monkeypatches to the various connection adapters, we
44
+ cannot reliably detect whether a given model is backed by a table or a view. I
45
+ wouldn't mind monkeypatching a bounded set of adapters, but I don't want to be
46
+ on the hook for arbitrary connection adapters that may require licenses to test
47
+ (e.g. SQL Server, Oracle).
48
+
33
49
  consistency\_fail depends on being able to find all your `ActiveRecord::Base`
34
50
  subclasses with some `$LOAD_PATH` trickery. If any models are in a path either
35
51
  not on your project's load path or in a path that doesn't include the word
@@ -21,7 +21,7 @@ stop ignoring the C in ACID.
21
21
  EOF
22
22
  s.license = "MIT"
23
23
 
24
- s.add_development_dependency "activerecord", "~>3.0"
24
+ s.add_development_dependency "activerecord", "~>5.0"
25
25
  s.add_development_dependency "sqlite3", "~>1.3"
26
26
  s.add_development_dependency "rspec", "~>3.2"
27
27
 
@@ -17,8 +17,9 @@ module ConsistencyFail
17
17
 
18
18
  def preload_all
19
19
  self.dirs.each do |d|
20
- Dir.glob(File.join(d, "**", "*.rb")).each do |model_filename|
21
- Kernel.require_dependency model_filename
20
+ ruby_files = Dir.glob(File.join(d, "**", "*.rb")).sort
21
+ ruby_files.each do |model_filename|
22
+ Kernel.require model_filename
22
23
  end
23
24
  end
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module ConsistencyFail
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/spec/index_spec.rb CHANGED
@@ -1,13 +1,16 @@
1
+ require_relative 'support/models/correct_address'
2
+ require_relative 'support/models/wrong_address'
3
+
1
4
  describe ConsistencyFail::Index do
2
-
5
+
3
6
  let(:index) do
4
7
  ConsistencyFail::Index.new(
5
- CorrectAddress,
6
- CorrectAddress.table_name,
8
+ CorrectAddress,
9
+ CorrectAddress.table_name,
7
10
  ["city", "state"]
8
11
  )
9
12
  end
10
-
13
+
11
14
  describe "value objectiness" do
12
15
  it "holds onto model, table name, and columns" do
13
16
  expect(index.model).to eq(CorrectAddress)
@@ -24,12 +27,12 @@ describe ConsistencyFail::Index do
24
27
  end
25
28
  end
26
29
 
27
- describe "equality test" do
30
+ describe "equality test" do
28
31
  it "passes when everything matches" do
29
32
  expect(index).to eq(
30
33
  ConsistencyFail::Index.new(
31
- "CorrectAddress".constantize,
32
- "correct_addresses",
34
+ "CorrectAddress".constantize,
35
+ "correct_addresses",
33
36
  ["city", "state"]
34
37
  )
35
38
  )
@@ -38,8 +41,8 @@ describe ConsistencyFail::Index do
38
41
  it "fails when tables are different" do
39
42
  expect(index).not_to eq(
40
43
  ConsistencyFail::Index.new(
41
- CorrectAttachment,
42
- CorrectAttachment.table_name,
44
+ CorrectAttachment,
45
+ CorrectAttachment.table_name,
43
46
  ["attachable_id", "attachable_type"]
44
47
  )
45
48
  )
@@ -48,12 +51,12 @@ describe ConsistencyFail::Index do
48
51
  it "fails when columns are different" do
49
52
  expect(index).not_to eq(
50
53
  ConsistencyFail::Index.new(
51
- CorrectAddress,
52
- CorrectAddress.table_name,
54
+ CorrectAddress,
55
+ CorrectAddress.table_name,
53
56
  ["correct_user_id"]
54
57
  )
55
58
  )
56
59
  end
57
60
  end
58
-
61
+
59
62
  end
data/spec/models_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  describe ConsistencyFail::Models do
2
-
2
+
3
3
  def models(load_path)
4
4
  ConsistencyFail::Models.new(load_path)
5
5
  end
@@ -19,7 +19,7 @@ describe ConsistencyFail::Models do
19
19
  expect(models.dirs).to eq([Pathname.new("app/models")])
20
20
  end
21
21
 
22
- it "preloads models by calling require_dependency" do
22
+ it "preloads models" do
23
23
  models = models(["foo/bar/baz", "app/models", "some/other/models"])
24
24
  allow(Dir).to receive(:glob).
25
25
  with(File.join("app/models", "**", "*.rb")).
@@ -28,9 +28,9 @@ describe ConsistencyFail::Models do
28
28
  with(File.join("some/other/models", "**", "*.rb")).
29
29
  and_return(["some/other/models/foo.rb"])
30
30
 
31
- expect(Kernel).to receive(:require_dependency).with("app/models/user.rb")
32
- expect(Kernel).to receive(:require_dependency).with("app/models/address.rb")
33
- expect(Kernel).to receive(:require_dependency).with("some/other/models/foo.rb")
31
+ expect(Kernel).to receive(:require).with("app/models/user.rb")
32
+ expect(Kernel).to receive(:require).with("app/models/address.rb")
33
+ expect(Kernel).to receive(:require).with("some/other/models/foo.rb")
34
34
 
35
35
  models.preload_all
36
36
  end
@@ -44,5 +44,9 @@ describe ConsistencyFail::Models do
44
44
 
45
45
  expect(models([]).all).to eq([model_a, model_c, model_b])
46
46
  end
47
-
47
+
48
+ it "preloads models successfully" do
49
+ models = models([File.join(File.dirname(__FILE__), "support/models")])
50
+ expect {models.preload_all}.not_to raise_error
51
+ end
48
52
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,10 @@ require 'bundler/setup'
2
2
 
3
3
  Bundler.require(:default, :test)
4
4
 
5
- Dir['./spec/support/**/*.rb'].sort.each { |file| require file }
5
+ require_relative 'support/active_record'
6
+ require_relative 'support/schema'
7
+ require 'active_support/dependencies'
8
+ ActiveSupport::Dependencies.autoload_paths << './spec/support/models'
6
9
 
7
10
  RSpec.configure do |config|
8
11
  config.around do |example|
@@ -0,0 +1,4 @@
1
+ class Blob < ActiveRecord::Base
2
+ require_dependency 'blob/edible'
3
+ include Edible
4
+ end
@@ -0,0 +1,2 @@
1
+ module Blob::Edible
2
+ end
@@ -118,4 +118,8 @@ ActiveRecord::Schema.define(version: 0) do
118
118
  execute 'CREATE VIEW new_correct_people AS '\
119
119
  'SELECT * FROM correct_people '\
120
120
  'WHERE created_at = updated_at'
121
+
122
+ create_table :blob do |t|
123
+ t.timestamps
124
+ end
121
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consistency_fail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '5.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
- version: '3.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +98,8 @@ files:
98
98
  - spec/reporter_spec.rb
99
99
  - spec/spec_helper.rb
100
100
  - spec/support/active_record.rb
101
+ - spec/support/models/blob.rb
102
+ - spec/support/models/blob/edible.rb
101
103
  - spec/support/models/correct_account.rb
102
104
  - spec/support/models/correct_address.rb
103
105
  - spec/support/models/correct_attachment.rb
@@ -150,6 +152,8 @@ test_files:
150
152
  - spec/reporter_spec.rb
151
153
  - spec/spec_helper.rb
152
154
  - spec/support/active_record.rb
155
+ - spec/support/models/blob.rb
156
+ - spec/support/models/blob/edible.rb
153
157
  - spec/support/models/correct_account.rb
154
158
  - spec/support/models/correct_address.rb
155
159
  - spec/support/models/correct_attachment.rb
@@ -168,4 +172,3 @@ test_files:
168
172
  - spec/support/models/wrong_post.rb
169
173
  - spec/support/models/wrong_user.rb
170
174
  - spec/support/schema.rb
171
- has_rdoc: