File tree 13 files changed +140
-55
lines changed
13 files changed +140
-55
lines changed Original file line number Diff line number Diff line change 9
9
10
10
gemfile :
11
11
- Gemfile
12
+ - gemfiles/mongoid3.gemfile
13
+ - gemfiles/mongoid4.gemfile
12
14
13
15
env :
14
16
global :
Original file line number Diff line number Diff line change
1
+ ## Mongoid::Includes 1.0.3 (2015-10-10) ##
2
+
3
+ * Add support for Mongoid 5.
4
+
1
5
## Mongoid::Includes 1.0.2 (2015-10-08) ##
2
6
3
7
* Fix error when using ` merge ` or ` merge! ` with a criteria and ` includes ` .
Original file line number Diff line number Diff line change 1
1
source 'https://rubygems.org'
2
2
3
3
gemspec
4
+
4
5
gem 'bundler'
5
6
gem 'rake'
6
7
gem 'pry'
8
+ gem 'mongoid' , '~> 5.0.0'
7
9
8
10
group :test do
9
11
gem 'rspec-given' , '~> 3.5'
Original file line number Diff line number Diff line change 1
1
PATH
2
2
remote: .
3
3
specs:
4
- mongoid_includes (1.0.2 )
5
- mongoid (>= 3.1.0 , < 5 .0.0 )
4
+ mongoid_includes (1.0.3 )
5
+ mongoid (>= 3.1.0 , < 6 .0.0 )
6
6
7
7
GEM
8
8
remote: https://rubygems.org/
9
9
specs:
10
- activemodel (4.2.3 )
11
- activesupport (= 4.2.3 )
10
+ activemodel (4.2.4 )
11
+ activesupport (= 4.2.4 )
12
12
builder (~> 3.1 )
13
- activesupport (4.2.3 )
13
+ activesupport (4.2.4 )
14
14
i18n (~> 0.7 )
15
15
json (~> 1.7 , >= 1.7.7 )
16
16
minitest (~> 5.1 )
17
17
thread_safe (~> 0.3 , >= 0.3.4 )
18
18
tzinfo (~> 1.1 )
19
- bson (3.2.1 )
19
+ bson (3.2.6 )
20
20
builder (3.2.2 )
21
21
codeclimate-test-reporter (0.4.7 )
22
22
simplecov (>= 0.7.1 , < 1.0.0 )
23
23
coderay (1.1.0 )
24
- connection_pool (2.2.0 )
25
24
diff-lcs (1.2.5 )
26
25
docile (1.1.5 )
27
26
given_core (3.7.1 )
28
27
sorcerer (>= 0.3.7 )
29
28
i18n (0.7.0 )
30
29
json (1.8.3 )
31
30
method_source (0.8.2 )
32
- minitest (5.8.0 )
33
- mongoid (4.0.2 )
31
+ minitest (5.8.1 )
32
+ mongo (2.1.1 )
33
+ bson (~> 3.0 )
34
+ mongoid (5.0.0 )
34
35
activemodel (~> 4.0 )
35
- moped (~> 2.0.0 )
36
+ mongo (~> 2.1 )
36
37
origin (~> 2.1 )
37
38
tzinfo (>= 0.3.37 )
38
- moped (2.0.6 )
39
- bson (~> 3.0 )
40
- connection_pool (~> 2.0 )
41
- optionable (~> 0.2.0 )
42
- optionable (0.2.0 )
43
39
origin (2.1.1 )
44
40
pry (0.10.1 )
45
41
coderay (~> 1.1.0 )
@@ -84,6 +80,7 @@ PLATFORMS
84
80
DEPENDENCIES
85
81
bundler
86
82
codeclimate-test-reporter
83
+ mongoid (~> 5.0.0 )
87
84
mongoid_includes !
88
85
pry
89
86
rake
Original file line number Diff line number Diff line change
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec '..'
4
+
5
+ gem 'bundler'
6
+ gem 'rake'
7
+ gem 'pry'
8
+ gem 'mongoid', '~> 3.1.0'
9
+
10
+ group :test do
11
+ gem 'rspec-given', '~> 3.5'
12
+ gem 'codeclimate-test-reporter', require: nil
13
+ end
14
+
15
+ group :doc do
16
+ gem 'yard'
17
+ gem 'yard-tomdoc'
18
+ end
Original file line number Diff line number Diff line change
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec '..'
4
+
5
+ gem 'bundler'
6
+ gem 'rake'
7
+ gem 'pry'
8
+ gem 'mongoid', '~> 4.0.2'
9
+
10
+ group :test do
11
+ gem 'rspec-given', '~> 3.5'
12
+ gem 'codeclimate-test-reporter', require: nil
13
+ end
14
+
15
+ group :doc do
16
+ gem 'yard'
17
+ gem 'yard-tomdoc'
18
+ end
Original file line number Diff line number Diff line change @@ -5,6 +5,6 @@ module Mongoid
5
5
module Includes
6
6
7
7
# Public: This library will attempt to follow semantic versioning (whatever that's supposed to be).
8
- VERSION = '1.0.2 '
8
+ VERSION = '1.0.3 '
9
9
end
10
10
end
Original file line number Diff line number Diff line change @@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
s . files = Dir . glob ( 'lib/**/*' ) + %w( CHANGELOG.md LICENSE.txt README.md Rakefile )
23
23
s . test_files = Dir . glob ( 'spec/**/*' )
24
24
25
- s . add_runtime_dependency 'mongoid' , [ '>= 3.1.0' , '< 5 .0.0' ]
25
+ s . add_runtime_dependency 'mongoid' , [ '>= 3.1.0' , '< 6 .0.0' ]
26
26
end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid ::Criteria do
4
+ Given ( :criteria ) { Band . includes ( :songs , :owner , from : :albums ) }
5
+ Given ( :other_criteria ) { Band . includes ( :musicians , :albums ) }
6
+
7
+ describe '#merge' do
8
+ context 'inclusions are combined properly' do
9
+ When ( :new_criteria ) { criteria . merge ( other_criteria ) }
10
+ Then { new_criteria . inclusions . size == 4 }
11
+ And { new_criteria . inclusions . class == Mongoid ::Includes ::Inclusions }
12
+ And { criteria . inclusions . size == 3 }
13
+ And { other_criteria . inclusions . size == 2 }
14
+ end
15
+ end
16
+
17
+ describe '#merge!' do
18
+ context 'inclusions are merged properly' do
19
+ When { criteria . merge! ( other_criteria ) }
20
+ Then { criteria . inclusions . size == 4 }
21
+ And { criteria . inclusions . class == Mongoid ::Includes ::Inclusions }
22
+ And { other_criteria . inclusions . size == 2 }
23
+ end
24
+ end
25
+ end
Original file line number Diff line number Diff line change @@ -285,13 +285,6 @@ class D
285
285
end
286
286
end
287
287
288
- it 'does not eager load the last document' do
289
- doc = criteria . last
290
- expect_query ( 1 ) do
291
- expect ( doc . person ) . to eq ( person_two )
292
- end
293
- end
294
-
295
288
it 'returns the first document' do
296
289
expect ( document ) . to eq ( post_one )
297
290
end
@@ -300,7 +293,7 @@ class D
300
293
context 'when calling last' do
301
294
302
295
let! ( :criteria ) do
303
- Post . includes ( :person )
296
+ Post . asc ( :_id ) . includes ( :person )
304
297
end
305
298
306
299
let! ( :document ) do
Original file line number Diff line number Diff line change @@ -27,6 +27,15 @@ def mongodb_version
27
27
# Set the database that the spec suite connects to.
28
28
Mongoid . configure do |config |
29
29
config . load_configuration (
30
+ clients : {
31
+ default : {
32
+ database : DATABASE ,
33
+ hosts : [ "#{ HOST } :#{ PORT . to_i } " ] ,
34
+ options : {
35
+ max_pool_size : 1 ,
36
+ }
37
+ }
38
+ } ,
30
39
sessions : {
31
40
default : {
32
41
database : DATABASE ,
Original file line number Diff line number Diff line change 1
1
test :
2
- sessions :
2
+ clients :
3
3
default :
4
4
database : mongoid_test
5
5
hosts :
6
6
- <%=ENV["MONGOID_SPEC_HOST"]%>:<%=ENV["MONGOID_SPEC_PORT"]%>
7
7
options :
8
- read : primary
9
- mongohq_single :
10
- database : <%=ENV["MONGOHQ_SINGLE_NAME"]%>
11
- username : <%=ENV["MONGOHQ_SINGLE_USER"]%>
12
- password : <%=ENV["MONGOHQ_SINGLE_PASS"]%>
13
- hosts :
14
- - <%=ENV["MONGOHQ_SINGLE_URL"]%>
15
- options :
16
- write :
17
- w : 1
18
- read : primary
19
- mongohq_repl :
20
- database : <%=ENV["MONGOHQ_REPL_NAME"]%>
21
- username : <%=ENV["MONGOHQ_REPL_USER"]%>
22
- password : <%=ENV["MONGOHQ_REPL_PASS"]%>
8
+ read :
9
+ mode : :primary
10
+ max_pool_size : 1
11
+
12
+ sessions :
13
+ default :
14
+ database : mongoid_test
23
15
hosts :
24
- - <%=ENV["MONGOHQ_REPL_1_URL"]%>
25
- - <%=ENV["MONGOHQ_REPL_2_URL"]%>
16
+ - <%=ENV["MONGOID_SPEC_HOST"]%>:<%=ENV["MONGOID_SPEC_PORT"]%>
26
17
options :
27
18
read : primary
28
- write :
29
- w : majority
30
- mongohq_repl_uri :
31
- uri : <%= ENV["MONGOHQ_REPL_URI"]%>
19
+
32
20
options :
33
21
include_root_in_json : false
34
22
include_type_for_serialization : false
Original file line number Diff line number Diff line change 1
- require 'mongoid/support/query_counter'
1
+ module Mongoid
2
+ class QueryCounter
3
+ attr_reader :events
4
+
5
+ def initialize
6
+ @events = [ ]
7
+ end
8
+
9
+ def instrument
10
+ subscriber = ActiveSupport ::Notifications . subscribe ( 'query.moped' ) do |*args |
11
+ @events << ActiveSupport ::Notifications ::Event . new ( *args )
12
+ end
13
+ yield
14
+ ensure
15
+ ActiveSupport ::Notifications . unsubscribe ( subscriber )
16
+ end
17
+
18
+ def inspect
19
+ @events . map { |e | e . payload [ :ops ] . map ( &:log_inspect ) } . join ( "\n " )
20
+ end
21
+ end
22
+ end
2
23
3
24
module Mongoid
4
25
module SpecHelpers
5
- def expect_query ( number , &block )
6
- query_counter = Mongoid ::QueryCounter . new
7
- query_counter . instrument ( &block )
8
- expect ( query_counter . events . size ) . to ( eq ( number ) , %[
9
- Expected to receive #{ number } queries, it received #{ query_counter . events . size }
10
- #{ query_counter . inspect }
11
- ] )
26
+ if defined? ( Mongo ::Logger . logger )
27
+ def expect_query ( number )
28
+ # There are both start and complete events for each query.
29
+ expect ( Mongo ::Logger . logger ) . to receive ( :debug? ) . exactly ( number * 4 ) . times . and_call_original
30
+ yield
31
+ end
32
+ else
33
+ def expect_query ( number , &block )
34
+ query_counter = Mongoid ::QueryCounter . new
35
+ query_counter . instrument ( &block )
36
+ expect ( query_counter . events . size ) . to ( eq ( number ) , %[
37
+ Expected to receive #{ number } queries, it received #{ query_counter . events . size }
38
+ #{ query_counter . inspect }
39
+ ] )
40
+ end
12
41
end
13
42
14
43
def expect_no_queries ( &block )
You can’t perform that action at this time.
0 commit comments