mongoid-embedded-errors 2.0.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::EmbeddedErrors do
4
-
5
- let(:article) { Article.new }
6
- let(:invalid_page) { Page.new }
7
- let(:invalid_section) { Section.new }
8
- let(:valid_section) { Section.new(header: "My Header") }
9
- let(:invalid_annotation){ Annotation.new }
10
-
11
- describe "errors" do
12
-
13
- it "bubbles up errors from embedded documents" do
14
- invalid_page.sections << valid_section
15
- invalid_page.sections << invalid_section
16
- article.pages << invalid_page
17
- article.annotation = invalid_annotation
18
- article.should_not be_valid
19
- article.errors.messages.should eql({
20
- name: ["can't be blank"],
21
- summary: ["can't be blank"],
22
- :"pages[0].title" => ["can't be blank"],
23
- :"pages[0].sections[1].header" => ["can't be blank"],
24
- :"annotation.text" => ["can't be blank"]
25
- })
26
- end
27
-
28
- it "save works as before" do
29
- article.save.should be_false
30
- article.should_not be_persisted
31
- article.errors.messages.should eql(name: ["can't be blank"], summary: ["can't be blank"])
32
- end
33
-
34
- it "handles errors on the main object" do
35
- article.should_not be_valid
36
- article.errors.messages.should eql(name: ["can't be blank"], summary: ["can't be blank"])
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,49 +0,0 @@
1
- class Article
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
- include Mongoid::EmbeddedErrors
5
-
6
- field :name, type: String
7
- field :summary, type: String
8
-
9
- validates :name, presence: true
10
- validates :summary, presence: true
11
-
12
- embeds_many :pages
13
- embeds_one :annotation
14
- end
15
-
16
- class Page
17
- include Mongoid::Document
18
- include Mongoid::Timestamps
19
-
20
- field :title, type: String
21
-
22
- validates :title, presence: true
23
-
24
- embedded_in :article, inverse_of: :pages
25
- embeds_many :sections
26
- end
27
-
28
- class Section
29
- include Mongoid::Document
30
- include Mongoid::Timestamps
31
-
32
- field :header, type: String
33
- field :body, type: String
34
-
35
- validates :header, presence: true
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
-
49
- end