mongoid 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/VERSION +1 -1
  2. data/lib/mongoid.rb +1 -0
  3. data/lib/mongoid/associations.rb +1 -1
  4. data/lib/mongoid/attributes.rb +1 -0
  5. data/lib/mongoid/collection.rb +1 -1
  6. data/lib/mongoid/commands.rb +1 -1
  7. data/lib/mongoid/commands/delete_all.rb +2 -1
  8. data/lib/mongoid/commands/destroy_all.rb +1 -1
  9. data/lib/mongoid/components.rb +1 -0
  10. data/lib/mongoid/config.rb +3 -1
  11. data/lib/mongoid/contexts.rb +21 -0
  12. data/lib/mongoid/contexts/enumerable.rb +15 -12
  13. data/lib/mongoid/contexts/ids.rb +25 -0
  14. data/lib/mongoid/contexts/mongo.rb +25 -23
  15. data/lib/mongoid/contexts/paging.rb +2 -2
  16. data/lib/mongoid/criteria.rb +5 -43
  17. data/lib/mongoid/document.rb +1 -0
  18. data/lib/mongoid/enslavement.rb +38 -0
  19. data/lib/mongoid/fields.rb +5 -2
  20. data/lib/mongoid/identity.rb +7 -1
  21. data/lib/mongoid/named_scope.rb +2 -0
  22. data/mongoid.gemspec +8 -2
  23. data/spec/integration/mongoid/commands_spec.rb +2 -2
  24. data/spec/integration/mongoid/contexts/enumerable_spec.rb +13 -0
  25. data/spec/integration/mongoid/criteria_spec.rb +2 -2
  26. data/spec/integration/mongoid/document_spec.rb +5 -1
  27. data/spec/integration/mongoid/finders_spec.rb +85 -28
  28. data/spec/models/person.rb +1 -0
  29. data/spec/unit/mongoid/associations_spec.rb +12 -0
  30. data/spec/unit/mongoid/attributes_spec.rb +60 -51
  31. data/spec/unit/mongoid/collection_spec.rb +30 -0
  32. data/spec/unit/mongoid/commands/delete_all_spec.rb +3 -3
  33. data/spec/unit/mongoid/commands_spec.rb +16 -0
  34. data/spec/unit/mongoid/config_spec.rb +7 -0
  35. data/spec/unit/mongoid/contexts/enumerable_spec.rb +151 -11
  36. data/spec/unit/mongoid/contexts/mongo_spec.rb +168 -42
  37. data/spec/unit/mongoid/contexts_spec.rb +25 -0
  38. data/spec/unit/mongoid/criteria_spec.rb +49 -75
  39. data/spec/unit/mongoid/criterion/exclusion_spec.rb +3 -13
  40. data/spec/unit/mongoid/criterion/inclusion_spec.rb +17 -19
  41. data/spec/unit/mongoid/criterion/optional_spec.rb +25 -8
  42. data/spec/unit/mongoid/document_spec.rb +4 -0
  43. data/spec/unit/mongoid/enslavement_spec.rb +63 -0
  44. data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
  45. data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -2
  46. data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
  47. data/spec/unit/mongoid/fields_spec.rb +10 -0
  48. data/spec/unit/mongoid/finders_spec.rb +1 -1
  49. data/spec/unit/mongoid/identity_spec.rb +23 -3
  50. data/spec/unit/mongoid/named_scope_spec.rb +15 -2
  51. data/spec/unit/mongoid/scope_spec.rb +1 -1
  52. metadata +8 -2
@@ -554,6 +554,10 @@ describe Mongoid::Document do
554
554
  @person.attributes.should == @attributes
555
555
  end
556
556
 
557
+ it 'should return a person object' do
558
+ @person.reload.should be_kind_of(Person)
559
+ end
560
+
557
561
  end
558
562
 
559
563
  describe "#remove" do
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Enslavement do
4
+
5
+ before do
6
+ @klass = Class.new do
7
+ include Mongoid::Enslavement
8
+ end
9
+ end
10
+
11
+ describe ".enslave" do
12
+
13
+ before do
14
+ @klass.enslave
15
+ end
16
+
17
+ it "sets the enslaved boolean on the class" do
18
+ @klass.enslaved.should be_true
19
+ end
20
+
21
+ end
22
+
23
+ describe ".enslaved" do
24
+
25
+ it "defaults to false" do
26
+ @klass.enslaved.should be_false
27
+ end
28
+ end
29
+
30
+ describe ".enslaved?" do
31
+
32
+ context "when the class is enslaved" do
33
+
34
+ before do
35
+ @klass.enslave
36
+ end
37
+
38
+ it "returns true" do
39
+ @klass.should be_enslaved
40
+ end
41
+ end
42
+
43
+ context "when the class is not enslaved" do
44
+
45
+ it "returns false" do
46
+ @klass.should_not be_enslaved
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ describe "#enslaved?" do
53
+
54
+ before do
55
+ @klass.enslave
56
+ @doc = @klass.new
57
+ end
58
+
59
+ it "returns the class enslaved? value" do
60
+ @doc.should be_enslaved
61
+ end
62
+ end
63
+ end
@@ -10,8 +10,8 @@ describe Mongoid::Extensions::Array::Conversions do
10
10
  Person.new(:_id => 2, :title => "Madam")
11
11
  ]
12
12
  array.mongoidize.should ==
13
- [ HashWithIndifferentAccess.new({ :_id => 1, :title => "Sir", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0 }),
14
- HashWithIndifferentAccess.new({ :_id => 2, :title => "Madam", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0 }) ]
13
+ [ HashWithIndifferentAccess.new({ :_id => 1, :title => "Sir", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0, :pets => false }),
14
+ HashWithIndifferentAccess.new({ :_id => 2, :title => "Madam", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0, :pets => false }) ]
15
15
  end
16
16
 
17
17
  end
@@ -6,7 +6,7 @@ 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
- { "_id" => 1, "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0 }
9
+ { "_id" => 1, "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0, "pets" => false}
10
10
  end
11
11
 
12
12
  end
@@ -28,7 +28,7 @@ describe Mongoid::Extensions::Object::Conversions do
28
28
  context "when object has attributes" do
29
29
 
30
30
  before do
31
- @attributes = { "_id" => "test", "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0 }
31
+ @attributes = { "_id" => "test", "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0, "pets" => false }
32
32
  @person = Person.new(@attributes)
33
33
  end
34
34
 
@@ -24,7 +24,7 @@ describe Mongoid::Extensions::Proc::Scoping do
24
24
 
25
25
  it "returns the criteria scoped" do
26
26
  @proc.scoped("Sir").should ==
27
- { :where => { :_type => { "$in" => [ "Doctor", "Person" ] }, :title => "Sir" } }
27
+ { :where => { :title => "Sir" } }
28
28
  end
29
29
 
30
30
  end
@@ -57,6 +57,12 @@ describe Mongoid::Fields do
57
57
  @person.testing.should == "Testy"
58
58
  end
59
59
 
60
+ it "adds an reader method with a question mark" do
61
+ @person = Person.new(:testing => "Test")
62
+ @person.testing?.should be_true
63
+ Person.new.testing?.should be_false
64
+ end
65
+
60
66
  end
61
67
 
62
68
  context "when type is an object" do
@@ -73,6 +79,10 @@ describe Mongoid::Fields do
73
79
  { "name" => "Jack and Coke" }
74
80
  end
75
81
 
82
+ it "adds an reader method with a question mark" do
83
+ @person.mixed_drink?.should be_true
84
+ end
85
+
76
86
  end
77
87
 
78
88
  context "when type is a boolean" do
@@ -360,7 +360,7 @@ describe Mongoid::Finders do
360
360
 
361
361
  it "returns a new criteria with select conditions added" do
362
362
  criteria = Person.where(:title => "Sir")
363
- criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }
363
+ criteria.selector.should == { :title => "Sir" }
364
364
  end
365
365
 
366
366
  end
@@ -40,9 +40,29 @@ describe Mongoid::Identity do
40
40
  Mongo::ObjectID.expects(:new).returns(@object_id)
41
41
  end
42
42
 
43
- it "sets the id to a mongo object id" do
44
- Mongoid::Identity.create(@person)
45
- @person.id.should == "1"
43
+ context "when using object ids" do
44
+
45
+ before do
46
+ Mongoid.use_object_ids = true
47
+ end
48
+
49
+ after do
50
+ Mongoid.use_object_ids = false
51
+ end
52
+
53
+ it "sets the id to a mongo object id" do
54
+ Mongoid::Identity.create(@person)
55
+ @person.id.should == @object_id
56
+ end
57
+ end
58
+
59
+ context "when not using object ids" do
60
+
61
+ it "sets the id to a mongo object id string" do
62
+ Mongoid::Identity.create(@person)
63
+ @person.id.should == "1"
64
+ end
65
+
46
66
  end
47
67
 
48
68
  end
@@ -17,6 +17,7 @@ describe Mongoid::NamedScope do
17
17
  named_scope :inactive, :where => { :active => false }
18
18
  named_scope :frags_over, lambda { |count| { :where => { :frags.gt => count } } }
19
19
  named_scope :deaths_under, lambda { |count| criteria.where(:deaths.lt => count) }
20
+ scope :deaths_over, lambda { |count| criteria.where(:deaths.gt => count) }
20
21
 
21
22
  class << self
22
23
  def alive
@@ -73,10 +74,22 @@ describe Mongoid::NamedScope do
73
74
 
74
75
  context "when a block is supplied" do
75
76
 
76
- it "adds the block as an extension" do
77
- Player.active.extension.should == "extension"
77
+ it "adds a class method for the scope" do
78
+ Player.should respond_to(:deaths_over)
78
79
  end
79
80
 
81
+ it "adds the scope to the scopes" do
82
+ Player.scopes.should include(:deaths_over)
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ describe ".scope" do
90
+
91
+ it "aliases to named_scope" do
92
+ Player.should respond_to(:deaths_over)
80
93
  end
81
94
 
82
95
  end
@@ -232,7 +232,7 @@ describe Mongoid::Scope do
232
232
 
233
233
  it "returns the conditions criteria" do
234
234
  @scope.target.selector.should ==
235
- { :title => "Sir", :_type => { "$in" => [ "Doctor", "Person" ] } }
235
+ { :title => "Sir" }
236
236
  end
237
237
 
238
238
  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: 1.2.6
4
+ version: 1.2.7
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: 2010-02-10 00:00:00 -05:00
12
+ date: 2010-02-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -119,6 +119,7 @@ files:
119
119
  - lib/mongoid/config.rb
120
120
  - lib/mongoid/contexts.rb
121
121
  - lib/mongoid/contexts/enumerable.rb
122
+ - lib/mongoid/contexts/ids.rb
122
123
  - lib/mongoid/contexts/mongo.rb
123
124
  - lib/mongoid/contexts/paging.rb
124
125
  - lib/mongoid/criteria.rb
@@ -128,6 +129,7 @@ files:
128
129
  - lib/mongoid/criterion/optional.rb
129
130
  - lib/mongoid/cursor.rb
130
131
  - lib/mongoid/document.rb
132
+ - lib/mongoid/enslavement.rb
131
133
  - lib/mongoid/errors.rb
132
134
  - lib/mongoid/extensions.rb
133
135
  - lib/mongoid/extensions/array/accessors.rb
@@ -233,6 +235,7 @@ files:
233
235
  - spec/unit/mongoid/config_spec.rb
234
236
  - spec/unit/mongoid/contexts/enumerable_spec.rb
235
237
  - spec/unit/mongoid/contexts/mongo_spec.rb
238
+ - spec/unit/mongoid/contexts_spec.rb
236
239
  - spec/unit/mongoid/criteria_spec.rb
237
240
  - spec/unit/mongoid/criterion/complex_spec.rb
238
241
  - spec/unit/mongoid/criterion/exclusion_spec.rb
@@ -240,6 +243,7 @@ files:
240
243
  - spec/unit/mongoid/criterion/optional_spec.rb
241
244
  - spec/unit/mongoid/cursor_spec.rb
242
245
  - spec/unit/mongoid/document_spec.rb
246
+ - spec/unit/mongoid/enslavement_spec.rb
243
247
  - spec/unit/mongoid/errors_spec.rb
244
248
  - spec/unit/mongoid/extensions/array/accessors_spec.rb
245
249
  - spec/unit/mongoid/extensions/array/assimilation_spec.rb
@@ -370,6 +374,7 @@ test_files:
370
374
  - spec/unit/mongoid/config_spec.rb
371
375
  - spec/unit/mongoid/contexts/enumerable_spec.rb
372
376
  - spec/unit/mongoid/contexts/mongo_spec.rb
377
+ - spec/unit/mongoid/contexts_spec.rb
373
378
  - spec/unit/mongoid/criteria_spec.rb
374
379
  - spec/unit/mongoid/criterion/complex_spec.rb
375
380
  - spec/unit/mongoid/criterion/exclusion_spec.rb
@@ -377,6 +382,7 @@ test_files:
377
382
  - spec/unit/mongoid/criterion/optional_spec.rb
378
383
  - spec/unit/mongoid/cursor_spec.rb
379
384
  - spec/unit/mongoid/document_spec.rb
385
+ - spec/unit/mongoid/enslavement_spec.rb
380
386
  - spec/unit/mongoid/errors_spec.rb
381
387
  - spec/unit/mongoid/extensions/array/accessors_spec.rb
382
388
  - spec/unit/mongoid/extensions/array/assimilation_spec.rb