mongoid 2.0.0.rc.1 → 2.0.0.rc.2

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.
@@ -11,7 +11,7 @@ module Mongoid #:nodoc
11
11
  # <tt>DocumentNotFound.new(Person, ["1", "2"])</tt>
12
12
  class DocumentNotFound < MongoidError
13
13
 
14
- attr_reader :klass, :indentifiers
14
+ attr_reader :klass, :identifiers
15
15
 
16
16
  def initialize(klass, ids)
17
17
  @klass = klass
@@ -2,7 +2,7 @@
2
2
  module Mongoid #:nodoc
3
3
  module Errors #:nodoc
4
4
 
5
- # Raised when a persisence method ending in ! fails validation. The message
5
+ # Raised when a persistence method ending in ! fails validation. The message
6
6
  # will contain the full error messages from the +Document+ in question.
7
7
  #
8
8
  # Example:
@@ -4,6 +4,7 @@ module Mongoid #:nodoc:
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module ClassMethods
7
+ REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |_, value| value.blank? } }
7
8
 
8
9
  # Used when needing to update related models from a parent relation. Can
9
10
  # be used on embedded or referenced relations.
@@ -29,6 +30,7 @@ module Mongoid #:nodoc:
29
30
  # @option *args [ true, false ] :update_only Only update existing docs.
30
31
  def accepts_nested_attributes_for(*args)
31
32
  options = args.extract_options!
33
+ options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
32
34
  args.each do |name|
33
35
  define_method("#{name}_attributes=") do |attrs|
34
36
  relation = relations[name.to_s]
@@ -10,7 +10,7 @@ module Rails #:nodoc:
10
10
  module Mongoid #:nodoc:
11
11
  class Railtie < Rails::Railtie #:nodoc:
12
12
 
13
- config.generators.orm :mongoid, :migration => false
13
+ config.app_generators.orm :mongoid, :migration => false
14
14
 
15
15
  rake_tasks do
16
16
  load "mongoid/railties/database.rake"
@@ -81,6 +81,15 @@ module Rails #:nodoc:
81
81
  ::Rails::Mongoid.load_models(app) unless $rails_rake_task
82
82
  end
83
83
  end
84
+
85
+ initializer "load http errors" do |app|
86
+ config.after_initialize do
87
+ ActionDispatch::ShowExceptions.rescue_responses.update({
88
+ "Mongoid::Errors::DocumentNotFound" => :not_found,
89
+ "Mongoid::Errors::Validations" => 422
90
+ })
91
+ end
92
+ end
84
93
 
85
94
  initializer "reconnect to master if application is preloaded" do
86
95
  config.after_initialize do
@@ -12,6 +12,8 @@ module Mongoid #:nodoc:
12
12
  included do
13
13
  include ActiveModel::Validations
14
14
 
15
+ attr_accessor :validated
16
+
15
17
  # Overrides the default ActiveModel behaviour since we need to handle
16
18
  # validations of relations slightly different than just calling the
17
19
  # getter.
@@ -25,11 +27,25 @@ module Mongoid #:nodoc:
25
27
  # @param [ Symbol ] attr The name of the field or relation.
26
28
  #
27
29
  # @return [ Object ] The value of the field or the relation.
30
+ #
31
+ # @since 2.0.0.rc.1
28
32
  def read_attribute_for_validation(attr)
29
33
  relations[attr.to_s] ? send(attr, false, :continue => false) : send(attr)
30
34
  end
31
35
  end
32
36
 
37
+ # Used to prevent infinite loops in associated validations.
38
+ #
39
+ # @example Is the document validated?
40
+ # document.validated?
41
+ #
42
+ # @return [ true, false ] Has the document already been validated?
43
+ #
44
+ # @since 2.0.0.rc.2
45
+ def validated?
46
+ !!@validated
47
+ end
48
+
33
49
  module ClassMethods #:nodoc:
34
50
 
35
51
  # Validates whether or not an association is valid or not. Will correctly
@@ -27,8 +27,13 @@ module Mongoid #:nodoc:
27
27
  # @param [ Symbol ] attribute The relation to validate.
28
28
  # @param [ Object ] value The value of the relation.
29
29
  def validate_each(document, attribute, value)
30
- return if value.to_a.collect { |doc| doc.nil? || doc.valid? }.all?
31
- document.errors.add(attribute, :invalid, options.merge(:value => value))
30
+ unless document.validated?
31
+ document.validated = true
32
+ return if value.to_a.collect { |doc| doc.nil? || doc.valid? }.all?
33
+ document.errors.add(attribute, :invalid, options.merge(:value => value))
34
+ else
35
+ document.validated = false
36
+ end
32
37
  end
33
38
  end
34
39
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.0.0.rc.1"
3
+ VERSION = "2.0.0.rc.2"
4
4
  end
@@ -9,7 +9,7 @@ module Rails #:nodoc:
9
9
  def load_models(app)
10
10
  app.config.paths['app/models'].each do |path|
11
11
  Dir.glob("#{path}/**/*.rb").sort.each do |file|
12
- require_dependency(file)
12
+ require_dependency(File.basename(file, ".rb"))
13
13
  end
14
14
  end
15
15
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - rc
10
- - 1
11
- version: 2.0.0.rc.1
10
+ - 2
11
+ version: 2.0.0.rc.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Durran Jordan
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-09 00:00:00 +01:00
19
+ date: 2011-01-10 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -356,7 +356,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
356
356
  requirements:
357
357
  - - ">="
358
358
  - !ruby/object:Gem::Version
359
- hash: 1989103359598370074
359
+ hash: 3519923910425248457
360
360
  segments:
361
361
  - 0
362
362
  version: "0"