mongoid 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.5.0
@@ -9,6 +9,7 @@ module Mongoid #:nodoc:
9
9
  def <<(object)
10
10
  object.parentize(@parent, @association_name)
11
11
  @documents << object
12
+ object.is_a?(Array) ? object.each(&:notify) : object.notify
12
13
  end
13
14
 
14
15
  # Appends the object to the +Array+, setting its parent in
@@ -52,8 +52,8 @@ module Mongoid #:nodoc:
52
52
  #
53
53
  # <tt>field :score, :default => 0</tt>
54
54
  def field(name, options = {})
55
- @fields ||= {}
56
- @fields[name] = Field.new(name, options)
55
+ @fields ||= HashWithIndifferentAccess.new
56
+ @fields[name.to_s] = Field.new(name.to_s, options)
57
57
  define_method(name) { read_attribute(name) }
58
58
  define_method("#{name}=") { |value| write_attribute(name, value) }
59
59
  end
@@ -172,8 +172,8 @@ module Mongoid #:nodoc:
172
172
  # Instantiate a new Document, setting the Document's attirbutes if given.
173
173
  # If no attributes are provided, they will be initialized with an empty Hash.
174
174
  def initialize(attributes = {})
175
- @attributes = attributes.symbolize_keys if attributes
176
- @attributes = {} unless attributes
175
+ @attributes = HashWithIndifferentAccess.new(attributes) if attributes
176
+ @attributes = HashWithIndifferentAccess.new unless attributes
177
177
  generate_key
178
178
  end
179
179
 
@@ -195,8 +195,7 @@ module Mongoid #:nodoc:
195
195
 
196
196
  # Read from the attributes hash.
197
197
  def read_attribute(name)
198
- symbol = name.to_sym
199
- fields[symbol].value(@attributes[symbol])
198
+ fields[name].value(@attributes[name])
200
199
  end
201
200
 
202
201
  # Returns the id of the Document
@@ -212,8 +211,7 @@ module Mongoid #:nodoc:
212
211
 
213
212
  # Write to the attributes hash.
214
213
  def write_attribute(name, value)
215
- symbol = name.to_sym
216
- @attributes[name.to_sym] = value
214
+ @attributes[name] = value
217
215
  notify
218
216
  end
219
217
 
@@ -16,13 +16,13 @@ module Mongoid
16
16
  # Update the created_at field on the Document to the current time. This is
17
17
  # only called on create.
18
18
  def update_created_at
19
- self.created_at = Time.now
19
+ self.created_at = Time.now.utc
20
20
  end
21
21
 
22
22
  # Update the last_modified field on the Document to the current time.
23
23
  # This is only called on create and on save.
24
24
  def update_modified_at
25
- self.modified_at = Time.now
25
+ self.modified_at = Time.now.utc
26
26
  end
27
27
  end
28
28
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.4.8"
8
+ s.version = "0.5.0"
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-10-25}
12
+ s.date = %q{2009-10-27}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -112,4 +112,41 @@ describe Mongoid::Document do
112
112
 
113
113
  end
114
114
 
115
+ context "the lot" do
116
+
117
+ before do
118
+ @person = Person.new(:title => "Sir")
119
+ @name = Name.new(:first_name => "Syd", :last_name => "Vicious")
120
+ @address = Address.new(:street => "Oxford Street")
121
+ @person.name = @name
122
+ @person.addresses << @address
123
+ end
124
+
125
+ context "when saving on a has_one" do
126
+
127
+ before do
128
+ @name.save
129
+ end
130
+
131
+ it "saves the entire graph up from the has_one" do
132
+ person = Person.first(:conditions => { :title => "Sir" })
133
+ person.name.first_name.should == @person.name.first_name
134
+ end
135
+
136
+ end
137
+
138
+ context "when saving on a has_many" do
139
+
140
+ before do
141
+ @address.save
142
+ end
143
+
144
+ it "saves the entire graph up from the has_many" do
145
+ person = Person.first(:conditions => { :title => "Sir" })
146
+ person.addresses.first.street.should == @person.addresses.first.street
147
+ end
148
+ end
149
+
150
+ end
151
+
115
152
  end
@@ -29,12 +29,14 @@ class Address < Mongoid::Document
29
29
  field :city
30
30
  field :state
31
31
  field :post_code
32
+ key :street
32
33
  belongs_to :person
33
34
  end
34
35
 
35
36
  class Name < Mongoid::Document
36
37
  field :first_name
37
38
  field :last_name
39
+ key :first_name, :last_name
38
40
  belongs_to :person
39
41
  end
40
42
 
@@ -3,11 +3,9 @@ require File.join(File.dirname(__FILE__), "/../../../spec_helper.rb")
3
3
  describe Mongoid::Associations::HasManyAssociation do
4
4
 
5
5
  before do
6
- @first_id = Mongo::ObjectID.new
7
- @second_id = Mongo::ObjectID.new
8
6
  @attributes = { :addresses => [
9
- { :_id => @first_id, :street => "Street 1" },
10
- { :_id => @second_id, :street => "Street 2" } ] }
7
+ { :street => "Street 1" },
8
+ { :street => "Street 2" } ] }
11
9
  @document = stub(:attributes => @attributes, :add_observer => true, :update => true)
12
10
  end
13
11
 
@@ -119,8 +117,8 @@ describe Mongoid::Associations::HasManyAssociation do
119
117
  context "when finding by id" do
120
118
 
121
119
  it "returns the document in the array with that id" do
122
- address = @association.find(@second_id)
123
- address.id.should == @second_id
120
+ address = @association.find("street-2")
121
+ address.should_not be_nil
124
122
  end
125
123
 
126
124
  end
@@ -29,7 +29,8 @@ describe Mongoid::Associations do
29
29
  end
30
30
 
31
31
  it "sets the child attributes on the parent" do
32
- @person.attributes[:name].should == { :first_name => "Test", :last_name => "User" }
32
+ @person.attributes[:name].should ==
33
+ HashWithIndifferentAccess.new({ :_id => "test-user", :first_name => "Test", :last_name => "User" })
33
34
  end
34
35
 
35
36
  end
@@ -250,10 +250,10 @@ describe Mongoid::Document do
250
250
  context "with attributes" do
251
251
 
252
252
  before do
253
- @attributes = { :test => "test" }
253
+ @attributes = HashWithIndifferentAccess.new({ :test => "test" })
254
254
  end
255
255
 
256
- it "sets the arributes hash on the object" do
256
+ it "sets the attributes hash on the object" do
257
257
  person = Person.new(@attributes)
258
258
  person.attributes.should == @attributes
259
259
  end
@@ -275,18 +275,6 @@ describe Mongoid::Document do
275
275
 
276
276
  end
277
277
 
278
- context "when the value for the key is nonexistant" do
279
-
280
- before do
281
- @address = Address.new(:street => "Test")
282
- end
283
-
284
- it "sets the primary key" do
285
- @address.id.should be_nil
286
- end
287
-
288
- end
289
-
290
278
  end
291
279
 
292
280
  end
@@ -6,9 +6,11 @@ describe Mongoid::Extensions::Array::Conversions do
6
6
 
7
7
  it "collects each of its attributes" do
8
8
  array = [Person.new(:title => "Sir"), Person.new(:title => "Madam")]
9
- array.mongoidize.should == [{ :title => "Sir" }, { :title => "Madam" }]
9
+ array.mongoidize.should ==
10
+ [HashWithIndifferentAccess.new({ :title => "Sir" }),
11
+ HashWithIndifferentAccess.new({ :title => "Madam" })]
10
12
  end
11
13
 
12
14
  end
13
15
 
14
- end
16
+ end
@@ -5,9 +5,10 @@ describe Mongoid::Extensions::Object::Conversions do
5
5
  describe "#mongoidize" do
6
6
 
7
7
  it "returns its attributes" do
8
- Person.new(:title => "Sir").mongoidize.should == { :title => "Sir" }
8
+ Person.new(:title => "Sir").mongoidize.should ==
9
+ HashWithIndifferentAccess.new({ :title => "Sir" })
9
10
  end
10
11
 
11
12
  end
12
13
 
13
- end
14
+ end
@@ -14,6 +14,12 @@ describe Mongoid::Timestamps do
14
14
  fields[:modified_at].should_not be_nil
15
15
  end
16
16
 
17
+ it "forces the timestamps to UTC" do
18
+ @person.run_callbacks(:before_create)
19
+ @person.created_at.should be_close(Time.now.utc, 10.seconds)
20
+ @person.modified_at.should be_close(Time.now.utc, 10.seconds)
21
+ end
22
+
17
23
  end
18
24
 
19
25
  end
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.4.8
4
+ version: 0.5.0
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-10-25 00:00:00 -04:00
12
+ date: 2009-10-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency