unidom-common-rspec 0.7.2 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8668718e519295468c144a5e4fbde4f6ddb7b4ee
4
- data.tar.gz: 2d311c582e71ef5ccf8c4d02a54d9f4699e11261
3
+ metadata.gz: c2cb81603835692cf41ec01b1b03d62b7551d1b1
4
+ data.tar.gz: 930f1e99959e6e4b0f9f2ec0b1874be75f308e06
5
5
  SHA512:
6
- metadata.gz: 1874e4a989989575e73d78723c2b9c22c928c0077582216ccc59315462bc9e48b09f7c1451df2cfb14f0ab53a7ee6347ccfd04fa5da6df18c90f3029f31b1165
7
- data.tar.gz: df2baf2d47b5b337ddf2f6713cfbfeea1f6bc967b2d72c5f6a3a889b6c3ac136dc2d29936bd1c08e8fc505b274f96ecf4bee0fe8d179583e7d4a0c0a48258ab6
6
+ metadata.gz: 33350926a4fbf769140f8f670db0fefce248ea9d79b9fd8e21f76b5eb9fa508f4f92691df00ed5461d610a3c504846f4c2b979d07142e1cea799bd5b566918e4
7
+ data.tar.gz: ab816b5f953bcb77e2989e3d431a52611348edeceb8dc378db1a36a13c7d049fafbc3da12adf60ed6de1a3a72508ca4d7161538c7e4125f6bfe5336083625b69
data/CHANGELOG.md CHANGED
@@ -25,14 +25,18 @@
25
25
  2. Improved the Has One shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
26
26
 
27
27
  ## v0.6.2
28
- 1. Improve the Has Many shared examples for the #``collection.build`` method, the #collection.create method, & the #collection.create! method
28
+ 1. Improved the Has Many shared examples for the #``collection.build`` method, the #``collection.create`` method, & the #collection.create! method
29
29
 
30
30
  ## v0.7
31
31
  1. Each Validator shared examples
32
32
 
33
33
  ## v0.7.1
34
- 1. Improve the Model Extension shared examples for the .ordinal_is scope, the .grade_is scope, the .grade_higher_than scope, the .grade_lower_than scope, the .priority_is scope, the .priority_higher_than scope, & the .priority_lower_than scope
35
- 2. Improve the Model Extension shared examples for the #ordinal validation
34
+ 1. Improved the Model Extension shared examples for the .ordinal_is scope, the .grade_is scope, the .grade_higher_than scope, the .grade_lower_than scope, the .priority_is scope, the .priority_higher_than scope, & the .priority_lower_than scope
35
+ 2. Improved the Model Extension shared examples for the #ordinal validation
36
36
 
37
37
  ## v0.7.2
38
- 1. Improve the Validates shared examples for the failure message
38
+ 1. Improved the Validates shared examples for the failure message
39
+
40
+ ## v0.8
41
+ 1. Monomorphic Scope shared examples
42
+ 2. Polymorphic Scope shared examples
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unidom-common-rspec (0.7.1)
4
+ unidom-common-rspec (0.7.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -88,4 +88,4 @@ DEPENDENCIES
88
88
  unidom-common-rspec!
89
89
 
90
90
  BUNDLED WITH
91
- 1.12.5
91
+ 1.13.6
data/README.md CHANGED
@@ -54,7 +54,9 @@ class Pet < ApplicationRecord
54
54
 
55
55
  include Unidom::Common::Concerns::ModelExtension
56
56
 
57
- belongs_to :person
57
+ belongs_to :owner, polymorphic: true
58
+
59
+ scope :owned_by, ->(owner) { where owner: owner }
58
60
 
59
61
  end
60
62
 
@@ -67,6 +69,8 @@ class IdentityCard < ApplicationRecord
67
69
 
68
70
  belongs_to :person
69
71
 
72
+ scope :owned_by, ->(owner) { where person_id: to_id(owner) }
73
+
70
74
  end
71
75
 
72
76
  # identification_number_validator.rb
@@ -127,6 +131,44 @@ describe Person, type: :model do
127
131
  end
128
132
  ```
129
133
 
134
+ ### Monomorphic Scope shared examples 单态 Scope 共享用例
135
+
136
+ The ``identity_card_spec.rb`` looks like the following:
137
+ ```ruby
138
+ require 'rails_helper'
139
+
140
+ describe IdentityCard, type: :model do
141
+
142
+ context do
143
+
144
+ tim_identity_card_attributes = { name: 'Tim', gender_code: '1', birth_date: '1980-07-01' }
145
+
146
+ it_behaves_like 'monomorphic scope', tim_identity_card_attributes, :owned_by, :person
147
+
148
+ end
149
+
150
+ end
151
+ ```
152
+
153
+ ### Polymorphic Scope shared examples 多态 Scope 共享用例
154
+
155
+ The ``pet_spec.rb`` looks like the following:
156
+ ```ruby
157
+ require 'rails_helper'
158
+
159
+ describe Pet, type: :model do
160
+
161
+ context do
162
+
163
+ cat_attributes = { name: 'Pearl', species: 'Persian' }
164
+
165
+ it_behaves_like 'polymorphic scope', cat_attributes, :owned_by, :person, [ Person ]
166
+
167
+ end
168
+
169
+ end
170
+ ```
171
+
130
172
  ### Validates shared examples Validates 共享用例
131
173
 
132
174
  The ``person_spec.rb`` looks like the following:
data/ROADMAP.md CHANGED
@@ -25,7 +25,7 @@
25
25
  2. Improve the Has One shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
26
26
 
27
27
  ## v0.6.2
28
- 1. Improve the Has Many shared examples for the #``collection.build`` method, the #collection.create method, & the #collection.create! method
28
+ 1. Improve the Has Many shared examples for the #``collection.build`` method, the #``collection.create`` method, & the #collection.create! method
29
29
 
30
30
  ## v0.7
31
31
  1. Each Validator shared examples
@@ -36,3 +36,7 @@
36
36
 
37
37
  ## v0.7.2
38
38
  1. Improve the Validates shared examples for the failure message
39
+
40
+ ## v0.8
41
+ 1. Monomorphic Scope shared examples
42
+ 2. Polymorphic Scope shared examples
@@ -29,3 +29,49 @@ shared_examples 'scope' do |scope_name, fixtures|
29
29
  end
30
30
 
31
31
  end
32
+
33
+
34
+
35
+ shared_examples 'monomorphic scope' do |model_attributes, scope_name, association_name|
36
+
37
+ attribute_name = :"#{association_name}_id"
38
+ reflection = described_class.reflections[association_name.to_s]
39
+ association_class = reflection.options[:class_name].safe_constantize
40
+ association_id = model_attributes[attribute_name]
41
+ association_instance = association_class.new id: association_id
42
+ variant_attribtues = model_attributes.merge attribute_name => Unidom::Common::NULL_UUID
43
+
44
+ it_behaves_like 'scope', scope_name, [
45
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_id ] },
46
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_instance ] },
47
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_id ] },
48
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_instance ] }
49
+ ]
50
+
51
+ end
52
+
53
+
54
+
55
+ shared_examples 'polymorphic scope' do |model_attributes, scope_name, association_name, association_class_list|
56
+
57
+ attribute_name = :"#{association_name}_id"
58
+ reflection = described_class.reflections[association_name.to_s]
59
+ association_id = model_attributes[attribute_name]
60
+
61
+ association_class_list.each do |association_class|
62
+
63
+ association_instance = association_class.new id: association_id
64
+ variant_instance = association_class.new id: Unidom::Common::NULL_UUID
65
+ model_attributes = model_attributes.merge :"#{association_name}_type" => association_class.name
66
+ variant_attribtues = model_attributes.merge attribute_name => Unidom::Common::NULL_UUID
67
+
68
+ it_behaves_like 'scope', scope_name, [
69
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_instance ] },
70
+ { attributes_collection: [ model_attributes ], count_diff: 0, args: [ variant_instance ] },
71
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_instance ] },
72
+ { attributes_collection: [ variant_attribtues ], count_diff: 1, args: [ variant_instance ] }
73
+ ]
74
+
75
+ end
76
+
77
+ end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-common-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails