mongoid 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.9
1
+ 0.5.10
@@ -21,8 +21,8 @@
21
21
  require "rubygems"
22
22
 
23
23
  gem "activesupport", "2.3.4"
24
- gem "mongo", "0.15.1"
25
- gem "durran-validatable", "1.7.5"
24
+ gem "mongo", "0.16"
25
+ gem "durran-validatable", "1.8.2"
26
26
  gem "will_paginate", "2.3.11"
27
27
 
28
28
  require "delegate"
@@ -173,7 +173,7 @@ module Mongoid #:nodoc:
173
173
  #
174
174
  # Returns: <tt>self</tt>
175
175
  def id(object_id)
176
- @selector[:_id] = Mongo::ObjectID.from_string(object_id); self
176
+ @selector[:_id] = object_id; self
177
177
  end
178
178
 
179
179
  # Create the new +Criteria+ object. This will initialize the selector
@@ -310,7 +310,7 @@ module Mongoid #:nodoc:
310
310
  # Returns a new +Criteria+ object.
311
311
  def self.translate(*args)
312
312
  type, params = args[0], args[1] || {}
313
- return new(:first).id(type.to_s) if type.is_a?(Mongo::ObjectID)
313
+ return new(:first).id(type) unless type.is_a?(Symbol)
314
314
  return new(type).where(params.delete(:conditions)).extras(params)
315
315
  end
316
316
 
@@ -4,6 +4,7 @@ require "mongoid/extensions/boolean/conversions"
4
4
  require "mongoid/extensions/date/conversions"
5
5
  require "mongoid/extensions/float/conversions"
6
6
  require "mongoid/extensions/hash/accessors"
7
+ require "mongoid/extensions/hash/conversions"
7
8
  require "mongoid/extensions/integer/conversions"
8
9
  require "mongoid/extensions/object/conversions"
9
10
  require "mongoid/extensions/object/parentization"
@@ -31,6 +32,7 @@ end
31
32
 
32
33
  class Hash #:nodoc
33
34
  include Mongoid::Extensions::Hash::Accessors
35
+ extend Mongoid::Extensions::Hash::Conversions
34
36
  end
35
37
 
36
38
  class Integer #:nodoc
@@ -0,0 +1,14 @@
1
+ module Mongoid #:nodoc:
2
+ module Extensions #:nodoc:
3
+ module Hash #:nodoc:
4
+ module Conversions #:nodoc:
5
+ def get(value)
6
+ value
7
+ end
8
+ def set(value)
9
+ value
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,11 +3,30 @@ module Mongoid #:nodoc:
3
3
  module Object #:nodoc:
4
4
  # This module converts objects into mongoid related objects.
5
5
  module Conversions #:nodoc:
6
- # Converts this object to a hash of attributes
7
- def mongoidize
8
- self.attributes
6
+ def self.included(base)
7
+ base.class_eval do
8
+ include InstanceMethods
9
+ extend ClassMethods
10
+ end
11
+ end
12
+
13
+ module InstanceMethods
14
+ # Converts this object to a hash of attributes
15
+ def mongoidize
16
+ self.attributes
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def set(value)
22
+ value.attributes
23
+ end
24
+
25
+ def get(value)
26
+ self.new(value)
27
+ end
9
28
  end
10
29
  end
11
30
  end
12
31
  end
13
- end
32
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.5.9"
8
+ s.version = "0.5.10"
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"]
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "lib/mongoid/extensions/date/conversions.rb",
46
46
  "lib/mongoid/extensions/float/conversions.rb",
47
47
  "lib/mongoid/extensions/hash/accessors.rb",
48
+ "lib/mongoid/extensions/hash/conversions.rb",
48
49
  "lib/mongoid/extensions/integer/conversions.rb",
49
50
  "lib/mongoid/extensions/object/casting.rb",
50
51
  "lib/mongoid/extensions/object/conversions.rb",
@@ -81,6 +82,7 @@ Gem::Specification.new do |s|
81
82
  "spec/unit/mongoid/extensions/date/conversions_spec.rb",
82
83
  "spec/unit/mongoid/extensions/float/conversions_spec.rb",
83
84
  "spec/unit/mongoid/extensions/hash/accessors_spec.rb",
85
+ "spec/unit/mongoid/extensions/hash/conversions_spec.rb",
84
86
  "spec/unit/mongoid/extensions/integer/conversions_spec.rb",
85
87
  "spec/unit/mongoid/extensions/object/conversions_spec.rb",
86
88
  "spec/unit/mongoid/extensions/object/parentization_spec.rb",
@@ -121,6 +123,7 @@ Gem::Specification.new do |s|
121
123
  "spec/unit/mongoid/extensions/date/conversions_spec.rb",
122
124
  "spec/unit/mongoid/extensions/float/conversions_spec.rb",
123
125
  "spec/unit/mongoid/extensions/hash/accessors_spec.rb",
126
+ "spec/unit/mongoid/extensions/hash/conversions_spec.rb",
124
127
  "spec/unit/mongoid/extensions/integer/conversions_spec.rb",
125
128
  "spec/unit/mongoid/extensions/object/conversions_spec.rb",
126
129
  "spec/unit/mongoid/extensions/object/parentization_spec.rb",
@@ -15,22 +15,23 @@ Spec::Runner.configure do |config|
15
15
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
16
16
  end
17
17
 
18
+ class MixedDrink < Mongoid::Document
19
+ field :name
20
+ end
21
+
18
22
  class Person < Mongoid::Document
19
23
  include Mongoid::Timestamps
20
24
  field :title
21
25
  field :terms, :type => Boolean
22
26
  field :age, :type => Integer, :default => 100
23
27
  field :dob, :type => Date
28
+ field :mixed_drink, :type => MixedDrink
24
29
  has_many :addresses
25
30
  has_many :phone_numbers, :class_name => "Phone"
26
31
  has_one :name
27
32
  has_one :pet, :class_name => "Animal"
28
33
  end
29
34
 
30
- class MixedDrink < Mongoid::Document
31
- field :name
32
- end
33
-
34
35
  class Address < Mongoid::Document
35
36
  field :street
36
37
  field :city
@@ -170,7 +170,7 @@ describe Mongoid::Criteria do
170
170
 
171
171
  it "adds the _id query to the selector" do
172
172
  id = Mongo::ObjectID.new
173
- @criteria.id(id.to_s)
173
+ @criteria.id(id)
174
174
  @criteria.selector.should == { :_id => id }
175
175
  end
176
176
 
@@ -384,14 +384,20 @@ describe Mongoid::Criteria do
384
384
 
385
385
  describe "#translate" do
386
386
 
387
- context "single argument as a string" do
387
+ context "with a single argument" do
388
388
 
389
- it "creates a new select criteria" do
389
+ it "creates a criteria for an object id" do
390
390
  id = Mongo::ObjectID.new
391
391
  criteria = Mongoid::Criteria.translate(id)
392
392
  criteria.selector.should == { :_id => id }
393
393
  end
394
394
 
395
+ it "creates a criteria for a string" do
396
+ id = Mongo::ObjectID.new.to_s
397
+ criteria = Mongoid::Criteria.translate(id)
398
+ criteria.selector.should == { :_id => id }
399
+ end
400
+
395
401
  end
396
402
 
397
403
  context "multiple arguments" do
@@ -145,6 +145,21 @@ describe Mongoid::Document do
145
145
 
146
146
  end
147
147
 
148
+ context "when type is an object" do
149
+
150
+ before do
151
+ @person = Person.new
152
+ @drink = MixedDrink.new(:name => "Jack and Coke")
153
+ @person.mixed_drink = @drink
154
+ end
155
+
156
+ it "allows proper access to the object" do
157
+ @person.mixed_drink.should == @drink
158
+ @person.attributes[:mixed_drink].except(:_id).should == { "name" => "Jack and Coke" }
159
+ end
160
+
161
+ end
162
+
148
163
  end
149
164
 
150
165
  describe "#find" do
@@ -623,6 +638,39 @@ describe Mongoid::Document do
623
638
 
624
639
  end
625
640
 
641
+ describe "#validates_uniqueness_of" do
642
+
643
+ it "adds the uniqueness validation" do
644
+ Person.class_eval do
645
+ validates_uniqueness_of :title
646
+ end
647
+ Person.validations.first.should be_a_kind_of(Validatable::ValidatesUniquenessOf)
648
+ end
649
+
650
+ end
651
+
652
+ describe "#validates_inclusion_of" do
653
+
654
+ it "adds the inclusion validation" do
655
+ Person.class_eval do
656
+ validates_inclusion_of :title, :within => ["test"]
657
+ end
658
+ Person.validations.first.should be_a_kind_of(Validatable::ValidatesInclusionOf)
659
+ end
660
+
661
+ end
662
+
663
+ describe "#validates_exclusion_of" do
664
+
665
+ it "adds the exclusion validation" do
666
+ Person.class_eval do
667
+ validates_exclusion_of :title, :within => ["test"]
668
+ end
669
+ Person.validations.first.should be_a_kind_of(Validatable::ValidatesExclusionOf)
670
+ end
671
+
672
+ end
673
+
626
674
  describe "#validates_true_for" do
627
675
 
628
676
  it "adds the true validation" do
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), "/../../../../spec_helper.rb")
2
+
3
+ describe Mongoid::Extensions::Hash::Conversions do
4
+
5
+ describe "#get" do
6
+
7
+ it "returns the hash" do
8
+ Hash.get({ :field => "test" }).should == { :field => "test" }
9
+ end
10
+
11
+ end
12
+
13
+ describe "#set" do
14
+
15
+ it "returns the hash" do
16
+ Hash.set({ :field => "test" }).should == { :field => "test" }
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -6,7 +6,32 @@ describe Mongoid::Extensions::Object::Conversions do
6
6
 
7
7
  it "returns its attributes" do
8
8
  Person.new(:_id => 1, :title => "Sir").mongoidize.should ==
9
- HashWithIndifferentAccess.new({ :_id => 1, :title => "Sir", :age => 100 })
9
+ { "_id" => 1, "title" => "Sir", "age" => 100 }
10
+ end
11
+
12
+ end
13
+
14
+ describe "#get" do
15
+
16
+ before do
17
+ @attributes = { :_id => "test", :title => "Sir", :age => 100 }
18
+ end
19
+
20
+ it "instantiates a new class from the attributes" do
21
+ Person.get(@attributes).should == Person.new(@attributes)
22
+ end
23
+
24
+ end
25
+
26
+ describe "#set" do
27
+
28
+ before do
29
+ @attributes = { "_id" => "test", "title" => "Sir", "age" => 100 }
30
+ @person = Person.new(@attributes)
31
+ end
32
+
33
+ it "converts the object to a hash" do
34
+ Person.set(@person).should == @attributes
10
35
  end
11
36
 
12
37
  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.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -91,6 +91,7 @@ files:
91
91
  - lib/mongoid/extensions/date/conversions.rb
92
92
  - lib/mongoid/extensions/float/conversions.rb
93
93
  - lib/mongoid/extensions/hash/accessors.rb
94
+ - lib/mongoid/extensions/hash/conversions.rb
94
95
  - lib/mongoid/extensions/integer/conversions.rb
95
96
  - lib/mongoid/extensions/object/casting.rb
96
97
  - lib/mongoid/extensions/object/conversions.rb
@@ -127,6 +128,7 @@ files:
127
128
  - spec/unit/mongoid/extensions/date/conversions_spec.rb
128
129
  - spec/unit/mongoid/extensions/float/conversions_spec.rb
129
130
  - spec/unit/mongoid/extensions/hash/accessors_spec.rb
131
+ - spec/unit/mongoid/extensions/hash/conversions_spec.rb
130
132
  - spec/unit/mongoid/extensions/integer/conversions_spec.rb
131
133
  - spec/unit/mongoid/extensions/object/conversions_spec.rb
132
134
  - spec/unit/mongoid/extensions/object/parentization_spec.rb
@@ -189,6 +191,7 @@ test_files:
189
191
  - spec/unit/mongoid/extensions/date/conversions_spec.rb
190
192
  - spec/unit/mongoid/extensions/float/conversions_spec.rb
191
193
  - spec/unit/mongoid/extensions/hash/accessors_spec.rb
194
+ - spec/unit/mongoid/extensions/hash/conversions_spec.rb
192
195
  - spec/unit/mongoid/extensions/integer/conversions_spec.rb
193
196
  - spec/unit/mongoid/extensions/object/conversions_spec.rb
194
197
  - spec/unit/mongoid/extensions/object/parentization_spec.rb