specstar-models 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/specstar/models/associations.rb +15 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a65ff9cddbe77e64aa33e3d7881486ac993ea4
|
4
|
+
data.tar.gz: 69a434f31ad64b2660d8ee7cb70189ef95837852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1442d0ca8e46eec559def1248295a7a70d1e51b1fae591931c2cccc5ce8b3f200b0ee05d2f3b5f2460361dff3bbd40d41de9af13a71cdb6968ffec97c9e3862f
|
7
|
+
data.tar.gz: b727ba9ad84e0ea85ffcbf8d80d07f47f80b757a1ee53e8a7bbcdcd447730f0799f2135f63275fc76f36cb851b921bfe564628e7aa65295b8b1b5b5fe66c6881
|
@@ -5,10 +5,16 @@ module Specstar
|
|
5
5
|
module Models
|
6
6
|
module Matchers
|
7
7
|
|
8
|
-
|
8
|
+
def match?(association, options)
|
9
|
+
options.each_pair.select do |key, value|
|
10
|
+
association.options[key.to_sym].to_s != value.to_s
|
11
|
+
end.size == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Matchers.define :belong_to do |attr, options={}|
|
9
15
|
match do |model|
|
10
16
|
association = model.class.reflect_on_association(attr)
|
11
|
-
association && association.macro == :belongs_to
|
17
|
+
association && association.macro == :belongs_to && match?(association, options)
|
12
18
|
end
|
13
19
|
|
14
20
|
failure_message do |model|
|
@@ -16,14 +22,18 @@ module Specstar
|
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
|
-
RSpec::Matchers.define :have_many do |attr|
|
25
|
+
RSpec::Matchers.define :have_many do |attr, options={}|
|
20
26
|
match do |model|
|
21
27
|
association = model.class.reflect_on_association(attr)
|
22
|
-
association && association.macro == :has_many
|
28
|
+
association && association.macro == :has_many && match?(association, options)
|
23
29
|
end
|
24
30
|
|
25
31
|
failure_message do |model|
|
26
|
-
|
32
|
+
if options
|
33
|
+
"expected #{model.class} to have many #{attr} with #{options}."
|
34
|
+
else
|
35
|
+
"expected #{model.class} to have many #{attr}."
|
36
|
+
end
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|