mongoid-embedded-errors 2.1.1 → 3.0.1
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 +5 -5
- data/.codeclimate.yml +8 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +15 -9
- data/.semaphore/semaphore.yml +46 -0
- data/Appraisals +4 -4
- data/CHANGELOG.md +27 -0
- data/Gemfile +8 -6
- data/README.md +3 -3
- data/Rakefile +2 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/mongoid_4.gemfile +10 -5
- data/gemfiles/mongoid_5.gemfile +10 -5
- data/gemfiles/mongoid_6.gemfile +10 -5
- data/gemfiles/mongoid_7.gemfile +16 -0
- data/lib/mongoid-embedded-errors.rb +2 -1
- data/lib/mongoid/embedded_errors.rb +23 -10
- data/lib/mongoid/embedded_errors/embedded_in.rb +10 -2
- data/lib/mongoid/embedded_errors/version.rb +3 -1
- data/mongoid-embedded-errors.gemspec +17 -8
- data/spec/lib/mongoid/embedded_errors_spec.rb +55 -4
- data/spec/spec_helper.rb +4 -2
- data/spec/support/models/annotation.rb +2 -0
- data/spec/support/models/article.rb +2 -0
- data/spec/support/models/page.rb +2 -0
- data/spec/support/models/section.rb +2 -0
- data/spec/support/mongoid.yml +1 -1
- metadata +55 -29
- data/Gemfile.lock +0 -168
- data/bin/_guard-core +0 -17
- data/bin/appraisal +0 -17
- data/bin/guard +0 -17
- data/bin/rake +0 -17
- data/bin/rspec +0 -17
- data/gemfiles/mongoid_3.gemfile +0 -11
- data/gemfiles/mongoid_3.gemfile.lock +0 -98
- data/gemfiles/mongoid_4.gemfile.lock +0 -110
- data/gemfiles/mongoid_5.gemfile.lock +0 -106
- data/gemfiles/mongoid_6.gemfile.lock +0 -100
@@ -1,33 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Mongoid::EmbeddedErrors do
|
2
4
|
describe '#errors_with_embedded_errors' do
|
3
5
|
subject(:article) { Article.new name: 'Test', summary: '-', pages: pages }
|
6
|
+
|
4
7
|
before { |spec| article.validate unless spec.metadata[:do_not_validate] }
|
5
8
|
|
9
|
+
context 'when module is already included in a class', :do_not_validate do
|
10
|
+
let(:dummy_class) do
|
11
|
+
Class.new do
|
12
|
+
include Mongoid::Document
|
13
|
+
include Mongoid::EmbeddedErrors
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not create errors_without_embedded_errors alias again' do
|
18
|
+
a = dummy_class.instance_method(:errors_without_embedded_errors)
|
19
|
+
dummy_class.include described_class
|
20
|
+
|
21
|
+
expect(
|
22
|
+
a
|
23
|
+
).to eq(dummy_class.instance_method(:errors_without_embedded_errors))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
6
27
|
context 'when article does not have any pages associated' do
|
7
28
|
let(:pages) { [] }
|
8
29
|
|
9
30
|
it { is_expected.not_to be_valid }
|
31
|
+
|
10
32
|
it "returns `can't be blank` error for pages" do
|
11
33
|
expect(article.errors[:pages]).to include "can't be blank"
|
12
34
|
end
|
13
35
|
end
|
36
|
+
|
14
37
|
context 'when article has one or more invalid pages' do
|
15
38
|
let(:pages) { [Page.new] }
|
16
39
|
|
17
40
|
it { is_expected.not_to be_valid }
|
41
|
+
|
18
42
|
it 'does not have any errors under `:pages` key' do
|
19
43
|
expect(article.errors[:pages]).to be_empty
|
20
44
|
end
|
45
|
+
|
21
46
|
it 'returns all errors for `pages[0]` object' do
|
22
47
|
expect(article.errors[:'pages[0].title']).to include "can't be blank"
|
23
48
|
end
|
24
49
|
end
|
25
|
-
context 'when all pages in article are valid' do
|
26
|
-
let(:pages) { [Page.new(title: 'First page')] }
|
27
50
|
|
28
|
-
|
51
|
+
context 'when validated multiple times' do
|
52
|
+
let(:pages) { [Page.new] }
|
53
|
+
|
54
|
+
it 'does not have duplicated errors for the same object' do
|
55
|
+
article.valid?
|
56
|
+
expect(article.errors[:'pages[0].title']).to eq(["can't be blank"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when embeds_many relation is invalid' do
|
61
|
+
let(:pages) { [Page.new(title: 'Test page', sections: sections)] }
|
62
|
+
let(:sections) { [Section.new] }
|
63
|
+
|
64
|
+
it 'returns all errors for `sections[0]` object' do
|
65
|
+
expect(article.errors[:'pages[0].sections[0].header']).to include "can't be blank"
|
66
|
+
end
|
29
67
|
end
|
30
|
-
|
68
|
+
|
69
|
+
context 'when embeds_one relation is invalid' do
|
70
|
+
subject(:article) { Article.new name: 'Test', summary: '-', pages: pages, annotation: annotation }
|
71
|
+
|
72
|
+
let(:pages) { [Page.new(title: 'Test page')] }
|
73
|
+
let(:annotation) { Annotation.new }
|
74
|
+
|
75
|
+
it 'returns all errors for `annotation` object' do
|
76
|
+
expect(article.errors[:'annotation.text']).to include "can't be blank"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when embedded document has not been validated',
|
81
|
+
:do_not_validate do
|
31
82
|
let(:pages) { [Page.new] }
|
32
83
|
|
33
84
|
it 'does not trigger validations' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'mongoid-embedded-errors'
|
3
5
|
require 'database_cleaner'
|
@@ -27,11 +29,11 @@ RSpec.configure do |config|
|
|
27
29
|
DatabaseCleaner.strategy = :truncation
|
28
30
|
end
|
29
31
|
|
30
|
-
config.around
|
32
|
+
config.around do |example|
|
31
33
|
DatabaseCleaner.cleaning { example.run }
|
32
34
|
end
|
33
35
|
|
34
|
-
config.before
|
36
|
+
config.before do
|
35
37
|
# Need to manually reload spec models for mutant to work as expected
|
36
38
|
if ENV['MUTANT']
|
37
39
|
Dir[SPEC_MODELS_PATH].each do |filename|
|
data/spec/support/models/page.rb
CHANGED
data/spec/support/mongoid.yml
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-embedded-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Bates
|
8
8
|
- Kristijan Novoselić
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -17,24 +17,57 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '4.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 8.0.0
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
28
|
-
|
30
|
+
version: '4.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 8.0.0
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rubocop
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.92'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.92'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rubocop-rspec
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.43'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.43'
|
62
|
+
description: Embedded documents in Mongoid can be really useful. However, when one
|
63
|
+
of those embedded documents is invalid, Mongoid does not say which validation has
|
64
|
+
failed. Instead of just saying that an embedded document is invalid, this gem modifies
|
65
|
+
Mongoid behavior so it explicitly provides validation errors on a per-field basis
|
66
|
+
for embedded documents, the same way it does for parent documents.
|
29
67
|
email:
|
30
68
|
- mark@markbates.com
|
31
69
|
- kristijan@glooko.com
|
32
|
-
executables:
|
33
|
-
- _guard-core
|
34
|
-
- appraisal
|
35
|
-
- guard
|
36
|
-
- rake
|
37
|
-
- rspec
|
70
|
+
executables: []
|
38
71
|
extensions: []
|
39
72
|
extra_rdoc_files: []
|
40
73
|
files:
|
@@ -42,26 +75,19 @@ files:
|
|
42
75
|
- ".gitignore"
|
43
76
|
- ".rspec"
|
44
77
|
- ".rubocop.yml"
|
78
|
+
- ".semaphore/semaphore.yml"
|
45
79
|
- Appraisals
|
80
|
+
- CHANGELOG.md
|
46
81
|
- Gemfile
|
47
|
-
- Gemfile.lock
|
48
82
|
- Guardfile
|
49
83
|
- LICENSE.txt
|
50
84
|
- README.md
|
51
85
|
- Rakefile
|
52
|
-
-
|
53
|
-
- bin/appraisal
|
54
|
-
- bin/guard
|
55
|
-
- bin/rake
|
56
|
-
- bin/rspec
|
57
|
-
- gemfiles/mongoid_3.gemfile
|
58
|
-
- gemfiles/mongoid_3.gemfile.lock
|
86
|
+
- gemfiles/.bundle/config
|
59
87
|
- gemfiles/mongoid_4.gemfile
|
60
|
-
- gemfiles/mongoid_4.gemfile.lock
|
61
88
|
- gemfiles/mongoid_5.gemfile
|
62
|
-
- gemfiles/mongoid_5.gemfile.lock
|
63
89
|
- gemfiles/mongoid_6.gemfile
|
64
|
-
- gemfiles/
|
90
|
+
- gemfiles/mongoid_7.gemfile
|
65
91
|
- lib/mongoid-embedded-errors.rb
|
66
92
|
- lib/mongoid/embedded_errors.rb
|
67
93
|
- lib/mongoid/embedded_errors/embedded_in.rb
|
@@ -74,10 +100,11 @@ files:
|
|
74
100
|
- spec/support/models/page.rb
|
75
101
|
- spec/support/models/section.rb
|
76
102
|
- spec/support/mongoid.yml
|
77
|
-
homepage:
|
78
|
-
licenses:
|
103
|
+
homepage: https://github.com/glooko/mongoid-embedded-errors
|
104
|
+
licenses:
|
105
|
+
- MIT
|
79
106
|
metadata: {}
|
80
|
-
post_install_message:
|
107
|
+
post_install_message:
|
81
108
|
rdoc_options: []
|
82
109
|
require_paths:
|
83
110
|
- lib
|
@@ -92,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
119
|
- !ruby/object:Gem::Version
|
93
120
|
version: '0'
|
94
121
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
122
|
+
rubygems_version: 3.1.4
|
123
|
+
signing_key:
|
98
124
|
specification_version: 4
|
99
125
|
summary: Easily bubble up errors from embedded documents in Mongoid.
|
100
126
|
test_files:
|
data/Gemfile.lock
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mongoid-embedded-errors (2.0.1)
|
5
|
-
mongoid (>= 3.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
abstract_type (0.0.7)
|
11
|
-
activemodel (4.2.6)
|
12
|
-
activesupport (= 4.2.6)
|
13
|
-
builder (~> 3.1)
|
14
|
-
activesupport (4.2.6)
|
15
|
-
i18n (~> 0.7)
|
16
|
-
json (~> 1.7, >= 1.7.7)
|
17
|
-
minitest (~> 5.1)
|
18
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
19
|
-
tzinfo (~> 1.1)
|
20
|
-
adamantium (0.2.0)
|
21
|
-
ice_nine (~> 0.11.0)
|
22
|
-
memoizable (~> 0.4.0)
|
23
|
-
anima (0.3.0)
|
24
|
-
abstract_type (~> 0.0.7)
|
25
|
-
adamantium (~> 0.2)
|
26
|
-
equalizer (~> 0.0.11)
|
27
|
-
appraisal (2.1.0)
|
28
|
-
bundler
|
29
|
-
rake
|
30
|
-
thor (>= 0.14.0)
|
31
|
-
ast (2.3.0)
|
32
|
-
bson (3.2.6)
|
33
|
-
builder (3.2.2)
|
34
|
-
coderay (1.1.1)
|
35
|
-
concord (0.1.5)
|
36
|
-
adamantium (~> 0.2.0)
|
37
|
-
equalizer (~> 0.0.9)
|
38
|
-
connection_pool (2.2.0)
|
39
|
-
database_cleaner (1.5.3)
|
40
|
-
diff-lcs (1.2.5)
|
41
|
-
equalizer (0.0.11)
|
42
|
-
ffi (1.9.14)
|
43
|
-
formatador (0.2.5)
|
44
|
-
guard (2.14.0)
|
45
|
-
formatador (>= 0.2.4)
|
46
|
-
listen (>= 2.7, < 4.0)
|
47
|
-
lumberjack (~> 1.0)
|
48
|
-
nenv (~> 0.1)
|
49
|
-
notiffany (~> 0.0)
|
50
|
-
pry (>= 0.9.12)
|
51
|
-
shellany (~> 0.0)
|
52
|
-
thor (>= 0.18.1)
|
53
|
-
guard-compat (1.2.1)
|
54
|
-
guard-rspec (4.7.3)
|
55
|
-
guard (~> 2.1)
|
56
|
-
guard-compat (~> 1.1)
|
57
|
-
rspec (>= 2.99.0, < 4.0)
|
58
|
-
i18n (0.7.0)
|
59
|
-
ice_nine (0.11.2)
|
60
|
-
json (1.8.3)
|
61
|
-
listen (3.1.5)
|
62
|
-
rb-fsevent (~> 0.9, >= 0.9.4)
|
63
|
-
rb-inotify (~> 0.9, >= 0.9.7)
|
64
|
-
ruby_dep (~> 1.2)
|
65
|
-
lumberjack (1.0.10)
|
66
|
-
memoizable (0.4.2)
|
67
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
68
|
-
method_source (0.8.2)
|
69
|
-
minitest (5.9.0)
|
70
|
-
mongoid (4.0.2)
|
71
|
-
activemodel (~> 4.0)
|
72
|
-
moped (~> 2.0.0)
|
73
|
-
origin (~> 2.1)
|
74
|
-
tzinfo (>= 0.3.37)
|
75
|
-
moped (2.0.7)
|
76
|
-
bson (~> 3.0)
|
77
|
-
connection_pool (~> 2.0)
|
78
|
-
optionable (~> 0.2.0)
|
79
|
-
morpher (0.2.6)
|
80
|
-
abstract_type (~> 0.0.7)
|
81
|
-
adamantium (~> 0.2.0)
|
82
|
-
anima (~> 0.3.0)
|
83
|
-
ast (~> 2.2)
|
84
|
-
concord (~> 0.1.5)
|
85
|
-
equalizer (~> 0.0.9)
|
86
|
-
ice_nine (~> 0.11.0)
|
87
|
-
procto (~> 0.0.2)
|
88
|
-
mutant (0.8.11)
|
89
|
-
abstract_type (~> 0.0.7)
|
90
|
-
adamantium (~> 0.2.0)
|
91
|
-
anima (~> 0.3.0)
|
92
|
-
ast (~> 2.2)
|
93
|
-
concord (~> 0.1.5)
|
94
|
-
diff-lcs (~> 1.2)
|
95
|
-
equalizer (~> 0.0.9)
|
96
|
-
ice_nine (~> 0.11.1)
|
97
|
-
memoizable (~> 0.4.2)
|
98
|
-
morpher (~> 0.2.6)
|
99
|
-
parallel (~> 1.3)
|
100
|
-
parser (~> 2.3.0, >= 2.3.0.2)
|
101
|
-
procto (~> 0.0.2)
|
102
|
-
regexp_parser (~> 0.3.6)
|
103
|
-
unparser (~> 0.2.5)
|
104
|
-
mutant-rspec (0.8.11)
|
105
|
-
mutant (~> 0.8.11)
|
106
|
-
rspec-core (>= 3.4.0, < 3.6.0)
|
107
|
-
nenv (0.3.0)
|
108
|
-
notiffany (0.1.1)
|
109
|
-
nenv (~> 0.1)
|
110
|
-
shellany (~> 0.0)
|
111
|
-
optionable (0.2.0)
|
112
|
-
origin (2.2.0)
|
113
|
-
parallel (1.9.0)
|
114
|
-
parser (2.3.1.4)
|
115
|
-
ast (~> 2.2)
|
116
|
-
procto (0.0.3)
|
117
|
-
pry (0.10.4)
|
118
|
-
coderay (~> 1.1.0)
|
119
|
-
method_source (~> 0.8.1)
|
120
|
-
slop (~> 3.4)
|
121
|
-
rake (11.3.0)
|
122
|
-
rb-fsevent (0.9.7)
|
123
|
-
rb-inotify (0.9.7)
|
124
|
-
ffi (>= 0.5.0)
|
125
|
-
regexp_parser (0.3.6)
|
126
|
-
rspec (3.5.0)
|
127
|
-
rspec-core (~> 3.5.0)
|
128
|
-
rspec-expectations (~> 3.5.0)
|
129
|
-
rspec-mocks (~> 3.5.0)
|
130
|
-
rspec-core (3.5.3)
|
131
|
-
rspec-support (~> 3.5.0)
|
132
|
-
rspec-expectations (3.5.0)
|
133
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
134
|
-
rspec-support (~> 3.5.0)
|
135
|
-
rspec-mocks (3.5.0)
|
136
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
137
|
-
rspec-support (~> 3.5.0)
|
138
|
-
rspec-support (3.5.0)
|
139
|
-
ruby_dep (1.4.0)
|
140
|
-
shellany (0.0.1)
|
141
|
-
slop (3.6.0)
|
142
|
-
thor (0.19.1)
|
143
|
-
thread_safe (0.3.5)
|
144
|
-
tzinfo (1.2.2)
|
145
|
-
thread_safe (~> 0.1)
|
146
|
-
unparser (0.2.5)
|
147
|
-
abstract_type (~> 0.0.7)
|
148
|
-
adamantium (~> 0.2.0)
|
149
|
-
concord (~> 0.1.5)
|
150
|
-
diff-lcs (~> 1.2.5)
|
151
|
-
equalizer (~> 0.0.9)
|
152
|
-
parser (~> 2.3.0)
|
153
|
-
procto (~> 0.0.2)
|
154
|
-
|
155
|
-
PLATFORMS
|
156
|
-
ruby
|
157
|
-
|
158
|
-
DEPENDENCIES
|
159
|
-
appraisal
|
160
|
-
database_cleaner
|
161
|
-
guard-rspec
|
162
|
-
mongoid-embedded-errors!
|
163
|
-
mutant-rspec
|
164
|
-
rake
|
165
|
-
rspec
|
166
|
-
|
167
|
-
BUNDLED WITH
|
168
|
-
1.13.1
|