tpitale-mongo_mapper 0.6.9
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 +53 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/bin/mmconsole +60 -0
- data/lib/mongo_mapper/associations/base.rb +110 -0
- data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +26 -0
- data/lib/mongo_mapper/associations/belongs_to_proxy.rb +21 -0
- data/lib/mongo_mapper/associations/collection.rb +19 -0
- data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +26 -0
- data/lib/mongo_mapper/associations/many_documents_proxy.rb +115 -0
- data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +31 -0
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +54 -0
- data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +11 -0
- data/lib/mongo_mapper/associations/proxy.rb +113 -0
- data/lib/mongo_mapper/associations.rb +70 -0
- data/lib/mongo_mapper/callbacks.rb +109 -0
- data/lib/mongo_mapper/dirty.rb +136 -0
- data/lib/mongo_mapper/document.rb +472 -0
- data/lib/mongo_mapper/dynamic_finder.rb +74 -0
- data/lib/mongo_mapper/embedded_document.rb +384 -0
- data/lib/mongo_mapper/finder_options.rb +133 -0
- data/lib/mongo_mapper/key.rb +36 -0
- data/lib/mongo_mapper/observing.rb +50 -0
- data/lib/mongo_mapper/pagination.rb +55 -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/serialization.rb +54 -0
- data/lib/mongo_mapper/serializers/json_serializer.rb +92 -0
- data/lib/mongo_mapper/support.rb +206 -0
- data/lib/mongo_mapper/validations.rb +41 -0
- data/lib/mongo_mapper.rb +120 -0
- data/mongo_mapper.gemspec +173 -0
- data/specs.watchr +32 -0
- data/test/NOTE_ON_TESTING +1 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +55 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +48 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +246 -0
- data/test/functional/associations/test_many_documents_proxy.rb +387 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +156 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +192 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +339 -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_dirty.rb +159 -0
- data/test/functional/test_document.rb +1235 -0
- data/test/functional/test_embedded_document.rb +135 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_pagination.rb +95 -0
- data/test/functional/test_rails_compatibility.rb +25 -0
- data/test/functional/test_string_id_compatibility.rb +72 -0
- data/test/functional/test_validations.rb +378 -0
- data/test/models.rb +271 -0
- data/test/support/custom_matchers.rb +55 -0
- data/test/support/timing.rb +16 -0
- data/test/test_helper.rb +27 -0
- data/test/unit/associations/test_base.rb +166 -0
- data/test/unit/associations/test_proxy.rb +91 -0
- data/test/unit/serializers/test_json_serializer.rb +189 -0
- data/test/unit/test_document.rb +204 -0
- data/test/unit/test_dynamic_finder.rb +125 -0
- data/test/unit/test_embedded_document.rb +718 -0
- data/test/unit/test_finder_options.rb +296 -0
- data/test/unit/test_key.rb +172 -0
- data/test/unit/test_mongo_mapper.rb +65 -0
- data/test/unit/test_observing.rb +101 -0
- data/test/unit/test_pagination.rb +113 -0
- data/test/unit/test_rails_compatibility.rb +49 -0
- data/test/unit/test_serializations.rb +52 -0
- data/test/unit/test_support.rb +342 -0
- data/test/unit/test_time_zones.rb +40 -0
- data/test/unit/test_validations.rb +503 -0
- metadata +235 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DynamicFinderTest < Test::Unit::TestCase
|
4
|
+
include MongoMapper
|
5
|
+
|
6
|
+
should "initialize with method" do
|
7
|
+
finder = DynamicFinder.new(:foobar)
|
8
|
+
finder.method.should == :foobar
|
9
|
+
end
|
10
|
+
|
11
|
+
context "found?" do
|
12
|
+
should "be true for find_by" do
|
13
|
+
DynamicFinder.new(:find_by_foo).found?.should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be true for find_by with !" do
|
17
|
+
DynamicFinder.new(:find_by_foo!).found?.should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be true for find_all_by" do
|
21
|
+
DynamicFinder.new(:find_all_by_foo).found?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be true for find_or_initialize_by" do
|
25
|
+
DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
should "be true for find_or_create_by" do
|
29
|
+
DynamicFinder.new(:find_or_create_by_foo).found?.should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
should "be false for anything else" do
|
33
|
+
[:foobar, :bazwick].each do |method|
|
34
|
+
DynamicFinder.new(method).found?.should be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "find_all_by" do
|
40
|
+
should "parse one attribute" do
|
41
|
+
DynamicFinder.new(:find_all_by_foo).attributes.should == %w(foo)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "parse multiple attributes" do
|
45
|
+
DynamicFinder.new(:find_all_by_foo_and_bar).attributes.should == %w(foo bar)
|
46
|
+
DynamicFinder.new(:find_all_by_foo_and_bar_and_baz).attributes.should == %w(foo bar baz)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "set finder to :all" do
|
50
|
+
DynamicFinder.new(:find_all_by_foo_and_bar).finder.should == :all
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "find_by" do
|
55
|
+
should "parse one attribute" do
|
56
|
+
DynamicFinder.new(:find_by_foo).attributes.should == %w(foo)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "parse multiple attributes" do
|
60
|
+
DynamicFinder.new(:find_by_foo_and_bar).attributes.should == %w(foo bar)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "set finder to :first" do
|
64
|
+
DynamicFinder.new(:find_by_foo).finder.should == :first
|
65
|
+
end
|
66
|
+
|
67
|
+
should "set bang to false" do
|
68
|
+
DynamicFinder.new(:find_by_foo).bang.should be_false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "find_by with !" do
|
73
|
+
should "parse one attribute" do
|
74
|
+
DynamicFinder.new(:find_by_foo!).attributes.should == %w(foo)
|
75
|
+
end
|
76
|
+
|
77
|
+
should "parse multiple attributes" do
|
78
|
+
DynamicFinder.new(:find_by_foo_and_bar!).attributes.should == %w(foo bar)
|
79
|
+
end
|
80
|
+
|
81
|
+
should "set finder to :first" do
|
82
|
+
DynamicFinder.new(:find_by_foo!).finder.should == :first
|
83
|
+
end
|
84
|
+
|
85
|
+
should "set bang to true" do
|
86
|
+
DynamicFinder.new(:find_by_foo!).bang.should be_true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "find_or_initialize_by" do
|
91
|
+
should "parse one attribute" do
|
92
|
+
DynamicFinder.new(:find_or_initialize_by_foo).attributes.should == %w(foo)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "parse multiple attributes" do
|
96
|
+
DynamicFinder.new(:find_or_initialize_by_foo_and_bar).attributes.should == %w(foo bar)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "set finder to :first" do
|
100
|
+
DynamicFinder.new(:find_or_initialize_by_foo).finder.should == :first
|
101
|
+
end
|
102
|
+
|
103
|
+
should "set instantiator to new" do
|
104
|
+
DynamicFinder.new(:find_or_initialize_by_foo).instantiator.should == :new
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "find_or_create_by" do
|
109
|
+
should "parse one attribute" do
|
110
|
+
DynamicFinder.new(:find_or_create_by_foo).attributes.should == %w(foo)
|
111
|
+
end
|
112
|
+
|
113
|
+
should "parse multiple attributes" do
|
114
|
+
DynamicFinder.new(:find_or_create_by_foo_and_bar).attributes.should == %w(foo bar)
|
115
|
+
end
|
116
|
+
|
117
|
+
should "set finder to :first" do
|
118
|
+
DynamicFinder.new(:find_or_create_by_foo).finder.should == :first
|
119
|
+
end
|
120
|
+
|
121
|
+
should "set instantiator to new" do
|
122
|
+
DynamicFinder.new(:find_or_create_by_foo).instantiator.should == :create
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|