drogus-mongo_mapper 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/bin/mmconsole +60 -0
- data/lib/mongo_mapper.rb +131 -0
- data/lib/mongo_mapper/document.rb +417 -0
- data/lib/mongo_mapper/embedded_document.rb +55 -0
- data/lib/mongo_mapper/finder_options.rb +127 -0
- data/lib/mongo_mapper/plugins.rb +30 -0
- data/lib/mongo_mapper/plugins/associations.rb +104 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +121 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +30 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +25 -0
- data/lib/mongo_mapper/plugins/associations/collection.rb +21 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +50 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +139 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +117 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +31 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +23 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +13 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +68 -0
- data/lib/mongo_mapper/plugins/associations/proxy.rb +118 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +134 -0
- data/lib/mongo_mapper/plugins/clone.rb +13 -0
- data/lib/mongo_mapper/plugins/descendants.rb +16 -0
- data/lib/mongo_mapper/plugins/dirty.rb +119 -0
- data/lib/mongo_mapper/plugins/equality.rb +23 -0
- data/lib/mongo_mapper/plugins/identity_map.rb +122 -0
- data/lib/mongo_mapper/plugins/inspect.rb +14 -0
- data/lib/mongo_mapper/plugins/keys.rb +324 -0
- data/lib/mongo_mapper/plugins/logger.rb +17 -0
- data/lib/mongo_mapper/plugins/pagination.rb +85 -0
- data/lib/mongo_mapper/plugins/protected.rb +45 -0
- data/lib/mongo_mapper/plugins/rails.rb +45 -0
- data/lib/mongo_mapper/plugins/serialization.rb +105 -0
- data/lib/mongo_mapper/plugins/validations.rb +57 -0
- data/lib/mongo_mapper/support.rb +217 -0
- data/lib/mongo_mapper/support/descendant_appends.rb +46 -0
- data/lib/mongo_mapper/support/find.rb +77 -0
- data/mongo_mapper.gemspec +195 -0
- data/performance/read_write.rb +52 -0
- data/specs.watchr +51 -0
- data/test/NOTE_ON_TESTING +1 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +63 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +101 -0
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +229 -0
- data/test/functional/associations/test_many_documents_proxy.rb +431 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +176 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +256 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +302 -0
- data/test/functional/associations/test_one_proxy.rb +161 -0
- data/test/functional/test_associations.rb +44 -0
- data/test/functional/test_binary.rb +27 -0
- data/test/functional/test_callbacks.rb +81 -0
- data/test/functional/test_dirty.rb +163 -0
- data/test/functional/test_document.rb +1264 -0
- data/test/functional/test_embedded_document.rb +125 -0
- data/test/functional/test_identity_map.rb +508 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_modifiers.rb +252 -0
- data/test/functional/test_pagination.rb +93 -0
- data/test/functional/test_protected.rb +155 -0
- data/test/functional/test_string_id_compatibility.rb +67 -0
- data/test/functional/test_validations.rb +329 -0
- data/test/models.rb +232 -0
- data/test/support/custom_matchers.rb +55 -0
- data/test/support/timing.rb +16 -0
- data/test/test_helper.rb +60 -0
- data/test/unit/associations/test_base.rb +207 -0
- data/test/unit/associations/test_proxy.rb +105 -0
- data/test/unit/serializers/test_json_serializer.rb +189 -0
- data/test/unit/test_descendant_appends.rb +71 -0
- data/test/unit/test_document.rb +231 -0
- data/test/unit/test_dynamic_finder.rb +123 -0
- data/test/unit/test_embedded_document.rb +663 -0
- data/test/unit/test_finder_options.rb +329 -0
- data/test/unit/test_keys.rb +169 -0
- data/test/unit/test_mongo_mapper.rb +65 -0
- data/test/unit/test_pagination.rb +127 -0
- data/test/unit/test_plugins.rb +50 -0
- data/test/unit/test_rails.rb +123 -0
- data/test/unit/test_rails_compatibility.rb +52 -0
- data/test/unit/test_serialization.rb +51 -0
- data/test/unit/test_support.rb +354 -0
- data/test/unit/test_time_zones.rb +39 -0
- data/test/unit/test_validations.rb +544 -0
- metadata +290 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Support
|
3
|
+
module DescendantAppends
|
4
|
+
def included(model)
|
5
|
+
extra_extensions.each { |extension| model.extend(extension) }
|
6
|
+
extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
|
7
|
+
descendants << model
|
8
|
+
end
|
9
|
+
|
10
|
+
# @api public
|
11
|
+
def descendants
|
12
|
+
@descendants ||= Set.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# @api public
|
16
|
+
def append_extensions(*extensions)
|
17
|
+
extra_extensions.concat extensions
|
18
|
+
|
19
|
+
# Add the extension to existing descendants
|
20
|
+
descendants.each do |model|
|
21
|
+
extensions.each { |extension| model.extend(extension) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @api public
|
26
|
+
def append_inclusions(*inclusions)
|
27
|
+
extra_inclusions.concat inclusions
|
28
|
+
|
29
|
+
# Add the inclusion to existing descendants
|
30
|
+
descendants.each do |model|
|
31
|
+
inclusions.each { |inclusion| model.send(:include, inclusion) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def extra_extensions
|
37
|
+
@extra_extensions ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def extra_inclusions
|
42
|
+
@extra_inclusions ||= []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Support
|
3
|
+
# @api private
|
4
|
+
module Find
|
5
|
+
def dynamic_find(finder, args)
|
6
|
+
attributes = {}
|
7
|
+
|
8
|
+
finder.attributes.each_with_index do |attr, index|
|
9
|
+
attributes[attr] = args[index]
|
10
|
+
end
|
11
|
+
|
12
|
+
options = args.extract_options!.merge(attributes)
|
13
|
+
|
14
|
+
if result = send(finder.finder, options)
|
15
|
+
result
|
16
|
+
else
|
17
|
+
if finder.raise?
|
18
|
+
raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
if finder.instantiator
|
22
|
+
self.send(finder.instantiator, attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class DynamicFinder
|
28
|
+
attr_reader :method, :attributes, :finder, :bang, :instantiator
|
29
|
+
|
30
|
+
def initialize(method)
|
31
|
+
@method = method
|
32
|
+
@finder = :first
|
33
|
+
@bang = false
|
34
|
+
match
|
35
|
+
end
|
36
|
+
|
37
|
+
def found?
|
38
|
+
@finder.present?
|
39
|
+
end
|
40
|
+
|
41
|
+
def raise?
|
42
|
+
bang == true
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def match
|
47
|
+
case method.to_s
|
48
|
+
when /^find_(all_by|by)_([_a-zA-Z]\w*)$/
|
49
|
+
@finder = :all if $1 == 'all_by'
|
50
|
+
names = $2
|
51
|
+
when /^find_by_([_a-zA-Z]\w*)\!$/
|
52
|
+
@bang = true
|
53
|
+
names = $1
|
54
|
+
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
|
55
|
+
@instantiator = $1 == 'initialize' ? :new : :create
|
56
|
+
names = $2
|
57
|
+
else
|
58
|
+
@finder = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
@attributes = names && names.split('_and_')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
def method_missing(method, *args, &block)
|
67
|
+
finder = DynamicFinder.new(method)
|
68
|
+
|
69
|
+
if finder.found?
|
70
|
+
dynamic_find(finder, args)
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{drogus-mongo_mapper}
|
8
|
+
s.version = "0.6.10"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Nunemaker"]
|
12
|
+
s.date = %q{2010-03-02}
|
13
|
+
s.default_executable = %q{mmconsole}
|
14
|
+
s.email = %q{nunemaker@gmail.com}
|
15
|
+
s.executables = ["mmconsole"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bin/mmconsole",
|
27
|
+
"lib/mongo_mapper.rb",
|
28
|
+
"lib/mongo_mapper/document.rb",
|
29
|
+
"lib/mongo_mapper/embedded_document.rb",
|
30
|
+
"lib/mongo_mapper/finder_options.rb",
|
31
|
+
"lib/mongo_mapper/plugins.rb",
|
32
|
+
"lib/mongo_mapper/plugins/associations.rb",
|
33
|
+
"lib/mongo_mapper/plugins/associations/base.rb",
|
34
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb",
|
35
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb",
|
36
|
+
"lib/mongo_mapper/plugins/associations/collection.rb",
|
37
|
+
"lib/mongo_mapper/plugins/associations/embedded_collection.rb",
|
38
|
+
"lib/mongo_mapper/plugins/associations/in_array_proxy.rb",
|
39
|
+
"lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb",
|
40
|
+
"lib/mongo_mapper/plugins/associations/many_documents_proxy.rb",
|
41
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb",
|
42
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb",
|
43
|
+
"lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb",
|
44
|
+
"lib/mongo_mapper/plugins/associations/one_proxy.rb",
|
45
|
+
"lib/mongo_mapper/plugins/associations/proxy.rb",
|
46
|
+
"lib/mongo_mapper/plugins/callbacks.rb",
|
47
|
+
"lib/mongo_mapper/plugins/clone.rb",
|
48
|
+
"lib/mongo_mapper/plugins/descendants.rb",
|
49
|
+
"lib/mongo_mapper/plugins/dirty.rb",
|
50
|
+
"lib/mongo_mapper/plugins/equality.rb",
|
51
|
+
"lib/mongo_mapper/plugins/identity_map.rb",
|
52
|
+
"lib/mongo_mapper/plugins/inspect.rb",
|
53
|
+
"lib/mongo_mapper/plugins/keys.rb",
|
54
|
+
"lib/mongo_mapper/plugins/logger.rb",
|
55
|
+
"lib/mongo_mapper/plugins/pagination.rb",
|
56
|
+
"lib/mongo_mapper/plugins/protected.rb",
|
57
|
+
"lib/mongo_mapper/plugins/rails.rb",
|
58
|
+
"lib/mongo_mapper/plugins/serialization.rb",
|
59
|
+
"lib/mongo_mapper/plugins/validations.rb",
|
60
|
+
"lib/mongo_mapper/support.rb",
|
61
|
+
"lib/mongo_mapper/support/descendant_appends.rb",
|
62
|
+
"lib/mongo_mapper/support/find.rb",
|
63
|
+
"mongo_mapper.gemspec",
|
64
|
+
"performance/read_write.rb",
|
65
|
+
"specs.watchr",
|
66
|
+
"test/NOTE_ON_TESTING",
|
67
|
+
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
68
|
+
"test/functional/associations/test_belongs_to_proxy.rb",
|
69
|
+
"test/functional/associations/test_in_array_proxy.rb",
|
70
|
+
"test/functional/associations/test_many_documents_as_proxy.rb",
|
71
|
+
"test/functional/associations/test_many_documents_proxy.rb",
|
72
|
+
"test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
|
73
|
+
"test/functional/associations/test_many_embedded_proxy.rb",
|
74
|
+
"test/functional/associations/test_many_polymorphic_proxy.rb",
|
75
|
+
"test/functional/associations/test_one_proxy.rb",
|
76
|
+
"test/functional/test_associations.rb",
|
77
|
+
"test/functional/test_binary.rb",
|
78
|
+
"test/functional/test_callbacks.rb",
|
79
|
+
"test/functional/test_dirty.rb",
|
80
|
+
"test/functional/test_document.rb",
|
81
|
+
"test/functional/test_embedded_document.rb",
|
82
|
+
"test/functional/test_identity_map.rb",
|
83
|
+
"test/functional/test_logger.rb",
|
84
|
+
"test/functional/test_modifiers.rb",
|
85
|
+
"test/functional/test_pagination.rb",
|
86
|
+
"test/functional/test_protected.rb",
|
87
|
+
"test/functional/test_string_id_compatibility.rb",
|
88
|
+
"test/functional/test_validations.rb",
|
89
|
+
"test/models.rb",
|
90
|
+
"test/support/custom_matchers.rb",
|
91
|
+
"test/support/timing.rb",
|
92
|
+
"test/test_helper.rb",
|
93
|
+
"test/unit/associations/test_base.rb",
|
94
|
+
"test/unit/associations/test_proxy.rb",
|
95
|
+
"test/unit/serializers/test_json_serializer.rb",
|
96
|
+
"test/unit/test_descendant_appends.rb",
|
97
|
+
"test/unit/test_document.rb",
|
98
|
+
"test/unit/test_dynamic_finder.rb",
|
99
|
+
"test/unit/test_embedded_document.rb",
|
100
|
+
"test/unit/test_finder_options.rb",
|
101
|
+
"test/unit/test_keys.rb",
|
102
|
+
"test/unit/test_mongo_mapper.rb",
|
103
|
+
"test/unit/test_pagination.rb",
|
104
|
+
"test/unit/test_plugins.rb",
|
105
|
+
"test/unit/test_rails.rb",
|
106
|
+
"test/unit/test_rails_compatibility.rb",
|
107
|
+
"test/unit/test_serialization.rb",
|
108
|
+
"test/unit/test_support.rb",
|
109
|
+
"test/unit/test_time_zones.rb",
|
110
|
+
"test/unit/test_validations.rb"
|
111
|
+
]
|
112
|
+
s.homepage = %q{http://github.com/jnunemaker/mongomapper}
|
113
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
114
|
+
s.require_paths = ["lib"]
|
115
|
+
s.rubygems_version = %q{1.3.6}
|
116
|
+
s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
|
117
|
+
s.test_files = [
|
118
|
+
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
119
|
+
"test/functional/associations/test_belongs_to_proxy.rb",
|
120
|
+
"test/functional/associations/test_in_array_proxy.rb",
|
121
|
+
"test/functional/associations/test_many_documents_as_proxy.rb",
|
122
|
+
"test/functional/associations/test_many_documents_proxy.rb",
|
123
|
+
"test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
|
124
|
+
"test/functional/associations/test_many_embedded_proxy.rb",
|
125
|
+
"test/functional/associations/test_many_polymorphic_proxy.rb",
|
126
|
+
"test/functional/associations/test_one_proxy.rb",
|
127
|
+
"test/functional/test_associations.rb",
|
128
|
+
"test/functional/test_binary.rb",
|
129
|
+
"test/functional/test_callbacks.rb",
|
130
|
+
"test/functional/test_dirty.rb",
|
131
|
+
"test/functional/test_document.rb",
|
132
|
+
"test/functional/test_embedded_document.rb",
|
133
|
+
"test/functional/test_identity_map.rb",
|
134
|
+
"test/functional/test_logger.rb",
|
135
|
+
"test/functional/test_modifiers.rb",
|
136
|
+
"test/functional/test_pagination.rb",
|
137
|
+
"test/functional/test_protected.rb",
|
138
|
+
"test/functional/test_string_id_compatibility.rb",
|
139
|
+
"test/functional/test_validations.rb",
|
140
|
+
"test/models.rb",
|
141
|
+
"test/support/custom_matchers.rb",
|
142
|
+
"test/support/timing.rb",
|
143
|
+
"test/test_helper.rb",
|
144
|
+
"test/unit/associations/test_base.rb",
|
145
|
+
"test/unit/associations/test_proxy.rb",
|
146
|
+
"test/unit/serializers/test_json_serializer.rb",
|
147
|
+
"test/unit/test_descendant_appends.rb",
|
148
|
+
"test/unit/test_document.rb",
|
149
|
+
"test/unit/test_dynamic_finder.rb",
|
150
|
+
"test/unit/test_embedded_document.rb",
|
151
|
+
"test/unit/test_finder_options.rb",
|
152
|
+
"test/unit/test_keys.rb",
|
153
|
+
"test/unit/test_mongo_mapper.rb",
|
154
|
+
"test/unit/test_pagination.rb",
|
155
|
+
"test/unit/test_plugins.rb",
|
156
|
+
"test/unit/test_rails.rb",
|
157
|
+
"test/unit/test_rails_compatibility.rb",
|
158
|
+
"test/unit/test_serialization.rb",
|
159
|
+
"test/unit/test_support.rb",
|
160
|
+
"test/unit/test_time_zones.rb",
|
161
|
+
"test/unit/test_validations.rb"
|
162
|
+
]
|
163
|
+
|
164
|
+
if s.respond_to? :specification_version then
|
165
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
166
|
+
s.specification_version = 3
|
167
|
+
|
168
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
169
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
170
|
+
s.add_runtime_dependency(%q<mongo>, ["= 0.19"])
|
171
|
+
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
172
|
+
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
173
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
174
|
+
s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
|
175
|
+
s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
|
176
|
+
else
|
177
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
178
|
+
s.add_dependency(%q<mongo>, ["= 0.19"])
|
179
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
180
|
+
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
181
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
182
|
+
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
183
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
184
|
+
end
|
185
|
+
else
|
186
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
187
|
+
s.add_dependency(%q<mongo>, ["= 0.19"])
|
188
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
189
|
+
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
190
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
191
|
+
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
192
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# The purpose of this is to check finding, initializing,
|
2
|
+
# and creating objects (typecasting times/dates and booleans).
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
# to test with slow version just do this:
|
9
|
+
# gem 'mongo_mapper', '0.6.10'
|
10
|
+
# and comment out this:
|
11
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
12
|
+
|
13
|
+
require 'mongo_mapper'
|
14
|
+
|
15
|
+
MongoMapper.database = 'testing'
|
16
|
+
|
17
|
+
class Foo
|
18
|
+
include MongoMapper::Document
|
19
|
+
key :approved, Boolean
|
20
|
+
key :count, Integer
|
21
|
+
key :approved_at, Time
|
22
|
+
key :expire_on, Date
|
23
|
+
timestamps!
|
24
|
+
end
|
25
|
+
Foo.collection.remove
|
26
|
+
|
27
|
+
Benchmark.bm(5) do |x|
|
28
|
+
ids = []
|
29
|
+
x.report("write") do
|
30
|
+
1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
|
31
|
+
end
|
32
|
+
|
33
|
+
x.report("read ") do
|
34
|
+
ids.each { |id| Foo.first(:id => id) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# I was get something like this on my puny macbook air:
|
39
|
+
# user system total real
|
40
|
+
# write 4.810000 0.090000 4.900000 ( 5.039949)
|
41
|
+
# read 2.730000 0.070000 2.800000 ( 2.990749)
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# After these commits:
|
45
|
+
#
|
46
|
+
# * http://github.com/jnunemaker/mongomapper/commit/e5091fa140d5fae2721017b53027092233694ee5
|
47
|
+
# * http://github.com/jnunemaker/mongomapper/commit/c22bbde4fa1cfbc310d79cb0e50203310ffb03d1
|
48
|
+
#
|
49
|
+
# I'm now getting something like this:
|
50
|
+
# user system total real
|
51
|
+
# write 1.660000 0.050000 1.710000 ( 1.752676)
|
52
|
+
# read 1.060000 0.050000 1.110000 ( 1.263429)
|
data/specs.watchr
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
def growl(title, msg, img)
|
2
|
+
%x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
|
3
|
+
end
|
4
|
+
|
5
|
+
def form_growl_message(str)
|
6
|
+
results = str.split("\n").last
|
7
|
+
if results =~ /[1-9]\s(failure|error)s?/
|
8
|
+
growl "Test Results", "#{results}", "fail"
|
9
|
+
elsif results != ""
|
10
|
+
growl "Test Results", "#{results}", "pass"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(cmd)
|
15
|
+
puts(cmd)
|
16
|
+
output = ""
|
17
|
+
IO.popen(cmd) do |com|
|
18
|
+
com.each_char do |c|
|
19
|
+
print c
|
20
|
+
output << c
|
21
|
+
$stdout.flush
|
22
|
+
end
|
23
|
+
end
|
24
|
+
form_growl_message output
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_test_file(file)
|
28
|
+
run %Q(ruby -I"lib:test" -rubygems #{file})
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_all_tests
|
32
|
+
run "rake test"
|
33
|
+
end
|
34
|
+
|
35
|
+
def related_test_files(path)
|
36
|
+
Dir['test/**/*.rb'].select { |file| file =~ /test_#{File.basename(path)}/ }
|
37
|
+
end
|
38
|
+
|
39
|
+
watch('test/test_helper\.rb') { system('clear'); run_all_tests }
|
40
|
+
watch('test/.*/test_.*\.rb') { |m| system('clear'); run_test_file(m[0]) }
|
41
|
+
watch('lib/.*') { |m| related_test_files(m[0]).each { |file| run_test_file(file) } }
|
42
|
+
|
43
|
+
# Ctrl-\
|
44
|
+
Signal.trap('QUIT') do
|
45
|
+
puts " --- Running all tests ---\n\n"
|
46
|
+
run_all_tests
|
47
|
+
end
|
48
|
+
|
49
|
+
# Ctrl-C
|
50
|
+
Signal.trap('INT') { abort("\n") }
|
51
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
I am doing my best to keep unit and functional tests separate. As I see them, functional tests hit the database and should never care about internals. Unit tests do not hit the database.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'models'
|
3
|
+
|
4
|
+
class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Status.collection.remove
|
7
|
+
Project.collection.remove
|
8
|
+
end
|
9
|
+
|
10
|
+
should "default to nil" do
|
11
|
+
status = Status.new
|
12
|
+
status.target.nil?.should be_true
|
13
|
+
status.target.inspect.should == "nil"
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have boolean presence method" do
|
17
|
+
status = Status.new
|
18
|
+
status.target?.should be_false
|
19
|
+
|
20
|
+
status.target = Project.new(:name => 'mongomapper')
|
21
|
+
status.target?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be able to replace the association" do
|
25
|
+
status = Status.new(:name => 'Foo!')
|
26
|
+
project = Project.new(:name => "mongomapper")
|
27
|
+
status.target = project
|
28
|
+
status.save.should be_true
|
29
|
+
|
30
|
+
status = status.reload
|
31
|
+
status.target.nil?.should be_false
|
32
|
+
status.target_id.should == project._id
|
33
|
+
status.target_type.should == "Project"
|
34
|
+
status.target.name.should == "mongomapper"
|
35
|
+
end
|
36
|
+
|
37
|
+
should "unset the association" do
|
38
|
+
status = Status.new(:name => 'Foo!')
|
39
|
+
project = Project.new(:name => "mongomapper")
|
40
|
+
status.target = project
|
41
|
+
status.save.should be_true
|
42
|
+
|
43
|
+
status = status.reload
|
44
|
+
status.target = nil
|
45
|
+
status.target_type.nil?.should be_true
|
46
|
+
status.target_id.nil?.should be_true
|
47
|
+
status.target.nil?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
context "association id set but document not found" do
|
51
|
+
setup do
|
52
|
+
@status = Status.new(:name => 'Foo!')
|
53
|
+
project = Project.new(:name => "mongomapper")
|
54
|
+
@status.target = project
|
55
|
+
@status.save.should be_true
|
56
|
+
project.destroy
|
57
|
+
end
|
58
|
+
|
59
|
+
should "return nil instead of raising error" do
|
60
|
+
@status.target.nil?.should be_true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|