mongo_doc 0.6.25 → 0.6.26

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. MongoDoc
2
2
 
3
- Version: 0.6.25 2010/10/17
3
+ Version: 0.6.26 2010/12/06
4
4
 
5
5
  h2. Notes
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.25
1
+ 0.6.26
@@ -114,14 +114,14 @@ module MongoDoc
114
114
  self.attributes = attrs
115
115
  return save if new_record?
116
116
  return false unless valid?
117
- _update_attributes(attrs, false)
117
+ _update_attributes(converted_attributes(attrs), false)
118
118
  end
119
119
 
120
120
  def update_attributes!(attrs)
121
121
  self.attributes = attrs
122
122
  return save! if new_record?
123
123
  raise DocumentInvalidError unless valid?
124
- _update_attributes(attrs, true)
124
+ _update_attributes(converted_attributes(attrs), true)
125
125
  end
126
126
 
127
127
  # Update without checking validations. The +Document+ will be saved without validations if it is a new record.
@@ -131,7 +131,7 @@ module MongoDoc
131
131
  _root.send(:_save, safe) if _root
132
132
  _save(safe)
133
133
  else
134
- _update_attributes(attrs, safe)
134
+ _update_attributes(converted_attributes(attrs), safe)
135
135
  end
136
136
  end
137
137
 
@@ -186,6 +186,14 @@ module MongoDoc
186
186
  raise e
187
187
  end
188
188
 
189
+ def converted_attributes(attrs)
190
+ converted = {}
191
+ attrs.keys.each do |attr|
192
+ converted[attr] = send(attr)
193
+ end
194
+ converted
195
+ end
196
+
189
197
  def hash_with_modifier_path_keys(hash)
190
198
  hash.stringify_keys!
191
199
  {}.tap do |dup|
data/lib/mongo_doc.rb CHANGED
@@ -3,7 +3,7 @@ require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
 
5
5
  module MongoDoc
6
- VERSION = '0.6.25'
6
+ VERSION = '0.6.26'
7
7
  end
8
8
 
9
9
  require 'mongo_doc/connection'
data/mongo_doc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_doc}
8
- s.version = "0.6.25"
8
+ s.version = "0.6.26"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Les Hill"]
12
- s.date = %q{2010-10-17}
12
+ s.date = %q{2010-12-06}
13
13
  s.description = %q{ODM for MongoDB}
14
14
  s.email = %q{leshill@gmail.com}
15
15
  s.extra_rdoc_files = [
data/spec/update_spec.rb CHANGED
@@ -6,12 +6,14 @@ describe "MongoDoc::Document" do
6
6
  include MongoDoc::Document
7
7
 
8
8
  attr_accessor :child_data
9
+ attr_accessor :child_int, :type => Integer
9
10
  end
10
11
 
11
12
  class UpdateAttributes
12
13
  include MongoDoc::Document
13
14
 
14
15
  attr_accessor :data
16
+ attr_accessor :int, :type => Integer
15
17
  embed :child
16
18
  end
17
19
 
@@ -40,33 +42,34 @@ describe "MongoDoc::Document" do
40
42
  context "with a new doc" do
41
43
  it "delegates to save! if the doc is a new record" do
42
44
  new_doc.should_receive(:_save)
43
- new_doc.update(:data => 'data')
45
+ new_doc.update(:data => 'data', :int => '1')
44
46
  end
45
47
 
46
48
  it "delegates to the root's save if the child is a new record" do
47
49
  existing_doc.should_receive(:_save)
48
- new_child.update(:child_data => 'data')
50
+ new_child.update(:child_data => 'data', :child_int => '1')
49
51
  end
50
52
  end
51
53
 
52
54
  context "with an existing doc" do
53
55
 
54
- subject { existing_doc.update(:data => 'data') }
56
+ subject { existing_doc.update(:data => 'data', :int => '1') }
55
57
 
56
58
  it "sets the attributes" do
57
59
  subject
58
60
  existing_doc.data.should == 'data'
61
+ existing_doc.int.should == 1
59
62
  end
60
63
 
61
64
  it "delegates to collection update" do
62
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data'}}, :safe => false)
65
+ collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => false)
63
66
  subject
64
67
  end
65
68
 
66
69
  context "that is embedded" do
67
70
  it "delegates to the root's collection update" do
68
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data'}}, :safe => true)
69
- child.update_attributes!(:child_data => 'data')
71
+ collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => true)
72
+ child.update_attributes!(:child_data => 'data', :child_int => '1')
70
73
  end
71
74
  end
72
75
  end
@@ -75,16 +78,17 @@ describe "MongoDoc::Document" do
75
78
  describe "#update_attributes" do
76
79
  it "delegates to save if the doc is a new record" do
77
80
  new_doc.should_receive(:save)
78
- new_doc.update_attributes(:data => 'data')
81
+ new_doc.update_attributes(:data => 'data', :int => '1')
79
82
  end
80
83
 
81
84
  context "with an existing doc" do
82
85
 
83
- subject { existing_doc.update_attributes(:data => 'data') }
86
+ subject { existing_doc.update_attributes(:data => 'data', :int => '1') }
84
87
 
85
88
  it "sets the attributes" do
86
89
  subject
87
90
  existing_doc.data.should == 'data'
91
+ existing_doc.int.should == 1
88
92
  end
89
93
 
90
94
  it "validates the doc" do
@@ -98,14 +102,14 @@ describe "MongoDoc::Document" do
98
102
  end
99
103
 
100
104
  it "delegates to collection update" do
101
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data'}}, :safe => false)
105
+ collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => false)
102
106
  subject
103
107
  end
104
108
 
105
109
  context "that is embedded" do
106
110
  it "delegates to the root's collection update" do
107
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data'}}, :safe => false)
108
- child.update_attributes(:child_data => 'data')
111
+ collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => false)
112
+ child.update_attributes(:child_data => 'data', :child_int => '1')
109
113
  end
110
114
  end
111
115
  end
@@ -114,16 +118,17 @@ describe "MongoDoc::Document" do
114
118
  describe "#update_attributes!" do
115
119
  it "delegates to save! if the doc is a new record" do
116
120
  new_doc.should_receive(:save!)
117
- new_doc.update_attributes!(:data => 'data')
121
+ new_doc.update_attributes!(:data => 'data', :int => '1')
118
122
  end
119
123
 
120
124
  context "with an existing doc" do
121
125
 
122
- subject { existing_doc.update_attributes!(:data => 'data') }
126
+ subject { existing_doc.update_attributes!(:data => 'data', :int => '1') }
123
127
 
124
128
  it "sets the attributes" do
125
129
  subject
126
130
  existing_doc.data.should == 'data'
131
+ existing_doc.int.should == 1
127
132
  end
128
133
 
129
134
  it "validates the doc" do
@@ -139,14 +144,14 @@ describe "MongoDoc::Document" do
139
144
  end
140
145
 
141
146
  it "delegates to collection update" do
142
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data'}}, :safe => true)
147
+ collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => true)
143
148
  subject
144
149
  end
145
150
 
146
151
  context "that is embedded" do
147
152
  it "delegates to the root's collection update" do
148
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data'}}, :safe => true)
149
- child.update_attributes!(:child_data => 'data')
153
+ collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => true)
154
+ child.update_attributes!(:child_data => 'data', :child_int => '1')
150
155
  end
151
156
  end
152
157
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 25
9
- version: 0.6.25
8
+ - 26
9
+ version: 0.6.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - Les Hill
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-17 00:00:00 -04:00
17
+ date: 2010-12-06 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency