specstar-models 0.2.4 → 0.2.5

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: 340d09c4db76d22befcbff8f1c415df6a5082656
4
- data.tar.gz: dc8ae599fbcdc34fb4106bc2f6b8e3dd19ffed54
3
+ metadata.gz: 22a65ff9cddbe77e64aa33e3d7881486ac993ea4
4
+ data.tar.gz: 69a434f31ad64b2660d8ee7cb70189ef95837852
5
5
  SHA512:
6
- metadata.gz: 6cb803ff9c732d9d2f764aa34daff7512410239c878936daba8ed1ac9e976f989e1d9d8ffd70c934812806fcd330b3f1860a3fd92b9ed6ec95c4305e8dfd9c13
7
- data.tar.gz: 655128e977fcc67f94a064a2db0753abd93d6b5433defc6eb59542b5ce2423dac23486a37fef18be4db9894c5962681792d8462ada097f6dfa530f63f226e28b
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
- RSpec::Matchers.define :belong_to do |attr|
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
- "expected #{model.class} to have many #{attr}."
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specstar-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sujoy Gupta