unidom-common-rspec 0.6.1 → 0.6.2
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 +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +7 -4
- data/README.md +2 -0
- data/ROADMAP.md +4 -1
- data/lib/unidom/common/rspec/has_many_shared_examples.rb +43 -11
- data/lib/unidom/common/rspec/has_one_shared_examples.rb +1 -1
- data/lib/unidom/common/rspec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a24751bce0e821610da99c8c6a045fd9dc3090be
|
4
|
+
data.tar.gz: 6a51b465d327824e09fca1bf74339e86293f7fe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c96579a57600c9de43e4c9bad7e3881977d4d980008b7662d45d5d103150133a38356bef9754ef1f263d4703e63bc6e5a428ecb09d33804a17d0d49283fab3
|
7
|
+
data.tar.gz: 785a786a4f58a1ec03a6cec9e73958d81c4f899f3f3c3502aff6ede535f5c7f9db12f357b0f181a0b0e8c3a0dcb7e5d2fda74502f41dec5726c6df3f6a540c5d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -14,12 +14,15 @@
|
|
14
14
|
|
15
15
|
## v0.5
|
16
16
|
1. Belongs To shared examples
|
17
|
-
2.
|
18
|
-
3.
|
17
|
+
2. Improved the Model Extension shared examples for the validates behaviors of the #grade attribute & the #priority attribute
|
18
|
+
3. Improved the Model Extension shared examples for the scope behaviours of the #priority attribute
|
19
19
|
|
20
20
|
## v0.6
|
21
21
|
1. Has One shared examples
|
22
22
|
|
23
23
|
## v0.6.1
|
24
|
-
1.
|
25
|
-
2.
|
24
|
+
1. Improved the Belongs To shared examples for the #build_association method, the #create_association method, & the #create_association! method
|
25
|
+
2. Improved the Has One shared examples for the #build_association method, the #create_association method, & the #create_association! method
|
26
|
+
|
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
|
data/README.md
CHANGED
@@ -71,6 +71,8 @@ end
|
|
71
71
|
The ``person_spec.rb`` looks like the following:
|
72
72
|
If the ``count_diff`` is set to 'E', an error was expected to be raised.
|
73
73
|
```ruby
|
74
|
+
# The :all scope and the :none scope are the scopes defined by Rails.
|
75
|
+
# The :transited_to scope is defined by Model Extension.
|
74
76
|
require 'rails_helper'
|
75
77
|
|
76
78
|
describe Person, type: :model do
|
data/ROADMAP.md
CHANGED
@@ -25,4 +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 #
|
28
|
+
1. Improve the Has Many shared examples for the #collection.build method, the #collection.create method, & the #collection.create! method
|
29
|
+
|
30
|
+
## v0.7
|
31
|
+
1. Each Validator shared examples
|
@@ -12,11 +12,11 @@ shared_examples 'has_many' do |model_attributes, collection_name, item_class, it
|
|
12
12
|
#association_immutable = reflection.source_reflection.blank? ? false : (:belongs_to != reflection.source_reflection.macro)
|
13
13
|
association_immutable = reflection.source_reflection.blank? ? false : being_through&&![ :belongs_to ].include?(reflection.source_reflection.macro)
|
14
14
|
|
15
|
-
[ collection_name, "#{collection_name}=", "#{collection_name.to_s.singularize}_ids", "#{collection_name.to_s.singularize}_ids=" ].each do |method|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
#[ collection_name, "#{collection_name}=", "#{collection_name.to_s.singularize}_ids", "#{collection_name.to_s.singularize}_ids=" ].each do |method|
|
16
|
+
# describe "##{method}" do
|
17
|
+
# it 'is responded to' do expect(model_instance).to respond_to(method.to_sym) end
|
18
|
+
# end
|
19
|
+
#end
|
20
20
|
|
21
21
|
%w{ << push concat build create create! size length count sum where empty? clear delete delete_all destroy destroy_all find exists? uniq reset }.each do |method|
|
22
22
|
|
@@ -25,7 +25,7 @@ shared_examples 'has_many' do |model_attributes, collection_name, item_class, it
|
|
25
25
|
before :each do collection.clear if collection.present? end
|
26
26
|
after :each do collection.clear if collection.present? end
|
27
27
|
|
28
|
-
it 'is responded to' do expect(collection).to respond_to(method.to_sym) end
|
28
|
+
#it 'is responded to' do expect(collection).to respond_to(method.to_sym) end
|
29
29
|
|
30
30
|
case method
|
31
31
|
|
@@ -45,6 +45,7 @@ shared_examples 'has_many' do |model_attributes, collection_name, item_class, it
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
=begin
|
48
49
|
when 'build'
|
49
50
|
if association_readonly #or association_immutable
|
50
51
|
it 'nested association can not build' do
|
@@ -62,17 +63,48 @@ shared_examples 'has_many' do |model_attributes, collection_name, item_class, it
|
|
62
63
|
expect(item_1).to_not be(item_2)
|
63
64
|
end
|
64
65
|
end
|
66
|
+
=end
|
65
67
|
|
66
68
|
end
|
67
69
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
subject do described_class.new model_attributes end
|
74
|
+
|
75
|
+
[ collection_name, "#{collection_name}=", "#{collection_name.to_s.singularize}_ids", "#{collection_name.to_s.singularize}_ids=" ].each do |method_name|
|
76
|
+
it do is_expected.to respond_to(method_name.to_sym) end
|
77
|
+
end
|
78
|
+
|
79
|
+
%w{ << push concat build create create! size length count sum where empty? clear delete delete_all destroy destroy_all find exists? uniq reset }.each do |method_name|
|
80
|
+
it "should respond to ##{collection_name}##{method_name}" do
|
81
|
+
expect(subject.send collection_name).to respond_to(method_name.to_sym)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "##{collection_name}#build" do
|
86
|
+
if association_readonly
|
87
|
+
it 'nested association can not build' do
|
88
|
+
error_class = association_readonly ? ActiveRecord::HasManyThroughNestedAssociationsAreReadonly : ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection
|
89
|
+
expect { collection.build }.to raise_error(error_class)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
let :item_1 do collection.build end
|
93
|
+
let :item_2 do collection.build end
|
94
|
+
it "should be a #{item_class.name}" do expect(item_1).to be_a(item_class) end
|
95
|
+
it 'should not be a new record' do expect(item_1).to be_new_record end
|
96
|
+
it "should be a #{item_class.name}" do expect(item_2).to be_a(item_class) end
|
97
|
+
it 'should not be a new record' do expect(item_2).to be_new_record end
|
98
|
+
it 'should not be identical' do expect(item_1).to_not be(item_2) end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
%w{ create create! }.each do |method_name|
|
103
|
+
context "##{collection_name}##{method_name}" do
|
104
|
+
subject do described_class.create! model_attributes end
|
105
|
+
let :created_item_instance do subject.send(collection_name).send method_name, item_attributes_collection.first end
|
106
|
+
it "should be a #{item_class.name}" do expect(created_item_instance).to be_a(item_class) end
|
107
|
+
it 'should not be a new record' do expect(created_item_instance).to_not be_new_record end
|
76
108
|
end
|
77
109
|
end
|
78
110
|
|
@@ -41,7 +41,7 @@ shared_examples 'has_one' do |model_attributes, association_name, association_cl
|
|
41
41
|
[ "create_#{association_name}", "create_#{association_name}!" ].each do |method_name|
|
42
42
|
context "##{method_name}" do
|
43
43
|
subject do described_class.create! model_attributes end
|
44
|
-
let :created_association_instance
|
44
|
+
let :created_association_instance do subject.send method_name, association_attributes end
|
45
45
|
it "should be a #{association_class.name}" do expect(created_association_instance).to be_an_instance_of(association_class) end
|
46
46
|
it 'should not be a new record' do expect(created_association_instance).to_not be_new_record end
|
47
47
|
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.6.
|
4
|
+
version: 0.6.2
|
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-01-
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|