specstar-models 0.3.1 → 1.0.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 +21 -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: 161a3a72cf8b6cf94f5ce52c8373c9b509fa7777
|
4
|
+
data.tar.gz: a23b81f62cb01fb578ca9a95c35563c33734b0dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2dd57980e3f5b68a76367719eac50463304a72d3f1e8db6dabfeaa152798ad02d1dcd6ac57e686c3c140c9bd31c50a1a94c850638f2e2132f5cd688e3461e7
|
7
|
+
data.tar.gz: 50e1a8073b9e934db0121479e28022d7d2dd904e94718436f60f7380f697c91b8fb2e04e21719c888f34b4d5cde5089f8527f4a2cd74ab45d1b61a5c40ac45df
|
@@ -75,6 +75,27 @@ module Specstar
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
RSpec::Matchers.define :validate_length_of do |attr, options|
|
79
|
+
match do |model|
|
80
|
+
(has_attribute?(model, attr) || has_association?(model, attr)) &&
|
81
|
+
model._validators[attr.to_sym].select do |validator|
|
82
|
+
validator.instance_of?(ActiveModel::Validations::LengthValidator) && (options.nil? || validate_presence_of_methods_in_options(model, options) && (options.to_a - validator.options.to_a).empty?)
|
83
|
+
end.size > 0
|
84
|
+
end
|
85
|
+
|
86
|
+
failure_message do |model|
|
87
|
+
if has_attribute?(model, attr) || has_association?(model, attr)
|
88
|
+
if options.nil? || validate_presence_of_methods_in_options(model, options)
|
89
|
+
"expected #{model.class} to validate length of #{attr}."
|
90
|
+
else
|
91
|
+
"expected #{model.class} to define #{undefined_method_in_options(model, options)}."
|
92
|
+
end
|
93
|
+
else
|
94
|
+
"expected #{model.class} to have an attribute or association #{attr}."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
78
99
|
RSpec::Matchers.define :validate_presence_of do |attr, options|
|
79
100
|
match do |model|
|
80
101
|
(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: 1.0.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-
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|