mongoid-embedded-errors 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96ef455929fe07047621a0d5a2e33c576ee05926
4
+ data.tar.gz: dff154361af3fac2c963cd4ba7652902b8190441
5
+ SHA512:
6
+ metadata.gz: b70add5efeb3f66dd603edd5104537cbead19775fe643afa265b7fc1aef6ff2f308dcba412f0aafb5ae67256bdf86318917bb5a2632f910b254f4f4cd39054a0
7
+ data.tar.gz: fd0881ccee8b5243333a6f8e3219c5002d9c2772267db2f438f66c7975c495896edaa66f7da8c2491ba5f67a6fe7c77c0bf16c8fc05ebc47e14336e76f3d450c
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-embedded-errors (2.0.0)
4
+ mongoid-embedded-errors (2.0.1)
5
5
  mongoid (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.12)
11
- activesupport (= 3.2.12)
10
+ activemodel (3.2.13)
11
+ activesupport (= 3.2.13)
12
12
  builder (~> 3.0.0)
13
- activesupport (3.2.12)
14
- i18n (~> 0.6)
13
+ activesupport (3.2.13)
14
+ i18n (= 0.6.1)
15
15
  multi_json (~> 1.0)
16
16
  builder (3.0.4)
17
17
  database_cleaner (0.9.1)
18
18
  diff-lcs (1.1.3)
19
19
  i18n (0.6.1)
20
- mongoid (3.0.9)
21
- activemodel (~> 3.1)
22
- moped (~> 1.1)
20
+ mongoid (3.1.2)
21
+ activemodel (~> 3.2)
22
+ moped (~> 1.4.2)
23
23
  origin (~> 1.0)
24
24
  tzinfo (~> 0.3.22)
25
- moped (1.4.2)
26
- multi_json (1.6.1)
27
- origin (1.0.11)
25
+ moped (1.4.5)
26
+ multi_json (1.7.7)
27
+ origin (1.1.0)
28
28
  rspec (2.11.0)
29
29
  rspec-core (~> 2.11.0)
30
30
  rspec-expectations (~> 2.11.0)
@@ -33,7 +33,7 @@ GEM
33
33
  rspec-expectations (2.11.3)
34
34
  diff-lcs (~> 1.1.3)
35
35
  rspec-mocks (2.11.3)
36
- tzinfo (0.3.35)
36
+ tzinfo (0.3.37)
37
37
 
38
38
  PLATFORMS
39
39
  ruby
data/README.md CHANGED
@@ -85,9 +85,9 @@ 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"],
88
+ :name => ["can't be blank"],
89
+ :summary => ["can't be blank"],
90
+ :"pages[0].title" => ["can't be blank"],
91
91
  :"pages[0].sections[0].header" => ["can't be blank"]
92
92
  }
93
93
  ```
@@ -105,4 +105,5 @@ Now, isn't that much nicer? Yeah, I think so to.
105
105
  ## Contributers
106
106
 
107
107
  * Mark Bates
108
+ * Evgeniy Denisov
108
109
  * Nick Plante
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module EmbeddedErrors
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -21,11 +21,11 @@ module Mongoid
21
21
  # first delete the unless 'is invalid' error for the relation
22
22
  errs.delete(name.to_sym)
23
23
  # next, loop through each of the relations (pages, sections, etc...)
24
- self.send(name).each_with_index do |rel, i|
24
+ [self.send(name)].flatten.reject(&:nil?).each_with_index do |rel, i|
25
25
  # get each of their individual message and add them to the parent's errors:
26
26
  if rel.errors.any?
27
27
  rel.errors.messages.each do |k, v|
28
- key = "#{name}[#{i}].#{k}".to_sym
28
+ key = (rel.metadata.relation == Mongoid::Relations::Embedded::Many ? "#{name}[#{i}].#{k}" : "#{name}.#{k}").to_sym
29
29
  errs.delete(key)
30
30
  errs[key] = v
31
31
  errs[key].flatten!
@@ -6,6 +6,7 @@ describe Mongoid::EmbeddedErrors do
6
6
  let(:invalid_page) { Page.new }
7
7
  let(:invalid_section) { Section.new }
8
8
  let(:valid_section) { Section.new(header: "My Header") }
9
+ let(:invalid_annotation){ Annotation.new }
9
10
 
10
11
  describe "errors" do
11
12
 
@@ -13,12 +14,14 @@ describe Mongoid::EmbeddedErrors do
13
14
  invalid_page.sections << valid_section
14
15
  invalid_page.sections << invalid_section
15
16
  article.pages << invalid_page
17
+ article.annotation = invalid_annotation
16
18
  article.should_not be_valid
17
19
  article.errors.messages.should eql({
18
20
  name: ["can't be blank"],
19
21
  summary: ["can't be blank"],
20
22
  :"pages[0].title" => ["can't be blank"],
21
- :"pages[0].sections[1].header" => ["can't be blank"]
23
+ :"pages[0].sections[1].header" => ["can't be blank"],
24
+ :"annotation.text" => ["can't be blank"]
22
25
  })
23
26
  end
24
27
 
@@ -10,6 +10,7 @@ class Article
10
10
  validates :summary, presence: true
11
11
 
12
12
  embeds_many :pages
13
+ embeds_one :annotation
13
14
  end
14
15
 
15
16
  class Page
@@ -34,4 +35,15 @@ class Section
34
35
  validates :header, presence: true
35
36
 
36
37
  embedded_in :page, inverse_of: :sections
38
+ end
39
+
40
+ class Annotation
41
+ include Mongoid::Document
42
+
43
+ embedded_in :article, inverse_of: :annotation
44
+
45
+ field :text, type: String
46
+
47
+ validates :text, presence: true
48
+
37
49
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-embedded-errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Bates
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
11
+ date: 2013-07-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mongoid
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  description: Easily bubble up errors from embedded documents in Mongoid.
@@ -50,30 +47,30 @@ files:
50
47
  - spec/support/models.rb
51
48
  homepage: ''
52
49
  licenses: []
50
+ metadata: {}
53
51
  post_install_message:
54
52
  rdoc_options: []
55
53
  require_paths:
56
54
  - lib
57
55
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
56
  requirements:
60
- - - ! '>='
57
+ - - '>='
61
58
  - !ruby/object:Gem::Version
62
59
  version: '0'
63
60
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
61
  requirements:
66
- - - ! '>='
62
+ - - '>='
67
63
  - !ruby/object:Gem::Version
68
64
  version: '0'
69
65
  requirements: []
70
66
  rubyforge_project:
71
- rubygems_version: 1.8.25
67
+ rubygems_version: 2.0.3
72
68
  signing_key:
73
- specification_version: 3
69
+ specification_version: 4
74
70
  summary: Easily bubble up errors from embedded documents in Mongoid.
75
71
  test_files:
76
72
  - spec/config.yml
77
73
  - spec/embedded_errors_spec.rb
78
74
  - spec/spec_helper.rb
79
75
  - spec/support/models.rb
76
+ has_rdoc: