jmonteiro-mongo_mapper 0.1.2 → 0.1.4
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/VERSION +1 -1
- data/lib/mongo_mapper.rb +3 -4
- data/lib/mongo_mapper/document.rb +6 -0
- data/test/functional/test_document.rb +10 -1
- data/test/unit/test_keys.rb +28 -28
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/mongo_mapper.rb
CHANGED
@@ -100,11 +100,10 @@ module MongoMapper
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
require 'mongo_mapper/finder_options'
|
104
103
|
require 'mongo_mapper/support'
|
105
|
-
require 'mongo_mapper/
|
106
|
-
|
104
|
+
require 'mongo_mapper/finder_options'
|
107
105
|
require 'mongo_mapper/dynamic_finder'
|
106
|
+
require 'mongo_mapper/descendant_appends'
|
108
107
|
|
109
108
|
require 'mongo_mapper/plugins'
|
110
109
|
require 'mongo_mapper/plugins/associations'
|
@@ -123,5 +122,5 @@ require 'mongo_mapper/plugins/rails'
|
|
123
122
|
require 'mongo_mapper/plugins/serialization'
|
124
123
|
require 'mongo_mapper/plugins/validations'
|
125
124
|
|
126
|
-
require 'mongo_mapper/embedded_document'
|
127
125
|
require 'mongo_mapper/document'
|
126
|
+
require 'mongo_mapper/embedded_document'
|
@@ -338,6 +338,12 @@ module MongoMapper
|
|
338
338
|
end
|
339
339
|
|
340
340
|
def save(options={})
|
341
|
+
# Support AR style save calls save(false) so ORM agnostic libs can
|
342
|
+
# successfully call save without validations, regardless of if they
|
343
|
+
# expect mongo_mapper's style of doing it, or they expect
|
344
|
+
# ActiveRecord's style of doing it.
|
345
|
+
options = {:validate => options} if options.is_a?(TrueClass) || options.is_a?(FalseClass)
|
346
|
+
|
341
347
|
options.reverse_merge!(:validate => true)
|
342
348
|
perform_validations = options.delete(:validate)
|
343
349
|
!perform_validations || valid? ? create_or_update(options) : false
|
@@ -727,8 +727,17 @@ class DocumentTest < Test::Unit::TestCase
|
|
727
727
|
doc.save(:validate => false)
|
728
728
|
@document.count.should == 1
|
729
729
|
end
|
730
|
+
|
731
|
+
context 'calling save with the ActiveRecord style of turning validations off' do
|
732
|
+
should 'insert an invalid document' do
|
733
|
+
doc = @document.new
|
734
|
+
doc.expects(:valid?).never
|
735
|
+
doc.save(false)
|
736
|
+
@document.count.should == 1
|
737
|
+
end
|
738
|
+
end
|
730
739
|
end
|
731
|
-
|
740
|
+
|
732
741
|
context "#save (with options)" do
|
733
742
|
setup do
|
734
743
|
MongoMapper.ensured_indexes = []
|
data/test/unit/test_keys.rb
CHANGED
@@ -20,49 +20,49 @@ class FooType < Struct.new(:bar)
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class KeyTest < Test::Unit::TestCase
|
23
|
-
include MongoMapper
|
23
|
+
include MongoMapper::Plugins::Keys
|
24
24
|
|
25
25
|
context "Initializing a new key" do
|
26
26
|
should "allow setting the name" do
|
27
|
-
|
27
|
+
Key.new(:foo, String).name.should == 'foo'
|
28
28
|
end
|
29
29
|
|
30
30
|
should "allow setting the type" do
|
31
|
-
|
31
|
+
Key.new(:foo, Integer).type.should be(Integer)
|
32
32
|
end
|
33
33
|
|
34
34
|
should "allow setting options" do
|
35
|
-
|
35
|
+
Key.new(:foo, Integer, :required => true).options[:required].should be(true)
|
36
36
|
end
|
37
37
|
|
38
38
|
should "default options to {}" do
|
39
|
-
|
39
|
+
Key.new(:foo, Integer, nil).options.should == {}
|
40
40
|
end
|
41
41
|
|
42
42
|
should "symbolize option keys" do
|
43
|
-
|
43
|
+
Key.new(:foo, Integer, 'required' => true).options[:required].should be(true)
|
44
44
|
end
|
45
45
|
|
46
46
|
should "work with just name" do
|
47
|
-
key =
|
47
|
+
key = Key.new(:foo)
|
48
48
|
key.name.should == 'foo'
|
49
49
|
end
|
50
50
|
|
51
51
|
should "work with name and type" do
|
52
|
-
key =
|
52
|
+
key = Key.new(:foo, String)
|
53
53
|
key.name.should == 'foo'
|
54
54
|
key.type.should == String
|
55
55
|
end
|
56
56
|
|
57
57
|
should "work with name, type, and options" do
|
58
|
-
key =
|
58
|
+
key = Key.new(:foo, String, :required => true)
|
59
59
|
key.name.should == 'foo'
|
60
60
|
key.type.should == String
|
61
61
|
key.options[:required].should be_true
|
62
62
|
end
|
63
63
|
|
64
64
|
should "work with name and options" do
|
65
|
-
key =
|
65
|
+
key = Key.new(:foo, :required => true)
|
66
66
|
key.name.should == 'foo'
|
67
67
|
key.options[:required].should be_true
|
68
68
|
end
|
@@ -70,62 +70,62 @@ class KeyTest < Test::Unit::TestCase
|
|
70
70
|
|
71
71
|
context "A key" do
|
72
72
|
should "be equal to another key with same name and type" do
|
73
|
-
|
73
|
+
Key.new(:name, String).should == Key.new(:name, String)
|
74
74
|
end
|
75
75
|
|
76
76
|
should "not be equal to another key with different name" do
|
77
|
-
|
77
|
+
Key.new(:name, String).should_not == Key.new(:foo, String)
|
78
78
|
end
|
79
79
|
|
80
80
|
should "not be equal to another key with different type" do
|
81
|
-
|
81
|
+
Key.new(:name, String).should_not == Key.new(:name, Integer)
|
82
82
|
end
|
83
83
|
|
84
84
|
should "know if it is a embedded_document" do
|
85
|
-
|
85
|
+
Key.new(:name, EDoc()).embeddable?.should be_true
|
86
86
|
end
|
87
87
|
|
88
88
|
should "know if it is not a embedded_document" do
|
89
|
-
|
89
|
+
Key.new(:name, String).embeddable?.should be_false
|
90
90
|
end
|
91
91
|
|
92
92
|
should "know if it is a number" do
|
93
|
-
|
94
|
-
|
93
|
+
Key.new(:age, Integer).number?.should be_true
|
94
|
+
Key.new(:age, Float).number?.should be_true
|
95
95
|
end
|
96
96
|
|
97
97
|
should "know if it is not a number" do
|
98
|
-
|
98
|
+
Key.new(:age, String).number?.should be_false
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
context "setting a value with a custom type" do
|
103
103
|
should "correctly typecast" do
|
104
|
-
key =
|
104
|
+
key = Key.new(:foo, FooType)
|
105
105
|
key.set("something").should == 'to_mongo'
|
106
106
|
end
|
107
107
|
|
108
108
|
should "correctly typecast if object of that type is given" do
|
109
|
-
key =
|
109
|
+
key = Key.new(:foo, FooType)
|
110
110
|
key.set(FooType.new('something')).should == 'to_mongo'
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
context "getting a value with a custom type" do
|
115
115
|
should "use #from_mongo to convert back to custom type" do
|
116
|
-
key =
|
116
|
+
key = Key.new(:foo, FooType)
|
117
117
|
key.get('something').should == 'from_mongo'
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
context "getting a value" do
|
122
122
|
should "work with a type" do
|
123
|
-
key =
|
123
|
+
key = Key.new(:foo, String)
|
124
124
|
key.get('bar').should == 'bar'
|
125
125
|
end
|
126
126
|
|
127
127
|
should "work without type" do
|
128
|
-
key =
|
128
|
+
key = Key.new(:foo)
|
129
129
|
key.get([1, '2']).should == [1, '2']
|
130
130
|
key.get(false).should == false
|
131
131
|
key.get({}).should == {}
|
@@ -133,13 +133,13 @@ class KeyTest < Test::Unit::TestCase
|
|
133
133
|
|
134
134
|
context "for a embedded_document" do
|
135
135
|
should "default to nil" do
|
136
|
-
key =
|
136
|
+
key = Key.new(:foo, Address)
|
137
137
|
key.get(nil).should be_nil
|
138
138
|
end
|
139
139
|
|
140
140
|
should "return instance if instance" do
|
141
141
|
address = Address.new(:city => 'South Bend', :state => 'IN', :zip => 46544)
|
142
|
-
key =
|
142
|
+
key = Key.new(:foo, Address)
|
143
143
|
key.get(address).should == address
|
144
144
|
end
|
145
145
|
end
|
@@ -147,7 +147,7 @@ class KeyTest < Test::Unit::TestCase
|
|
147
147
|
|
148
148
|
context "getting a value with a default set" do
|
149
149
|
setup do
|
150
|
-
@key =
|
150
|
+
@key = Key.new(:foo, String, :default => 'baz')
|
151
151
|
end
|
152
152
|
|
153
153
|
should "return default value if value nil" do
|
@@ -159,11 +159,11 @@ class KeyTest < Test::Unit::TestCase
|
|
159
159
|
end
|
160
160
|
|
161
161
|
should "work with Boolean type and false value" do
|
162
|
-
|
162
|
+
Key.new(:active, Boolean, :default => false).get(nil).should be_false
|
163
163
|
end
|
164
164
|
|
165
165
|
should "work with Boolean type and true value" do
|
166
|
-
|
166
|
+
Key.new(:active, Boolean, :default => true).get(nil).should be_true
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end # KeyTest
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jmonteiro-mongo_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-15 00:00:00 -02:00
|
14
14
|
default_executable: mmconsole
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|