mongoid 0.9.4 → 0.9.5

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.
Files changed (55) hide show
  1. data/Rakefile +2 -4
  2. data/VERSION +1 -1
  3. data/lib/mongoid.rb +3 -2
  4. data/lib/mongoid/associations.rb +1 -0
  5. data/lib/mongoid/associations/accessor.rb +1 -0
  6. data/lib/mongoid/associations/belongs_to.rb +1 -0
  7. data/lib/mongoid/associations/decorator.rb +1 -0
  8. data/lib/mongoid/associations/has_many.rb +1 -0
  9. data/lib/mongoid/associations/has_one.rb +1 -0
  10. data/lib/mongoid/associations/options.rb +1 -0
  11. data/lib/mongoid/associations/relates_to_many.rb +1 -0
  12. data/lib/mongoid/associations/relates_to_one.rb +1 -0
  13. data/lib/mongoid/attributes.rb +1 -0
  14. data/lib/mongoid/commands.rb +1 -0
  15. data/lib/mongoid/commands/create.rb +1 -0
  16. data/lib/mongoid/commands/delete.rb +1 -0
  17. data/lib/mongoid/commands/delete_all.rb +1 -0
  18. data/lib/mongoid/commands/destroy.rb +1 -0
  19. data/lib/mongoid/commands/destroy_all.rb +1 -0
  20. data/lib/mongoid/commands/save.rb +1 -0
  21. data/lib/mongoid/commands/validate.rb +1 -0
  22. data/lib/mongoid/criteria.rb +28 -2
  23. data/lib/mongoid/document.rb +14 -7
  24. data/lib/mongoid/dynamic_finder.rb +1 -0
  25. data/lib/mongoid/extensions.rb +3 -0
  26. data/lib/mongoid/extensions/array/accessors.rb +15 -0
  27. data/lib/mongoid/extensions/array/assimilation.rb +1 -0
  28. data/lib/mongoid/extensions/array/conversions.rb +1 -0
  29. data/lib/mongoid/extensions/array/parentization.rb +1 -0
  30. data/lib/mongoid/extensions/boolean/conversions.rb +1 -0
  31. data/lib/mongoid/extensions/date/conversions.rb +1 -0
  32. data/lib/mongoid/extensions/datetime/conversions.rb +1 -0
  33. data/lib/mongoid/extensions/float/conversions.rb +1 -0
  34. data/lib/mongoid/extensions/hash/accessors.rb +2 -1
  35. data/lib/mongoid/extensions/hash/assimilation.rb +1 -0
  36. data/lib/mongoid/extensions/hash/conversions.rb +1 -0
  37. data/lib/mongoid/extensions/integer/conversions.rb +1 -0
  38. data/lib/mongoid/extensions/object/conversions.rb +1 -0
  39. data/lib/mongoid/extensions/string/conversions.rb +1 -0
  40. data/lib/mongoid/extensions/string/inflections.rb +1 -0
  41. data/lib/mongoid/extensions/symbol/inflections.rb +1 -0
  42. data/lib/mongoid/extensions/time/conversions.rb +1 -0
  43. data/lib/mongoid/field.rb +1 -0
  44. data/lib/mongoid/finders.rb +1 -0
  45. data/lib/mongoid/timestamps.rb +7 -6
  46. data/lib/mongoid/versioning.rb +1 -0
  47. data/mongoid.gemspec +11 -8
  48. data/spec/integration/mongoid/document_spec.rb +36 -1
  49. data/spec/spec.opts +2 -4
  50. data/spec/spec_helper.rb +6 -0
  51. data/spec/unit/mongoid/criteria_spec.rb +42 -3
  52. data/spec/unit/mongoid/document_spec.rb +17 -22
  53. data/spec/unit/mongoid/extensions/array/accessors_spec.rb +50 -0
  54. data/spec/unit/mongoid/timestamps_spec.rb +3 -3
  55. metadata +7 -4
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "rubygems"
2
2
  require "rake"
3
3
  require "rake/rdoctask"
4
4
  require "spec/rake/spectask"
5
- require "metric_fu"
6
5
 
7
6
  begin
8
7
  require "jeweler"
@@ -16,8 +15,8 @@ begin
16
15
  gem.add_dependency("durran-validatable", "1.8.3")
17
16
  gem.add_dependency("leshill-will_paginate", "2.3.11")
18
17
  gem.add_dependency("activesupport", "2.3.4")
19
- gem.add_dependency("mongo", "0.17.1")
20
- gem.add_dependency("mongo_ext", "0.17.1")
18
+ gem.add_dependency("mongo", "0.18.1")
19
+ gem.add_dependency("mongo_ext", "0.18.1")
21
20
 
22
21
  gem.add_development_dependency("rspec", "1.2.9")
23
22
  gem.add_development_dependency("mocha", "0.9.8")
@@ -53,4 +52,3 @@ Rake::RDocTask.new do |rdoc|
53
52
  end
54
53
 
55
54
  task :default => ["spec"]
56
- task :metrics => ["rcov", "metrics:all"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # Copyright (c) 2009 Durran Jordan
2
3
  #
3
4
  # Permission is hereby granted, free of charge, to any person obtaining
@@ -21,8 +22,8 @@
21
22
  require "rubygems"
22
23
 
23
24
  gem "activesupport", "2.3.4"
24
- gem "mongo", "0.17.1"
25
- gem "mongo_ext", "0.17.1"
25
+ gem "mongo", "0.18.1"
26
+ gem "mongo_ext", "0.18.1"
26
27
  gem "durran-validatable", "1.8.3"
27
28
  gem "leshill-will_paginate", "2.3.11"
28
29
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "mongoid/associations/decorator"
2
3
  require "mongoid/associations/accessor"
3
4
  require "mongoid/associations/belongs_to"
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class Accessor #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class BelongsTo #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  module Decorator #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class HasMany < DelegateClass(Array) #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class HasOne #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class Options #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class RelatesToMany < DelegateClass(Array) #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Associations #:nodoc:
3
4
  class RelatesToOne #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Attributes #:nodoc:
3
4
  # Process the provided attributes casting them to their proper values if a
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "mongoid/commands/create"
2
3
  require "mongoid/commands/delete"
3
4
  require "mongoid/commands/delete_all"
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class Create
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class Delete
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class DeleteAll
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class Destroy
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class DestroyAll
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class Save
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Commands
3
4
  class Validate
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  # The +Criteria+ class is the core object needed in Mongoid to retrieve
3
4
  # objects from the database. It is a DSL that essentially sets up the
@@ -73,6 +74,25 @@ module Mongoid #:nodoc:
73
74
  selections.each { |key, value| @selector[key] = { "$all" => value } }; self
74
75
  end
75
76
 
77
+ # Adds a criterion to the +Criteria+ that specifies values that must
78
+ # be matched in order to return results. This is similar to a SQL "WHERE"
79
+ # clause. This is the actual selector that will be provided to MongoDB,
80
+ # similar to the Javascript object that is used when performing a find()
81
+ # in the MongoDB console.
82
+ #
83
+ # Options:
84
+ #
85
+ # selectior: A +Hash+ that must match the attributes of the +Document+.
86
+ #
87
+ # Example:
88
+ #
89
+ # <tt>criteria.and(:field1 => "value1", :field2 => 15)</tt>
90
+ #
91
+ # Returns: <tt>self</tt>
92
+ def and(selector = nil)
93
+ where(selector)
94
+ end
95
+
76
96
  # Get the count of matching documents in the database for the +Criteria+.
77
97
  #
78
98
  # Example:
@@ -447,8 +467,14 @@ module Mongoid #:nodoc:
447
467
  # <tt>criteria.where(:field1 => "value1", :field2 => 15)</tt>
448
468
  #
449
469
  # Returns: <tt>self</tt>
450
- def where(selector = {})
451
- @selector = selector; self
470
+ def where(selector = nil)
471
+ case selector
472
+ when String
473
+ @selector.update("$where" => selector)
474
+ else
475
+ @selector.update(selector || {})
476
+ end
477
+ self
452
478
  end
453
479
 
454
480
  protected
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  class Document
3
4
  include ActiveSupport::Callbacks
@@ -57,10 +58,9 @@ module Mongoid #:nodoc:
57
58
  def field(name, options = {})
58
59
  @fields ||= {}.with_indifferent_access
59
60
  @defaults ||= {}.with_indifferent_access
60
- @fields[name.to_s] = Field.new(name.to_s, options)
61
- @defaults[name.to_s] = options[:default] if options[:default]
62
- define_method(name) { read_attribute(name) }
63
- define_method("#{name}=") { |value| write_attribute(name, value) }
61
+ @fields[name] = Field.new(name.to_s, options)
62
+ @defaults[name] = options[:default] if options[:default]
63
+ define_field_methods(name, options)
64
64
  end
65
65
 
66
66
  # Returns all the fields for the Document as a +Hash+ with names as keys.
@@ -80,9 +80,9 @@ module Mongoid #:nodoc:
80
80
  end
81
81
 
82
82
  # Instantiate a new object, only when loaded from the database.
83
- def instantiate(attrs = {})
83
+ def instantiate(attrs = {}, allocating = false)
84
84
  attributes = attrs.with_indifferent_access
85
- if attributes[:_id]
85
+ if attributes[:_id] || allocating
86
86
  document = allocate
87
87
  document.instance_variable_set(:@attributes, attributes)
88
88
  return document
@@ -106,6 +106,13 @@ module Mongoid #:nodoc:
106
106
  @primary_key
107
107
  end
108
108
 
109
+ protected
110
+ def define_field_methods(name, options)
111
+ define_method(name) { read_attribute(name) }
112
+ define_method("#{name}=") { |value| write_attribute(name, value) }
113
+ define_method("#{name}?") { read_attribute(name) == true } if options[:type] == Boolean
114
+ end
115
+
109
116
  end
110
117
 
111
118
  # Performs equality checking on the attributes. For now we chack against
@@ -139,7 +146,7 @@ module Mongoid #:nodoc:
139
146
  # Clone the current +Document+. This will return all attributes with the
140
147
  # exception of the document's id and versions.
141
148
  def clone
142
- self.class.new(@attributes.except(:_id).except(:versions).dup)
149
+ self.class.instantiate(@attributes.except(:_id).except(:versions).dup, true)
143
150
  end
144
151
 
145
152
  # Get the Mongo::Collection associated with this Document.
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  class DynamicFinder
3
4
  # Regex for standard dynamic finder methods.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+ require "mongoid/extensions/array/accessors"
1
3
  require "mongoid/extensions/array/assimilation"
2
4
  require "mongoid/extensions/array/conversions"
3
5
  require "mongoid/extensions/array/parentization"
@@ -16,6 +18,7 @@ require "mongoid/extensions/symbol/inflections"
16
18
  require "mongoid/extensions/time/conversions"
17
19
 
18
20
  class Array #:nodoc:
21
+ include Mongoid::Extensions::Array::Accessors
19
22
  include Mongoid::Extensions::Array::Assimilation
20
23
  include Mongoid::Extensions::Array::Conversions
21
24
  include Mongoid::Extensions::Array::Parentization
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Extensions #:nodoc:
4
+ module Array #:nodoc:
5
+ module Accessors #:nodoc:
6
+ # If the attributes already exists in the array then they will be
7
+ # updated, otherwise they will be appended.
8
+ def update(attributes)
9
+ delete_if { |e| attributes[:_id] && (e[:_id] == attributes[:_id]) }
10
+ self.<< attributes
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Array #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Array #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Array #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Boolean #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Date #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module DateTime #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Float #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Hash #:nodoc:
@@ -8,7 +9,7 @@ module Mongoid #:nodoc:
8
9
  self[key] = self[key].merge(attrs) if self[key]
9
10
  else
10
11
  if elements = self[key]
11
- elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
12
+ elements.update(attrs)
12
13
  else
13
14
  self[key] = [attrs]
14
15
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Hash #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Hash #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Integer #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Object #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module String #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module String #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Symbol #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Time #:nodoc:
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  class Field
3
4
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Finders #:nodoc:
3
4
  # Find +Documents+ given the conditions.
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid
2
3
  module Timestamps
3
4
 
@@ -5,8 +6,8 @@ module Mongoid
5
6
  base.class_eval do
6
7
  include InstanceMethods
7
8
  field :created_at, :type => Time
8
- field :modified_at, :type => Time
9
- before_save :update_created_at, :update_modified_at
9
+ field :updated_at, :type => Time
10
+ before_save :set_created_at, :set_updated_at
10
11
  end
11
12
  end
12
13
 
@@ -14,14 +15,14 @@ module Mongoid
14
15
 
15
16
  # Update the created_at field on the Document to the current time. This is
16
17
  # only called on create.
17
- def update_created_at
18
+ def set_created_at
18
19
  self.created_at = Time.now.utc if !created_at
19
20
  end
20
21
 
21
- # Update the last_modified field on the Document to the current time.
22
+ # Update the updated_at field on the Document to the current time.
22
23
  # This is only called on create and on save.
23
- def update_modified_at
24
- self.modified_at = Time.now.utc
24
+ def set_updated_at
25
+ self.updated_at = Time.now.utc
25
26
  end
26
27
  end
27
28
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  # Include this module to get automatic versioning of root level documents.
3
4
  # This will add a version field to the +Document+ and a has_many association
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.9.4"
8
+ s.version = "0.9.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
12
- s.date = %q{2009-12-01}
12
+ s.date = %q{2009-12-08}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "lib/mongoid/document.rb",
45
45
  "lib/mongoid/dynamic_finder.rb",
46
46
  "lib/mongoid/extensions.rb",
47
+ "lib/mongoid/extensions/array/accessors.rb",
47
48
  "lib/mongoid/extensions/array/assimilation.rb",
48
49
  "lib/mongoid/extensions/array/conversions.rb",
49
50
  "lib/mongoid/extensions/array/parentization.rb",
@@ -91,6 +92,7 @@ Gem::Specification.new do |s|
91
92
  "spec/unit/mongoid/criteria_spec.rb",
92
93
  "spec/unit/mongoid/document_spec.rb",
93
94
  "spec/unit/mongoid/dynamic_finder_spec.rb",
95
+ "spec/unit/mongoid/extensions/array/accessors_spec.rb",
94
96
  "spec/unit/mongoid/extensions/array/assimilation_spec.rb",
95
97
  "spec/unit/mongoid/extensions/array/conversions_spec.rb",
96
98
  "spec/unit/mongoid/extensions/array/parentization_spec.rb",
@@ -141,6 +143,7 @@ Gem::Specification.new do |s|
141
143
  "spec/unit/mongoid/criteria_spec.rb",
142
144
  "spec/unit/mongoid/document_spec.rb",
143
145
  "spec/unit/mongoid/dynamic_finder_spec.rb",
146
+ "spec/unit/mongoid/extensions/array/accessors_spec.rb",
144
147
  "spec/unit/mongoid/extensions/array/assimilation_spec.rb",
145
148
  "spec/unit/mongoid/extensions/array/conversions_spec.rb",
146
149
  "spec/unit/mongoid/extensions/array/parentization_spec.rb",
@@ -171,16 +174,16 @@ Gem::Specification.new do |s|
171
174
  s.add_runtime_dependency(%q<durran-validatable>, ["= 1.8.3"])
172
175
  s.add_runtime_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
173
176
  s.add_runtime_dependency(%q<activesupport>, ["= 2.3.4"])
174
- s.add_runtime_dependency(%q<mongo>, ["= 0.17.1"])
175
- s.add_runtime_dependency(%q<mongo_ext>, ["= 0.17.1"])
177
+ s.add_runtime_dependency(%q<mongo>, ["= 0.18.1"])
178
+ s.add_runtime_dependency(%q<mongo_ext>, ["= 0.18.1"])
176
179
  s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
177
180
  s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
178
181
  else
179
182
  s.add_dependency(%q<durran-validatable>, ["= 1.8.3"])
180
183
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
181
184
  s.add_dependency(%q<activesupport>, ["= 2.3.4"])
182
- s.add_dependency(%q<mongo>, ["= 0.17.1"])
183
- s.add_dependency(%q<mongo_ext>, ["= 0.17.1"])
185
+ s.add_dependency(%q<mongo>, ["= 0.18.1"])
186
+ s.add_dependency(%q<mongo_ext>, ["= 0.18.1"])
184
187
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
185
188
  s.add_dependency(%q<mocha>, ["= 0.9.8"])
186
189
  end
@@ -188,8 +191,8 @@ Gem::Specification.new do |s|
188
191
  s.add_dependency(%q<durran-validatable>, ["= 1.8.3"])
189
192
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
190
193
  s.add_dependency(%q<activesupport>, ["= 2.3.4"])
191
- s.add_dependency(%q<mongo>, ["= 0.17.1"])
192
- s.add_dependency(%q<mongo_ext>, ["= 0.17.1"])
194
+ s.add_dependency(%q<mongo>, ["= 0.18.1"])
195
+ s.add_dependency(%q<mongo_ext>, ["= 0.18.1"])
193
196
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
194
197
  s.add_dependency(%q<mocha>, ["= 0.9.8"])
195
198
  end
@@ -376,6 +376,10 @@ describe Mongoid::Document do
376
376
  @comment.save
377
377
  end
378
378
 
379
+ after do
380
+ Comment.collection.drop
381
+ end
382
+
379
383
  context "first save" do
380
384
 
381
385
  it "creates a new version" do
@@ -392,7 +396,6 @@ describe Mongoid::Document do
392
396
 
393
397
  before do
394
398
  5.times do |n|
395
- @comment.text = "#{n}"
396
399
  @comment.save
397
400
  end
398
401
  end
@@ -407,4 +410,36 @@ describe Mongoid::Document do
407
410
 
408
411
  end
409
412
 
413
+ context "executing criteria with date comparisons" do
414
+
415
+ context "handling specific dates" do
416
+
417
+ before do
418
+ @person = Person.create(:dob => Date.new(2000, 10, 31))
419
+ end
420
+
421
+ it "handles comparisons with todays date"do
422
+ people = Person.select.where("this.dob < new Date()")
423
+ people.first.should == @person
424
+ end
425
+
426
+ it "handles conparisons with a date range" do
427
+ people = Person.select.where("new Date(1976, 10, 31) < this.dob && this.dob < new Date()")
428
+ people.first.should == @person
429
+ end
430
+
431
+ it "handles false comparisons in a date range" do
432
+ people = Person.select.where("new Date(2005, 10, 31) < this.dob && this.dob < new Date()")
433
+ people.should be_empty
434
+ end
435
+
436
+ it "handles comparisons with date objects"do
437
+ people = Person.select.where(:dob => { "$lt" => Date.today.midnight })
438
+ people.first.should == @person
439
+ end
440
+
441
+ end
442
+
443
+ end
444
+
410
445
  end
@@ -1,5 +1,3 @@
1
1
  --colour
2
- -fs
3
- --loadby
4
- mtime
5
- --reverse
2
+ --format nested
3
+ --drb
@@ -36,6 +36,11 @@ class Person < Mongoid::Document
36
36
  has_one :name
37
37
  has_one :pet, :class_name => "Animal"
38
38
 
39
+ index :title
40
+ index :dob
41
+ index :addresses
42
+ index :name
43
+
39
44
  relates_to_one :game
40
45
  relates_to_many :posts
41
46
 
@@ -124,6 +129,7 @@ end
124
129
  class Comment < Mongoid::Document
125
130
  include Mongoid::Versioning
126
131
  field :text
132
+ key :text
127
133
  end
128
134
 
129
135
  class Decorated
@@ -54,6 +54,32 @@ describe Mongoid::Criteria do
54
54
 
55
55
  end
56
56
 
57
+ describe "#and" do
58
+
59
+ context "when provided a hash" do
60
+
61
+ it "adds the clause to the selector" do
62
+ @criteria.and(:title => "Title", :text => "Text")
63
+ @criteria.selector.should == { :title => "Title", :text => "Text" }
64
+ end
65
+
66
+ end
67
+
68
+ context "when provided a string" do
69
+
70
+ it "adds the $where clause to the selector" do
71
+ @criteria.and("this.date < new Date()")
72
+ @criteria.selector.should == { "$where" => "this.date < new Date()" }
73
+ end
74
+
75
+ end
76
+
77
+ it "returns self" do
78
+ @criteria.and.should == @criteria
79
+ end
80
+
81
+ end
82
+
57
83
  describe "#collect" do
58
84
 
59
85
  context "filtering" do
@@ -821,9 +847,22 @@ describe Mongoid::Criteria do
821
847
 
822
848
  describe "#where" do
823
849
 
824
- it "adds the clause to the selector" do
825
- @criteria.where(:title => "Title", :text => "Text")
826
- @criteria.selector.should == { :title => "Title", :text => "Text" }
850
+ context "when provided a hash" do
851
+
852
+ it "adds the clause to the selector" do
853
+ @criteria.where(:title => "Title", :text => "Text")
854
+ @criteria.selector.should == { :title => "Title", :text => "Text" }
855
+ end
856
+
857
+ end
858
+
859
+ context "when provided a string" do
860
+
861
+ it "adds the $where clause to the selector" do
862
+ @criteria.where("this.date < new Date()")
863
+ @criteria.selector.should == { "$where" => "this.date < new Date()" }
864
+ end
865
+
827
866
  end
828
867
 
829
868
  it "returns self" do
@@ -207,6 +207,18 @@ describe Mongoid::Document do
207
207
 
208
208
  end
209
209
 
210
+ context "when type is a boolean" do
211
+
212
+ before do
213
+ @person = Person.new(:terms => true)
214
+ end
215
+
216
+ it "adds an accessor method with a question mark" do
217
+ @person.terms?.should be_true
218
+ end
219
+
220
+ end
221
+
210
222
  end
211
223
 
212
224
  describe ".human_name" do
@@ -253,30 +265,13 @@ describe Mongoid::Document do
253
265
 
254
266
  describe ".instantiate" do
255
267
 
256
- context "when document is new" do
257
-
258
- before do
259
- @attributes = { :_id => "1", :title => "Sir", :age => 30 }
260
- @person = Person.new(@attributes)
261
- end
262
-
263
- it "sets the attributes directly" do
264
- Person.instantiate(@attributes).should == @person
265
- end
266
-
268
+ before do
269
+ @attributes = { :_id => "1", :title => "Sir", :age => 30 }
270
+ @person = Person.new(@attributes)
267
271
  end
268
272
 
269
- context "when document is not new" do
270
-
271
- before do
272
- @attributes = { :title => "Sir", :age => 30 }
273
- @person = Person.new(@attributes)
274
- end
275
-
276
- it "instantiates normally" do
277
- Person.instantiate(@attributes).id.should_not be_nil
278
- end
279
-
273
+ it "sets the attributes directly" do
274
+ Person.instantiate(@attributes).should == @person
280
275
  end
281
276
 
282
277
  end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Extensions::Array::Accessors do
4
+
5
+ describe "#update" do
6
+
7
+ context "when the attributes exist" do
8
+
9
+ before do
10
+ @array = [{ :_id => 1, :name => "James T. Kirk" }]
11
+ end
12
+
13
+ it "overwrites with the new attributes" do
14
+ @array.update({ :_id => 1, :name => "Spock" })
15
+ @array.first[:name].should == "Spock"
16
+ end
17
+
18
+ end
19
+
20
+ context "when the attributes do not exist" do
21
+
22
+ before do
23
+ @array = [{ :_id => 1, :name => "James T. Kirk" }]
24
+ end
25
+
26
+ it "appends the new attributes" do
27
+ @array.update({ :_id => 2, :name => "Scotty" })
28
+ @array.size.should == 2
29
+ @array.last[:name].should == "Scotty"
30
+ end
31
+
32
+ end
33
+
34
+ context "when the new attribtues have no id" do
35
+
36
+ before do
37
+ @array = [{ :_id => 1, :name => "James T. Kirk" }]
38
+ end
39
+
40
+ it "appends the new attributes" do
41
+ @array.update({:name => "Scotty" })
42
+ @array.size.should == 2
43
+ @array.last[:name].should == "Scotty"
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -8,16 +8,16 @@ describe Mongoid::Timestamps do
8
8
  @person = Person.new
9
9
  end
10
10
 
11
- it "adds created_at and modified_at to the document" do
11
+ it "adds created_at and updated_at to the document" do
12
12
  fields = Person.instance_variable_get(:@fields)
13
13
  fields[:created_at].should_not be_nil
14
- fields[:modified_at].should_not be_nil
14
+ fields[:updated_at].should_not be_nil
15
15
  end
16
16
 
17
17
  it "forces the timestamps to UTC" do
18
18
  @person.run_callbacks(:before_save)
19
19
  @person.created_at.should be_close(Time.now.utc, 10.seconds)
20
- @person.modified_at.should be_close(Time.now.utc, 10.seconds)
20
+ @person.updated_at.should be_close(Time.now.utc, 10.seconds)
21
21
  end
22
22
 
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-01 00:00:00 -05:00
12
+ date: 2009-12-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - "="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.17.1
53
+ version: 0.18.1
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mongo_ext
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - "="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.17.1
63
+ version: 0.18.1
64
64
  version:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: rspec
@@ -120,6 +120,7 @@ files:
120
120
  - lib/mongoid/document.rb
121
121
  - lib/mongoid/dynamic_finder.rb
122
122
  - lib/mongoid/extensions.rb
123
+ - lib/mongoid/extensions/array/accessors.rb
123
124
  - lib/mongoid/extensions/array/assimilation.rb
124
125
  - lib/mongoid/extensions/array/conversions.rb
125
126
  - lib/mongoid/extensions/array/parentization.rb
@@ -167,6 +168,7 @@ files:
167
168
  - spec/unit/mongoid/criteria_spec.rb
168
169
  - spec/unit/mongoid/document_spec.rb
169
170
  - spec/unit/mongoid/dynamic_finder_spec.rb
171
+ - spec/unit/mongoid/extensions/array/accessors_spec.rb
170
172
  - spec/unit/mongoid/extensions/array/assimilation_spec.rb
171
173
  - spec/unit/mongoid/extensions/array/conversions_spec.rb
172
174
  - spec/unit/mongoid/extensions/array/parentization_spec.rb
@@ -239,6 +241,7 @@ test_files:
239
241
  - spec/unit/mongoid/criteria_spec.rb
240
242
  - spec/unit/mongoid/document_spec.rb
241
243
  - spec/unit/mongoid/dynamic_finder_spec.rb
244
+ - spec/unit/mongoid/extensions/array/accessors_spec.rb
242
245
  - spec/unit/mongoid/extensions/array/assimilation_spec.rb
243
246
  - spec/unit/mongoid/extensions/array/conversions_spec.rb
244
247
  - spec/unit/mongoid/extensions/array/parentization_spec.rb