mongoid 0.8.5 → 0.8.6

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 CHANGED
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.8.6
@@ -101,7 +101,7 @@ module Mongoid # :nodoc:
101
101
  end
102
102
  define_method("#{name}=") do |object|
103
103
  proxy = Associations::Accessor.set(type, self, object, options)
104
- instance_variable_set("@#{name}", proxy)
104
+ remove_instance_variable("@#{name}") if instance_variable_defined?("@#{name}")
105
105
  end
106
106
  end
107
107
  end
@@ -3,7 +3,7 @@ module Mongoid #:nodoc:
3
3
  module Date #:nodoc:
4
4
  module Conversions #:nodoc:
5
5
  def set(value)
6
- value.to_time unless value.blank?
6
+ value.to_date.at_midnight.to_time unless value.blank?
7
7
  end
8
8
  def get(value)
9
9
  value ? value.getlocal.to_date : value
@@ -3,8 +3,10 @@ module Mongoid #:nodoc:
3
3
  module Hash #:nodoc:
4
4
  module Accessors #:nodoc:
5
5
  def insert(key, attrs)
6
- self[key] = attrs if key.singular?
7
- if key.plural?
6
+ if key.singular?
7
+ self[key] = attrs unless self[key]
8
+ self[key] = self[key].merge(attrs) if self[key]
9
+ else
8
10
  if elements = self[key]
9
11
  elements.delete_if { |e| (e[:_id] == attrs[:_id]) } << attrs
10
12
  else
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.8.5"
8
+ s.version = "0.8.6"
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"]
@@ -551,6 +551,28 @@ describe Mongoid::Document do
551
551
 
552
552
  end
553
553
 
554
+ context "on a parent document" do
555
+
556
+ context "when the parent has a has many through a has one" do
557
+
558
+ before do
559
+ @owner = PetOwner.new(:title => "Mr")
560
+ @pet = Pet.new(:name => "Fido")
561
+ @owner.pet = @pet
562
+ @vet_visit = VetVisit.new(:date => Date.today)
563
+ @pet.vet_visits = [@vet_visit]
564
+ end
565
+
566
+ it "does not overwrite child attributes if not in the hash" do
567
+ @owner.write_attributes({ :pet => { :name => "Bingo" } })
568
+ @owner.pet.name.should == "Bingo"
569
+ @owner.pet.vet_visits.size.should == 1
570
+ end
571
+
572
+ end
573
+
574
+ end
575
+
554
576
  context "on a child document" do
555
577
 
556
578
  context "when child is part of a has one" do
@@ -10,8 +10,20 @@ describe Mongoid::Extensions::Date::Conversions do
10
10
 
11
11
  context "when string provided" do
12
12
 
13
- it "returns a time from the string" do
14
- Date.set(@time.utc.to_s).should == @time
13
+ context "when string is a utc time" do
14
+
15
+ it "returns a time from the string" do
16
+ Date.set(@time.utc.to_s).should == @time
17
+ end
18
+
19
+ end
20
+
21
+ context "when string is a date" do
22
+
23
+ it "returns a time from the string" do
24
+ Date.set("01/15/2007").should == Date.new(2007, 1, 15).at_midnight
25
+ end
26
+
15
27
  end
16
28
 
17
29
  context "when string is empty" do
@@ -54,6 +66,30 @@ describe Mongoid::Extensions::Date::Conversions do
54
66
 
55
67
  context "when value is not nil" do
56
68
 
69
+ context "when time is UTC" do
70
+
71
+ before do
72
+ @utc = Date.new(1974, 12, 1).to_time.utc
73
+ end
74
+
75
+ context "when time zone is not utc" do
76
+
77
+ before do
78
+ Time.zone = "Eastern Time (US & Canada)"
79
+ end
80
+
81
+ after do
82
+ Time.zone = "UTC"
83
+ end
84
+
85
+ it "converts to the proper date" do
86
+ Date.get(@utc).should == Date.new(1974, 12, 1)
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
57
93
  it "converts the time back to a date" do
58
94
  Date.get(@time).should == @time.to_date
59
95
  end
@@ -11,6 +11,11 @@ describe Mongoid::Extensions::Hash::Accessors do
11
11
  :name => {
12
12
  :_id => 2, :first_name => "Test", :last_name => "User"
13
13
  },
14
+ :pet => {
15
+ :_id => 6,
16
+ :name => "Fido",
17
+ :vet_visits => [ { :date => Date.new(2007, 1, 1) } ]
18
+ },
14
19
  :addresses => [
15
20
  { :_id => 3, :street => "First Street" },
16
21
  { :_id => 4, :street => "Second Street" }
@@ -18,6 +23,32 @@ describe Mongoid::Extensions::Hash::Accessors do
18
23
  }
19
24
  end
20
25
 
26
+ context "when writing to a hash with a child array" do
27
+
28
+ context "when child attributes not present" do
29
+
30
+ it "does nothing to the children" do
31
+ @hash.insert(:pet, { :name => "Bingo" })
32
+ @hash[:pet].should == {
33
+ :_id => 6,
34
+ :name => "Bingo",
35
+ :vet_visits => [ { :date => Date.new(2007, 1, 1) } ]
36
+ }
37
+ end
38
+
39
+ end
40
+
41
+ context "when child attributes present" do
42
+
43
+ it "overwrites the child attributes" do
44
+ @hash.insert(:pet, { :vet_visits => [ { :date => Date.new(2009, 11, 11) } ] })
45
+ @hash[:pet][:vet_visits].should == [ { :date => Date.new(2009, 11, 11) } ]
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
21
52
  context "when writing a single attribute" do
22
53
 
23
54
  context "when attribute exists" do
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.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan