mongoid-embedded-errors 1.1.0 → 2.0.0
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.
- data/Gemfile.lock +7 -7
- data/README.md +6 -1
- data/lib/mongoid-embedded-errors.rb +13 -1
- data/lib/mongoid-embedded-errors/version.rb +1 -1
- data/spec/embedded_errors_spec.rb +2 -10
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid-embedded-errors (
|
4
|
+
mongoid-embedded-errors (2.0.0)
|
5
5
|
mongoid (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (3.2.
|
11
|
-
activesupport (= 3.2.
|
10
|
+
activemodel (3.2.12)
|
11
|
+
activesupport (= 3.2.12)
|
12
12
|
builder (~> 3.0.0)
|
13
|
-
activesupport (3.2.
|
13
|
+
activesupport (3.2.12)
|
14
14
|
i18n (~> 0.6)
|
15
15
|
multi_json (~> 1.0)
|
16
16
|
builder (3.0.4)
|
@@ -22,9 +22,9 @@ GEM
|
|
22
22
|
moped (~> 1.1)
|
23
23
|
origin (~> 1.0)
|
24
24
|
tzinfo (~> 0.3.22)
|
25
|
-
moped (1.2
|
26
|
-
multi_json (1.
|
27
|
-
origin (1.0.
|
25
|
+
moped (1.4.2)
|
26
|
+
multi_json (1.6.1)
|
27
|
+
origin (1.0.11)
|
28
28
|
rspec (2.11.0)
|
29
29
|
rspec-core (~> 2.11.0)
|
30
30
|
rspec-expectations (~> 2.11.0)
|
data/README.md
CHANGED
@@ -84,7 +84,12 @@ article = Article.new(pages: [Page.new(sections: [Section.new])])
|
|
84
84
|
article.valid? # => false
|
85
85
|
|
86
86
|
article.error.messages
|
87
|
-
|
87
|
+
{
|
88
|
+
:name => ["can't be blank"],
|
89
|
+
:summary => ["can't be blank"],
|
90
|
+
:"pages[0].title" => ["can't be blank"],
|
91
|
+
:"pages[0].sections[0].header" => ["can't be blank"]
|
92
|
+
}
|
88
93
|
```
|
89
94
|
|
90
95
|
Now, isn't that much nicer? Yeah, I think so to.
|
@@ -15,10 +15,22 @@ module Mongoid
|
|
15
15
|
def errors_with_embedded_errors
|
16
16
|
errs = errors_without_embedded_errors
|
17
17
|
self.embedded_relations.each do |name, metadata|
|
18
|
+
# name is something like pages or sections
|
19
|
+
# if there is an 'is invalid' message for the relation then let's work it:
|
18
20
|
if errs[name]
|
21
|
+
# first delete the unless 'is invalid' error for the relation
|
19
22
|
errs.delete(name.to_sym)
|
23
|
+
# next, loop through each of the relations (pages, sections, etc...)
|
20
24
|
self.send(name).each_with_index do |rel, i|
|
21
|
-
|
25
|
+
# get each of their individual message and add them to the parent's errors:
|
26
|
+
if rel.errors.any?
|
27
|
+
rel.errors.messages.each do |k, v|
|
28
|
+
key = "#{name}[#{i}].#{k}".to_sym
|
29
|
+
errs.delete(key)
|
30
|
+
errs[key] = v
|
31
|
+
errs[key].flatten!
|
32
|
+
end
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
24
36
|
end
|
@@ -17,16 +17,8 @@ describe Mongoid::EmbeddedErrors do
|
|
17
17
|
article.errors.messages.should eql({
|
18
18
|
name: ["can't be blank"],
|
19
19
|
summary: ["can't be blank"],
|
20
|
-
pages
|
21
|
-
|
22
|
-
title: ["can't be blank"],
|
23
|
-
sections: [{
|
24
|
-
1 => {
|
25
|
-
header: ["can't be blank"]
|
26
|
-
}
|
27
|
-
}]
|
28
|
-
}
|
29
|
-
}]
|
20
|
+
:"pages[0].title" => ["can't be blank"],
|
21
|
+
:"pages[0].sections[1].header" => ["can't be blank"]
|
30
22
|
})
|
31
23
|
end
|
32
24
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-embedded-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.25
|
72
72
|
signing_key:
|
73
73
|
specification_version: 3
|
74
74
|
summary: Easily bubble up errors from embedded documents in Mongoid.
|