shoulda-matchers 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cad2b70febc8044b3a8a61bc3ce7aa00b780708d3e0d2baccedaa3922d6f42f
|
|
4
|
+
data.tar.gz: 4a3fca99d9bccfac2bc74035f1e1a8608ef24775a19dd7bc30b0a979e6f87ed1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29dcf4008451127b46e668f2399fe58d851ec54d2057595e59c7a57937b2f0e72d4a2aa4bdacd90f78d6a12a6de79f253675ab15ff4339c4222813bcaa449c04
|
|
7
|
+
data.tar.gz: 3f5b06b148848185c566f381f8cf3871dc56e454ea9ff59cb6106f1e969b854de53d07d84d6fa6d9554090440efcb568f30f33ac3dcfaada6fd4304fcbc284b5
|
|
@@ -18,26 +18,11 @@ module Shoulda
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def clear
|
|
21
|
-
test_model_classes = []
|
|
22
|
-
|
|
23
21
|
constant.constants.each do |child_constant|
|
|
24
|
-
child = constant.const_get(child_constant)
|
|
25
|
-
|
|
26
|
-
if defined?(::ActiveRecord::Base) &&
|
|
27
|
-
child.is_a?(Class) &&
|
|
28
|
-
child < ::ActiveRecord::Base
|
|
29
|
-
test_model_classes << child
|
|
30
|
-
end
|
|
31
|
-
|
|
32
22
|
constant.remove_const(child_constant)
|
|
33
23
|
rescue NameError
|
|
34
24
|
# Constant may have been removed elsewhere; ignore
|
|
35
25
|
end
|
|
36
|
-
|
|
37
|
-
if defined?(::ActiveSupport::DescendantsTracker) &&
|
|
38
|
-
test_model_classes.any?
|
|
39
|
-
::ActiveSupport::DescendantsTracker.clear(test_model_classes)
|
|
40
|
-
end
|
|
41
26
|
end
|
|
42
27
|
|
|
43
28
|
def to_s
|
|
@@ -5,7 +5,25 @@ module Shoulda
|
|
|
5
5
|
module Uniqueness
|
|
6
6
|
# @private
|
|
7
7
|
module TestModels
|
|
8
|
+
# Test models subclass real ActiveRecord models, so they register
|
|
9
|
+
# in `descendants`/`subclasses` and cannot be unregistered after
|
|
10
|
+
# the fact: ActiveSupport::DescendantsTracker.clear raises when
|
|
11
|
+
# config.enable_reloading is false (the default in the test
|
|
12
|
+
# environment), and the classes cannot be reliably garbage
|
|
13
|
+
# collected. Instead, mirror the filtering technique Rails itself
|
|
14
|
+
# uses for reloaded classes and hide them at the source.
|
|
15
|
+
module DescendantsFiltering
|
|
16
|
+
def descendants
|
|
17
|
+
super.reject { |klass| TestModels.contains?(klass) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def subclasses
|
|
21
|
+
super.reject { |klass| TestModels.contains?(klass) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
8
25
|
def self.create(model_name)
|
|
26
|
+
hide_from_descendants
|
|
9
27
|
TestModelCreator.create(model_name, root_namespace)
|
|
10
28
|
end
|
|
11
29
|
|
|
@@ -16,6 +34,20 @@ module Shoulda
|
|
|
16
34
|
def self.root_namespace
|
|
17
35
|
@_root_namespace ||= Namespace.new(self)
|
|
18
36
|
end
|
|
37
|
+
|
|
38
|
+
def self.contains?(klass)
|
|
39
|
+
!klass.name.nil? && klass.name.start_with?(name_prefix)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.name_prefix
|
|
43
|
+
@_name_prefix ||= "#{name}::"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.hide_from_descendants
|
|
47
|
+
@_hide_from_descendants ||=
|
|
48
|
+
::ActiveRecord::Base.singleton_class.
|
|
49
|
+
prepend(DescendantsFiltering) && true
|
|
50
|
+
end
|
|
19
51
|
end
|
|
20
52
|
end
|
|
21
53
|
end
|