mongoid 7.0.8 → 7.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef78cc81c2ff0304744dfd71a941ccb445860abea33dc7b2afd99058a0949bf2
4
- data.tar.gz: 99cd2f0255d3ccb8a5487f35a39cd54a01e482602191f117cde26780ecd02037
3
+ metadata.gz: 5ad9fbedf524c291d800a33349aed2f382c34bbe7b2db4417b7fc73f4c6b0ced
4
+ data.tar.gz: 2dc25b9b97f8a9d56249ea690affb49537f3d8cc73d03e149abf5b3f9511f5bf
5
5
  SHA512:
6
- metadata.gz: 57c42d28d64c7cb07cd6f67b4428bdb9565119df4428075d2c93502b270bb42f4446fa41aaf1e698ab5b47b5d6623389a1c13b2e67d6a30330699fed19958d69
7
- data.tar.gz: 1f510169b514e67dd7c4c1692e829af73848c8997d03752dda28a8edc054f79a9679298004776a0b9fb059d7e35debaae51b1981b71f47dc7a0d89edacec8ac9
6
+ metadata.gz: 86f6b6b3df1aaa98de5344f58e152b0a05b6f0ea21153e7fadd4a1d3b1ba74bed9a7b967ab608ce01dc2cb401c81e153f69569f5e8d19a96dcc953be27b16823
7
+ data.tar.gz: e99a2501707a844f35a4eecc827163f871b77fd2f681e347e9bede2b0708dab8bdec0ce8520304f01f475c63cc33fc0216bd7d8b7e98556f5f6b696b8682ffe1
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler"
2
+ require "bundler/gem_tasks"
2
3
  Bundler.setup
3
4
 
4
5
  require "rake"
@@ -7,6 +8,9 @@ require "rspec/core/rake_task"
7
8
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
8
9
  require "mongoid/version"
9
10
 
11
+ tasks = Rake.application.instance_variable_get('@tasks')
12
+ tasks['release:do'] = tasks.delete('release')
13
+
10
14
  task :gem => :build
11
15
  task :build do
12
16
  system "gem build mongoid.gemspec"
@@ -45,3 +49,13 @@ namespace :docs do
45
49
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
46
50
  end
47
51
  end
52
+
53
+ namespace :release do
54
+ task :check_private_key do
55
+ unless File.exist?('gem-private_key.pem')
56
+ raise "No private key present, cannot release"
57
+ end
58
+ end
59
+ end
60
+
61
+ task :release => ['release:check_private_key', 'release:do']
@@ -38,12 +38,20 @@ module Mongoid
38
38
  #
39
39
  # @since 6.4.0
40
40
  def with_session(options = {})
41
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
41
+ if Threaded.get_session
42
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
43
+ end
42
44
  session = persistence_context.client.start_session(options)
43
45
  Threaded.set_session(session)
44
46
  yield(session)
45
47
  rescue Mongo::Error::InvalidSession => ex
46
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
48
+ if
49
+ # Driver 2.13.0+
50
+ defined?(Mongo::Error::SessionsNotSupported) &&
51
+ Mongo::Error::SessionsNotSupported === ex ||
52
+ # Legacy drivers
53
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
54
+ then
47
55
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
48
56
  end
49
57
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -89,12 +97,20 @@ module Mongoid
89
97
  #
90
98
  # @since 6.4.0
91
99
  def with_session(options = {})
92
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
100
+ if Threaded.get_session
101
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
102
+ end
93
103
  session = persistence_context.client.start_session(options)
94
104
  Threaded.set_session(session)
95
105
  yield(session)
96
106
  rescue Mongo::Error::InvalidSession => ex
97
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
107
+ if
108
+ # Driver 2.13.0+
109
+ defined?(Mongo::Error::SessionsNotSupported) &&
110
+ Mongo::Error::SessionsNotSupported === ex ||
111
+ # Legacy drivers
112
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
113
+ then
98
114
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
99
115
  end
100
116
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -28,7 +28,7 @@ module Mongoid
28
28
  #
29
29
  # @since 1.0.0
30
30
  def __evolve_time__
31
- utc
31
+ getutc
32
32
  end
33
33
 
34
34
  module ClassMethods
@@ -7,6 +7,18 @@ module Mongoid
7
7
  # This module contains additional time with zone behaviour.
8
8
  module TimeWithZone
9
9
 
10
+ # Evolve the time as a date, UTC midnight.
11
+ #
12
+ # @example Evolve the time to a date query format.
13
+ # time.__evolve_date__
14
+ #
15
+ # @return [ Time ] The date at midnight UTC.
16
+ #
17
+ # @since 1.0.0
18
+ def __evolve_date__
19
+ ::Time.utc(year, month, day, 0, 0, 0, 0)
20
+ end
21
+
10
22
  # Evolve the time into a utc time.
11
23
  #
12
24
  # @example Evolve the time.
@@ -230,14 +230,29 @@ module Mongoid
230
230
  unless cursor = cached_cursor
231
231
  read_with_retry do
232
232
  server = server_selector.select_server(cluster)
233
- cursor = CachedCursor.new(view, send_initial_query(server), server)
234
- QueryCache.cache_table[cache_key] = cursor
233
+ result = send_initial_query(server)
234
+ if result.cursor_id == 0 || result.cursor_id.nil?
235
+ cursor = CachedCursor.new(view, result, server)
236
+ QueryCache.cache_table[cache_key] = cursor
237
+ else
238
+ cursor = Mongo::Cursor.new(view, result, server)
239
+ end
235
240
  end
236
241
  end
237
- cursor.each do |doc|
238
- yield doc
239
- end if block_given?
240
- cursor
242
+
243
+ if block_given?
244
+ if limit && limit != -1
245
+ cursor.to_a[0...limit].each do |doc|
246
+ yield doc
247
+ end
248
+ else
249
+ cursor.each do |doc|
250
+ yield doc
251
+ end
252
+ end
253
+ else
254
+ cursor
255
+ end
241
256
  end
242
257
  end
243
258
 
@@ -247,9 +262,6 @@ module Mongoid
247
262
  if limit
248
263
  key = [ collection.namespace, selector, nil, skip, sort, projection, collation ]
249
264
  cursor = QueryCache.cache_table[key]
250
- if cursor
251
- cursor.to_a[0...limit.abs]
252
- end
253
265
  end
254
266
  cursor || QueryCache.cache_table[cache_key]
255
267
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Mongoid
4
- VERSION = "7.0.8"
4
+ VERSION = "7.0.10"
5
5
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'Queries on Date fields' do
7
+ let(:query) do
8
+ Band.where(founded: arg)
9
+ end
10
+
11
+ let(:selector) { query.selector }
12
+
13
+ shared_examples 'converts to beginning of day in UTC' do
14
+ it 'converts to beginning of day in UTC' do
15
+ selector['founded'].should == arg.dup.beginning_of_day.utc.beginning_of_day
16
+ end
17
+ end
18
+
19
+ context 'using Time' do
20
+ let(:arg) do
21
+ Time.now.freeze
22
+ end
23
+
24
+ it_behaves_like 'converts to beginning of day in UTC'
25
+ end
26
+
27
+ context 'using TimeWithZone' do
28
+ let(:time_zone_name) { 'Pacific Time (US & Canada)' }
29
+ let(:arg) { Time.now.in_time_zone(time_zone_name).freeze }
30
+
31
+ it_behaves_like 'converts to beginning of day in UTC'
32
+ end
33
+
34
+ context 'using DateTime' do
35
+ let(:arg) do
36
+ DateTime.now.freeze
37
+ end
38
+
39
+ it_behaves_like 'converts to beginning of day in UTC'
40
+ end
41
+ end
@@ -1754,6 +1754,43 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
1754
1754
  end
1755
1755
  end
1756
1756
 
1757
+ describe "#any?" do
1758
+
1759
+ let(:person) do
1760
+ Person.create
1761
+ end
1762
+
1763
+ context "when nothing exists on the relation" do
1764
+
1765
+ context "when no document is added" do
1766
+
1767
+ let!(:sandwich) do
1768
+ Sandwich.create!
1769
+ end
1770
+
1771
+ it "returns false" do
1772
+ expect(sandwich.meats.any?).to be false
1773
+ end
1774
+ end
1775
+
1776
+ context "when the document is destroyed" do
1777
+
1778
+ before do
1779
+ Meat.create!
1780
+ end
1781
+
1782
+ let!(:sandwich) do
1783
+ Sandwich.create!
1784
+ end
1785
+
1786
+ it "returns false" do
1787
+ sandwich.destroy
1788
+ expect(sandwich.meats.any?).to be false
1789
+ end
1790
+ end
1791
+ end
1792
+ end
1793
+
1757
1794
  context "when documents have been persisted" do
1758
1795
 
1759
1796
  let!(:preference) do
@@ -1843,6 +1880,107 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
1843
1880
  end
1844
1881
  end
1845
1882
 
1883
+ describe "#any?" do
1884
+
1885
+ let(:sandwich) do
1886
+ Sandwich.create
1887
+ end
1888
+
1889
+ context "when nothing exists on the relation" do
1890
+
1891
+ context "when no document is added" do
1892
+
1893
+ let!(:sandwich) do
1894
+ Sandwich.create!
1895
+ end
1896
+
1897
+ it "returns false" do
1898
+ expect(sandwich.meats.any?).to be false
1899
+ end
1900
+ end
1901
+
1902
+ context "when the document is destroyed" do
1903
+
1904
+ before do
1905
+ Meat.create!
1906
+ end
1907
+
1908
+ let!(:sandwich) do
1909
+ Sandwich.create!
1910
+ end
1911
+
1912
+ it "returns false" do
1913
+ sandwich.destroy
1914
+ expect(sandwich.meats.any?).to be false
1915
+ end
1916
+ end
1917
+ end
1918
+
1919
+ context "when appending to a relation and _loaded/_unloaded are empty" do
1920
+
1921
+ let!(:sandwich) do
1922
+ Sandwich.create!
1923
+ end
1924
+
1925
+ before do
1926
+ sandwich.meats << Meat.new
1927
+ end
1928
+
1929
+ it "returns true" do
1930
+ expect(sandwich.meats.any?).to be true
1931
+ end
1932
+ end
1933
+
1934
+ context "when appending to a relation in a transaction" do
1935
+ require_transaction_support
1936
+
1937
+ let!(:sandwich) do
1938
+ Sandwich.create!
1939
+ end
1940
+
1941
+ it "returns true" do
1942
+ sandwich.with_session do |session|
1943
+ session.with_transaction do
1944
+ expect{ sandwich.meats << Meat.new }.to_not raise_error
1945
+ expect(sandwich.meats.any?).to be true
1946
+ end
1947
+ end
1948
+ end
1949
+ end
1950
+
1951
+ context "when documents have been persisted" do
1952
+
1953
+ let!(:meat) do
1954
+ sandwich.meats.create
1955
+ end
1956
+
1957
+ it "returns true" do
1958
+ expect(sandwich.meats.any?).to be true
1959
+ end
1960
+ end
1961
+
1962
+ context "when documents have not been persisted" do
1963
+
1964
+ let!(:meat) do
1965
+ sandwich.meats.build
1966
+ end
1967
+
1968
+ it "returns false" do
1969
+ expect(sandwich.meats.any?).to be true
1970
+ end
1971
+ end
1972
+
1973
+ context "when new documents exist in the database" do
1974
+ before do
1975
+ Meat.create(sandwiches: [sandwich])
1976
+ end
1977
+
1978
+ it "returns true" do
1979
+ expect(sandwich.meats.any?).to be true
1980
+ end
1981
+ end
1982
+ end
1983
+
1846
1984
  [ :create, :create! ].each do |method|
1847
1985
 
1848
1986
  describe "##{method}" do
@@ -253,6 +253,111 @@ describe Mongoid::Association::Referenced::HasMany::Targets::Enumerable do
253
253
  end
254
254
  end
255
255
  end
256
+
257
+ context "when the documents have been loaded" do
258
+ let(:criteria) do
259
+ Post.where(person_id: person.id)
260
+ end
261
+
262
+ let!(:enumerable) do
263
+ described_class.new(criteria)
264
+ end
265
+
266
+ before do
267
+ enumerable.load_all!
268
+ end
269
+
270
+ it "is _loaded" do
271
+ expect(enumerable._loaded?).to be true
272
+ end
273
+
274
+ context "when a block is given" do
275
+ it "returns true when the predicate is true" do
276
+ expect(
277
+ enumerable.any? { |doc| true }
278
+ ).to be true
279
+ end
280
+
281
+ it "returns false when the predicate is false" do
282
+ expect(
283
+ enumerable.any? { |doc| false }
284
+ ).to be false
285
+ end
286
+ end
287
+
288
+ context "when an argument is given" do
289
+ ruby_version_gte '2.5'
290
+
291
+ it "returns true when the argument is true" do
292
+ expect(enumerable.any?(Post)).to be true
293
+ end
294
+
295
+ it "returns false when the argument is false" do
296
+ expect(enumerable.any?(Sandwich)).to be false
297
+ end
298
+ end
299
+
300
+ context "when both an argument and a block are given" do
301
+ ruby_version_gte '2.5'
302
+
303
+ it "gives precedence to the pattern" do
304
+ expect(
305
+ enumerable.any?(Post) { |doc| false }
306
+ ).to be true
307
+ end
308
+ end
309
+ end
310
+
311
+ context "when the documents are not loaded" do
312
+
313
+ let(:criteria) do
314
+ Post.where(person_id: person.id)
315
+ end
316
+
317
+ let!(:enumerable) do
318
+ described_class.new(criteria)
319
+ end
320
+
321
+ it "is not _loaded" do
322
+ expect(enumerable._loaded?).to be false
323
+ end
324
+
325
+ context "when a block is given" do
326
+ it "returns true when the predicate is true" do
327
+ expect(
328
+ enumerable.any? { |doc| true }
329
+ ).to be true
330
+ end
331
+
332
+ it "returns false when the predicate is false" do
333
+ expect(
334
+ enumerable.any? { |doc| false }
335
+ ).to be false
336
+ end
337
+ end
338
+
339
+ context "when an argument is given" do
340
+ ruby_version_gte '2.5'
341
+
342
+ it "returns true when the argument is true" do
343
+ expect(enumerable.any?(Post)).to be true
344
+ end
345
+
346
+ it "returns false when the argument is false" do
347
+ expect(enumerable.any?(Sandwich)).to be false
348
+ end
349
+ end
350
+
351
+ context "when both an argument and a block are given" do
352
+ ruby_version_gte '2.5'
353
+
354
+ it "gives precedence to the pattern" do
355
+ expect(
356
+ enumerable.any?(Post) { |doc| false }
357
+ ).to be true
358
+ end
359
+ end
360
+ end
256
361
  end
257
362
 
258
363
  describe "#clear" do