unidom-common-rspec 0.10 → 2.0

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
- SHA1:
3
- metadata.gz: bc9f1aade781883ed8d968ddd012226828dc9f21
4
- data.tar.gz: e0dbea08eb51150996cf6c45bf843c91d56963d8
2
+ SHA256:
3
+ metadata.gz: '08978e31550f24686da26c0a790887b6fe033aac165ec7db16bb4dcc5f56b1cb'
4
+ data.tar.gz: 78c99b4e6a005aa3313bc7c88ea88e32141ba4bd6d34981e6c90db7c9dd17328
5
5
  SHA512:
6
- metadata.gz: 7c74dd4f8f502ed40ab419689d3ed26745c2fccd568a1fd5c374533300bdc1a3f68224d77da38a83ac38ec1a9ff2ebf23ab6bfe3d031d208937b857e6f4fb995
7
- data.tar.gz: 5d18a4e0e28d2290753962e3dfac8d25cc960fe2969b993fafc8500b6c9db6cfaf6cbda4bde88d4ee1f3de3b150e1b66383c61a44b940d1b10f369f99ad0a9b7
6
+ metadata.gz: '0902ba335e02cd60910258edbe8a89fc488205a5983b4d2084b4971c935b89c12250cab02baeb6c120d2f132ead3a75d095eda3c8356f02ffd8501da25a130c3'
7
+ data.tar.gz: f928fc097ae1207abda9b12f497c425e0f43b6068bf9fab9b450b92f7526050e2eced2efb949bf1657564860e8f46a6831e4149d38bc3dc89d789e4698cfe395
data/CHANGELOG.md CHANGED
@@ -1,52 +1,84 @@
1
1
  # Unidom Common RSpec Change Log Unidom Common RSpec 库变更日志
2
2
 
3
3
  ## v0.1
4
+
4
5
  1. Scope shared examples
5
6
 
6
7
  ## v0.2
8
+
7
9
  1. Validates shared examples
8
10
 
9
11
  ## v0.3
12
+
10
13
  1. Model Extension shared examples
11
14
 
12
15
  ## v0.4
16
+
13
17
  1. Has Many shared examples
14
18
 
15
19
  ## v0.5
20
+
16
21
  1. Belongs To shared examples
17
22
  2. Improved the Model Extension shared examples for the validates behaviors of the #``grade`` attribute & the #``priority`` attribute
18
23
  3. Improved the Model Extension shared examples for the scope behaviours of the #``priority`` attribute
19
24
 
20
25
  ## v0.6
26
+
21
27
  1. Has One shared examples
22
28
 
23
29
  ## v0.6.1
30
+
24
31
  1. Improved the Belongs To shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
25
32
  2. Improved the Has One shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
26
33
 
27
34
  ## v0.6.2
35
+
28
36
  1. Improved the Has Many shared examples for the #``collection.build`` method, the #``collection.create`` method, & the #``collection.create!`` method
29
37
 
30
38
  ## v0.7
39
+
31
40
  1. Each Validator shared examples
32
41
 
33
42
  ## v0.7.1
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
43
+
44
+ 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
45
+ 2. Improved the Model Extension shared examples for the validations on the #``ordinal`` attribute
36
46
 
37
47
  ## v0.7.2
48
+
38
49
  1. Improved the Validates shared examples for the failure message
39
50
 
40
51
  ## v0.8
52
+
41
53
  1. Monomorphic Scope shared examples
42
54
  2. Polymorphic Scope shared examples
43
55
 
44
56
  ## v0.9
57
+
45
58
  1. Validates Text shared examples
46
59
  2. Validates Numericality shared examples
47
60
 
48
61
  ## v0.9.1
49
- 1. Improve the Validates Text shared examples for the length
62
+
63
+ 1. Improved the Validates Text shared examples for the length
50
64
 
51
65
  ## v0.10
66
+
52
67
  1. Assert Present shared examples
68
+
69
+ ## v0.10.1
70
+
71
+ 1. Improved the Scope shared examples to separate the Monomorphic Scope shared examples, & the Polymorphic Scope shared examples
72
+ 2. Improved the Validates shared examples to separate the Validates Text shared examples, & the Validates Numericality shared examples
73
+
74
+ ## v1.0
75
+
76
+ 1. Improved the compatibility for Rails 6.x & RSpec Rails 4.x
77
+
78
+ ## v1.1
79
+
80
+ 1. Improved the Ruby Gem Specification to depend on Rake v13.0, & RSpec v3.9
81
+
82
+ ## v2.0
83
+
84
+ 1. Improved the Scope shared examples for Ruby 3.0
data/Gemfile.lock CHANGED
@@ -1,91 +1,96 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unidom-common-rspec (0.9.1)
4
+ unidom-common-rspec (1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (5.0.1)
10
- actionview (= 5.0.1)
11
- activesupport (= 5.0.1)
12
- rack (~> 2.0)
13
- rack-test (~> 0.6.3)
9
+ actionpack (6.0.2.2)
10
+ actionview (= 6.0.2.2)
11
+ activesupport (= 6.0.2.2)
12
+ rack (~> 2.0, >= 2.0.8)
13
+ rack-test (>= 0.6.3)
14
14
  rails-dom-testing (~> 2.0)
15
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
- actionview (5.0.1)
17
- activesupport (= 5.0.1)
15
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
+ actionview (6.0.2.2)
17
+ activesupport (= 6.0.2.2)
18
18
  builder (~> 3.1)
19
- erubis (~> 2.7.0)
19
+ erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
- activesupport (5.0.1)
21
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
+ activesupport (6.0.2.2)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
- i18n (~> 0.7)
24
+ i18n (>= 0.7, < 2)
25
25
  minitest (~> 5.1)
26
26
  tzinfo (~> 1.1)
27
- builder (3.2.3)
28
- concurrent-ruby (1.0.4)
27
+ zeitwerk (~> 2.2)
28
+ builder (3.2.4)
29
+ concurrent-ruby (1.1.6)
30
+ crass (1.0.6)
29
31
  diff-lcs (1.3)
30
- erubis (2.7.0)
31
- i18n (0.8.0)
32
- loofah (2.0.3)
32
+ erubi (1.9.0)
33
+ i18n (1.8.2)
34
+ concurrent-ruby (~> 1.0)
35
+ loofah (2.5.0)
36
+ crass (~> 1.0.2)
33
37
  nokogiri (>= 1.5.9)
34
- method_source (0.8.2)
35
- mini_portile2 (2.1.0)
36
- minitest (5.10.1)
37
- nokogiri (1.7.0.1)
38
- mini_portile2 (~> 2.1.0)
39
- rack (2.0.1)
40
- rack-test (0.6.3)
41
- rack (>= 1.0)
42
- rails-dom-testing (2.0.2)
43
- activesupport (>= 4.2.0, < 6.0)
44
- nokogiri (~> 1.6)
45
- rails-html-sanitizer (1.0.3)
46
- loofah (~> 2.0)
47
- railties (5.0.1)
48
- actionpack (= 5.0.1)
49
- activesupport (= 5.0.1)
38
+ method_source (1.0.0)
39
+ mini_portile2 (2.4.0)
40
+ minitest (5.14.0)
41
+ nokogiri (1.10.9)
42
+ mini_portile2 (~> 2.4.0)
43
+ rack (2.2.2)
44
+ rack-test (1.1.0)
45
+ rack (>= 1.0, < 3)
46
+ rails-dom-testing (2.0.3)
47
+ activesupport (>= 4.2.0)
48
+ nokogiri (>= 1.6)
49
+ rails-html-sanitizer (1.3.0)
50
+ loofah (~> 2.3)
51
+ railties (6.0.2.2)
52
+ actionpack (= 6.0.2.2)
53
+ activesupport (= 6.0.2.2)
50
54
  method_source
51
55
  rake (>= 0.8.7)
52
- thor (>= 0.18.1, < 2.0)
53
- rake (10.5.0)
54
- rspec (3.5.0)
55
- rspec-core (~> 3.5.0)
56
- rspec-expectations (~> 3.5.0)
57
- rspec-mocks (~> 3.5.0)
58
- rspec-core (3.5.4)
59
- rspec-support (~> 3.5.0)
60
- rspec-expectations (3.5.0)
56
+ thor (>= 0.20.3, < 2.0)
57
+ rake (13.0.1)
58
+ rspec (3.9.0)
59
+ rspec-core (~> 3.9.0)
60
+ rspec-expectations (~> 3.9.0)
61
+ rspec-mocks (~> 3.9.0)
62
+ rspec-core (3.9.1)
63
+ rspec-support (~> 3.9.1)
64
+ rspec-expectations (3.9.1)
61
65
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.5.0)
63
- rspec-mocks (3.5.0)
66
+ rspec-support (~> 3.9.0)
67
+ rspec-mocks (3.9.1)
64
68
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.5.0)
66
- rspec-rails (3.5.2)
67
- actionpack (>= 3.0)
68
- activesupport (>= 3.0)
69
- railties (>= 3.0)
70
- rspec-core (~> 3.5.0)
71
- rspec-expectations (~> 3.5.0)
72
- rspec-mocks (~> 3.5.0)
73
- rspec-support (~> 3.5.0)
74
- rspec-support (3.5.0)
75
- thor (0.19.4)
76
- thread_safe (0.3.5)
77
- tzinfo (1.2.2)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-rails (4.0.0)
71
+ actionpack (>= 4.2)
72
+ activesupport (>= 4.2)
73
+ railties (>= 4.2)
74
+ rspec-core (~> 3.9)
75
+ rspec-expectations (~> 3.9)
76
+ rspec-mocks (~> 3.9)
77
+ rspec-support (~> 3.9)
78
+ rspec-support (3.9.2)
79
+ thor (1.0.1)
80
+ thread_safe (0.3.6)
81
+ tzinfo (1.2.7)
78
82
  thread_safe (~> 0.1)
83
+ zeitwerk (2.3.0)
79
84
 
80
85
  PLATFORMS
81
86
  ruby
82
87
 
83
88
  DEPENDENCIES
84
- bundler (~> 1.12)
85
- rake (~> 10.0)
86
- rspec (~> 3.0)
87
- rspec-rails (~> 3.5)
89
+ bundler (~> 2.0)
90
+ rake (~> 13.0)
91
+ rspec (~> 3.9)
92
+ rspec-rails (~> 4.0)
88
93
  unidom-common-rspec!
89
94
 
90
95
  BUNDLED WITH
91
- 1.13.6
96
+ 2.1.4
data/README.md CHANGED
@@ -27,12 +27,15 @@ gem 'unidom-common-rspec'
27
27
 
28
28
  And then execute:
29
29
 
30
- $ bundle
30
+ ```shell
31
+ $ bundle
32
+ ```
31
33
 
32
34
  Or install it yourself as:
33
35
 
34
- $ gem install unidom-common-rspec
35
-
36
+ ```shell
37
+ $ gem install unidom-common-rspec
38
+ ```
36
39
 
37
40
 
38
41
  ## Usage
@@ -183,7 +186,7 @@ require 'rails_helper'
183
186
 
184
187
  describe Person, type: :model do
185
188
 
186
- context '.validates' do
189
+ context do
187
190
 
188
191
  tim_attributes = { name: 'Tim' }
189
192
 
@@ -229,7 +232,7 @@ require 'rails_helper'
229
232
 
230
233
  describe Person, type: :model do
231
234
 
232
- context '.validates' do
235
+ context do
233
236
 
234
237
  tim_attributes = { name: 'Tim', age: 28 }
235
238
 
@@ -345,22 +348,26 @@ The ``identification_number_validator_spec.rb`` looks like the following:
345
348
  ```ruby
346
349
  RSpec.describe IdentificationNumberValidator, type: :validator do
347
350
 
348
- valid_values = %w{
349
- 231024198506186916
350
- 231024198506188110
351
- 231024198506185470
352
- 231024198506182851
353
- 231024198506187193
354
- }
355
- invalid_values = %w{
356
- 231024198506186917
357
- 231024198506188111
358
- 231024198506185471
359
- 231024198506182852
360
- 231024198506187194
361
- }
362
-
363
- it_behaves_like 'ActiveModel::EachValidator', valid_values, invalid_values
351
+ context do
352
+
353
+ valid_values = %w{
354
+ 231024198506186916
355
+ 231024198506188110
356
+ 231024198506185470
357
+ 231024198506182851
358
+ 231024198506187193
359
+ }
360
+ invalid_values = %w{
361
+ 231024198506186917
362
+ 231024198506188111
363
+ 231024198506185471
364
+ 231024198506182852
365
+ 231024198506187194
366
+ }
367
+
368
+ it_behaves_like 'ActiveModel::EachValidator', valid_values, invalid_values
369
+
370
+ end
364
371
 
365
372
  end
366
373
  ```
data/ROADMAP.md CHANGED
@@ -1,52 +1,84 @@
1
1
  # Unidom Common RSpec Roadmap Unidom Common RSpec 库线路图
2
2
 
3
3
  ## v0.1
4
+
4
5
  1. Scope shared examples
5
6
 
6
7
  ## v0.2
8
+
7
9
  1. Validates shared examples
8
10
 
9
11
  ## v0.3
12
+
10
13
  1. Model Extension shared examples
11
14
 
12
15
  ## v0.4
16
+
13
17
  1. Has Many shared examples
14
18
 
15
19
  ## v0.5
20
+
16
21
  1. Belongs To shared examples
17
22
  2. Improve the Model Extension shared examples for the validates behaviors of the #``grade`` attribute & the #``priority`` attribute
18
23
  3. Improve the Model Extension shared examples for the scope behaviours of the #``priority`` attribute
19
24
 
20
25
  ## v0.6
26
+
21
27
  1. Has One shared examples
22
28
 
23
29
  ## v0.6.1
30
+
24
31
  1. Improve the Belongs To shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
25
32
  2. Improve the Has One shared examples for the #``build_association`` method, the #``create_association`` method, & the #``create_association!`` method
26
33
 
27
34
  ## v0.6.2
35
+
28
36
  1. Improve the Has Many shared examples for the #``collection.build`` method, the #``collection.create`` method, & the #``collection.create!`` method
29
37
 
30
38
  ## v0.7
39
+
31
40
  1. Each Validator shared examples
32
41
 
33
42
  ## 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
43
+
44
+ 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
45
+ 2. Improve the Model Extension shared examples for the validations on the #``ordinal`` attribute
36
46
 
37
47
  ## v0.7.2
48
+
38
49
  1. Improve the Validates shared examples for the failure message
39
50
 
40
51
  ## v0.8
52
+
41
53
  1. Monomorphic Scope shared examples
42
54
  2. Polymorphic Scope shared examples
43
55
 
44
56
  ## v0.9
57
+
45
58
  1. Validates Text shared examples
46
59
  2. Validates Numericality shared examples
47
60
 
48
61
  ## v0.9.1
62
+
49
63
  1. Improve the Validates Text shared examples for the length
50
64
 
51
65
  ## v0.10
66
+
52
67
  1. Assert Present shared examples
68
+
69
+ ## v0.10.1
70
+
71
+ 1. Improve the Scope shared examples to separate the Monomorphic Scope shared examples, & the Polymorphic Scope shared examples
72
+ 2. Improve the Validates shared examples to separate the Validates Text shared examples, & the Validates Numericality shared examples
73
+
74
+ ## v1.0
75
+
76
+ 1. Improve the compatibility for Rails 6.x & RSpec Rails 4.x
77
+
78
+ ## v1.1
79
+
80
+ 1. Improve the Ruby Gem Specification to depend on Rake v13.0, & RSpec v4.0
81
+
82
+ ## v2.0
83
+
84
+ 1. Improve the Scope shared examples for Ruby 3.0
@@ -1,11 +1,18 @@
1
- require "unidom/common/rspec/version"
1
+ require 'rspec/core'
2
+
3
+ require 'unidom/common/rspec/version'
2
4
 
3
5
  require 'unidom/common/rspec/assert_present_shared_examples'
4
6
 
5
7
  require 'unidom/common/rspec/each_validator_shared_examples'
6
8
 
7
9
  require 'unidom/common/rspec/scope_shared_examples'
10
+ require 'unidom/common/rspec/monomorphic_scope_shared_examples'
11
+ require 'unidom/common/rspec/polymorphic_scope_shared_examples'
12
+
8
13
  require 'unidom/common/rspec/validates_shared_examples'
14
+ require 'unidom/common/rspec/validates_numericality_shared_examples'
15
+ require 'unidom/common/rspec/validates_text_shared_examples'
9
16
 
10
17
  require 'unidom/common/rspec/belongs_to_shared_examples'
11
18
  require 'unidom/common/rspec/has_many_shared_examples'
@@ -0,0 +1,17 @@
1
+ shared_examples 'monomorphic scope' do |model_attributes, scope_name, association_name|
2
+
3
+ attribute_name = :"#{association_name}_id"
4
+ reflection = described_class.reflections[association_name.to_s]
5
+ association_class = reflection.options[:class_name].safe_constantize
6
+ association_id = model_attributes[attribute_name]
7
+ association_instance = association_class.new id: association_id
8
+ variant_attribtues = model_attributes.merge attribute_name => Unidom::Common::NULL_UUID
9
+
10
+ it_behaves_like 'scope', scope_name, [
11
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_id ] },
12
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_instance ] },
13
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_id ] },
14
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_instance ] }
15
+ ]
16
+
17
+ end
@@ -0,0 +1,23 @@
1
+ shared_examples 'polymorphic scope' do |model_attributes, scope_name, association_name, association_class_list|
2
+
3
+ attribute_name = :"#{association_name}_id"
4
+ reflection = described_class.reflections[association_name.to_s]
5
+ association_id = model_attributes[attribute_name]
6
+
7
+ association_class_list.each do |association_class|
8
+
9
+ association_instance = association_class.new id: association_id
10
+ variant_instance = association_class.new id: Unidom::Common::NULL_UUID
11
+ model_attributes = model_attributes.merge :"#{association_name}_type" => association_class.name
12
+ variant_attribtues = model_attributes.merge attribute_name => Unidom::Common::NULL_UUID
13
+
14
+ it_behaves_like 'scope', scope_name, [
15
+ { attributes_collection: [ model_attributes ], count_diff: 1, args: [ association_instance ] },
16
+ { attributes_collection: [ model_attributes ], count_diff: 0, args: [ variant_instance ] },
17
+ { attributes_collection: [ variant_attribtues ], count_diff: 0, args: [ association_instance ] },
18
+ { attributes_collection: [ variant_attribtues ], count_diff: 1, args: [ variant_instance ] }
19
+ ]
20
+
21
+ end
22
+
23
+ end
@@ -6,19 +6,41 @@ shared_examples 'scope' do |scope_name, fixtures|
6
6
 
7
7
  fixtures.select { |fixture| 'E'!=fixture[:count_diff] } .each do |fixture|
8
8
  describe ".#{scope_name}(#{fixture[:args].blank? ? '' : (fixture[:args].map &:inspect).join(', ')})" do
9
+
9
10
  before :each do
10
- @count = fixture[:args].present? ? described_class.send(scope_name, *fixture[:args]).count : described_class.send(scope_name).count
11
+ #@count = fixture[:args].present? ? described_class.send(scope_name, *fixture[:args]).count : described_class.send(scope_name).count
12
+ if fixture[:args].present?
13
+ if fixture[:args][0].is_a? Hash
14
+ @count = described_class.send(scope_name, **fixture[:args][0]).count
15
+ else
16
+ @count = described_class.send(scope_name, *fixture[:args]).count
17
+ end
18
+ else
19
+ @count = described_class.send(scope_name).count
20
+ end
11
21
  @model_instances = []
12
22
  fixture[:attributes_collection].each do |attributes| @model_instances << (described_class.create! attributes) end
13
23
  end
24
+
14
25
  after :each do
15
26
  @count = 0
16
27
  @model_instances.each do |model_instance| model_instance.destroy end if @model_instances.present?
17
28
  end
29
+
18
30
  it "has #{fixture[:count_diff]} added" do
19
- actual_count = fixture[:args].present? ? described_class.send(scope_name, *fixture[:args]).count : described_class.send(scope_name).count
31
+ if fixture[:args].present?
32
+ if fixture[:args][0].is_a? Hash
33
+ actual_count = described_class.send(scope_name, **fixture[:args][0]).count
34
+ else
35
+ actual_count = described_class.send(scope_name, *fixture[:args]).count
36
+ end
37
+ else
38
+ actual_count = described_class.send(scope_name).count
39
+ end
40
+ #actual_count = fixture[:args].present? ? described_class.send(scope_name, **fixture[:args][0]).count : described_class.send(scope_name).count
20
41
  expect(actual_count).to eq(fixture[:count_diff]+@count)
21
42
  end
43
+
22
44
  end
23
45
  end
24
46
 
@@ -29,49 +51,3 @@ shared_examples 'scope' do |scope_name, fixtures|
29
51
  end
30
52
 
31
53
  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
@@ -0,0 +1,47 @@
1
+ shared_examples 'validates numericality' do |model_attributes, attribute_name, options|
2
+
3
+ attribute_name = attribute_name.to_sym
4
+ presence_validator = described_class.validators.select { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator)&&v.attributes.include?(attribute_name) }.first
5
+ excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveModel::Validations::NumericalityValidator ].include?(v.class) }
6
+
7
+ if excluded_validators.present?
8
+ raise ArgumentError.new("The validators on the #{attribute_name.inspect} attribute must be PresenceValidator or NumericalityValidator. The excluded validator#{excluded_validators.size>1 ? 's are' : ' is'}: #{excluded_validators.inspect}.")
9
+ end
10
+
11
+ attributes_collection = { {} => 0 }
12
+
13
+ attributes_collection[ { attribute_name => nil } ] = presence_validator.present? ? 2 : 0
14
+ attributes_collection[ { attribute_name => '' } ] = presence_validator.present? ? 2 : 0
15
+
16
+ minimum = options[:range].min
17
+ maximum = options[:range].max
18
+ minimum_inclusive = options[:minimum_inclusive]
19
+ maximum_inclusive = options[:maximum_inclusive]
20
+ only_integer = options[:only_integer]
21
+ scale = described_class.columns_hash[attribute_name.to_s].scale.to_i
22
+ unit = only_integer ? 1 : (scale>0 ? (10**-scale).to_f : 0.01)
23
+
24
+ attributes_collection[ { attribute_name => minimum-unit } ] = 1
25
+ attributes_collection[ { attribute_name => minimum } ] = minimum_inclusive ? 0 : 1
26
+ attributes_collection[ { attribute_name => minimum+unit } ] = 0
27
+
28
+ attributes_collection[ { attribute_name => maximum-unit } ] = 0
29
+ attributes_collection[ { attribute_name => maximum } ] = maximum_inclusive ? 0 : 1
30
+ attributes_collection[ { attribute_name => maximum+unit } ] = 1
31
+
32
+ average = (minimum+maximum)/(only_integer ? 2 : 2.0)
33
+ attributes_collection[ { attribute_name => average } ] = 0
34
+
35
+ if only_integer
36
+ attributes_collection[ { attribute_name => minimum+0.01 } ] = 1
37
+ attributes_collection[ { attribute_name => maximum-0.01 } ] = 1
38
+ end
39
+
40
+ letters = ('a'..'z').to_a+('A'..'Z').to_a
41
+ symbols = '~`!@#$%^&*()-_=+{}[];:"\',.<>/?\\|'.chars
42
+
43
+ (letters+symbols).each do |c| attributes_collection[ { attribute_name => c } ] = 1 end
44
+
45
+ it_behaves_like 'validates', model_attributes, attribute_name, attributes_collection
46
+
47
+ end
@@ -34,97 +34,3 @@ shared_examples 'validates' do |model_attributes, attribute_name, error_attribut
34
34
  end
35
35
 
36
36
  end
37
-
38
-
39
-
40
- shared_examples 'validates text' do |model_attributes, attribute_name, options|
41
-
42
- attribute_name = attribute_name.to_sym
43
- presence_validator = described_class.validators.select { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator)&&v.attributes.include?(attribute_name) }.first
44
- excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveRecord::Validations::LengthValidator ].include?(v.class) }
45
-
46
- if excluded_validators.present?
47
- raise ArgumentError.new("The validators on the #{attribute_name.inspect} attribute must be PresenceValidator or LengthValidator. The excluded validator#{excluded_validators.size>1 ? 's are' : ' is'}: #{excluded_validators.inspect}.")
48
- end
49
-
50
- attributes_collection = { {} => 0 }
51
-
52
- attributes_collection[ { attribute_name => nil } ] = presence_validator.present? ? 2 : 0
53
- attributes_collection[ { attribute_name => '' } ] = presence_validator.present? ? 2 : 0
54
-
55
- minimum_length = options[:length].min
56
- maximum_length = options[:length].max
57
-
58
- numbers = ('0'..'9').to_a
59
- letters = ('a'..'z').to_a+('A'..'Z').to_a
60
- symbols = '~`!@#$%^&*()-_=+{}[];:"\',.<>/?\\|'.chars
61
- chars = numbers+letters+symbols
62
-
63
- if minimum_length==maximum_length
64
- length = maximum_length
65
- chars.each do |c| attributes_collection[ { attribute_name => c*(length-1) } ] = 1 end
66
- chars.each do |c| attributes_collection[ { attribute_name => c*length } ] = 0 end
67
- chars.each do |c| attributes_collection[ { attribute_name => c*(length+1) } ] = 1 end
68
- else
69
- chars.each do |c| attributes_collection[ { attribute_name => c } ] = 0 end if 1==minimum_length
70
- chars.each do |c| attributes_collection[ { attribute_name => c*(minimum_length-1) } ] = 1 end if minimum_length>1
71
- chars.each do |c| attributes_collection[ { attribute_name => c*minimum_length } ] = 0 end
72
- chars.each do |c| attributes_collection[ { attribute_name => c*(minimum_length+1) } ] = 0 end if minimum_length<maximum_length
73
- chars.each do |c| attributes_collection[ { attribute_name => c*(maximum_length-1) } ] = 0 end
74
- chars.each do |c| attributes_collection[ { attribute_name => c*maximum_length } ] = 0 end
75
- chars.each do |c| attributes_collection[ { attribute_name => c*(maximum_length+1) } ] = 1 end
76
- end
77
-
78
- it_behaves_like 'validates', model_attributes, attribute_name, attributes_collection
79
-
80
- end
81
-
82
-
83
-
84
- shared_examples 'validates numericality' do |model_attributes, attribute_name, options|
85
-
86
- attribute_name = attribute_name.to_sym
87
- presence_validator = described_class.validators.select { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator)&&v.attributes.include?(attribute_name) }.first
88
- excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveModel::Validations::NumericalityValidator ].include?(v.class) }
89
-
90
- if excluded_validators.present?
91
- raise ArgumentError.new("The validators on the #{attribute_name.inspect} attribute must be PresenceValidator or NumericalityValidator. The excluded validator#{excluded_validators.size>1 ? 's are' : ' is'}: #{excluded_validators.inspect}.")
92
- end
93
-
94
- attributes_collection = { {} => 0 }
95
-
96
- attributes_collection[ { attribute_name => nil } ] = presence_validator.present? ? 2 : 0
97
- attributes_collection[ { attribute_name => '' } ] = presence_validator.present? ? 2 : 0
98
-
99
- minimum = options[:range].min
100
- maximum = options[:range].max
101
- minimum_inclusive = options[:minimum_inclusive]
102
- maximum_inclusive = options[:maximum_inclusive]
103
- only_integer = options[:only_integer]
104
- scale = described_class.columns_hash[attribute_name.to_s].scale.to_i
105
- unit = only_integer ? 1 : (scale>0 ? (10**-scale).to_f : 0.01)
106
-
107
- attributes_collection[ { attribute_name => minimum-unit } ] = 1
108
- attributes_collection[ { attribute_name => minimum } ] = minimum_inclusive ? 0 : 1
109
- attributes_collection[ { attribute_name => minimum+unit } ] = 0
110
-
111
- attributes_collection[ { attribute_name => maximum-unit } ] = 0
112
- attributes_collection[ { attribute_name => maximum } ] = maximum_inclusive ? 0 : 1
113
- attributes_collection[ { attribute_name => maximum+unit } ] = 1
114
-
115
- average = (minimum+maximum)/(only_integer ? 2 : 2.0)
116
- attributes_collection[ { attribute_name => average } ] = 0
117
-
118
- if only_integer
119
- attributes_collection[ { attribute_name => minimum+0.01 } ] = 1
120
- attributes_collection[ { attribute_name => maximum-0.01 } ] = 1
121
- end
122
-
123
- letters = ('a'..'z').to_a+('A'..'Z').to_a
124
- symbols = '~`!@#$%^&*()-_=+{}[];:"\',.<>/?\\|'.chars
125
-
126
- (letters+symbols).each do |c| attributes_collection[ { attribute_name => c } ] = 1 end
127
-
128
- it_behaves_like 'validates', model_attributes, attribute_name, attributes_collection
129
-
130
- end
@@ -0,0 +1,41 @@
1
+ shared_examples 'validates text' do |model_attributes, attribute_name, options|
2
+
3
+ attribute_name = attribute_name.to_sym
4
+ presence_validator = described_class.validators.select { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator)&&v.attributes.include?(attribute_name) }.first
5
+ excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveRecord::Validations::LengthValidator ].include?(v.class) }
6
+
7
+ if excluded_validators.present?
8
+ raise ArgumentError.new("The validators on the #{attribute_name.inspect} attribute must be PresenceValidator or LengthValidator. The excluded validator#{excluded_validators.size>1 ? 's are' : ' is'}: #{excluded_validators.inspect}.")
9
+ end
10
+
11
+ attributes_collection = { {} => 0 }
12
+
13
+ attributes_collection[ { attribute_name => nil } ] = presence_validator.present? ? 2 : 0
14
+ attributes_collection[ { attribute_name => '' } ] = presence_validator.present? ? 2 : 0
15
+
16
+ minimum_length = options[:length].min
17
+ maximum_length = options[:length].max
18
+
19
+ numbers = ('0'..'9').to_a
20
+ letters = ('a'..'z').to_a+('A'..'Z').to_a
21
+ symbols = '~`!@#$%^&*()-_=+{}[];:"\',.<>/?\\|'.chars
22
+ chars = numbers+letters+symbols
23
+
24
+ if minimum_length==maximum_length
25
+ length = maximum_length
26
+ chars.each do |c| attributes_collection[ { attribute_name => c*(length-1) } ] = 1 end
27
+ chars.each do |c| attributes_collection[ { attribute_name => c*length } ] = 0 end
28
+ chars.each do |c| attributes_collection[ { attribute_name => c*(length+1) } ] = 1 end
29
+ else
30
+ chars.each do |c| attributes_collection[ { attribute_name => c } ] = 0 end if 1==minimum_length
31
+ chars.each do |c| attributes_collection[ { attribute_name => c*(minimum_length-1) } ] = 1 end if minimum_length>1
32
+ chars.each do |c| attributes_collection[ { attribute_name => c*minimum_length } ] = 0 end
33
+ chars.each do |c| attributes_collection[ { attribute_name => c*(minimum_length+1) } ] = 0 end if minimum_length<maximum_length
34
+ chars.each do |c| attributes_collection[ { attribute_name => c*(maximum_length-1) } ] = 0 end
35
+ chars.each do |c| attributes_collection[ { attribute_name => c*maximum_length } ] = 0 end
36
+ chars.each do |c| attributes_collection[ { attribute_name => c*(maximum_length+1) } ] = 1 end
37
+ end
38
+
39
+ it_behaves_like 'validates', model_attributes, attribute_name, attributes_collection
40
+
41
+ end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '0.10'
4
+ VERSION = '2.0'
5
5
  end
6
6
  end
7
7
  end
@@ -27,10 +27,10 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = [ 'lib' ]
29
29
 
30
- spec.add_development_dependency 'rspec-rails', '~> 3.5'
30
+ spec.add_development_dependency 'rspec-rails', '~> 4.0'
31
31
 
32
- spec.add_development_dependency 'bundler', '~> 1.12'
33
- spec.add_development_dependency 'rake', '~> 10.0'
34
- spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.9'
35
35
 
36
36
  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.10'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2021-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.5'
19
+ version: '4.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.5'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '3.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '3.9'
69
69
  description: Unidom Common RSpec is a RSpec-based Shared Example for the Unidom Common-based
70
70
  models. Unidom Common RSpec 是为 Unidom Common 设计的基于 RSpec 的共享测试用例。
71
71
  email:
@@ -94,15 +94,19 @@ files:
94
94
  - lib/unidom/common/rspec/has_many_shared_examples.rb
95
95
  - lib/unidom/common/rspec/has_one_shared_examples.rb
96
96
  - lib/unidom/common/rspec/model_extension_shared_examples.rb
97
+ - lib/unidom/common/rspec/monomorphic_scope_shared_examples.rb
98
+ - lib/unidom/common/rspec/polymorphic_scope_shared_examples.rb
97
99
  - lib/unidom/common/rspec/scope_shared_examples.rb
100
+ - lib/unidom/common/rspec/validates_numericality_shared_examples.rb
98
101
  - lib/unidom/common/rspec/validates_shared_examples.rb
102
+ - lib/unidom/common/rspec/validates_text_shared_examples.rb
99
103
  - lib/unidom/common/rspec/version.rb
100
104
  - unidom-common-rspec.gemspec
101
105
  homepage: https://github.com/topbitdu/unidom-common-rspec
102
106
  licenses:
103
107
  - MIT
104
108
  metadata: {}
105
- post_install_message:
109
+ post_install_message:
106
110
  rdoc_options: []
107
111
  require_paths:
108
112
  - lib
@@ -117,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  - !ruby/object:Gem::Version
118
122
  version: '0'
119
123
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.6.4
122
- signing_key:
124
+ rubygems_version: 3.2.3
125
+ signing_key:
123
126
  specification_version: 4
124
127
  summary: Unidom Common RSpec 是为 Unidom Common 设计的基于 RSpec 的共享测试用例。
125
128
  test_files: []