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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb5d80b65b01397c8136543df44ab5cdfd5837a7
4
- data.tar.gz: 467969881bad160ded787df276a9fe94891d7b53
3
+ metadata.gz: 13690914c226ba34126023e5fa4780c96bb72013
4
+ data.tar.gz: 8e65d4cc3d287db504038d6ecdd56c303c72ccc7
5
5
  SHA512:
6
- metadata.gz: 8a933d6e82dc514ec4e750dcc78b44ebc39629a5bcd29048c6c00c0d62527a28154fb45cb0cfe867448c59d6581f2bfc97d6f4f87c2c3e269c2dbc18589979a2
7
- data.tar.gz: cf819995ff2f9a87094b94afdf58d9c2cb2699f4047643510c77af70dc17af2f2a463778dca1ac759d05778e6393a9063b5aa2a608abb2a3f5dd04f4775bac8f
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.2.10
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 00:00:00.000000000 Z
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core