mongo_mapper 0.5.8 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/bin/mmconsole +10 -5
- data/lib/mongo_mapper.rb +28 -5
- data/lib/mongo_mapper/associations.rb +113 -12
- data/lib/mongo_mapper/associations/base.rb +24 -9
- data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +1 -1
- data/lib/mongo_mapper/associations/belongs_to_proxy.rb +1 -1
- data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +2 -2
- data/lib/mongo_mapper/associations/many_documents_proxy.rb +7 -2
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +22 -36
- data/lib/mongo_mapper/associations/proxy.rb +11 -6
- data/lib/mongo_mapper/document.rb +37 -21
- data/lib/mongo_mapper/embedded_document.rb +32 -18
- data/lib/mongo_mapper/finder_options.rb +19 -12
- data/lib/mongo_mapper/rails_compatibility/document.rb +4 -0
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +4 -0
- data/lib/mongo_mapper/support.rb +18 -46
- data/lib/mongo_mapper/types.rb +64 -0
- data/lib/mongo_mapper/validations.rb +13 -43
- data/mongo_mapper.gemspec +13 -10
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +10 -10
- data/test/functional/associations/test_belongs_to_proxy.rb +29 -30
- data/test/functional/associations/test_many_documents_as_proxy.rb +13 -12
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +34 -34
- data/test/functional/associations/test_many_embedded_proxy.rb +69 -74
- data/test/functional/associations/test_many_polymorphic_proxy.rb +10 -10
- data/test/functional/associations/test_many_proxy.rb +14 -15
- data/test/functional/test_associations.rb +4 -4
- data/test/functional/test_binary.rb +1 -1
- data/test/functional/test_dirty.rb +6 -6
- data/test/functional/test_document.rb +76 -69
- data/test/functional/test_embedded_document.rb +15 -14
- data/test/functional/test_pagination.rb +9 -1
- data/test/functional/test_string_id_compatibility.rb +72 -0
- data/test/functional/test_validations.rb +56 -7
- data/test/models.rb +7 -7
- data/test/test_helper.rb +2 -5
- data/test/unit/test_association_base.rb +6 -1
- data/test/unit/test_document.rb +22 -13
- data/test/unit/test_embedded_document.rb +47 -5
- data/test/unit/test_finder_options.rb +22 -3
- data/test/unit/test_mongo_mapper.rb +65 -0
- data/test/unit/test_rails_compatibility.rb +14 -0
- data/test/unit/test_support.rb +45 -0
- metadata +9 -6
- data/test/unit/test_mongomapper.rb +0 -28
@@ -0,0 +1,64 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Types
|
3
|
+
class Binary
|
4
|
+
def self.to_mongo(value)
|
5
|
+
if value.is_a?(ByteBuffer)
|
6
|
+
value
|
7
|
+
else
|
8
|
+
value.nil? ? nil : ByteBuffer.new(value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_mongo(value)
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Boolean
|
18
|
+
def self.to_mongo(value)
|
19
|
+
if value.is_a?(Boolean)
|
20
|
+
value
|
21
|
+
else
|
22
|
+
['true', 't', '1'].include?(value.to_s.downcase)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_mongo(value)
|
27
|
+
!!value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ObjectId
|
32
|
+
def self.to_mongo(value)
|
33
|
+
if value.nil?
|
34
|
+
nil
|
35
|
+
elsif value.is_a?(Mongo::ObjectID)
|
36
|
+
value
|
37
|
+
else
|
38
|
+
Mongo::ObjectID.from_string(value.to_s)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.from_mongo(value)
|
43
|
+
value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# This allows using just Boolean when defining
|
48
|
+
# keys instead of MongoMapper::Types::Boolean
|
49
|
+
module Lookup
|
50
|
+
def const_missing(name)
|
51
|
+
if MongoMapper::Types.const_defined?(name)
|
52
|
+
MongoMapper::Types.const_get(name)
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# This was required to get in front of ActiveSupports Class#const_missing
|
62
|
+
Class.instance_eval do
|
63
|
+
include MongoMapper::Types::Lookup
|
64
|
+
end
|
@@ -4,67 +4,37 @@ module MongoMapper
|
|
4
4
|
def validates_uniqueness_of(*args)
|
5
5
|
add_validations(args, MongoMapper::Validations::ValidatesUniquenessOf)
|
6
6
|
end
|
7
|
-
|
8
|
-
def validates_exclusion_of(*args)
|
9
|
-
add_validations(args, MongoMapper::Validations::ValidatesExclusionOf)
|
10
|
-
end
|
11
|
-
|
12
|
-
def validates_inclusion_of(*args)
|
13
|
-
add_validations(args, MongoMapper::Validations::ValidatesInclusionOf)
|
14
|
-
end
|
15
7
|
end
|
16
8
|
|
17
9
|
class ValidatesUniquenessOf < Validatable::ValidationBase
|
18
|
-
option :scope
|
19
|
-
|
10
|
+
option :scope, :case_sensitive
|
11
|
+
default :case_sensitive => true
|
12
|
+
|
20
13
|
def valid?(instance)
|
21
14
|
value = instance[attribute]
|
22
15
|
return true if allow_blank && value.blank?
|
23
|
-
|
24
|
-
doc
|
16
|
+
base_conditions = case_sensitive ? {self.attribute => value} : {}
|
17
|
+
doc = instance.class.first(base_conditions.merge(scope_conditions(instance)).merge(where_conditions(instance)))
|
18
|
+
doc.nil? || instance._id == doc._id
|
25
19
|
end
|
26
20
|
|
27
21
|
def message(instance)
|
28
22
|
super || "has already been taken"
|
29
23
|
end
|
30
|
-
|
24
|
+
|
31
25
|
def scope_conditions(instance)
|
32
26
|
return {} unless scope
|
33
27
|
Array(scope).inject({}) do |conditions, key|
|
34
28
|
conditions.merge(key => instance[key])
|
35
29
|
end
|
36
30
|
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class ValidatesExclusionOf < Validatable::ValidationBase
|
40
|
-
required_option :within
|
41
|
-
|
42
|
-
def valid?(instance)
|
43
|
-
value = instance[attribute]
|
44
|
-
return true if allow_nil && value.nil?
|
45
|
-
return true if allow_blank && value.blank?
|
46
|
-
|
47
|
-
!within.include?(instance[attribute])
|
48
|
-
end
|
49
|
-
|
50
|
-
def message(instance)
|
51
|
-
super || "is reserved"
|
52
|
-
end
|
53
|
-
end
|
54
31
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return true if allow_blank && value.blank?
|
62
|
-
|
63
|
-
within.include?(value)
|
64
|
-
end
|
65
|
-
|
66
|
-
def message(instance)
|
67
|
-
super || "is not in the list"
|
32
|
+
def where_conditions(instance)
|
33
|
+
conditions = {}
|
34
|
+
unless case_sensitive
|
35
|
+
conditions.merge!({'$where' => "this.#{attribute}.toLowerCase() == '#{instance[attribute].downcase}'"})
|
36
|
+
end
|
37
|
+
conditions
|
68
38
|
end
|
69
39
|
end
|
70
40
|
end
|
data/mongo_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_mapper}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Nunemaker"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-14}
|
13
13
|
s.default_executable = %q{mmconsole}
|
14
14
|
s.email = %q{nunemaker@gmail.com}
|
15
15
|
s.executables = ["mmconsole"]
|
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
"lib/mongo_mapper/serialization.rb",
|
51
51
|
"lib/mongo_mapper/serializers/json_serializer.rb",
|
52
52
|
"lib/mongo_mapper/support.rb",
|
53
|
+
"lib/mongo_mapper/types.rb",
|
53
54
|
"lib/mongo_mapper/validations.rb",
|
54
55
|
"mongo_mapper.gemspec",
|
55
56
|
"specs.watchr",
|
@@ -70,6 +71,7 @@ Gem::Specification.new do |s|
|
|
70
71
|
"test/functional/test_logger.rb",
|
71
72
|
"test/functional/test_pagination.rb",
|
72
73
|
"test/functional/test_rails_compatibility.rb",
|
74
|
+
"test/functional/test_string_id_compatibility.rb",
|
73
75
|
"test/functional/test_validations.rb",
|
74
76
|
"test/models.rb",
|
75
77
|
"test/support/custom_matchers.rb",
|
@@ -82,7 +84,7 @@ Gem::Specification.new do |s|
|
|
82
84
|
"test/unit/test_embedded_document.rb",
|
83
85
|
"test/unit/test_finder_options.rb",
|
84
86
|
"test/unit/test_key.rb",
|
85
|
-
"test/unit/
|
87
|
+
"test/unit/test_mongo_mapper.rb",
|
86
88
|
"test/unit/test_observing.rb",
|
87
89
|
"test/unit/test_pagination.rb",
|
88
90
|
"test/unit/test_rails_compatibility.rb",
|
@@ -113,6 +115,7 @@ Gem::Specification.new do |s|
|
|
113
115
|
"test/functional/test_logger.rb",
|
114
116
|
"test/functional/test_pagination.rb",
|
115
117
|
"test/functional/test_rails_compatibility.rb",
|
118
|
+
"test/functional/test_string_id_compatibility.rb",
|
116
119
|
"test/functional/test_validations.rb",
|
117
120
|
"test/models.rb",
|
118
121
|
"test/support/custom_matchers.rb",
|
@@ -125,7 +128,7 @@ Gem::Specification.new do |s|
|
|
125
128
|
"test/unit/test_embedded_document.rb",
|
126
129
|
"test/unit/test_finder_options.rb",
|
127
130
|
"test/unit/test_key.rb",
|
128
|
-
"test/unit/
|
131
|
+
"test/unit/test_mongo_mapper.rb",
|
129
132
|
"test/unit/test_observing.rb",
|
130
133
|
"test/unit/test_pagination.rb",
|
131
134
|
"test/unit/test_rails_compatibility.rb",
|
@@ -142,28 +145,28 @@ Gem::Specification.new do |s|
|
|
142
145
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
143
146
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
144
147
|
s.add_runtime_dependency(%q<mongo>, ["= 0.16"])
|
145
|
-
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.
|
148
|
+
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
146
149
|
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
147
150
|
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
148
151
|
s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
|
149
|
-
s.add_development_dependency(%q<mocha>, ["= 0.9.
|
152
|
+
s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
|
150
153
|
else
|
151
154
|
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
152
155
|
s.add_dependency(%q<mongo>, ["= 0.16"])
|
153
|
-
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.
|
156
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
154
157
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
155
158
|
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
156
159
|
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
157
|
-
s.add_dependency(%q<mocha>, ["= 0.9.
|
160
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
158
161
|
end
|
159
162
|
else
|
160
163
|
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
161
164
|
s.add_dependency(%q<mongo>, ["= 0.16"])
|
162
|
-
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.
|
165
|
+
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
163
166
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
164
167
|
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
165
168
|
s.add_dependency(%q<timecop>, ["= 0.3.1"])
|
166
|
-
s.add_dependency(%q<mocha>, ["= 0.9.
|
169
|
+
s.add_dependency(%q<mocha>, ["= 0.9.8"])
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
@@ -19,11 +19,11 @@ class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
|
|
19
19
|
status.target = project
|
20
20
|
status.save.should be_true
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
status = status.reload
|
23
|
+
status.target.nil?.should be_false
|
24
|
+
status.target_id.should == project._id
|
25
|
+
status.target_type.should == "Project"
|
26
|
+
status.target.name.should == "mongomapper"
|
27
27
|
end
|
28
28
|
|
29
29
|
should "unset the association" do
|
@@ -32,11 +32,11 @@ class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
|
|
32
32
|
status.target = project
|
33
33
|
status.save.should be_true
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
status = status.reload
|
36
|
+
status.target = nil
|
37
|
+
status.target_type.nil?.should be_true
|
38
|
+
status.target_id.nil?.should be_true
|
39
|
+
status.target.nil?.should be_true
|
40
40
|
end
|
41
41
|
|
42
42
|
context "association id set but document not found" do
|
@@ -2,48 +2,47 @@ require 'test_helper'
|
|
2
2
|
require 'models'
|
3
3
|
|
4
4
|
class BelongsToProxyTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
|
7
|
-
|
5
|
+
def setup
|
6
|
+
@post_class = Class.new do
|
7
|
+
include MongoMapper::Document
|
8
|
+
end
|
9
|
+
|
10
|
+
@comment_class = Class.new do
|
11
|
+
include MongoMapper::Document
|
12
|
+
key :post_id, String
|
13
|
+
end
|
14
|
+
@comment_class.belongs_to :post, :class => @post_class
|
15
|
+
|
16
|
+
@post_class.collection.remove
|
17
|
+
@comment_class.collection.remove
|
8
18
|
end
|
9
19
|
|
10
20
|
should "default to nil" do
|
11
|
-
|
12
|
-
status.project.nil?.should == true
|
13
|
-
status.project.inspect.should == 'nil'
|
21
|
+
@comment_class.new.post.nil?.should be_true
|
14
22
|
end
|
15
23
|
|
16
24
|
should "be able to replace the association" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
status.save.should be_true
|
25
|
+
post = @post_class.new(:name => 'mongomapper')
|
26
|
+
comment = @comment_class.new(:name => 'Foo!', :post => post)
|
27
|
+
comment.save.should be_true
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
comment = comment.reload
|
30
|
+
comment.post.should == post
|
31
|
+
comment.post.nil?.should be_false
|
25
32
|
end
|
26
33
|
|
27
34
|
should "unset the association" do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
status.save.should be_true
|
35
|
+
post = @post_class.new(:name => 'mongomapper')
|
36
|
+
comment = @comment_class.new(:name => 'Foo!', :post => post)
|
37
|
+
comment.save.should be_true
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
from_db.project.inspect.should == 'nil'
|
39
|
+
comment = comment.reload
|
40
|
+
comment.post = nil
|
41
|
+
comment.post.nil?.should be_true
|
37
42
|
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
should "return nil instead of raising error" do
|
45
|
-
@status.project.nil?.should be_true
|
46
|
-
@status.project.inspect.should == 'nil'
|
47
|
-
end
|
44
|
+
should "return nil if id set but document not found" do
|
45
|
+
id = Mongo::ObjectID.new
|
46
|
+
@comment_class.new(:name => 'Foo', :post_id => id).post.nil?.should be_true
|
48
47
|
end
|
49
48
|
end
|
@@ -35,19 +35,20 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
|
|
35
35
|
PostComment.new(:body => 'baz')
|
36
36
|
]
|
37
37
|
}.should change { PostComment.count }.by(3)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
|
39
|
+
post = post.reload
|
40
|
+
post.comments.size.should == 3
|
41
|
+
bodies = post.comments.collect(&:body)
|
42
|
+
bodies.should include('foo')
|
43
|
+
bodies.should include('bar')
|
44
|
+
bodies.should include('baz')
|
44
45
|
end
|
45
46
|
|
46
47
|
context "build" do
|
47
48
|
should "assign foreign key" do
|
48
49
|
post = Post.new
|
49
50
|
comment = post.comments.build
|
50
|
-
comment.commentable_id.should == post.
|
51
|
+
comment.commentable_id.should == post._id
|
51
52
|
end
|
52
53
|
|
53
54
|
should "assign _type" do
|
@@ -67,7 +68,7 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
|
|
67
68
|
should "assign foreign key" do
|
68
69
|
post = Post.new
|
69
70
|
comment = post.comments.create
|
70
|
-
comment.commentable_id.should == post.
|
71
|
+
comment.commentable_id.should == post._id
|
71
72
|
end
|
72
73
|
|
73
74
|
should "assign _type" do
|
@@ -166,25 +167,25 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
|
|
166
167
|
|
167
168
|
context "with one id" do
|
168
169
|
should "work for id in association" do
|
169
|
-
@post.comments.find(@comment2.
|
170
|
+
@post.comments.find(@comment2._id).should == @comment2
|
170
171
|
end
|
171
172
|
|
172
173
|
should "not work for id not in association" do
|
173
174
|
lambda {
|
174
|
-
@post.comments.find(@comment5.
|
175
|
+
@post.comments.find!(@comment5._id)
|
175
176
|
}.should raise_error(MongoMapper::DocumentNotFound)
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
180
|
context "with multiple ids" do
|
180
181
|
should "work for ids in association" do
|
181
|
-
posts = @post.comments.find(@comment1.
|
182
|
+
posts = @post.comments.find!(@comment1._id, @comment2._id)
|
182
183
|
posts.should == [@comment1, @comment2]
|
183
184
|
end
|
184
185
|
|
185
186
|
should "not work for ids not in association" do
|
186
187
|
lambda {
|
187
|
-
@post.comments.find(@comment1.
|
188
|
+
@post.comments.find!(@comment1._id, @comment2._id, @comment4._id)
|
188
189
|
}.should raise_error(MongoMapper::DocumentNotFound)
|
189
190
|
end
|
190
191
|
end
|
@@ -24,9 +24,9 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
|
|
24
24
|
catalog.medias = [Video.new("file" => "video.mpg", "length" => 3600)]
|
25
25
|
catalog.save.should be_true
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
catalog = catalog.reload
|
28
|
+
catalog.medias.size.should == 1
|
29
|
+
catalog.medias[0].file.should == "video.mpg"
|
30
30
|
end
|
31
31
|
|
32
32
|
should "store different associations" do
|
@@ -38,15 +38,15 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
|
|
38
38
|
]
|
39
39
|
catalog.save.should be_true
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
catalog = catalog.reload
|
42
|
+
catalog.medias.size.should == 3
|
43
|
+
catalog.medias[0].file.should == "video.mpg"
|
44
|
+
catalog.medias[0].length.should == 3600
|
45
|
+
catalog.medias[1].file.should == "music.mp3"
|
46
|
+
catalog.medias[1].bitrate.should == "128kbps"
|
47
|
+
catalog.medias[2].file.should == "image.png"
|
48
|
+
catalog.medias[2].width.should == 800
|
49
|
+
catalog.medias[2].height.should == 600
|
50
50
|
end
|
51
51
|
|
52
52
|
context "With modularized models" do
|
@@ -75,16 +75,16 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
|
|
75
75
|
fleet.transports[2].year.should == 2008
|
76
76
|
fleet.save.should be_true
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
78
|
+
fleet = fleet.reload
|
79
|
+
fleet.transports.size.should == 3
|
80
|
+
fleet.transports[0].license_plate.should == "GGG123"
|
81
|
+
fleet.transports[0].icu.should be_true
|
82
|
+
fleet.transports[1].license_plate.should == "ABC123"
|
83
|
+
fleet.transports[1].model.should == "VW Golf"
|
84
|
+
fleet.transports[1].year.should == 2001
|
85
|
+
fleet.transports[2].license_plate.should == "DEF123"
|
86
|
+
fleet.transports[2].model.should == "Honda Accord"
|
87
|
+
fleet.transports[2].year.should == 2008
|
88
88
|
end
|
89
89
|
|
90
90
|
should "default reader to empty array" do
|
@@ -104,9 +104,9 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
|
|
104
104
|
fleet.transports = [TrModels::Car.new("license_plate" => "DCU2013", "model" => "Honda Civic")]
|
105
105
|
fleet.save.should be_true
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
fleet = fleet.reload
|
108
|
+
fleet.transports.size.should == 1
|
109
|
+
fleet.transports[0].license_plate.should == "DCU2013"
|
110
110
|
end
|
111
111
|
|
112
112
|
should "store different associations" do
|
@@ -118,15 +118,15 @@ class ManyEmbeddedPolymorphicProxyTest < Test::Unit::TestCase
|
|
118
118
|
]
|
119
119
|
fleet.save.should be_true
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
121
|
+
fleet = fleet.reload
|
122
|
+
fleet.transports.size.should == 3
|
123
|
+
fleet.transports[0].license_plate.should == "ABC1223"
|
124
|
+
fleet.transports[0].model.should == "Honda Civic"
|
125
|
+
fleet.transports[0].year.should == 2003
|
126
|
+
fleet.transports[1].license_plate.should == "XYZ9090"
|
127
|
+
fleet.transports[1].max_passengers.should == 51
|
128
|
+
fleet.transports[2].license_plate.should == "HDD3030"
|
129
|
+
fleet.transports[2].icu.should == true
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|