mongoid 4.0.0.alpha2 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -0
- data/README.md +3 -3
- data/lib/config/locales/en.yml +13 -0
- data/lib/mongoid.rb +3 -1
- data/lib/mongoid/atomic.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/attributes.rb +23 -1
- data/lib/mongoid/attributes/processing.rb +1 -1
- data/lib/mongoid/composable.rb +3 -2
- data/lib/mongoid/contextual/command.rb +0 -26
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/mongo.rb +6 -29
- data/lib/mongoid/contextual/text_search.rb +3 -5
- data/lib/mongoid/criteria.rb +1 -1
- data/lib/mongoid/criteria/modifiable.rb +27 -7
- data/lib/mongoid/criteria/permission.rb +70 -0
- data/lib/mongoid/document.rb +5 -6
- data/lib/mongoid/errors.rb +2 -0
- data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
- data/lib/mongoid/errors/readonly_document.rb +24 -0
- data/lib/mongoid/extensions/boolean.rb +1 -0
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/factory.rb +5 -3
- data/lib/mongoid/fields.rb +32 -0
- data/lib/mongoid/fields/localized.rb +1 -1
- data/lib/mongoid/fields/standard.rb +1 -1
- data/lib/mongoid/findable.rb +1 -0
- data/lib/mongoid/interceptable.rb +11 -6
- data/lib/mongoid/log_subscriber.rb +34 -1
- data/lib/mongoid/persistable/deletable.rb +1 -0
- data/lib/mongoid/persistable/destroyable.rb +7 -2
- data/lib/mongoid/persistable/updatable.rb +27 -26
- data/lib/mongoid/query_cache.rb +246 -0
- data/lib/mongoid/railties/database.rake +4 -26
- data/lib/mongoid/relations.rb +8 -22
- data/lib/mongoid/relations/accessors.rb +0 -3
- data/lib/mongoid/relations/binding.rb +1 -1
- data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
- data/lib/mongoid/relations/eager.rb +5 -6
- data/lib/mongoid/relations/eager/base.rb +97 -5
- data/lib/mongoid/relations/eager/belongs_to.rb +1 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +16 -9
- data/lib/mongoid/relations/eager/has_many.rb +1 -0
- data/lib/mongoid/relations/eager/has_one.rb +1 -0
- data/lib/mongoid/relations/embedded/batchable.rb +1 -1
- data/lib/mongoid/relations/embedded/in.rb +4 -4
- data/lib/mongoid/relations/embedded/many.rb +7 -5
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/relations/macros.rb +1 -0
- data/lib/mongoid/relations/marshalable.rb +3 -3
- data/lib/mongoid/relations/proxy.rb +12 -10
- data/lib/mongoid/relations/referenced/in.rb +2 -2
- data/lib/mongoid/relations/referenced/many.rb +9 -9
- data/lib/mongoid/relations/referenced/many_to_many.rb +7 -7
- data/lib/mongoid/relations/referenced/one.rb +4 -4
- data/lib/mongoid/{state.rb → stateful.rb} +13 -1
- data/lib/mongoid/tasks/database.rake +31 -0
- data/lib/mongoid/tasks/database.rb +107 -0
- data/lib/mongoid/threaded.rb +0 -47
- data/lib/mongoid/validatable/uniqueness.rb +4 -16
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +0 -3
- data/lib/rails/mongoid.rb +0 -124
- data/spec/app/models/edit.rb +5 -0
- data/spec/app/models/even.rb +7 -0
- data/spec/app/models/line_item.rb +1 -1
- data/spec/app/models/note.rb +2 -0
- data/spec/app/models/odd.rb +7 -0
- data/spec/app/models/record.rb +5 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +76 -1
- data/spec/mongoid/changeable_spec.rb +6 -2
- data/spec/mongoid/contextual/mongo_spec.rb +3 -1
- data/spec/mongoid/contextual/text_search_spec.rb +3 -1
- data/spec/mongoid/criteria/modifiable_spec.rb +192 -0
- data/spec/mongoid/criteria_spec.rb +6 -2
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
- data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
- data/spec/mongoid/fields/localized_spec.rb +15 -0
- data/spec/mongoid/fields_spec.rb +88 -2
- data/spec/mongoid/log_subscriber_spec.rb +3 -3
- data/spec/mongoid/persistable/deletable_spec.rb +14 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +45 -1
- data/spec/mongoid/persistable/savable_spec.rb +34 -5
- data/spec/mongoid/query_cache_spec.rb +197 -0
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +2 -2
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +1 -1
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +11 -37
- data/spec/mongoid/relations/eager/has_one_spec.rb +1 -1
- data/spec/mongoid/relations/embedded/in_spec.rb +1 -1
- data/spec/mongoid/relations/embedded/many_spec.rb +10 -10
- data/spec/mongoid/relations/embedded/one_spec.rb +10 -2
- data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +37 -2
- data/spec/mongoid/relations/touchable_spec.rb +20 -0
- data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +26 -1
- data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
- data/spec/mongoid/tasks/database_spec.rb +148 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +7 -0
- data/spec/rails/mongoid_spec.rb +0 -316
- data/spec/spec_helper.rb +1 -0
- metadata +30 -8
@@ -88,11 +88,11 @@ describe Mongoid::Relations::Bindings::Embedded::In do
|
|
88
88
|
context "when the base has metadata" do
|
89
89
|
|
90
90
|
before do
|
91
|
-
address.
|
91
|
+
address.__metadata = person_metadata
|
92
92
|
end
|
93
93
|
|
94
94
|
it "does not overwrite the existing metadata" do
|
95
|
-
expect(address).to receive(:
|
95
|
+
expect(address).to receive(:__metadata=).never
|
96
96
|
binding.bind_one
|
97
97
|
end
|
98
98
|
end
|
@@ -127,7 +127,7 @@ describe Mongoid::Relations::Builders::Referenced::Many do
|
|
127
127
|
it "returns an empty array" do
|
128
128
|
Person.new do |p|
|
129
129
|
expect(p.posts).to be_empty
|
130
|
-
expect(p.posts.
|
130
|
+
expect(p.posts.__metadata).to_not be_nil
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::Relations::Eager::HasAndBelongsToMany do
|
4
4
|
|
5
|
-
describe ".
|
5
|
+
describe ".keys_from_docs" do
|
6
6
|
|
7
7
|
let(:docs) do
|
8
8
|
Person.all.to_a
|
@@ -26,40 +26,8 @@ describe Mongoid::Relations::Eager::HasAndBelongsToMany do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it "aggregates by the
|
30
|
-
expect(eager.
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe ".set_on_parent" do
|
35
|
-
|
36
|
-
let(:docs) do
|
37
|
-
Person.all.to_a
|
38
|
-
end
|
39
|
-
|
40
|
-
let!(:person) do
|
41
|
-
Person.create!(houses: [house])
|
42
|
-
end
|
43
|
-
|
44
|
-
let!(:house) do
|
45
|
-
House.create!
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:metadata) do
|
49
|
-
Person.reflect_on_association(:houses)
|
50
|
-
end
|
51
|
-
|
52
|
-
let(:eager) do
|
53
|
-
described_class.new([metadata], docs).tap do |b|
|
54
|
-
b.shift_metadata
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "sets the relation into the parent" do
|
59
|
-
docs.each do |doc|
|
60
|
-
expect(doc).to receive(:__build__).once.with(:houses, :foo, metadata)
|
61
|
-
end
|
62
|
-
eager.set_on_parent(person.id, :foo)
|
29
|
+
it "aggregates by the foreign key" do
|
30
|
+
expect(eager.keys_from_docs).to eq([house.id])
|
63
31
|
end
|
64
32
|
end
|
65
33
|
|
@@ -76,14 +44,20 @@ describe Mongoid::Relations::Eager::HasAndBelongsToMany do
|
|
76
44
|
context "when including the has_and_belongs_to_many relation" do
|
77
45
|
|
78
46
|
it "queries twice" do
|
79
|
-
|
80
47
|
expect_query(2) do
|
81
|
-
|
82
48
|
Person.all.includes(:houses).each do |person|
|
83
49
|
expect(person.houses).to_not be_nil
|
50
|
+
|
51
|
+
expect(person.houses.length).to be(3)
|
84
52
|
end
|
85
53
|
end
|
86
54
|
end
|
55
|
+
|
56
|
+
it "has all items" do
|
57
|
+
Person.all.includes(:houses).each do |person|
|
58
|
+
expect(person.ivar(:houses).length).to be(3)
|
59
|
+
end
|
60
|
+
end
|
87
61
|
end
|
88
62
|
|
89
63
|
context "when the relation is not polymorphic" do
|
@@ -41,7 +41,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "sets the metadata on the child" do
|
44
|
-
expect(address.
|
44
|
+
expect(address.__metadata).to_not be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "sets the index on the child" do
|
@@ -181,7 +181,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it "sets the metadata on the child" do
|
184
|
-
expect(child_role.
|
184
|
+
expect(child_role.__metadata).to_not be_nil
|
185
185
|
end
|
186
186
|
|
187
187
|
it "sets the index on the child" do
|
@@ -283,7 +283,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
283
283
|
end
|
284
284
|
|
285
285
|
it "sets the metadata on the child" do
|
286
|
-
expect(address.
|
286
|
+
expect(address.__metadata).to_not be_nil
|
287
287
|
end
|
288
288
|
|
289
289
|
it "sets the index on the child" do
|
@@ -634,7 +634,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
634
634
|
end
|
635
635
|
|
636
636
|
it "sets the metadata on the child" do
|
637
|
-
expect(child_role.
|
637
|
+
expect(child_role.__metadata).to_not be_nil
|
638
638
|
end
|
639
639
|
|
640
640
|
it "sets the index on the child" do
|
@@ -981,7 +981,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
981
981
|
end
|
982
982
|
|
983
983
|
it "sets the metadata on the child" do
|
984
|
-
expect(address.
|
984
|
+
expect(address.__metadata).to_not be_nil
|
985
985
|
end
|
986
986
|
|
987
987
|
it "sets the index on the child" do
|
@@ -1024,7 +1024,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1024
1024
|
end
|
1025
1025
|
|
1026
1026
|
it "sets the metadata on the child" do
|
1027
|
-
expect(child_role.
|
1027
|
+
expect(child_role.__metadata).to_not be_nil
|
1028
1028
|
end
|
1029
1029
|
|
1030
1030
|
it "sets the index on the child" do
|
@@ -1213,7 +1213,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1213
1213
|
end
|
1214
1214
|
|
1215
1215
|
it "sets the metadata on the child" do
|
1216
|
-
expect(address.
|
1216
|
+
expect(address.__metadata).to_not be_nil
|
1217
1217
|
end
|
1218
1218
|
|
1219
1219
|
it "sets the index on the child" do
|
@@ -1320,7 +1320,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1320
1320
|
end
|
1321
1321
|
|
1322
1322
|
it "sets the metadata on the child" do
|
1323
|
-
expect(child_role.
|
1323
|
+
expect(child_role.__metadata).to_not be_nil
|
1324
1324
|
end
|
1325
1325
|
|
1326
1326
|
it "sets the index on the child" do
|
@@ -1427,7 +1427,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1427
1427
|
end
|
1428
1428
|
|
1429
1429
|
it "sets the metadata on the child" do
|
1430
|
-
expect(address.
|
1430
|
+
expect(address.__metadata).to_not be_nil
|
1431
1431
|
end
|
1432
1432
|
|
1433
1433
|
it "sets the index on the child" do
|
@@ -1526,7 +1526,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1526
1526
|
end
|
1527
1527
|
|
1528
1528
|
it "sets the metadata on the child" do
|
1529
|
-
expect(address.
|
1529
|
+
expect(address.__metadata).to_not be_nil
|
1530
1530
|
end
|
1531
1531
|
|
1532
1532
|
it "sets the index on the child" do
|
@@ -174,11 +174,11 @@ describe Mongoid::Relations::Embedded::One do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
let(:pet_one) do
|
177
|
-
Pet.new
|
177
|
+
Pet.new(name: 'kika')
|
178
178
|
end
|
179
179
|
|
180
180
|
let(:pet_two) do
|
181
|
-
Pet.new
|
181
|
+
Pet.new(name: 'tiksy')
|
182
182
|
end
|
183
183
|
|
184
184
|
before do
|
@@ -189,6 +189,14 @@ describe Mongoid::Relations::Embedded::One do
|
|
189
189
|
it "runs the destroy callbacks on the old document" do
|
190
190
|
expect(pet_one.destroy_flag).to be true
|
191
191
|
end
|
192
|
+
|
193
|
+
it "keeps the name of the destroyed" do
|
194
|
+
expect(pet_one.name).to eq("kika")
|
195
|
+
end
|
196
|
+
|
197
|
+
it "saves the new name" do
|
198
|
+
expect(pet_owner.pet.name).to eq("tiksy")
|
199
|
+
end
|
192
200
|
end
|
193
201
|
end
|
194
202
|
|
@@ -1577,6 +1577,33 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1577
1577
|
expect(person.posts.count).to eq(1)
|
1578
1578
|
end
|
1579
1579
|
end
|
1580
|
+
|
1581
|
+
context "when passing a new object" do
|
1582
|
+
|
1583
|
+
let!(:odd) do
|
1584
|
+
Odd.create(name: 'one')
|
1585
|
+
end
|
1586
|
+
|
1587
|
+
let!(:even) do
|
1588
|
+
odd.evens.create(name: 'two', odds: [Odd.new(name: 'three')])
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
it "only push one even to the list" do
|
1592
|
+
expect(odd.evens.count).to eq(1)
|
1593
|
+
end
|
1594
|
+
|
1595
|
+
it "saves the reference back" do
|
1596
|
+
expect(odd.evens.first.odds.count).to eq(1)
|
1597
|
+
end
|
1598
|
+
|
1599
|
+
it "only saves one even" do
|
1600
|
+
expect(Even.count).to eq(1)
|
1601
|
+
end
|
1602
|
+
|
1603
|
+
it "saves the first odd and the second" do
|
1604
|
+
expect(Odd.count).to eq(2)
|
1605
|
+
end
|
1606
|
+
end
|
1580
1607
|
end
|
1581
1608
|
|
1582
1609
|
context "when the relation is polymorphic" do
|
@@ -2361,8 +2388,16 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2361
2388
|
movie.ratings.find([ rating_one.id, rating_two.id ])
|
2362
2389
|
end
|
2363
2390
|
|
2364
|
-
it "returns the matching
|
2365
|
-
expect(ratings).to
|
2391
|
+
it "returns the first matching document" do
|
2392
|
+
expect(ratings).to include(rating_one)
|
2393
|
+
end
|
2394
|
+
|
2395
|
+
it "returns the second matching document" do
|
2396
|
+
expect(ratings).to include(rating_two)
|
2397
|
+
end
|
2398
|
+
|
2399
|
+
it "returns the correct number of documents" do
|
2400
|
+
expect(ratings.size).to eq(2)
|
2366
2401
|
end
|
2367
2402
|
end
|
2368
2403
|
|
@@ -207,6 +207,26 @@ describe Mongoid::Relations::Touchable do
|
|
207
207
|
|
208
208
|
context "when relations have touch options" do
|
209
209
|
|
210
|
+
context "when the relation is a parent of an embedded doc" do
|
211
|
+
|
212
|
+
let(:page) do
|
213
|
+
WikiPage.create(title: "test")
|
214
|
+
end
|
215
|
+
|
216
|
+
let!(:edit) do
|
217
|
+
page.edits.create
|
218
|
+
end
|
219
|
+
|
220
|
+
before do
|
221
|
+
page.unset(:updated_at)
|
222
|
+
edit.touch
|
223
|
+
end
|
224
|
+
|
225
|
+
it "touches the parent document" do
|
226
|
+
expect(page.updated_at).to be_within(5).of(Time.now)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
210
230
|
context "when the relation is nil" do
|
211
231
|
|
212
232
|
let!(:agent) do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Mongoid::
|
3
|
+
describe Mongoid::Stateful do
|
4
4
|
|
5
5
|
describe "#new_record?" do
|
6
6
|
|
@@ -99,4 +99,29 @@ describe Mongoid::State do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
describe "#readonly?" do
|
104
|
+
|
105
|
+
let(:document) do
|
106
|
+
Band.new
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when the document is readonly" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
document.__selected_fields = { test: 1 }
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns true" do
|
116
|
+
expect(document).to be_readonly
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when no readonly has been set" do
|
121
|
+
|
122
|
+
it "returns false" do
|
123
|
+
expect(document).to_not be_readonly
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
102
127
|
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
unless defined?(Rails)
|
5
|
+
module Rails
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_context "rake task" do
|
10
|
+
let(:task_name) { self.class.top_level_description }
|
11
|
+
let(:task) { Rake.application[task_name] }
|
12
|
+
let(:task_file) { "mongoid/tasks/database" }
|
13
|
+
|
14
|
+
let(:logger) do
|
15
|
+
double("logger").tap do |log|
|
16
|
+
allow(log).to receive(:info)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
rake = Rake::Application.new
|
22
|
+
Rake.application = rake
|
23
|
+
rake.rake_require(task_file, $LOAD_PATH, [])
|
24
|
+
Rake::Task.define_task(:environment)
|
25
|
+
|
26
|
+
allow(Mongoid::Tasks::Database).to receive(:logger).and_return(logger)
|
27
|
+
end
|
28
|
+
|
29
|
+
shared_examples_for "create_indexes" do
|
30
|
+
|
31
|
+
it "receives create_indexes" do
|
32
|
+
expect(Mongoid::Tasks::Database).to receive(:create_indexes)
|
33
|
+
task.invoke
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
shared_context "rails rake task" do
|
39
|
+
let(:task_file) { "mongoid/railties/database" }
|
40
|
+
|
41
|
+
let(:application) do
|
42
|
+
app = double("application")
|
43
|
+
allow(app).to receive(:eager_load!)
|
44
|
+
app
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "db:drop" do
|
49
|
+
include_context "rake task"
|
50
|
+
include_context "rails rake task"
|
51
|
+
|
52
|
+
it "calls mongoid:drop" do
|
53
|
+
expect(task.prerequisites).to include("mongoid:drop")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "works" do
|
57
|
+
task.invoke
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "db:purge" do
|
62
|
+
include_context "rake task"
|
63
|
+
include_context "rails rake task"
|
64
|
+
|
65
|
+
it "calls mongoid:drop" do
|
66
|
+
expect(task.prerequisites).to include("mongoid:purge")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "works" do
|
70
|
+
task.invoke
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "db:seed" do
|
75
|
+
include_context "rake task"
|
76
|
+
include_context "rails rake task"
|
77
|
+
|
78
|
+
it "calls environment" do
|
79
|
+
expect(task.prerequisites).to include("environment")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "works" do
|
83
|
+
expect(Rails).to receive(:root).and_return(".")
|
84
|
+
task.invoke
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "db:setup" do
|
89
|
+
include_context "rake task"
|
90
|
+
include_context "rails rake task"
|
91
|
+
|
92
|
+
it "calls db:create" do
|
93
|
+
expect(task.prerequisites).to include("db:create")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "calls db:mongoid:create_indexes" do
|
97
|
+
expect(task.prerequisites).to include("mongoid:create_indexes")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "calls db:seed" do
|
101
|
+
expect(task.prerequisites).to include("db:seed")
|
102
|
+
end
|
103
|
+
|
104
|
+
it_behaves_like "create_indexes" do
|
105
|
+
|
106
|
+
before do
|
107
|
+
expect(Rails).to receive(:root).and_return(".")
|
108
|
+
expect(Rails).to receive(:application).and_return(application)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "works" do
|
113
|
+
expect(Mongoid::Tasks::Database).to receive(:create_indexes)
|
114
|
+
expect(Rails).to receive(:root).and_return(".")
|
115
|
+
expect(Rails).to receive(:application).and_return(application)
|
116
|
+
task.invoke
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "db:reset" do
|
121
|
+
include_context "rake task"
|
122
|
+
include_context "rails rake task"
|
123
|
+
|
124
|
+
it "calls db:drop" do
|
125
|
+
expect(task.prerequisites).to include("db:drop")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "calls db:seed" do
|
129
|
+
expect(task.prerequisites).to include("db:seed")
|
130
|
+
end
|
131
|
+
|
132
|
+
it "works" do
|
133
|
+
expect(Rails).to receive(:root).and_return(".")
|
134
|
+
task.invoke
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "db:create" do
|
139
|
+
include_context "rake task"
|
140
|
+
include_context "rails rake task"
|
141
|
+
|
142
|
+
it "works" do
|
143
|
+
task.invoke
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "db:migrate" do
|
148
|
+
include_context "rake task"
|
149
|
+
include_context "rails rake task"
|
150
|
+
|
151
|
+
it "works" do
|
152
|
+
task.invoke
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "db:test:prepare" do
|
157
|
+
include_context "rake task"
|
158
|
+
include_context "rails rake task"
|
159
|
+
|
160
|
+
it_behaves_like "create_indexes" do
|
161
|
+
before do
|
162
|
+
expect(Rails).to receive(:application).and_return(application)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "calls mongoid:create_indexes" do
|
167
|
+
expect(task.prerequisites).to include("mongoid:create_indexes")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "works" do
|
171
|
+
expect(Rails).to receive(:application).and_return(application)
|
172
|
+
expect(Mongoid::Tasks::Database).to receive(:create_indexes)
|
173
|
+
task.invoke
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "db:mongoid:create_indexes" do
|
178
|
+
include_context "rake task"
|
179
|
+
|
180
|
+
it_behaves_like "create_indexes"
|
181
|
+
|
182
|
+
it "calls load_models" do
|
183
|
+
expect(task.prerequisites).to include("load_models")
|
184
|
+
end
|
185
|
+
|
186
|
+
it "calls environment" do
|
187
|
+
expect(task.prerequisites).to include("environment")
|
188
|
+
end
|
189
|
+
|
190
|
+
context "when using rails task" do
|
191
|
+
include_context "rails rake task"
|
192
|
+
|
193
|
+
before do
|
194
|
+
expect(Rails).to receive(:application).and_return(application)
|
195
|
+
end
|
196
|
+
|
197
|
+
it_behaves_like "create_indexes"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "db:mongoid:remove_undefined_indexes" do
|
202
|
+
include_context "rake task"
|
203
|
+
|
204
|
+
it "receives remove_undefined_indexes" do
|
205
|
+
expect(Mongoid::Tasks::Database).to receive(:remove_undefined_indexes)
|
206
|
+
task.invoke
|
207
|
+
end
|
208
|
+
|
209
|
+
it "calls environment" do
|
210
|
+
expect(task.prerequisites).to include("environment")
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when using rails task" do
|
214
|
+
include_context "rails rake task"
|
215
|
+
|
216
|
+
before do
|
217
|
+
expect(Rails).to receive(:application).and_return(application)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "receives remove_undefined_indexes" do
|
221
|
+
expect(Mongoid::Tasks::Database).to receive(:remove_undefined_indexes)
|
222
|
+
task.invoke
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "db:mongoid:remove_indexes" do
|
228
|
+
include_context "rake task"
|
229
|
+
|
230
|
+
it "receives remove_indexes" do
|
231
|
+
expect(Mongoid::Tasks::Database).to receive(:remove_indexes)
|
232
|
+
task.invoke
|
233
|
+
end
|
234
|
+
|
235
|
+
it "calls environment" do
|
236
|
+
expect(task.prerequisites).to include("environment")
|
237
|
+
end
|
238
|
+
|
239
|
+
context "when using rails task" do
|
240
|
+
include_context "rails rake task"
|
241
|
+
|
242
|
+
before do
|
243
|
+
expect(Rails).to receive(:application).and_return(application)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "receives remove_indexes" do
|
247
|
+
expect(Mongoid::Tasks::Database).to receive(:remove_indexes)
|
248
|
+
task.invoke
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "db:mongoid:drop" do
|
254
|
+
include_context "rake task"
|
255
|
+
|
256
|
+
it "works" do
|
257
|
+
task.invoke
|
258
|
+
end
|
259
|
+
|
260
|
+
context "when using rails task" do
|
261
|
+
include_context "rails rake task"
|
262
|
+
|
263
|
+
it "works" do
|
264
|
+
task.invoke
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "db:mongoid:purge" do
|
270
|
+
include_context "rake task"
|
271
|
+
|
272
|
+
it "receives a purge" do
|
273
|
+
expect(Mongoid).to receive(:purge!)
|
274
|
+
task.invoke
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when using rails task" do
|
278
|
+
include_context "rails rake task"
|
279
|
+
|
280
|
+
it "receives a purge" do
|
281
|
+
expect(Mongoid).to receive(:purge!)
|
282
|
+
task.invoke
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|