mongoid 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid.rb +13 -2
- data/lib/mongoid/deprecation.rb +22 -0
- data/lib/mongoid/extras.rb +2 -2
- data/lib/mongoid/fields.rb +10 -8
- data/mongoid.gemspec +5 -2
- data/spec/integration/mongoid/associations_spec.rb +6 -0
- data/spec/unit/mongoid/deprecation_spec.rb +24 -0
- data/spec/unit/mongoid/extras_spec.rb +0 -14
- data/spec/unit/mongoid/fields_spec.rb +17 -0
- data/spec/unit/mongoid_spec.rb +11 -2
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.10
|
data/lib/mongoid.rb
CHANGED
@@ -46,6 +46,7 @@ require "mongoid/config"
|
|
46
46
|
require "mongoid/contexts"
|
47
47
|
require "mongoid/criteria"
|
48
48
|
require "mongoid/cursor"
|
49
|
+
require "mongoid/deprecation"
|
49
50
|
require "mongoid/extensions"
|
50
51
|
require "mongoid/extras"
|
51
52
|
require "mongoid/errors"
|
@@ -88,10 +89,20 @@ module Mongoid #:nodoc
|
|
88
89
|
#
|
89
90
|
# The Mongoid +Config+ singleton instance.
|
90
91
|
def configure
|
91
|
-
config = Config.instance
|
92
|
+
config = Mongoid::Config.instance
|
92
93
|
block_given? ? yield(config) : config
|
93
94
|
end
|
94
95
|
|
96
|
+
# Easy convenience method for having an alert generated from the
|
97
|
+
# deprecation module.
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
#
|
101
|
+
# <tt>Mongoid.deprecate("Method no longer used")</tt>
|
102
|
+
def deprecate(message)
|
103
|
+
Mongoid::Deprecation.instance.alert(message)
|
104
|
+
end
|
105
|
+
|
95
106
|
alias :config :configure
|
96
107
|
end
|
97
108
|
|
@@ -101,7 +112,7 @@ module Mongoid #:nodoc
|
|
101
112
|
# Example:
|
102
113
|
#
|
103
114
|
# <tt>Mongoid.database = Mongo::Connection.new.db("test")</tt>
|
104
|
-
Config.public_instance_methods(false).each do |name|
|
115
|
+
Mongoid::Config.public_instance_methods(false).each do |name|
|
105
116
|
(class << self; self; end).class_eval <<-EOT
|
106
117
|
def #{name}(*args)
|
107
118
|
configure.send("#{name}", *args)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid #:nodoc:
|
3
|
+
class Deprecation #:nodoc
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
# Alert of a deprecation. This will delegate to the logger and call warn on
|
7
|
+
# it.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# <tt>deprecation.alert("Method no longer used")</tt>
|
12
|
+
def alert(message)
|
13
|
+
@logger.warn("Deprecation: #{message}")
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
# Instantiate a new logger to stdout or a rails logger if available.
|
18
|
+
def initialize
|
19
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new($stdout)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/mongoid/extras.rb
CHANGED
@@ -35,7 +35,7 @@ module Mongoid #:nodoc:
|
|
35
35
|
#
|
36
36
|
# True if cached, false if not.
|
37
37
|
def cached?
|
38
|
-
self.cached
|
38
|
+
!!self.cached
|
39
39
|
end
|
40
40
|
|
41
41
|
# Set whether or not this documents read operations should delegate to
|
@@ -57,7 +57,7 @@ module Mongoid #:nodoc:
|
|
57
57
|
#
|
58
58
|
# True if enslaved, false if not.
|
59
59
|
def enslaved?
|
60
|
-
self.enslaved
|
60
|
+
!!self.enslaved
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
data/lib/mongoid/fields.rb
CHANGED
@@ -6,9 +6,8 @@ module Mongoid #:nodoc
|
|
6
6
|
extend ClassMethods
|
7
7
|
# Set up the class attributes that must be available to all subclasses.
|
8
8
|
# These include defaults, fields
|
9
|
-
class_inheritable_accessor :
|
9
|
+
class_inheritable_accessor :fields
|
10
10
|
|
11
|
-
self.defaults = {}
|
12
11
|
self.fields = {}
|
13
12
|
|
14
13
|
delegate :defaults, :fields, :to => "self.class"
|
@@ -31,7 +30,15 @@ module Mongoid #:nodoc
|
|
31
30
|
def field(name, options = {})
|
32
31
|
access = name.to_s
|
33
32
|
set_field(access, options)
|
34
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the default values for the fields on the document
|
36
|
+
def defaults
|
37
|
+
fields.inject({}) do |defs,(field_name,field)|
|
38
|
+
next(defs) if field.default.nil?
|
39
|
+
defs[field_name.to_s] = field.default
|
40
|
+
defs
|
41
|
+
end
|
35
42
|
end
|
36
43
|
|
37
44
|
protected
|
@@ -52,11 +59,6 @@ module Mongoid #:nodoc
|
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
# Set up a default value for a field.
|
56
|
-
def set_default(name, options = {})
|
57
|
-
value = options[:default]
|
58
|
-
defaults[name] = value unless value.nil?
|
59
|
-
end
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
data/mongoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.10"
|
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{2010-03-
|
12
|
+
s.date = %q{2010-03-12}
|
13
13
|
s.email = %q{durran@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
|
|
62
62
|
"lib/mongoid/criterion/inclusion.rb",
|
63
63
|
"lib/mongoid/criterion/optional.rb",
|
64
64
|
"lib/mongoid/cursor.rb",
|
65
|
+
"lib/mongoid/deprecation.rb",
|
65
66
|
"lib/mongoid/document.rb",
|
66
67
|
"lib/mongoid/errors.rb",
|
67
68
|
"lib/mongoid/extensions.rb",
|
@@ -181,6 +182,7 @@ Gem::Specification.new do |s|
|
|
181
182
|
"spec/unit/mongoid/criterion/inclusion_spec.rb",
|
182
183
|
"spec/unit/mongoid/criterion/optional_spec.rb",
|
183
184
|
"spec/unit/mongoid/cursor_spec.rb",
|
185
|
+
"spec/unit/mongoid/deprecation_spec.rb",
|
184
186
|
"spec/unit/mongoid/document_spec.rb",
|
185
187
|
"spec/unit/mongoid/errors_spec.rb",
|
186
188
|
"spec/unit/mongoid/extensions/array/accessors_spec.rb",
|
@@ -302,6 +304,7 @@ Gem::Specification.new do |s|
|
|
302
304
|
"spec/unit/mongoid/criterion/inclusion_spec.rb",
|
303
305
|
"spec/unit/mongoid/criterion/optional_spec.rb",
|
304
306
|
"spec/unit/mongoid/cursor_spec.rb",
|
307
|
+
"spec/unit/mongoid/deprecation_spec.rb",
|
305
308
|
"spec/unit/mongoid/document_spec.rb",
|
306
309
|
"spec/unit/mongoid/errors_spec.rb",
|
307
310
|
"spec/unit/mongoid/extensions/array/accessors_spec.rb",
|
@@ -240,6 +240,12 @@ describe Mongoid::Associations do
|
|
240
240
|
@person.name.last_name.should == "Brown"
|
241
241
|
end
|
242
242
|
|
243
|
+
it "sets the new_record values properly" do
|
244
|
+
from_db = Person.find(@person.id)
|
245
|
+
new_name = from_db.create_name(:first_name => "Flash")
|
246
|
+
new_name.new_record?.should be_false
|
247
|
+
end
|
248
|
+
|
243
249
|
end
|
244
250
|
|
245
251
|
context "multiple levels nested" do
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Deprecation do
|
4
|
+
|
5
|
+
let(:logger) do
|
6
|
+
stub.quacks_like(Logger.allocate)
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
Logger.expects(:new).with($stdout).returns(logger)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#alert" do
|
14
|
+
|
15
|
+
let(:deprecation) do
|
16
|
+
Mongoid::Deprecation.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
it "calls warn on the memoized logger" do
|
20
|
+
logger.expects(:warn).with("Deprecation: testing")
|
21
|
+
deprecation.alert("testing")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -20,13 +20,6 @@ describe Mongoid::Extras do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
describe ".cached" do
|
24
|
-
|
25
|
-
it "defaults to false" do
|
26
|
-
@klass.cached.should be_false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
23
|
describe ".cached?" do
|
31
24
|
|
32
25
|
context "when the class is cached" do
|
@@ -73,13 +66,6 @@ describe Mongoid::Extras do
|
|
73
66
|
|
74
67
|
end
|
75
68
|
|
76
|
-
describe ".enslaved" do
|
77
|
-
|
78
|
-
it "defaults to false" do
|
79
|
-
@klass.enslaved.should be_false
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
69
|
describe ".enslaved?" do
|
84
70
|
|
85
71
|
context "when the class is enslaved" do
|
@@ -12,6 +12,23 @@ describe Mongoid::Fields do
|
|
12
12
|
|
13
13
|
describe "#defaults" do
|
14
14
|
|
15
|
+
context "with defaults specified as a non-primitive" do
|
16
|
+
before do
|
17
|
+
Person.field(:hash_testing, :type => Hash, :default => {})
|
18
|
+
Person.field(:array_testing, :type => Array, :default => [])
|
19
|
+
@first_person = Person.new
|
20
|
+
@second_person = Person.new
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not return the same object when calling defaults with a default hash" do
|
24
|
+
@first_person.hash_testing.object_id.should_not == @second_person.hash_testing.object_id
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not return the same object when calling defaults with a default array" do
|
28
|
+
@first_person.array_testing.object_id.should_not == @second_person.array_testing.object_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
15
32
|
context "on parent classes" do
|
16
33
|
|
17
34
|
before do
|
data/spec/unit/mongoid_spec.rb
CHANGED
@@ -9,7 +9,6 @@ describe Mongoid do
|
|
9
9
|
it "returns the config singleton" do
|
10
10
|
Mongoid.configure.should == Mongoid::Config.instance
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
13
|
|
15
14
|
context "when a block is supplied" do
|
@@ -29,9 +28,19 @@ describe Mongoid do
|
|
29
28
|
it "sets the values on the config instance" do
|
30
29
|
Mongoid.allow_dynamic_fields.should be_false
|
31
30
|
end
|
31
|
+
end
|
32
|
+
end
|
32
33
|
|
34
|
+
describe ".deprecate" do
|
35
|
+
|
36
|
+
before do
|
37
|
+
@deprecation = mock
|
38
|
+
Mongoid::Deprecation.expects(:instance).returns(@deprecation)
|
33
39
|
end
|
34
40
|
|
41
|
+
it "calls alert on the deprecation singleton" do
|
42
|
+
@deprecation.expects(:alert).with("testing")
|
43
|
+
Mongoid.deprecate("testing")
|
44
|
+
end
|
35
45
|
end
|
36
|
-
|
37
46
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 10
|
9
|
+
version: 1.2.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Durran Jordan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-12 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/mongoid/criterion/inclusion.rb
|
157
157
|
- lib/mongoid/criterion/optional.rb
|
158
158
|
- lib/mongoid/cursor.rb
|
159
|
+
- lib/mongoid/deprecation.rb
|
159
160
|
- lib/mongoid/document.rb
|
160
161
|
- lib/mongoid/errors.rb
|
161
162
|
- lib/mongoid/extensions.rb
|
@@ -275,6 +276,7 @@ files:
|
|
275
276
|
- spec/unit/mongoid/criterion/inclusion_spec.rb
|
276
277
|
- spec/unit/mongoid/criterion/optional_spec.rb
|
277
278
|
- spec/unit/mongoid/cursor_spec.rb
|
279
|
+
- spec/unit/mongoid/deprecation_spec.rb
|
278
280
|
- spec/unit/mongoid/document_spec.rb
|
279
281
|
- spec/unit/mongoid/errors_spec.rb
|
280
282
|
- spec/unit/mongoid/extensions/array/accessors_spec.rb
|
@@ -420,6 +422,7 @@ test_files:
|
|
420
422
|
- spec/unit/mongoid/criterion/inclusion_spec.rb
|
421
423
|
- spec/unit/mongoid/criterion/optional_spec.rb
|
422
424
|
- spec/unit/mongoid/cursor_spec.rb
|
425
|
+
- spec/unit/mongoid/deprecation_spec.rb
|
423
426
|
- spec/unit/mongoid/document_spec.rb
|
424
427
|
- spec/unit/mongoid/errors_spec.rb
|
425
428
|
- spec/unit/mongoid/extensions/array/accessors_spec.rb
|