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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e784cb5e009f04f5e545f88d7a1f14c86c706167
4
- data.tar.gz: 561662558a4501a27744b28db68d6e3535dc94e9
3
+ metadata.gz: 161a3a72cf8b6cf94f5ce52c8373c9b509fa7777
4
+ data.tar.gz: a23b81f62cb01fb578ca9a95c35563c33734b0dc
5
5
  SHA512:
6
- metadata.gz: aa7b2ac4f129c95b90fd4871b1d80ba4440d2c54ff7919da7b687b64908d24e052025c931399979047b107ae0452c938921b3753325204202f31da527ba927dc
7
- data.tar.gz: 189eb054e7ce5f2abc3787dac866d45782b47abba561d70c49766dd78ec8df5fefaac0a3991248bb4bb3c724ecb4bebda1a308e3bb7abfc78de0f843adb5b1d5
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.3.1
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-01-24 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core