mongomodel 0.4.6 → 0.4.7
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/Appraisals +12 -0
- data/bin/console +1 -2
- data/gemfiles/mongo_mapper.gemfile +12 -0
- data/gemfiles/mongoid.gemfile +12 -0
- data/lib/mongomodel.rb +3 -0
- data/lib/mongomodel/compatibility/mongo_mapper.rb +23 -0
- data/lib/mongomodel/compatibility/mongoid.rb +17 -0
- data/lib/mongomodel/concerns/properties.rb +5 -0
- data/lib/mongomodel/concerns/validations.rb +5 -3
- data/lib/mongomodel/support/core_extensions.rb +4 -4
- data/lib/mongomodel/support/mongo_options.rb +4 -2
- data/lib/mongomodel/support/mongo_order.rb +4 -0
- data/lib/mongomodel/support/scope.rb +1 -1
- data/lib/mongomodel/version.rb +1 -1
- data/spec/mongomodel/attributes/store_spec.rb +12 -12
- data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +13 -13
- data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +25 -25
- data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +25 -25
- data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +5 -5
- data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +21 -21
- data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +3 -3
- data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +10 -10
- data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +6 -6
- data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +6 -6
- data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +5 -5
- data/spec/mongomodel/concerns/attribute_methods_spec.rb +5 -5
- data/spec/mongomodel/concerns/attributes_spec.rb +13 -13
- data/spec/mongomodel/concerns/callbacks_spec.rb +11 -11
- data/spec/mongomodel/concerns/logging_spec.rb +2 -2
- data/spec/mongomodel/concerns/observing_spec.rb +3 -3
- data/spec/mongomodel/concerns/pretty_inspect_spec.rb +5 -5
- data/spec/mongomodel/concerns/properties_spec.rb +6 -6
- data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +6 -6
- data/spec/mongomodel/concerns/timestamps_spec.rb +10 -10
- data/spec/mongomodel/concerns/translation_spec.rb +1 -1
- data/spec/mongomodel/concerns/validations_spec.rb +12 -4
- data/spec/mongomodel/document/callbacks_spec.rb +10 -10
- data/spec/mongomodel/document/collection_modifiers_spec.rb +1 -1
- data/spec/mongomodel/document/dynamic_finders_spec.rb +5 -5
- data/spec/mongomodel/document/finders_spec.rb +9 -9
- data/spec/mongomodel/document/indexes_spec.rb +19 -19
- data/spec/mongomodel/document/optimistic_locking_spec.rb +8 -8
- data/spec/mongomodel/document/persistence_spec.rb +38 -38
- data/spec/mongomodel/document/scopes_spec.rb +8 -8
- data/spec/mongomodel/document/validations/uniqueness_spec.rb +9 -9
- data/spec/mongomodel/document/validations_spec.rb +16 -16
- data/spec/mongomodel/document_spec.rb +11 -11
- data/spec/mongomodel/embedded_document_spec.rb +13 -13
- data/spec/mongomodel/mongomodel_spec.rb +4 -4
- data/spec/mongomodel/support/collection_spec.rb +40 -40
- data/spec/mongomodel/support/map_spec.rb +41 -41
- data/spec/mongomodel/support/mongo_operator_spec.rb +11 -9
- data/spec/mongomodel/support/mongo_options_spec.rb +17 -17
- data/spec/mongomodel/support/mongo_order_spec.rb +22 -22
- data/spec/mongomodel/support/property_spec.rb +21 -12
- data/spec/mongomodel/support/scope_spec.rb +134 -134
- data/spec/spec_helper.rb +1 -0
- data/spec/specdoc.opts +0 -3
- metadata +7 -5
@@ -18,7 +18,7 @@ module MongoModel
|
|
18
18
|
TestModel.new(:name => 'Hello World', :age => 25, :paid => true, :prefs => { :foo => 'bar' }, :internal => 'hideme')
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "includes root in json" do
|
22
22
|
begin
|
23
23
|
TestModel.include_root_in_json = true
|
24
24
|
|
@@ -29,7 +29,7 @@ module MongoModel
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "encodes all public attributes" do
|
33
33
|
json = instance.to_json
|
34
34
|
json.should match(/"name":"Hello World"/)
|
35
35
|
json.should match(/"age":25/)
|
@@ -37,12 +37,12 @@ module MongoModel
|
|
37
37
|
json.should match(/"prefs":\{"foo":"bar"\}/)
|
38
38
|
end
|
39
39
|
|
40
|
-
it "
|
40
|
+
it "does not encode internal attributes" do
|
41
41
|
json = instance.to_json
|
42
42
|
json.should_not match(/"internal":"hideme"/)
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
45
|
+
it "allows attribute filtering with only" do
|
46
46
|
json = instance.to_json(:only => [:name, :age])
|
47
47
|
json.should match(/"name":"Hello World"/)
|
48
48
|
json.should match(/"age":25/)
|
@@ -50,7 +50,7 @@ module MongoModel
|
|
50
50
|
json.should_not match(/"prefs":\{"foo":"bar"\}/)
|
51
51
|
end
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "allows attribute filtering with except" do
|
54
54
|
json = instance.to_json(:except => [:name, :age])
|
55
55
|
json.should_not match(/"name":"Hello World"/)
|
56
56
|
json.should_not match(/"age":25/)
|
@@ -58,7 +58,7 @@ module MongoModel
|
|
58
58
|
json.should match(/"prefs":\{"foo":"bar"\}/)
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "allows methods to be included" do
|
62
62
|
json = instance.to_json(:methods => [:hello, :type])
|
63
63
|
json.should match(/"hello":"Hi friend!"/)
|
64
64
|
json.should match(/"type":"TestModel"/)
|
@@ -8,12 +8,12 @@ module MongoModel
|
|
8
8
|
timestamps!
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "defines a Time property updated_at" do
|
12
12
|
TestDocument.properties.should include(:updated_at)
|
13
13
|
TestDocument.properties[:updated_at].type.should == Time
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "defines a Time property created_at" do
|
17
17
|
TestDocument.properties.should include(:created_at)
|
18
18
|
TestDocument.properties[:created_at].type.should == Time
|
19
19
|
end
|
@@ -42,7 +42,7 @@ module MongoModel
|
|
42
42
|
Time.stub!(:now).and_return(@now)
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
45
|
+
it "sets the updated_at property to the current time when saved" do
|
46
46
|
doc.save
|
47
47
|
subject.updated_at.should == @now
|
48
48
|
end
|
@@ -66,7 +66,7 @@ module MongoModel
|
|
66
66
|
|
67
67
|
subject { TestDocument.new }
|
68
68
|
|
69
|
-
it "
|
69
|
+
it "sets the updated_on property to the current date when saved" do
|
70
70
|
doc.save
|
71
71
|
subject.updated_on.should == Date.today
|
72
72
|
end
|
@@ -95,12 +95,12 @@ module MongoModel
|
|
95
95
|
Time.stub!(:now).and_return(@now)
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
98
|
+
it "sets the created_at property to the current time when created" do
|
99
99
|
doc.save
|
100
100
|
subject.created_at.should == @now
|
101
101
|
end
|
102
102
|
|
103
|
-
it "
|
103
|
+
it "does not change the created_at property when updated" do
|
104
104
|
@next = 1.day.from_now
|
105
105
|
|
106
106
|
Time.stub!(:now).and_return(@now)
|
@@ -113,7 +113,7 @@ module MongoModel
|
|
113
113
|
subject.created_at.should == @now
|
114
114
|
end
|
115
115
|
|
116
|
-
it "
|
116
|
+
it "preserves created_at attribute when set explicitly" do
|
117
117
|
@a_year_ago = 1.year.ago
|
118
118
|
|
119
119
|
subject.created_at = @a_year_ago
|
@@ -141,12 +141,12 @@ module MongoModel
|
|
141
141
|
|
142
142
|
subject { TestDocument.new }
|
143
143
|
|
144
|
-
it "
|
144
|
+
it "sets the created_on property to the current date when created" do
|
145
145
|
doc.save
|
146
146
|
subject.created_on.should == Date.today
|
147
147
|
end
|
148
148
|
|
149
|
-
it "
|
149
|
+
it "does not change the created_on property when updated" do
|
150
150
|
doc.save
|
151
151
|
|
152
152
|
@today = Date.today
|
@@ -158,7 +158,7 @@ module MongoModel
|
|
158
158
|
subject.created_on.should == @today
|
159
159
|
end
|
160
160
|
|
161
|
-
it "
|
161
|
+
it "preserves created_on attribute when set explicitly" do
|
162
162
|
@a_year_ago = 1.year.ago.to_date
|
163
163
|
|
164
164
|
subject.created_on = @a_year_ago
|
@@ -26,7 +26,7 @@ module MongoModel
|
|
26
26
|
subject { doc }
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "has an errors collection" do
|
30
30
|
subject.errors.should be_an_instance_of(ActiveModel::Errors)
|
31
31
|
end
|
32
32
|
|
@@ -87,7 +87,7 @@ module MongoModel
|
|
87
87
|
|
88
88
|
it { should be_valid }
|
89
89
|
|
90
|
-
it "
|
90
|
+
it "is not valid in custom context" do
|
91
91
|
subject.valid?(:custom).should be_false
|
92
92
|
end
|
93
93
|
end
|
@@ -95,20 +95,28 @@ module MongoModel
|
|
95
95
|
|
96
96
|
describe "validation shortcuts" do
|
97
97
|
define_class(:TestDocument, described_class)
|
98
|
+
define_class(:SubDocument, EmbeddedDocument)
|
98
99
|
|
99
100
|
describe ":required => true" do
|
100
|
-
it "
|
101
|
+
it "adds a validates_presence_of validation" do
|
101
102
|
TestDocument.should_receive(:validates_presence_of).with(:title)
|
102
103
|
TestDocument.property :title, String, :required => true
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
107
|
describe ":format => /regex/" do
|
107
|
-
it "
|
108
|
+
it "adds a validates_format_of validation" do
|
108
109
|
TestDocument.should_receive(:validates_format_of).with(:email, /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i)
|
109
110
|
TestDocument.property :email, String, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
110
111
|
end
|
111
112
|
end
|
113
|
+
|
114
|
+
describe ":validate => false" do
|
115
|
+
it "skips validations on embedded/associated models" do
|
116
|
+
TestDocument.should_not_receive(:validates_associated).with(:sub_object)
|
117
|
+
TestDocument.property :sub_object, SubDocument, :validate => false
|
118
|
+
end
|
119
|
+
end
|
112
120
|
end
|
113
121
|
end
|
114
122
|
|
@@ -9,46 +9,46 @@ module MongoModel
|
|
9
9
|
|
10
10
|
let(:doc) { CallbackTestDocument.create! }
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "runs each type of callback when initializing" do
|
13
13
|
instance = CallbackTestDocument.new
|
14
14
|
instance.should run_callbacks(:after_initialize)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "runs each type of callback on find" do
|
18
18
|
instance = CallbackTestDocument.find(doc.id)
|
19
19
|
instance.should run_callbacks(:after_initialize, :after_find)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "runs each type of callback when validating a new document" do
|
23
23
|
instance = CallbackTestDocument.new
|
24
24
|
instance.valid?
|
25
25
|
instance.should run_callbacks(:after_initialize, :before_validation, :after_validation)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "runs each type of callback when validating an existing document" do
|
29
29
|
instance = CallbackTestDocument.find(doc.id)
|
30
30
|
instance.valid?
|
31
31
|
instance.should run_callbacks(:after_initialize, :after_find, :before_validation, :after_validation)
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "runs each type of callback when creating a document" do
|
35
35
|
instance = CallbackTestDocument.create!
|
36
36
|
instance.should run_callbacks(:after_initialize, :before_validation, :after_validation, :before_save, :before_create, :after_create, :after_save)
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "runs each type of callback when saving an existing document" do
|
40
40
|
instance = CallbackTestDocument.find(doc.id)
|
41
41
|
instance.save
|
42
42
|
instance.should run_callbacks(:after_initialize, :after_find, :before_validation, :after_validation, :before_save, :before_update, :after_update, :after_save)
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
45
|
+
it "runs each type of callback when destroying a document" do
|
46
46
|
instance = CallbackTestDocument.find(doc.id)
|
47
47
|
instance.destroy
|
48
48
|
instance.should run_callbacks(:after_initialize, :after_find, :before_destroy, :after_destroy)
|
49
49
|
end
|
50
50
|
|
51
|
-
it "
|
51
|
+
it "does not run destroy callbacks when deleting a document" do
|
52
52
|
instance = CallbackTestDocument.find(doc.id)
|
53
53
|
instance.delete
|
54
54
|
instance.should run_callbacks(:after_initialize, :after_find)
|
@@ -64,13 +64,13 @@ module MongoModel
|
|
64
64
|
subject { CallbackTestDocument.new }
|
65
65
|
|
66
66
|
describe "#save" do
|
67
|
-
it "
|
67
|
+
it "returns false" do
|
68
68
|
subject.save.should be_false
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "#save!" do
|
73
|
-
it "
|
73
|
+
it "raises a MongoModel::DocumentNotSaved exception" do
|
74
74
|
lambda { subject.save! }.should raise_error(MongoModel::DocumentNotSaved)
|
75
75
|
end
|
76
76
|
end
|
@@ -13,7 +13,7 @@ module MongoModel
|
|
13
13
|
subject { Post }
|
14
14
|
|
15
15
|
def self.should_update_collection(expression, &block)
|
16
|
-
it "
|
16
|
+
it "updates the collection" do
|
17
17
|
collection.should_receive(:update).with(selector, expression, :multi => true)
|
18
18
|
instance_eval(&block)
|
19
19
|
end
|
@@ -19,21 +19,21 @@ module MongoModel
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.should_find(*args, &block)
|
22
|
-
it "
|
22
|
+
it "returns correct results when called with #{args.inspect}" do
|
23
23
|
expected = instance_eval(&block)
|
24
24
|
subject.send(valid_finder, *args).should == expected
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.should_raise(*args, &block)
|
29
|
-
it "
|
29
|
+
it "raises DocumentNotFound exception if results not found" do
|
30
30
|
message = instance_eval(&block)
|
31
31
|
lambda { subject.send(valid_finder, *args) }.should raise_error(DocumentNotFound, message)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.should_initialize(*args, &block)
|
36
|
-
it "
|
36
|
+
it "initializes new instance" do
|
37
37
|
result = subject.send(valid_finder, *args)
|
38
38
|
result.should be_a_new_record
|
39
39
|
result.should be_an_instance_of(Person)
|
@@ -42,7 +42,7 @@ module MongoModel
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.should_create(*args, &block)
|
45
|
-
it "
|
45
|
+
it "creates new instance" do
|
46
46
|
result = subject.send(valid_finder, *args)
|
47
47
|
result.should_not be_a_new_record
|
48
48
|
result.should be_an_instance_of(Person)
|
@@ -54,7 +54,7 @@ module MongoModel
|
|
54
54
|
it { should respond_to(valid_finder) }
|
55
55
|
it { should_not respond_to(invalid_finder) }
|
56
56
|
|
57
|
-
it "
|
57
|
+
it "raises NoMethodError calling an invalid finder" do
|
58
58
|
lambda { subject.send(invalid_finder, "Foo") }.should raise_error(NoMethodError)
|
59
59
|
end
|
60
60
|
end
|
@@ -20,24 +20,24 @@ module MongoModel
|
|
20
20
|
context "document exists" do
|
21
21
|
subject { User.find('2') }
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "returns a User" do
|
24
24
|
subject.should be_a(User)
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "loads the document attributes" do
|
28
28
|
subject.id.should == '2'
|
29
29
|
subject.name.should == 'Alistair'
|
30
30
|
end
|
31
31
|
|
32
32
|
it { should_not be_a_new_record }
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "stringifies ids" do
|
35
35
|
User.find(2).id.should == '2'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "document does not exist" do
|
40
|
-
it "
|
40
|
+
it "raises a DocumentNotFound exception" do
|
41
41
|
lambda {
|
42
42
|
User.find('4')
|
43
43
|
}.should raise_error(MongoModel::DocumentNotFound)
|
@@ -45,7 +45,7 @@ module MongoModel
|
|
45
45
|
end
|
46
46
|
|
47
47
|
context "no id specified" do
|
48
|
-
it "
|
48
|
+
it "raises an ArgumentError" do
|
49
49
|
lambda {
|
50
50
|
User.find
|
51
51
|
}.should raise_error(ArgumentError)
|
@@ -57,17 +57,17 @@ module MongoModel
|
|
57
57
|
context "all documents exist" do
|
58
58
|
subject { User.find('1', '2') }
|
59
59
|
|
60
|
-
it "
|
60
|
+
it "returns an array of Users" do
|
61
61
|
subject[0].should be_a(User)
|
62
62
|
subject[1].should be_a(User)
|
63
63
|
end
|
64
64
|
|
65
|
-
it "
|
65
|
+
it "loads document attributes" do
|
66
66
|
subject[0].name.should == 'Fred'
|
67
67
|
subject[1].name.should == 'Alistair'
|
68
68
|
end
|
69
69
|
|
70
|
-
it "
|
70
|
+
it "loads documents in correct order" do
|
71
71
|
result = User.find('2', '1')
|
72
72
|
result[0].id.should == '2'
|
73
73
|
result[1].id.should == '1'
|
@@ -75,7 +75,7 @@ module MongoModel
|
|
75
75
|
end
|
76
76
|
|
77
77
|
context "some documents missing" do
|
78
|
-
it "
|
78
|
+
it "raises a DocumentNotFound exception" do
|
79
79
|
lambda {
|
80
80
|
User.find('1', '2', '4')
|
81
81
|
}.should raise_error(MongoModel::DocumentNotFound)
|
@@ -13,23 +13,23 @@ module MongoModel
|
|
13
13
|
Class.new(klass)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "has an indexes collection" do
|
17
17
|
Article.indexes.should be_an_instance_of(Array)
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "inherits indexes from parent classes" do
|
21
21
|
index = mock('index')
|
22
22
|
Article.indexes << index
|
23
23
|
subclass(Article).indexes.should include(index)
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#index" do
|
27
|
-
it "
|
27
|
+
it "adds an index to the indexes collection" do
|
28
28
|
Article.index :title, :unique => true
|
29
29
|
Article.indexes.last.should == Index.new(:title, :unique => true)
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "marks indexes as uninitialized" do
|
33
33
|
Article.ensure_indexes!
|
34
34
|
|
35
35
|
Article.indexes_initialized?.should be_true
|
@@ -45,7 +45,7 @@ module MongoModel
|
|
45
45
|
Article.index :position => :geo2d, :min => -100, :max => 100
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "creates indexes on the collection" do
|
49
49
|
Article.collection.should_receive(:create_index).with(:_type)
|
50
50
|
Article.collection.should_receive(:create_index).with(:title, :unique => true)
|
51
51
|
Article.collection.should_receive(:create_index).with([[:age, Mongo::DESCENDING]])
|
@@ -53,7 +53,7 @@ module MongoModel
|
|
53
53
|
Article.ensure_indexes!
|
54
54
|
end
|
55
55
|
|
56
|
-
it "
|
56
|
+
it "marks indexes as initialized" do
|
57
57
|
Article.indexes_initialized?.should be_false
|
58
58
|
Article.ensure_indexes!
|
59
59
|
Article.indexes_initialized?.should be_true
|
@@ -61,12 +61,12 @@ module MongoModel
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#_find" do
|
64
|
-
it "
|
64
|
+
it "runs ensure_indexes!" do
|
65
65
|
Article.should_receive(:ensure_indexes!)
|
66
66
|
Article.first
|
67
67
|
end
|
68
68
|
|
69
|
-
it "
|
69
|
+
it "reruns ensure_indexes! if indexes are initialized" do
|
70
70
|
Article.ensure_indexes!
|
71
71
|
Article.should_not_receive(:ensure_indexes!)
|
72
72
|
Article.first
|
@@ -78,7 +78,7 @@ module MongoModel
|
|
78
78
|
define_class(:TestDocument, Document)
|
79
79
|
|
80
80
|
describe ":index => true" do
|
81
|
-
it "
|
81
|
+
it "adds an index on the property" do
|
82
82
|
TestDocument.should_receive(:index).with(:title)
|
83
83
|
TestDocument.property :title, String, :index => true
|
84
84
|
end
|
@@ -87,44 +87,44 @@ module MongoModel
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe Index do
|
90
|
-
it "
|
90
|
+
it "converts index with single key to arguments for Mongo::Collection#create_index" do
|
91
91
|
Index.new(:title).to_args.should == [:title]
|
92
92
|
end
|
93
93
|
|
94
|
-
it "
|
94
|
+
it "converts nested index with single key to arguments for Mongo::Collection#create_index" do
|
95
95
|
Index.new('page.title').to_args.should == [:'page.title']
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
98
|
+
it "converts index with unique option to arguments for Mongo::Collection#create_index" do
|
99
99
|
Index.new(:title, :unique => true).to_args.should == [:title, { :unique => true }]
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "converts index with descending key to arguments for Mongo::Collection#create_index" do
|
103
103
|
Index.new(:title => :descending).to_args.should == [[[:title, Mongo::DESCENDING]]]
|
104
104
|
end
|
105
105
|
|
106
|
-
it "
|
106
|
+
it "converts index with multiple keys to arguments for Mongo::Collection#create_index" do
|
107
107
|
Index.new(:title, :age).to_args.should == [[[:age, Mongo::ASCENDING], [:title, Mongo::ASCENDING]]]
|
108
108
|
end
|
109
109
|
|
110
|
-
it "
|
110
|
+
it "converts index with multiple keys (ascending and descending) to arguments for Mongo::Collection#create_index" do
|
111
111
|
Index.new(:title => :ascending, :age => :descending).to_args.should == [[[:age, Mongo::DESCENDING], [:title, Mongo::ASCENDING]]]
|
112
112
|
end
|
113
113
|
|
114
|
-
it "
|
114
|
+
it "converts geospatial index with no options" do
|
115
115
|
Index.new(:position => :geo2d).to_args.should == [[[:position, Mongo::GEO2D]]]
|
116
116
|
end
|
117
117
|
|
118
|
-
it "
|
118
|
+
it "converts geospatial index with min/max options" do
|
119
119
|
Index.new(:position => :geo2d, :min => -50, :max => 50).to_args.should == [[[:position, Mongo::GEO2D]], { :min => -50, :max => 50 }]
|
120
120
|
end
|
121
121
|
|
122
|
-
it "
|
122
|
+
it "is equal to an equivalent index" do
|
123
123
|
Index.new(:title).should == Index.new(:title)
|
124
124
|
Index.new(:title, :age).should == Index.new(:title => :ascending, :age => :ascending)
|
125
125
|
end
|
126
126
|
|
127
|
-
it "
|
127
|
+
it "is not equal to an non-equivalent index" do
|
128
128
|
Index.new(:title).should_not == Index.new(:age)
|
129
129
|
Index.new(:title, :age).should_not == Index.new(:title => :ascending, :age => :descending)
|
130
130
|
end
|