mongoid 0.9.2 → 0.9.3

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.
Files changed (51) hide show
  1. data/README.textile +17 -2
  2. data/VERSION +1 -1
  3. data/lib/mongoid/associations.rb +71 -5
  4. data/lib/mongoid/associations/options.rb +8 -3
  5. data/lib/mongoid/associations/relates_to_many.rb +44 -0
  6. data/lib/mongoid/associations/relates_to_one.rb +43 -0
  7. data/mongoid.gemspec +8 -2
  8. data/spec/integration/mongoid/document_spec.rb +41 -5
  9. data/spec/spec_helper.rb +4 -0
  10. data/spec/unit/mongoid/associations/accessor_spec.rb +1 -1
  11. data/spec/unit/mongoid/associations/belongs_to_spec.rb +1 -1
  12. data/spec/unit/mongoid/associations/decorator_spec.rb +1 -1
  13. data/spec/unit/mongoid/associations/has_many_spec.rb +1 -1
  14. data/spec/unit/mongoid/associations/has_one_spec.rb +1 -1
  15. data/spec/unit/mongoid/associations/options_spec.rb +14 -1
  16. data/spec/unit/mongoid/associations/relates_to_many_spec.rb +54 -0
  17. data/spec/unit/mongoid/associations/relates_to_one_spec.rb +48 -0
  18. data/spec/unit/mongoid/associations_spec.rb +23 -1
  19. data/spec/unit/mongoid/attributes_spec.rb +1 -1
  20. data/spec/unit/mongoid/commands/create_spec.rb +1 -1
  21. data/spec/unit/mongoid/commands/delete_all_spec.rb +1 -1
  22. data/spec/unit/mongoid/commands/delete_spec.rb +1 -1
  23. data/spec/unit/mongoid/commands/destroy_all_spec.rb +1 -1
  24. data/spec/unit/mongoid/commands/destroy_spec.rb +1 -1
  25. data/spec/unit/mongoid/commands/save_spec.rb +1 -1
  26. data/spec/unit/mongoid/commands/validate_spec.rb +1 -1
  27. data/spec/unit/mongoid/commands_spec.rb +1 -1
  28. data/spec/unit/mongoid/criteria_spec.rb +1 -1
  29. data/spec/unit/mongoid/document_spec.rb +1 -1
  30. data/spec/unit/mongoid/dynamic_finder_spec.rb +1 -1
  31. data/spec/unit/mongoid/extensions/array/assimilation_spec.rb +1 -1
  32. data/spec/unit/mongoid/extensions/array/conversions_spec.rb +1 -1
  33. data/spec/unit/mongoid/extensions/array/parentization_spec.rb +1 -1
  34. data/spec/unit/mongoid/extensions/boolean/conversions_spec.rb +1 -1
  35. data/spec/unit/mongoid/extensions/date/conversions_spec.rb +1 -1
  36. data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +10 -5
  37. data/spec/unit/mongoid/extensions/float/conversions_spec.rb +1 -1
  38. data/spec/unit/mongoid/extensions/hash/accessors_spec.rb +1 -1
  39. data/spec/unit/mongoid/extensions/hash/assimilation_spec.rb +1 -1
  40. data/spec/unit/mongoid/extensions/hash/conversions_spec.rb +1 -1
  41. data/spec/unit/mongoid/extensions/integer/conversions_spec.rb +1 -1
  42. data/spec/unit/mongoid/extensions/object/conversions_spec.rb +1 -1
  43. data/spec/unit/mongoid/extensions/string/conversions_spec.rb +1 -1
  44. data/spec/unit/mongoid/extensions/string/inflections_spec.rb +1 -1
  45. data/spec/unit/mongoid/extensions/symbol/inflections_spec.rb +1 -1
  46. data/spec/unit/mongoid/extensions/time/conversions_spec.rb +1 -1
  47. data/spec/unit/mongoid/field_spec.rb +1 -1
  48. data/spec/unit/mongoid/finders_spec.rb +1 -1
  49. data/spec/unit/mongoid/timestamps_spec.rb +1 -1
  50. data/spec/unit/mongoid/versioning_spec.rb +1 -1
  51. metadata +8 -2
@@ -19,8 +19,11 @@
19
19
  </p>
20
20
 
21
21
  <p>
22
- Note API changes will be frequent until the 1.0 release, and do not expect
23
- the gem to be of full production quality until that point.
22
+ Note API changes will be frequent until 1.0, releases will be frequent, and
23
+ backwards compatibility will not be supported. Do not expect the gem to be of full
24
+ production quality until that point. However, once 1.0 is released I will be providing
25
+ backwards compatibility through each minor version upgrade, as well as detailed
26
+ release notes and documentation with each release.
24
27
  </p>
25
28
 
26
29
  <h2>Mongoid in Action</h2>
@@ -36,10 +39,15 @@ Example of a simple domain model:
36
39
  <pre>
37
40
  class Person < Mongoid::Document
38
41
  include Mongoid::Versioning
42
+
39
43
  field :title
40
44
  field :age, :type => Integer, :default => 0
45
+
41
46
  has_many :addresses
42
47
  has_one :name
48
+
49
+ relates_to_one :game
50
+ relates_to_many :posts
43
51
  end
44
52
 
45
53
  class Address < Mongoid::Document
@@ -56,6 +64,13 @@ Example of a simple domain model:
56
64
  field :last_name
57
65
  belongs_to :person, :inverse_of => :name
58
66
  end
67
+
68
+ class Post < Mongoid::Document
69
+ include Mongoid::Timestamps
70
+ field :title
71
+ field :text
72
+ field :tags, :type => Array
73
+ end
59
74
  </pre>
60
75
 
61
76
  Mongoid supports all the basic ActiveRecord creation and persistence methods.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
@@ -3,6 +3,8 @@ require "mongoid/associations/accessor"
3
3
  require "mongoid/associations/belongs_to"
4
4
  require "mongoid/associations/has_many"
5
5
  require "mongoid/associations/has_one"
6
+ require "mongoid/associations/relates_to_many"
7
+ require "mongoid/associations/relates_to_one"
6
8
 
7
9
  module Mongoid # :nodoc:
8
10
  module Associations #:nodoc:
@@ -14,9 +16,15 @@ module Mongoid # :nodoc:
14
16
  end
15
17
 
16
18
  module InstanceMethods
19
+ # Returns the associations for the +Document+.
17
20
  def associations
18
21
  self.class.associations
19
22
  end
23
+
24
+ # Updates all the relational associations for the document.
25
+ def update_associations(name)
26
+ send(name).each { |doc| doc.save }
27
+ end
20
28
  end
21
29
 
22
30
  module ClassMethods
@@ -46,7 +54,10 @@ module Mongoid # :nodoc:
46
54
  raise InvalidOptionsError.new("Options for belongs_to association must include :inverse_of")
47
55
  end
48
56
  @embedded = true
49
- add_association(Associations::BelongsTo, Associations::Options.new(options.merge(:name => name)))
57
+ add_association(
58
+ Associations::BelongsTo,
59
+ Associations::Options.new(options.merge(:name => name))
60
+ )
50
61
  end
51
62
 
52
63
  # Adds the association from a parent document to its children. The name
@@ -67,7 +78,10 @@ module Mongoid # :nodoc:
67
78
  # belongs_to :person, :inverse_of => :addresses
68
79
  # end
69
80
  def has_many(name, options = {})
70
- add_association(Associations::HasMany, Associations::Options.new(options.merge(:name => name)))
81
+ add_association(
82
+ Associations::HasMany,
83
+ Associations::Options.new(options.merge(:name => name))
84
+ )
71
85
  end
72
86
 
73
87
  # Adds the association from a parent document to its child. The name
@@ -88,7 +102,10 @@ module Mongoid # :nodoc:
88
102
  # belongs_to :person
89
103
  # end
90
104
  def has_one(name, options = {})
91
- add_association(Associations::HasOne, Associations::Options.new(options.merge(:name => name)))
105
+ add_association(
106
+ Associations::HasOne,
107
+ Associations::Options.new(options.merge(:name => name))
108
+ )
92
109
  end
93
110
 
94
111
  # Returns the macro associated with the supplied association name. This
@@ -106,7 +123,52 @@ module Mongoid # :nodoc:
106
123
  association ? association.macro : nil
107
124
  end
108
125
 
109
- private
126
+ # Adds a relational association from the Document to a Document in
127
+ # another database or collection.
128
+ #
129
+ # Options:
130
+ #
131
+ # name: A +Symbol+ that is the related class name.
132
+ #
133
+ # Example:
134
+ #
135
+ # class Person < Mongoid::Document
136
+ # relates_to_one :game
137
+ # end
138
+ #
139
+ def relates_to_one(name, options = {})
140
+ field "#{name.to_s}_id"
141
+ index "#{name.to_s}_id"
142
+ add_association(
143
+ Associations::RelatesToOne,
144
+ Associations::Options.new(options.merge(:name => name))
145
+ )
146
+ end
147
+
148
+ # Adds a relational association from the Document to many Documents in
149
+ # another database or collection.
150
+ #
151
+ # Options:
152
+ #
153
+ # name: A +Symbol+ that is the related class name pluralized.
154
+ #
155
+ # Example:
156
+ #
157
+ # class Person < Mongoid::Document
158
+ # relates_to_many :posts
159
+ # end
160
+ #
161
+ def relates_to_many(name, options = {})
162
+ add_association(
163
+ Associations::RelatesToMany,
164
+ Associations::Options.new(options.merge(:name => name))
165
+ )
166
+ before_save do |document|
167
+ document.update_associations(name)
168
+ end
169
+ end
170
+
171
+ protected
110
172
  # Adds the association to the associations hash with the type as the key,
111
173
  # then adds the accessors for the association.
112
174
  def add_association(type, options)
@@ -119,7 +181,11 @@ module Mongoid # :nodoc:
119
181
  end
120
182
  define_method("#{name}=") do |object|
121
183
  proxy = Associations::Accessor.set(type, self, object, options)
122
- remove_instance_variable("@#{name}") if instance_variable_defined?("@#{name}")
184
+ if instance_variable_defined?("@#{name}")
185
+ remove_instance_variable("@#{name}")
186
+ else
187
+ instance_variable_set("@#{name}", proxy)
188
+ end
123
189
  end
124
190
  end
125
191
  end
@@ -8,9 +8,9 @@ module Mongoid #:nodoc:
8
8
  @attributes = attributes
9
9
  end
10
10
 
11
- # Returns the association name of the options.
12
- def name
13
- @attributes[:name]
11
+ # Return the foreign key based off the association name.
12
+ def foreign_key
13
+ name.to_s.foreign_key
14
14
  end
15
15
 
16
16
  # Returns the name of the inverse_of association
@@ -26,6 +26,11 @@ module Mongoid #:nodoc:
26
26
  class_name ? class_name.constantize : name.to_s.classify.constantize
27
27
  end
28
28
 
29
+ # Returns the association name of the options.
30
+ def name
31
+ @attributes[:name]
32
+ end
33
+
29
34
  # Returns whether or not this association is polymorphic.
30
35
  def polymorphic
31
36
  @attributes[:polymorphic] == true
@@ -0,0 +1,44 @@
1
+ module Mongoid #:nodoc:
2
+ module Associations #:nodoc:
3
+ class RelatesToMany < DelegateClass(Array) #:nodoc:
4
+
5
+ # Initializing a related association only requires looking up the objects
6
+ # by their ids.
7
+ #
8
+ # Options:
9
+ #
10
+ # document: The +Document+ that contains the relationship.
11
+ # options: The association +Options+.
12
+ def initialize(document, options)
13
+ name = document.class.to_s.foreign_key
14
+ @documents = options.klass.all(:conditions => { name => document.id })
15
+ super(@documents)
16
+ end
17
+
18
+ class << self
19
+ # Returns the macro used to create the association.
20
+ def macro
21
+ :relates_to_many
22
+ end
23
+
24
+ # Perform an update of the relationship of the parent and child. This
25
+ # will assimilate the child +Document+ into the parent's object graph.
26
+ #
27
+ # Options:
28
+ #
29
+ # related: The related object
30
+ # parent: The parent +Document+ to update.
31
+ # options: The association +Options+
32
+ #
33
+ # Example:
34
+ #
35
+ # <tt>RelatesToOne.update(game, person, options)</tt>
36
+ def update(related, document, options)
37
+ name = document.class.to_s.underscore
38
+ related.each { |child| child.send("#{name}=", document) }
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ module Mongoid #:nodoc:
2
+ module Associations #:nodoc:
3
+ class RelatesToOne #:nodoc:
4
+ include Decorator
5
+
6
+ # Initializing a related association only requires looking up the object
7
+ # by its id.
8
+ #
9
+ # Options:
10
+ #
11
+ # document: The +Document+ that contains the relationship.
12
+ # options: The association +Options+.
13
+ def initialize(document, options)
14
+ @document = options.klass.find(document.send(options.foreign_key))
15
+ decorate!
16
+ end
17
+
18
+ class << self
19
+ # Returns the macro used to create the association.
20
+ def macro
21
+ :relates_to_one
22
+ end
23
+
24
+ # Perform an update of the relationship of the parent and child. This
25
+ # will assimilate the child +Document+ into the parent's object graph.
26
+ #
27
+ # Options:
28
+ #
29
+ # related: The related object
30
+ # parent: The parent +Document+ to update.
31
+ # options: The association +Options+
32
+ #
33
+ # Example:
34
+ #
35
+ # <tt>RelatesToOne.update(game, person, options)</tt>
36
+ def update(related, parent, options)
37
+ parent.send("#{options.foreign_key}=", related.id)
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
12
- s.date = %q{2009-11-28}
12
+ s.date = %q{2009-11-30}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
29
29
  "lib/mongoid/associations/has_many.rb",
30
30
  "lib/mongoid/associations/has_one.rb",
31
31
  "lib/mongoid/associations/options.rb",
32
+ "lib/mongoid/associations/relates_to_many.rb",
33
+ "lib/mongoid/associations/relates_to_one.rb",
32
34
  "lib/mongoid/attributes.rb",
33
35
  "lib/mongoid/commands.rb",
34
36
  "lib/mongoid/commands/create.rb",
@@ -74,6 +76,8 @@ Gem::Specification.new do |s|
74
76
  "spec/unit/mongoid/associations/has_many_spec.rb",
75
77
  "spec/unit/mongoid/associations/has_one_spec.rb",
76
78
  "spec/unit/mongoid/associations/options_spec.rb",
79
+ "spec/unit/mongoid/associations/relates_to_many_spec.rb",
80
+ "spec/unit/mongoid/associations/relates_to_one_spec.rb",
77
81
  "spec/unit/mongoid/associations_spec.rb",
78
82
  "spec/unit/mongoid/attributes_spec.rb",
79
83
  "spec/unit/mongoid/commands/create_spec.rb",
@@ -122,6 +126,8 @@ Gem::Specification.new do |s|
122
126
  "spec/unit/mongoid/associations/has_many_spec.rb",
123
127
  "spec/unit/mongoid/associations/has_one_spec.rb",
124
128
  "spec/unit/mongoid/associations/options_spec.rb",
129
+ "spec/unit/mongoid/associations/relates_to_many_spec.rb",
130
+ "spec/unit/mongoid/associations/relates_to_one_spec.rb",
125
131
  "spec/unit/mongoid/associations_spec.rb",
126
132
  "spec/unit/mongoid/attributes_spec.rb",
127
133
  "spec/unit/mongoid/commands/create_spec.rb",
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Document do
4
4
 
@@ -188,18 +188,18 @@ describe Mongoid::Document do
188
188
  describe "#paginate" do
189
189
 
190
190
  before do
191
- 30.times do |num|
191
+ 10.times do |num|
192
192
  Person.create(:title => "Test-#{num}")
193
193
  end
194
194
  end
195
195
 
196
196
  it "returns paginated documents" do
197
- Person.paginate(:per_page => 20, :page => 2).length.should == 10
197
+ Person.paginate(:per_page => 5, :page => 2).length.should == 5
198
198
  end
199
199
 
200
200
  it "returns a proper count" do
201
- @criteria = Mongoid::Criteria.translate(Person, { :per_page => 20, :page => 1 })
202
- @criteria.count.should == 30
201
+ @criteria = Mongoid::Criteria.translate(Person, { :per_page => 5, :page => 1 })
202
+ @criteria.count.should == 10
203
203
  end
204
204
 
205
205
  end
@@ -259,6 +259,42 @@ describe Mongoid::Document do
259
259
 
260
260
  end
261
261
 
262
+ context "associating relational data" do
263
+
264
+ context "when relational data is a single object" do
265
+
266
+ before do
267
+ @game = Game.create(:score => 100)
268
+ @person = Person.new(:title => "Sir")
269
+ @person.game = @game
270
+ @person.save
271
+ end
272
+
273
+ it "properly associates the object" do
274
+ person = Person.find(@person.id)
275
+ person.game.should == @game
276
+ end
277
+
278
+ end
279
+
280
+ context "when relational data is many objects" do
281
+
282
+ before do
283
+ @post = Post.new(:title => "New Post")
284
+ @person = Person.new(:title => "Sir")
285
+ @person.posts = [@post]
286
+ @person.save
287
+ end
288
+
289
+ it "properly associates the objects" do
290
+ person = Person.find(@person.id)
291
+ person.posts.should == [@post]
292
+ end
293
+
294
+ end
295
+
296
+ end
297
+
262
298
  context "the lot" do
263
299
 
264
300
  before do
@@ -36,6 +36,9 @@ class Person < Mongoid::Document
36
36
  has_one :name
37
37
  has_one :pet, :class_name => "Animal"
38
38
 
39
+ relates_to_one :game
40
+ relates_to_many :posts
41
+
39
42
  def update_addresses
40
43
  addresses.each_with_index do |address, i|
41
44
  address.street = "Updated #{i}"
@@ -133,6 +136,7 @@ end
133
136
  class Post < Mongoid::Document
134
137
  include Mongoid::Versioning
135
138
  field :title
139
+ relates_to_one :person
136
140
  end
137
141
 
138
142
  class Game < Mongoid::Document
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::Accessor do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::BelongsTo do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::Decorator do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::HasMany do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::HasOne do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations::Options do
4
4
 
@@ -15,6 +15,19 @@ describe Mongoid::Associations::Options do
15
15
 
16
16
  end
17
17
 
18
+ describe "#foreign_key" do
19
+
20
+ before do
21
+ @attributes = { :name => :game }
22
+ @options = Mongoid::Associations::Options.new(@attributes)
23
+ end
24
+
25
+ it "returns the association foreign_key" do
26
+ @options.foreign_key.should == "game_id"
27
+ end
28
+
29
+ end
30
+
18
31
  describe "#inverse_of" do
19
32
 
20
33
  before do
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Associations::RelatesToMany do
4
+
5
+ describe ".initialize" do
6
+
7
+ context "when related id has been set" do
8
+
9
+ before do
10
+ @document = Person.new
11
+ @options = Mongoid::Associations::Options.new(:name => :posts)
12
+ @criteria = stub
13
+ @first = stub(:person_id => @document.id)
14
+ @second = stub(:person_id => @document.id)
15
+ @related = [@first, @second]
16
+ end
17
+
18
+ it "finds the object by id" do
19
+ Post.expects(:all).with(:conditions => { "person_id" => @document.id }).returns(@related)
20
+ association = Mongoid::Associations::RelatesToMany.new(@document, @options)
21
+ association.should == @related
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ describe ".macro" do
29
+
30
+ it "returns :relates_to_many" do
31
+ Mongoid::Associations::RelatesToMany.macro.should == :relates_to_many
32
+ end
33
+
34
+ end
35
+
36
+ describe ".update" do
37
+
38
+ before do
39
+ @first = Post.new
40
+ @second = Post.new
41
+ @related = [@first, @second]
42
+ @parent = Person.new
43
+ @options = Mongoid::Associations::Options.new(:name => :posts)
44
+ end
45
+
46
+ it "sets the related object id on the parent" do
47
+ Mongoid::Associations::RelatesToMany.update(@related, @parent, @options)
48
+ @first.person_id.should == @parent.id
49
+ @second.person_id.should == @parent.id
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Associations::RelatesToOne do
4
+
5
+ describe ".initialize" do
6
+
7
+ context "when related id has been set" do
8
+
9
+ before do
10
+ @document = stub(:game_id => "5")
11
+ @options = Mongoid::Associations::Options.new(:name => :game)
12
+ @related = stub
13
+ end
14
+
15
+ it "finds the object by id" do
16
+ Game.expects(:find).with(@document.game_id).returns(@related)
17
+ association = Mongoid::Associations::RelatesToOne.new(@document, @options)
18
+ association.should == @related
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ describe ".macro" do
26
+
27
+ it "returns :relates_to_one" do
28
+ Mongoid::Associations::RelatesToOne.macro.should == :relates_to_one
29
+ end
30
+
31
+ end
32
+
33
+ describe ".update" do
34
+
35
+ before do
36
+ @related = stub(:id => "5")
37
+ @parent = Person.new
38
+ @options = Mongoid::Associations::Options.new(:name => :game)
39
+ end
40
+
41
+ it "sets the related object id on the parent" do
42
+ Mongoid::Associations::RelatesToOne.update(@related, @parent, @options)
43
+ @parent.game_id.should == "5"
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Associations do
4
4
 
@@ -240,4 +240,26 @@ describe Mongoid::Associations do
240
240
 
241
241
  end
242
242
 
243
+ describe ".relates_to_one" do
244
+
245
+ it "creates an id field for the relationship" do
246
+ Person.new.should respond_to(:game_id)
247
+ end
248
+
249
+ it "creates a getter and setter for the relationship" do
250
+ Person.new.should respond_to(:game)
251
+ Person.new.should respond_to(:game=)
252
+ end
253
+
254
+ end
255
+
256
+ describe ".relates_to_many" do
257
+
258
+ it "creates a getter and setter for the relationship" do
259
+ Person.new.should respond_to(:posts)
260
+ Person.new.should respond_to(:posts=)
261
+ end
262
+
263
+ end
264
+
243
265
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Attributes do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::Create do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::DeleteAll do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::Delete do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::DestroyAll do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::Destroy do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::Save do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands::Validate do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Criteria do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Document do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::DynamicFinder do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Array::Assimilation do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Array::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Array::Parentization do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Boolean::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Date::Conversions do
4
4
 
@@ -1,7 +1,16 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::DateTime::Conversions do
4
4
 
5
+ before do
6
+ Time.zone = "Eastern Time (US & Canada)"
7
+ @time = Time.local(1976, 11, 19)
8
+ end
9
+
10
+ after do
11
+ Time.zone = nil
12
+ end
13
+
5
14
  describe "#set" do
6
15
 
7
16
  before do
@@ -36,10 +45,6 @@ describe Mongoid::Extensions::DateTime::Conversions do
36
45
 
37
46
  describe "#get" do
38
47
 
39
- before do
40
- @time = Time.now.utc
41
- end
42
-
43
48
  context "when time is provided" do
44
49
 
45
50
  it "returns a DateTime" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Float::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Hash::Accessors do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Hash::Assimilation do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Hash::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Integer::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Object::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::String::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::String::Inflections do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Symbol::Inflections do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Extensions::Time::Conversions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Field do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Finders do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Timestamps do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Versioning do
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-28 00:00:00 -05:00
12
+ date: 2009-11-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -105,6 +105,8 @@ files:
105
105
  - lib/mongoid/associations/has_many.rb
106
106
  - lib/mongoid/associations/has_one.rb
107
107
  - lib/mongoid/associations/options.rb
108
+ - lib/mongoid/associations/relates_to_many.rb
109
+ - lib/mongoid/associations/relates_to_one.rb
108
110
  - lib/mongoid/attributes.rb
109
111
  - lib/mongoid/commands.rb
110
112
  - lib/mongoid/commands/create.rb
@@ -150,6 +152,8 @@ files:
150
152
  - spec/unit/mongoid/associations/has_many_spec.rb
151
153
  - spec/unit/mongoid/associations/has_one_spec.rb
152
154
  - spec/unit/mongoid/associations/options_spec.rb
155
+ - spec/unit/mongoid/associations/relates_to_many_spec.rb
156
+ - spec/unit/mongoid/associations/relates_to_one_spec.rb
153
157
  - spec/unit/mongoid/associations_spec.rb
154
158
  - spec/unit/mongoid/attributes_spec.rb
155
159
  - spec/unit/mongoid/commands/create_spec.rb
@@ -220,6 +224,8 @@ test_files:
220
224
  - spec/unit/mongoid/associations/has_many_spec.rb
221
225
  - spec/unit/mongoid/associations/has_one_spec.rb
222
226
  - spec/unit/mongoid/associations/options_spec.rb
227
+ - spec/unit/mongoid/associations/relates_to_many_spec.rb
228
+ - spec/unit/mongoid/associations/relates_to_one_spec.rb
223
229
  - spec/unit/mongoid/associations_spec.rb
224
230
  - spec/unit/mongoid/attributes_spec.rb
225
231
  - spec/unit/mongoid/commands/create_spec.rb