mongoid 0.10.5 → 0.10.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/HISTORY CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.10.6
2
+ - Fixed bug when trying to set empty strings on number
3
+ fields. (TypeError: can't convert Fixnum into String)
4
+
5
+ - Document.delete_all now drops the collection if
6
+ conditions are empty or nil.
7
+
1
8
  === 0.10.5
2
9
 
3
10
  - Documents that are embedded not properly respond to
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.5
1
+ 0.10.6
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc
2
3
  module Associations #:nodoc
3
4
  module Proxy #:nodoc
@@ -14,7 +14,7 @@ module Mongoid #:nodoc:
14
14
  # put into the document's attributes.
15
15
  def process(attrs = {})
16
16
  attrs.each_pair do |key, value|
17
- send("#{key}=", value)
17
+ send("#{key}=", value) unless value.blank?
18
18
  end
19
19
  end
20
20
 
@@ -13,8 +13,8 @@ module Mongoid #:nodoc:
13
13
  # Example:
14
14
  #
15
15
  # <tt>DeleteAll.execute(Person, :conditions => { :field => "value" })</tt>
16
- def self.execute(klass, params = nil)
17
- params ? klass.find(:all, params).each do
16
+ def self.execute(klass, params = {})
17
+ params.any? ? klass.find(:all, params).each do
18
18
  |doc| Delete.execute(doc)
19
19
  end : klass.collection.drop
20
20
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc
2
3
  module Commands #:nodoc
3
4
  module Deletion #:nodoc
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  class ComplexCriterion
3
4
  attr_accessor :key, :operator
@@ -6,4 +7,4 @@ module Mongoid #:nodoc:
6
7
  @key, @operator = opts[:key], opts[:operator]
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc
2
3
  class Config #:nodoc
3
4
  include Singleton
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc
2
3
  module Errors #:nodoc
3
4
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Mongoid #:nodoc:
2
3
  module Extensions #:nodoc:
3
4
  module Hash #:nodoc:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.10.5"
8
+ s.version = "0.10.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"]
12
- s.date = %q{2009-12-28}
12
+ s.date = %q{2009-12-29}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -61,7 +61,6 @@ Gem::Specification.new do |s|
61
61
  "lib/mongoid/extensions/hash/conversions.rb",
62
62
  "lib/mongoid/extensions/hash/criteria_helpers.rb",
63
63
  "lib/mongoid/extensions/integer/conversions.rb",
64
- "lib/mongoid/extensions/object/casting.rb",
65
64
  "lib/mongoid/extensions/object/conversions.rb",
66
65
  "lib/mongoid/extensions/string/conversions.rb",
67
66
  "lib/mongoid/extensions/string/inflections.rb",
@@ -70,6 +70,41 @@ describe Mongoid::Document do
70
70
 
71
71
  end
72
72
 
73
+ context "#destroy" do
74
+
75
+ context "on a root document" do
76
+
77
+ before do
78
+ @person = Person.create(:title => "Sir")
79
+ end
80
+
81
+ it "deletes the document" do
82
+ @person.destroy
83
+ lambda { Person.find(@person.id) }.should raise_error
84
+ end
85
+
86
+ end
87
+
88
+ context "on an embedded document" do
89
+
90
+ before do
91
+ @person = Person.create(:title => "Lead")
92
+ @person.addresses.create(:street => "1st Street")
93
+ @person.name.create(:first_name => "Emmanuel")
94
+ @person.save
95
+ end
96
+
97
+ it "deletes the document" do
98
+ @person.addresses.first.destroy
99
+ @person.name.destroy
100
+ @person.addresses.first.should be_nil
101
+ @person.name.document.should be_nil
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
73
108
  context "using dynamic finders" do
74
109
 
75
110
  before do
@@ -265,6 +300,8 @@ describe Mongoid::Document do
265
300
 
266
301
  it "always persists" do
267
302
  @comment.save(false).should be_true
303
+ @from_db = Comment.find(@comment.id)
304
+ @from_db.should == @comment
268
305
  end
269
306
 
270
307
  end
@@ -32,6 +32,9 @@ class Person
32
32
  field :employer_id
33
33
  field :lunch_time, :type => Time
34
34
  field :aliases, :type => Array
35
+ field :score, :type => Integer
36
+
37
+ attr_reader :rescored
35
38
 
36
39
  has_many :addresses
37
40
  has_many :phone_numbers, :class_name => "Phone"
@@ -50,6 +53,13 @@ class Person
50
53
  has_one_related :game
51
54
  has_many_related :posts
52
55
 
56
+ def score_with_rescoring=(score)
57
+ @rescored = score + 20
58
+ self.score_without_rescoring = score
59
+ end
60
+
61
+ alias_method_chain :score=, :rescoring
62
+
53
63
  def update_addresses
54
64
  addresses.each do |address|
55
65
  address.street = "Updated Address"
@@ -74,8 +84,8 @@ class Person
74
84
 
75
85
  end
76
86
 
77
- class Admin < Person
78
- field :code
87
+ class Doctor < Person
88
+ field :specialty
79
89
  end
80
90
 
81
91
  class Employer
@@ -187,3 +197,39 @@ class Object
187
197
  end
188
198
  end
189
199
  end
200
+
201
+ # Inhertiance test models:
202
+ class Canvas
203
+ include Mongoid::Document
204
+ field :size, :type => Integer, :default => 0
205
+ has_many :shapes
206
+
207
+ def render
208
+ shapes.each { |shape| render }
209
+ end
210
+ end
211
+
212
+ class Browser < Canvas
213
+ def render; end
214
+ end
215
+
216
+ class Firefox < Browser
217
+ def render; end
218
+ end
219
+
220
+ class Shape
221
+ include Mongoid::Document
222
+ field :x, :type => Integer, :default => 0
223
+ field :y, :type => Integer, :default => 0
224
+
225
+ def render; end
226
+ end
227
+
228
+ class Square < Shape
229
+ field :width, :type => Integer, :default => 0
230
+ field :height, :type => Integer, :default => 0
231
+ end
232
+
233
+ class Circle < Shape
234
+ field :radius, :type => Integer, :default => 0
235
+ end
@@ -99,6 +99,7 @@ describe Mongoid::Attributes do
99
99
  :title => "value",
100
100
  :age => "30",
101
101
  :terms => "true",
102
+ :score => "",
102
103
  :name => {
103
104
  :_id => "2", :first_name => "Test", :last_name => "User"
104
105
  },
@@ -109,11 +110,12 @@ describe Mongoid::Attributes do
109
110
  }
110
111
  end
111
112
 
112
- it "returns a properly cast the attributes" do
113
+ it "returns properly cast attributes" do
113
114
  attrs = Person.new(@attributes).attributes
114
115
  attrs[:age].should == 30
115
116
  attrs[:terms].should == true
116
117
  attrs[:_id].should == "1"
118
+ attrs[:score].should be_nil
117
119
  end
118
120
 
119
121
  end
@@ -38,6 +38,20 @@ describe Mongoid::Commands::DeleteAll do
38
38
 
39
39
  end
40
40
 
41
+ context "when empty conditions supplied" do
42
+
43
+ before do
44
+ @collection = mock
45
+ end
46
+
47
+ it "drops the collection" do
48
+ @klass.expects(:collection).returns(@collection)
49
+ @collection.expects(:drop)
50
+ Mongoid::Commands::DeleteAll.execute(@klass, {})
51
+ end
52
+
53
+ end
54
+
41
55
  end
42
56
 
43
57
  end
@@ -56,6 +56,23 @@ describe Mongoid::Document do
56
56
 
57
57
  end
58
58
 
59
+ describe "#alias_method_chain" do
60
+
61
+ context "on a field setter" do
62
+
63
+ before do
64
+ @person = Person.new
65
+ end
66
+
67
+ it "chains the method properly" do
68
+ @person.score = 10
69
+ @person.rescored.should == 30
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
59
76
  describe "#assimilate" do
60
77
 
61
78
  before 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.10.5
4
+ version: 0.10.6
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-12-28 00:00:00 -05:00
12
+ date: 2009-12-29 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -137,7 +137,6 @@ files:
137
137
  - lib/mongoid/extensions/hash/conversions.rb
138
138
  - lib/mongoid/extensions/hash/criteria_helpers.rb
139
139
  - lib/mongoid/extensions/integer/conversions.rb
140
- - lib/mongoid/extensions/object/casting.rb
141
140
  - lib/mongoid/extensions/object/conversions.rb
142
141
  - lib/mongoid/extensions/string/conversions.rb
143
142
  - lib/mongoid/extensions/string/inflections.rb
File without changes