specstar-models 0.2.10 → 0.3.0
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 +4 -4
- data/lib/specstar/models/validations.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13690914c226ba34126023e5fa4780c96bb72013
|
4
|
+
data.tar.gz: 8e65d4cc3d287db504038d6ecdd56c303c72ccc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d31f50b197a678b571269815d5d9da6cf4e0b2bb01d87ad418b1d2e8b08a0163e4ca4da9e97f127e47967b45fc0dd9c9517635d552002ba284bf5d4d32ed24a7
|
7
|
+
data.tar.gz: d203ab21ab597047ef02d5369d1dfeb277ccf51e191de79549caf52df1716a673a9e547d9d734634f92d67dbc53ab76f593935a71b1f13f79904642bcc3ae544
|
@@ -47,6 +47,33 @@ module Specstar
|
|
47
47
|
model.class.reflect_on_all_associations.map { |a| a.name.to_s }.include? association.to_s
|
48
48
|
end
|
49
49
|
|
50
|
+
RSpec::Matchers.define :validate do |attr, *options, **custom_validations|
|
51
|
+
match do |model|
|
52
|
+
if !has_attribute?(model, attr) && !has_association?(model, attr)
|
53
|
+
false
|
54
|
+
else
|
55
|
+
begin
|
56
|
+
validators = custom_validations.each_pair.to_a.select { |attr, value| value == true }.map(&:first)
|
57
|
+
validators.all? do |validator|
|
58
|
+
klass = "#{validator}_validator".classify.constantize
|
59
|
+
model._validators[attr.to_sym].select { |v| v.instance_of? klass }.size > 0
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
failure_message do |model|
|
68
|
+
options = [*options, custom_validations]
|
69
|
+
if has_attribute?(model, attr) || has_association?(model, attr)
|
70
|
+
"expected #{model.class} to validate #{attr}."
|
71
|
+
else
|
72
|
+
"expected #{model.class} to have an attribute or association #{attr}."
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
50
77
|
RSpec::Matchers.define :validate_presence_of do |attr, options|
|
51
78
|
match do |model|
|
52
79
|
(has_attribute?(model, attr) || has_association?(model, attr)) &&
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specstar-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sujoy Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|