mongo_mapper-unstable 2009.12.30 → 2010.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -17
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_mapper/associations/base.rb +19 -10
- data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
- data/lib/mongo_mapper/associations/one_proxy.rb +64 -0
- data/lib/mongo_mapper/associations/proxy.rb +7 -4
- data/lib/mongo_mapper/associations.rb +11 -3
- data/lib/mongo_mapper/callbacks.rb +30 -78
- data/lib/mongo_mapper/dirty.rb +5 -24
- data/lib/mongo_mapper/document.rb +117 -144
- data/lib/mongo_mapper/embedded_document.rb +7 -11
- data/lib/mongo_mapper/finder_options.rb +13 -21
- data/lib/mongo_mapper/mongo_mapper.rb +125 -0
- data/lib/mongo_mapper/pagination.rb +12 -1
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
- data/lib/mongo_mapper/serialization.rb +2 -2
- data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
- data/lib/mongo_mapper/support.rb +2 -2
- data/lib/mongo_mapper.rb +8 -2
- data/mongo_mapper.gemspec +14 -8
- data/specs.watchr +3 -5
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +8 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +54 -9
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_proxy.rb +103 -53
- data/test/functional/associations/test_many_embedded_proxy.rb +4 -14
- data/test/functional/associations/test_many_polymorphic_proxy.rb +2 -1
- data/test/functional/associations/test_one_proxy.rb +149 -0
- data/test/functional/test_binary.rb +13 -4
- data/test/functional/test_callbacks.rb +1 -5
- data/test/functional/test_dirty.rb +1 -4
- data/test/functional/test_document.rb +576 -640
- data/test/functional/test_embedded_document.rb +7 -20
- data/test/functional/test_modifiers.rb +238 -0
- data/test/functional/test_pagination.rb +1 -3
- data/test/functional/test_string_id_compatibility.rb +3 -8
- data/test/functional/test_validations.rb +13 -75
- data/test/models.rb +1 -1
- data/test/support/timing.rb +1 -1
- data/test/test_helper.rb +28 -0
- data/test/unit/associations/test_base.rb +54 -13
- data/test/unit/associations/test_proxy.rb +12 -0
- data/test/unit/test_document.rb +36 -26
- data/test/unit/test_embedded_document.rb +14 -51
- data/test/unit/test_finder_options.rb +20 -7
- data/test/unit/test_key.rb +1 -4
- data/test/unit/test_pagination.rb +6 -0
- data/test/unit/test_rails_compatibility.rb +4 -1
- data/test/unit/test_serializations.rb +1 -2
- data/test/unit/test_support.rb +4 -0
- data/test/unit/test_time_zones.rb +1 -2
- data/test/unit/test_validations.rb +3 -14
- metadata +12 -6
- data/lib/mongo_mapper/observing.rb +0 -50
- data/test/unit/test_observing.rb +0 -101
data/test/unit/test_observing.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Comment
|
4
|
-
include MongoMapper::Document
|
5
|
-
|
6
|
-
key :name, String
|
7
|
-
key :body, String
|
8
|
-
|
9
|
-
attr_accessor :callers
|
10
|
-
before_validation :record_callers
|
11
|
-
|
12
|
-
def after_validation
|
13
|
-
record_callers
|
14
|
-
end
|
15
|
-
|
16
|
-
def record_callers
|
17
|
-
callers << self.class if callers
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Article
|
22
|
-
include MongoMapper::Document
|
23
|
-
|
24
|
-
key :title, String
|
25
|
-
key :body, String
|
26
|
-
end
|
27
|
-
|
28
|
-
class CommentObserver < MongoMapper::Observer
|
29
|
-
attr_accessor :callers
|
30
|
-
|
31
|
-
def after_validation(model)
|
32
|
-
callers << self.class if callers
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class AuditObserver < MongoMapper::Observer
|
37
|
-
observe Article, Comment
|
38
|
-
attr_reader :document
|
39
|
-
|
40
|
-
def after_validation(document)
|
41
|
-
@document = document
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class GlobalObserver < MongoMapper::Observer
|
46
|
-
observe Article, Comment
|
47
|
-
attr_reader :document
|
48
|
-
|
49
|
-
def before_save(document)
|
50
|
-
@document = document
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class NonAutomaticObserver < MongoMapper::Observer
|
55
|
-
observe Comment
|
56
|
-
attr_reader :comment
|
57
|
-
|
58
|
-
def after_validation(comment)
|
59
|
-
@comment = comment
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class ObserverTest < Test::Unit::TestCase
|
64
|
-
should "fire model callbacks before observer" do
|
65
|
-
callers = []
|
66
|
-
comment = Comment.new
|
67
|
-
comment.callers = callers
|
68
|
-
|
69
|
-
CommentObserver.instance.callers = callers
|
70
|
-
|
71
|
-
comment.valid?
|
72
|
-
callers.should == [Comment, Comment, CommentObserver]
|
73
|
-
end
|
74
|
-
|
75
|
-
should "automatically observe model based on name when possible" do
|
76
|
-
CommentObserver.observed_class.should == Comment
|
77
|
-
end
|
78
|
-
|
79
|
-
should "be able to observe other models using observe" do
|
80
|
-
obs = NonAutomaticObserver.instance
|
81
|
-
comment = Comment.new(:name => 'John Nunemaker', :body => 'is awesome')
|
82
|
-
comment.valid?
|
83
|
-
obs.comment.name.should == 'John Nunemaker'
|
84
|
-
obs.comment.body.should == 'is awesome'
|
85
|
-
end
|
86
|
-
|
87
|
-
should "be able to observe multiple models" do
|
88
|
-
obs = AuditObserver.instance
|
89
|
-
comment = Comment.new(:name => 'Steve Smith', :body => 'is awesome')
|
90
|
-
comment.valid?
|
91
|
-
|
92
|
-
obs.document.name.should == 'Steve Smith'
|
93
|
-
obs.document.body.should == 'is awesome'
|
94
|
-
|
95
|
-
article = Article.new(:title => 'Ordered List Is Awesome', :body => 'Learn to accept it!')
|
96
|
-
article.valid?
|
97
|
-
|
98
|
-
obs.document.title.should == 'Ordered List Is Awesome'
|
99
|
-
obs.document.body.should == 'Learn to accept it!'
|
100
|
-
end
|
101
|
-
end
|