mongoid-embedded-errors 2.0.1 → 2.1.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 +4 -4
- data/.codeclimate.yml +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +77 -0
- data/Appraisals +15 -0
- data/Gemfile +7 -3
- data/Gemfile.lock +152 -28
- data/Guardfile +42 -0
- data/README.md +4 -5
- data/Rakefile +9 -7
- data/bin/_guard-core +17 -0
- data/bin/appraisal +17 -0
- data/bin/guard +17 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/gemfiles/mongoid_3.gemfile +11 -0
- data/gemfiles/mongoid_3.gemfile.lock +98 -0
- data/gemfiles/mongoid_4.gemfile +11 -0
- data/gemfiles/mongoid_4.gemfile.lock +110 -0
- data/gemfiles/mongoid_5.gemfile +11 -0
- data/gemfiles/mongoid_5.gemfile.lock +106 -0
- data/gemfiles/mongoid_6.gemfile +11 -0
- data/gemfiles/mongoid_6.gemfile.lock +100 -0
- data/lib/mongoid-embedded-errors.rb +2 -41
- data/lib/mongoid/embedded_errors.rb +36 -0
- data/lib/mongoid/embedded_errors/embedded_in.rb +10 -0
- data/lib/mongoid/embedded_errors/version.rb +4 -0
- data/mongoid-embedded-errors.gemspec +13 -11
- data/spec/lib/mongoid/embedded_errors_spec.rb +38 -0
- data/spec/spec_helper.rb +34 -9
- data/spec/support/models/annotation.rb +9 -0
- data/spec/support/models/article.rb +15 -0
- data/spec/support/models/page.rb +11 -0
- data/spec/support/models/section.rb +11 -0
- data/spec/support/mongoid.yml +13 -0
- metadata +51 -20
- data/lib/mongoid-embedded-errors/embedded_in.rb +0 -16
- data/lib/mongoid-embedded-errors/version.rb +0 -5
- data/spec/config.yml +0 -6
- data/spec/embedded_errors_spec.rb +0 -41
- data/spec/support/models.rb +0 -49
@@ -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
|
data/spec/support/models.rb
DELETED
@@ -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
|