mongoid_monkey 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid_monkey.rb +5 -13
- data/lib/patches/atomic.rb +5 -0
- data/lib/patches/big_decimal.rb +24 -21
- data/lib/patches/db_commands.rb +98 -28
- data/lib/patches/instrument.rb +27 -24
- data/lib/patches/reorder.rb +8 -5
- data/lib/version.rb +1 -1
- data/spec/app/models/account.rb +4 -0
- data/spec/app/models/address.rb +7 -0
- data/spec/app/models/draft.rb +7 -0
- data/spec/app/models/person.rb +11 -0
- data/spec/app/models/user.rb +6 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/db_commands/mongoid3_indexes_spec.rb +408 -0
- data/spec/unit/db_commands/mongoid3_tasks_spec.rb +112 -0
- data/spec/unit/db_commands/mongoid4_indexes_spec.rb +527 -0
- data/spec/unit/db_commands/mongoid4_tasks_spec.rb +163 -0
- data/spec/unit/db_commands/moped_database_spec.rb +62 -0
- data/spec/unit/db_commands/moped_indexes_spec.rb +85 -0
- metadata +23 -3
- data/spec/unit/db_commands_spec.rb +0 -1086
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if defined?(Moped)
|
4
|
+
|
5
|
+
describe Moped::Database do
|
6
|
+
|
7
|
+
describe "#collection_names" do
|
8
|
+
|
9
|
+
let(:session) do
|
10
|
+
Moped::Session.new([ "127.0.0.1:27017" ], database: $database_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:database) do
|
14
|
+
described_class.new(session, $database_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:collection_names) do
|
18
|
+
database.collection_names
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
session.drop
|
23
|
+
names.map do |name|
|
24
|
+
session.command(create: name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when name doesn't include system" do
|
29
|
+
|
30
|
+
let(:names) do
|
31
|
+
%w[ users comments ]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the name of all non system collections" do
|
35
|
+
expect(collection_names.sort).to eq([ "comments", "users" ])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when name includes system not at the beginning" do
|
40
|
+
|
41
|
+
let(:names) do
|
42
|
+
%w[ users comments_system_fu ]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns the name of all non system collections" do
|
46
|
+
expect(collection_names.sort).to eq([ "comments_system_fu", "users" ])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when name includes system at the beginning" do
|
51
|
+
|
52
|
+
let(:names) do
|
53
|
+
%w[ users system_comments_fu ]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns the name of all non system collections" do
|
57
|
+
expect(collection_names.sort).to eq([ "system_comments_fu", "users" ])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if defined?(Moped)
|
4
|
+
|
5
|
+
describe Moped::Indexes do
|
6
|
+
|
7
|
+
let(:session) do
|
8
|
+
Moped::Session.new %w[127.0.0.1:27017], database: $database_name
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:indexes) do
|
12
|
+
session[:users].indexes
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
begin
|
17
|
+
indexes.drop
|
18
|
+
rescue Exception
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#create" do
|
23
|
+
|
24
|
+
context "when called without extra options" do
|
25
|
+
|
26
|
+
it "creates an index with no options" do
|
27
|
+
indexes.create name: 1
|
28
|
+
indexes[name: 1].should_not eq nil
|
29
|
+
keys = []
|
30
|
+
indexes.each do |idx|
|
31
|
+
keys << idx['key']
|
32
|
+
end
|
33
|
+
keys.should eq([{"_id" => 1}, {"name" => 1}])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when called with extra options" do
|
38
|
+
|
39
|
+
it "creates an index with the extra options" do
|
40
|
+
indexes.create({name: 1}, {unique: true})
|
41
|
+
index = indexes[name: 1]
|
42
|
+
index["unique"].should eq true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when there is existent data" do
|
47
|
+
|
48
|
+
before do
|
49
|
+
3.times { session[:users].insert(name: 'John') }
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises an error" do
|
53
|
+
expect {
|
54
|
+
indexes.create({name: 1}, {unique: true})
|
55
|
+
}.to raise_error(Moped::Errors::OperationFailure)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#drop" do
|
61
|
+
|
62
|
+
context "when provided a key" do
|
63
|
+
before { session.drop }
|
64
|
+
|
65
|
+
it "drops the index" do
|
66
|
+
indexes.create(name: 1)["numIndexesAfter"].should eq 2
|
67
|
+
indexes.drop(name: 1).should eq true
|
68
|
+
indexes.create({name: 1}, {unique: true})["numIndexesAfter"].should eq 2
|
69
|
+
indexes.drop(name: 1).should eq true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when not provided a key" do
|
74
|
+
|
75
|
+
it "drops all indexes" do
|
76
|
+
indexes.create name: 1
|
77
|
+
indexes.create age: 1
|
78
|
+
indexes.drop
|
79
|
+
indexes[name: 1].should eq nil
|
80
|
+
indexes[age: 1].should eq nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johnnyshields
|
@@ -69,6 +69,11 @@ files:
|
|
69
69
|
- lib/patches/instrument.rb
|
70
70
|
- lib/patches/reorder.rb
|
71
71
|
- lib/version.rb
|
72
|
+
- spec/app/models/account.rb
|
73
|
+
- spec/app/models/address.rb
|
74
|
+
- spec/app/models/draft.rb
|
75
|
+
- spec/app/models/person.rb
|
76
|
+
- spec/app/models/user.rb
|
72
77
|
- spec/config/mongodb-mmapv1.conf
|
73
78
|
- spec/config/mongodb-wiredtiger.conf
|
74
79
|
- spec/gemfile/mongoid3.gemfile
|
@@ -77,7 +82,12 @@ files:
|
|
77
82
|
- spec/spec_helper.rb
|
78
83
|
- spec/unit/atomic_spec.rb
|
79
84
|
- spec/unit/big_decimal_spec.rb
|
80
|
-
- spec/unit/
|
85
|
+
- spec/unit/db_commands/mongoid3_indexes_spec.rb
|
86
|
+
- spec/unit/db_commands/mongoid3_tasks_spec.rb
|
87
|
+
- spec/unit/db_commands/mongoid4_indexes_spec.rb
|
88
|
+
- spec/unit/db_commands/mongoid4_tasks_spec.rb
|
89
|
+
- spec/unit/db_commands/moped_database_spec.rb
|
90
|
+
- spec/unit/db_commands/moped_indexes_spec.rb
|
81
91
|
- spec/unit/instrument_spec.rb
|
82
92
|
- spec/unit/reorder_spec.rb
|
83
93
|
homepage: https://github.com/johnnyshields/mongoid_monkey
|
@@ -105,6 +115,11 @@ signing_key:
|
|
105
115
|
specification_version: 4
|
106
116
|
summary: Monkey patches for Mongoid
|
107
117
|
test_files:
|
118
|
+
- spec/app/models/account.rb
|
119
|
+
- spec/app/models/address.rb
|
120
|
+
- spec/app/models/draft.rb
|
121
|
+
- spec/app/models/person.rb
|
122
|
+
- spec/app/models/user.rb
|
108
123
|
- spec/config/mongodb-mmapv1.conf
|
109
124
|
- spec/config/mongodb-wiredtiger.conf
|
110
125
|
- spec/gemfile/mongoid3.gemfile
|
@@ -113,7 +128,12 @@ test_files:
|
|
113
128
|
- spec/spec_helper.rb
|
114
129
|
- spec/unit/atomic_spec.rb
|
115
130
|
- spec/unit/big_decimal_spec.rb
|
116
|
-
- spec/unit/
|
131
|
+
- spec/unit/db_commands/mongoid3_indexes_spec.rb
|
132
|
+
- spec/unit/db_commands/mongoid3_tasks_spec.rb
|
133
|
+
- spec/unit/db_commands/mongoid4_indexes_spec.rb
|
134
|
+
- spec/unit/db_commands/mongoid4_tasks_spec.rb
|
135
|
+
- spec/unit/db_commands/moped_database_spec.rb
|
136
|
+
- spec/unit/db_commands/moped_indexes_spec.rb
|
117
137
|
- spec/unit/instrument_spec.rb
|
118
138
|
- spec/unit/reorder_spec.rb
|
119
139
|
has_rdoc:
|