djsun-mongo_mapper 0.5.0.1
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.
- data/.gitignore +8 -0
- data/LICENSE +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/bin/mmconsole +55 -0
- data/lib/mongo_mapper/associations/base.rb +83 -0
- data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +34 -0
- data/lib/mongo_mapper/associations/belongs_to_proxy.rb +22 -0
- data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +27 -0
- data/lib/mongo_mapper/associations/many_documents_proxy.rb +116 -0
- data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +33 -0
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +67 -0
- data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +11 -0
- data/lib/mongo_mapper/associations/many_proxy.rb +6 -0
- data/lib/mongo_mapper/associations/proxy.rb +74 -0
- data/lib/mongo_mapper/associations.rb +86 -0
- data/lib/mongo_mapper/callbacks.rb +106 -0
- data/lib/mongo_mapper/document.rb +308 -0
- data/lib/mongo_mapper/dynamic_finder.rb +35 -0
- data/lib/mongo_mapper/embedded_document.rb +354 -0
- data/lib/mongo_mapper/finder_options.rb +94 -0
- data/lib/mongo_mapper/key.rb +32 -0
- data/lib/mongo_mapper/observing.rb +50 -0
- data/lib/mongo_mapper/pagination.rb +51 -0
- data/lib/mongo_mapper/rails_compatibility/document.rb +15 -0
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +27 -0
- data/lib/mongo_mapper/save_with_validation.rb +19 -0
- data/lib/mongo_mapper/serialization.rb +55 -0
- data/lib/mongo_mapper/serializers/json_serializer.rb +92 -0
- data/lib/mongo_mapper/support.rb +171 -0
- data/lib/mongo_mapper/validations.rb +69 -0
- data/lib/mongo_mapper.rb +95 -0
- data/mongo_mapper.gemspec +156 -0
- data/specs.watchr +32 -0
- data/test/NOTE_ON_TESTING +1 -0
- data/test/custom_matchers.rb +48 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +55 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +49 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +244 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +132 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +174 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +297 -0
- data/test/functional/associations/test_many_proxy.rb +331 -0
- data/test/functional/test_associations.rb +44 -0
- data/test/functional/test_binary.rb +18 -0
- data/test/functional/test_callbacks.rb +85 -0
- data/test/functional/test_document.rb +964 -0
- data/test/functional/test_embedded_document.rb +97 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_pagination.rb +87 -0
- data/test/functional/test_rails_compatibility.rb +30 -0
- data/test/functional/test_validations.rb +279 -0
- data/test/models.rb +169 -0
- data/test/test_helper.rb +30 -0
- data/test/unit/serializers/test_json_serializer.rb +193 -0
- data/test/unit/test_association_base.rb +144 -0
- data/test/unit/test_document.rb +165 -0
- data/test/unit/test_dynamic_finder.rb +125 -0
- data/test/unit/test_embedded_document.rb +643 -0
- data/test/unit/test_finder_options.rb +193 -0
- data/test/unit/test_key.rb +175 -0
- data/test/unit/test_mongomapper.rb +28 -0
- data/test/unit/test_observing.rb +101 -0
- data/test/unit/test_pagination.rb +109 -0
- data/test/unit/test_rails_compatibility.rb +39 -0
- data/test/unit/test_serializations.rb +52 -0
- data/test/unit/test_support.rb +272 -0
- data/test/unit/test_time_zones.rb +40 -0
- data/test/unit/test_validations.rb +503 -0
- metadata +207 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CallbacksTest < Test::Unit::TestCase
|
4
|
+
context "Defining and running callbacks" do
|
5
|
+
setup do
|
6
|
+
@document = Class.new do
|
7
|
+
include MongoMapper::Document
|
8
|
+
set_collection_name 'test'
|
9
|
+
|
10
|
+
key :name, String
|
11
|
+
|
12
|
+
[ :before_validation_on_create, :before_validation_on_update,
|
13
|
+
:before_validation, :after_validation,
|
14
|
+
:before_create, :after_create,
|
15
|
+
:before_update, :after_update,
|
16
|
+
:before_save, :after_save,
|
17
|
+
:before_destroy, :after_destroy].each do |callback|
|
18
|
+
callback_method = "#{callback}_callback"
|
19
|
+
send(callback, callback_method)
|
20
|
+
define_method(callback_method) do
|
21
|
+
history << callback.to_sym
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def history
|
26
|
+
@history ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear_history
|
30
|
+
@history = nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
@document.collection.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
should "get the order right for creating documents" do
|
37
|
+
doc = @document.create(:name => 'John Nunemaker')
|
38
|
+
doc.history.should == [:before_validation, :before_validation_on_create, :after_validation, :before_save, :before_create, :after_create, :after_save]
|
39
|
+
end
|
40
|
+
|
41
|
+
should "get the order right for updating documents" do
|
42
|
+
doc = @document.create(:name => 'John Nunemaker')
|
43
|
+
doc.clear_history
|
44
|
+
doc.name = 'John'
|
45
|
+
doc.save
|
46
|
+
doc.history.should == [:before_validation, :before_validation_on_update, :after_validation, :before_save, :before_update, :after_update, :after_save]
|
47
|
+
end
|
48
|
+
|
49
|
+
should "work for before and after validation" do
|
50
|
+
doc = @document.new(:name => 'John Nunemaker')
|
51
|
+
doc.valid?
|
52
|
+
doc.history.should include(:before_validation)
|
53
|
+
doc.history.should include(:after_validation)
|
54
|
+
end
|
55
|
+
|
56
|
+
should "work for before and after create" do
|
57
|
+
doc = @document.create(:name => 'John Nunemaker')
|
58
|
+
doc.history.should include(:before_create)
|
59
|
+
doc.history.should include(:after_create)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "work for before and after update" do
|
63
|
+
doc = @document.create(:name => 'John Nunemaker')
|
64
|
+
doc.name = 'John Doe'
|
65
|
+
doc.save
|
66
|
+
doc.history.should include(:before_update)
|
67
|
+
doc.history.should include(:after_update)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "work for before and after save" do
|
71
|
+
doc = @document.new
|
72
|
+
doc.name = 'John Doe'
|
73
|
+
doc.save
|
74
|
+
doc.history.should include(:before_save)
|
75
|
+
doc.history.should include(:after_save)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "work for before and after destroy" do
|
79
|
+
doc = @document.create(:name => 'John Nunemaker')
|
80
|
+
doc.destroy
|
81
|
+
doc.history.should include(:before_destroy)
|
82
|
+
doc.history.should include(:after_destroy)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|