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.
Files changed (56) hide show
  1. data/README.rdoc +2 -17
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/mongo_mapper/associations/base.rb +19 -10
  5. data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
  6. data/lib/mongo_mapper/associations/one_proxy.rb +64 -0
  7. data/lib/mongo_mapper/associations/proxy.rb +7 -4
  8. data/lib/mongo_mapper/associations.rb +11 -3
  9. data/lib/mongo_mapper/callbacks.rb +30 -78
  10. data/lib/mongo_mapper/dirty.rb +5 -24
  11. data/lib/mongo_mapper/document.rb +117 -144
  12. data/lib/mongo_mapper/embedded_document.rb +7 -11
  13. data/lib/mongo_mapper/finder_options.rb +13 -21
  14. data/lib/mongo_mapper/mongo_mapper.rb +125 -0
  15. data/lib/mongo_mapper/pagination.rb +12 -1
  16. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
  17. data/lib/mongo_mapper/serialization.rb +2 -2
  18. data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
  19. data/lib/mongo_mapper/support.rb +2 -2
  20. data/lib/mongo_mapper.rb +8 -2
  21. data/mongo_mapper.gemspec +14 -8
  22. data/specs.watchr +3 -5
  23. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +8 -0
  24. data/test/functional/associations/test_belongs_to_proxy.rb +54 -9
  25. data/test/functional/associations/test_in_array_proxy.rb +309 -0
  26. data/test/functional/associations/test_many_documents_proxy.rb +103 -53
  27. data/test/functional/associations/test_many_embedded_proxy.rb +4 -14
  28. data/test/functional/associations/test_many_polymorphic_proxy.rb +2 -1
  29. data/test/functional/associations/test_one_proxy.rb +149 -0
  30. data/test/functional/test_binary.rb +13 -4
  31. data/test/functional/test_callbacks.rb +1 -5
  32. data/test/functional/test_dirty.rb +1 -4
  33. data/test/functional/test_document.rb +576 -640
  34. data/test/functional/test_embedded_document.rb +7 -20
  35. data/test/functional/test_modifiers.rb +238 -0
  36. data/test/functional/test_pagination.rb +1 -3
  37. data/test/functional/test_string_id_compatibility.rb +3 -8
  38. data/test/functional/test_validations.rb +13 -75
  39. data/test/models.rb +1 -1
  40. data/test/support/timing.rb +1 -1
  41. data/test/test_helper.rb +28 -0
  42. data/test/unit/associations/test_base.rb +54 -13
  43. data/test/unit/associations/test_proxy.rb +12 -0
  44. data/test/unit/test_document.rb +36 -26
  45. data/test/unit/test_embedded_document.rb +14 -51
  46. data/test/unit/test_finder_options.rb +20 -7
  47. data/test/unit/test_key.rb +1 -4
  48. data/test/unit/test_pagination.rb +6 -0
  49. data/test/unit/test_rails_compatibility.rb +4 -1
  50. data/test/unit/test_serializations.rb +1 -2
  51. data/test/unit/test_support.rb +4 -0
  52. data/test/unit/test_time_zones.rb +1 -2
  53. data/test/unit/test_validations.rb +3 -14
  54. metadata +12 -6
  55. data/lib/mongo_mapper/observing.rb +0 -50
  56. data/test/unit/test_observing.rb +0 -101
@@ -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