mongo_mapper 0.16.0 → 0.18.0

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.
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe "GlobalID" do
4
+ before do
5
+ @document = stub_const("TestDocument", Doc("TestDocument") do
6
+ key :name, String
7
+ end)
8
+ end
9
+
10
+ it "generates a valid GlobalID" do
11
+ doc = @document.create!(name: "Test")
12
+ doc.to_global_id.should be_a(GlobalID)
13
+ end
14
+
15
+ it "can be found by GlobalID" do
16
+ doc = @document.create!(name: "Test")
17
+ global_id = doc.to_global_id
18
+ found_doc = GlobalID::Locator.locate(global_id)
19
+ found_doc.should == doc
20
+ end
21
+ end
@@ -18,6 +18,10 @@ describe MongoMapper::Plugins::Keys::Static do
18
18
 
19
19
  describe "a class with static keys" do
20
20
  before do
21
+ @other_klass = EDoc('Other') do
22
+ key :key, String
23
+ end
24
+
21
25
  @klass = Class.new do
22
26
  include MongoMapper::Document
23
27
 
@@ -28,6 +32,8 @@ describe MongoMapper::Plugins::Keys::Static do
28
32
  key "valid_key", String
29
33
  end
30
34
 
35
+ @klass.many :other, class: @other_klass
36
+
31
37
  @obj = @klass.new
32
38
  end
33
39
 
@@ -100,6 +106,24 @@ describe MongoMapper::Plugins::Keys::Static do
100
106
  @obj.foo
101
107
  }.should raise_error(NoMethodError)
102
108
  end
109
+
110
+ it "should allow saving embedded documents" do
111
+ @obj.other.build(key: "foo")
112
+ @obj.save!
113
+
114
+ db_obj = @klass.collection.find(_id: @obj.id).first
115
+ db_obj["other"].should be_present
116
+ db_obj["other"][0]["key"].should == "foo"
117
+ end
118
+
119
+ it "should allow loading embedded documents" do
120
+ @obj.other.build(key: "foo")
121
+ @obj.save!
122
+
123
+ @obj.reload
124
+ @obj.other.count.should == 1
125
+ @obj.other.first.key.should == "foo"
126
+ end
103
127
  end
104
128
 
105
129
  describe "a class without static keys" do
@@ -150,4 +174,4 @@ describe MongoMapper::Plugins::Keys::Static do
150
174
  }.should raise_error(MongoMapper::Plugins::Keys::Static::MissingKeyError)
151
175
  end
152
176
  end
153
- end
177
+ end
@@ -82,5 +82,11 @@ describe "Stats" do
82
82
  it "should have the correct total index size" do
83
83
  Docs.stats.total_index_size.should == get_stats['totalIndexSize']
84
84
  end
85
+
86
+ context 'with scale keyword argument' do
87
+ it "should have the correct total index size (with scale)" do
88
+ Docs.stats(scale: 1_024).total_index_size.should == (get_stats['totalIndexSize'] / 1_024)
89
+ end
90
+ end
85
91
  end
86
92
  end
data/spec/spec_helper.rb CHANGED
@@ -37,6 +37,8 @@ end
37
37
 
38
38
  require 'mongo_mapper'
39
39
 
40
+ GlobalID.app = 'MongoMapper'
41
+
40
42
  def Doc(name='Class', &block)
41
43
  klass = Class.new
42
44
  klass.class_eval do
@@ -105,7 +105,7 @@ describe "Proxy" do
105
105
  end
106
106
  end)
107
107
 
108
- lambda { @proxy.private_foo }.should raise_error(NoMethodError, /private method `private_foo' called/)
108
+ lambda { @proxy.private_foo }.should raise_error(NoMethodError, /private method ['`]private_foo' called/)
109
109
  end
110
110
  end
111
111
 
@@ -393,7 +393,12 @@ describe "Support" do
393
393
 
394
394
  it "should support ruby driver syntax also" do
395
395
  id = BSON::ObjectId.new
396
- id.original_to_json.should == %Q({"$oid":"#{id}"})
396
+
397
+ if Gem::Version.new(BSON::VERSION) >= Gem::Version.new("5.0.0")
398
+ id.original_to_json.should == %Q("#{id}")
399
+ else
400
+ id.original_to_json.should == %Q({"$oid":"#{id}"})
401
+ end
397
402
  end
398
403
  end
399
404
  end
@@ -46,7 +46,7 @@ describe "MongoMapper" do
46
46
  MongoMapper.config = {
47
47
  'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
48
48
  }
49
- Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', {})
49
+ Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', { :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
50
50
  MongoMapper.connect('development')
51
51
  end
52
52
 
@@ -54,7 +54,7 @@ describe "MongoMapper" do
54
54
  MongoMapper.config = {
55
55
  'development' => {'hosts' => ['127.0.0.1:27017']}
56
56
  }
57
- Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
57
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
58
58
  MongoMapper.connect('development')
59
59
  end
60
60
 
@@ -62,7 +62,7 @@ describe "MongoMapper" do
62
62
  MongoMapper.config = {
63
63
  'development' => {'host' => '127.0.0.1:27017'}
64
64
  }
65
- Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
65
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
66
66
  MongoMapper.connect('development')
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ describe "MongoMapper" do
71
71
  'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'read' => 'primary'}
72
72
  }
73
73
  logger = double('logger')
74
- Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :logger => logger, :read => :primary, :database => 'test' })
74
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :logger => logger, :read => :primary, :database => 'test', :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
75
75
  MongoMapper.connect('development', :logger => logger)
76
76
  end
77
77
 
@@ -80,7 +80,7 @@ describe "MongoMapper" do
80
80
  'development' => {'hosts' => ['192.168.1.1:2222'], 'database' => 'test', 'safe' => true}
81
81
  }
82
82
  logger = double('logger')
83
- Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], { :logger => logger, :safe => true, :database => 'test' })
83
+ Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], { :logger => logger, :safe => true, :database => 'test', :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
84
84
  MongoMapper.connect('development', :logger => logger)
85
85
  end
86
86
 
@@ -89,7 +89,7 @@ describe "MongoMapper" do
89
89
  'development' => {'uri' => 'mongodb://127.0.0.1:27017/test', 'options'=> {:foo => 1}}
90
90
  }
91
91
  logger = double('logger')
92
- Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', { :logger => logger, :foo => 1 })
92
+ Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', { :logger => logger, :foo => 1, :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
93
93
  MongoMapper.connect('development', :logger => logger)
94
94
  end
95
95
 
@@ -97,7 +97,7 @@ describe "MongoMapper" do
97
97
  MongoMapper.config = {
98
98
  'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'user' => 'john', 'password' => 'secret'}
99
99
  }
100
- Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :database => 'test', :user => 'john', :password => 'secret' })
100
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :database => 'test', :user => 'john', :password => 'secret', :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}] })
101
101
  MongoMapper.connect('development')
102
102
  end
103
103
 
@@ -105,7 +105,7 @@ describe "MongoMapper" do
105
105
  MongoMapper.config = {
106
106
  'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
107
107
  }
108
- Mongo::Client.should_receive(:new).with('mongodb://john:secret@127.0.0.1:27017/test', {})
108
+ Mongo::Client.should_receive(:new).with('mongodb://john:secret@127.0.0.1:27017/test', { :wrapping_libraries=>[{:name=>"MongoMapper", :version=>::MongoMapper::Version}]})
109
109
  MongoMapper.connect('development')
110
110
  end
111
111
 
@@ -140,6 +140,54 @@ describe "MongoMapper" do
140
140
  end
141
141
  end
142
142
 
143
+ context "setup_with_config_file" do
144
+ it "should work with config/simple.yml" do
145
+ logger = double('logger')
146
+ path = File.expand_path('../../config/simple.yml', __FILE__)
147
+ MongoMapper.should_receive(:config=).with({
148
+ "production" => { "host" => "127.0.0.1:21017", "database" => "production" },
149
+ "development" => { "host" => "127.0.0.1:21017", "database" => "development" },
150
+ "test" => { "host" => "127.0.0.1:21017", "database" => "test" },
151
+ })
152
+ MongoMapper.should_receive(:connect).with('development', { :logger => logger })
153
+ MongoMapper.should_receive(:handle_passenger_forking).once
154
+ MongoMapper.setup_with_config_file(path, 'development', :logger => logger)
155
+ end
156
+
157
+ it "should work with config/alias.yml" do
158
+ logger = double('logger')
159
+ path = File.expand_path('../../config/alias.yml', __FILE__)
160
+ MongoMapper.should_receive(:config=).with({
161
+ "default" => { "host" => "127.0.0.1:21017" },
162
+ "production" => { "host" => "127.0.0.1:21017", "database" => "production" },
163
+ "development" => { "host" => "127.0.0.1:21017", "database" => "development" },
164
+ "test" => { "host" => "127.0.0.1:21017", "database" => "test" },
165
+ })
166
+ MongoMapper.should_receive(:connect).with('development', { :logger => logger })
167
+ MongoMapper.should_receive(:handle_passenger_forking).once
168
+ MongoMapper.setup_with_config_file(path, 'development', :logger => logger)
169
+ end
170
+
171
+ it "should work with config/erb.yml" do
172
+ begin
173
+ old_mongodb_uri, ENV["MONGODB_URI"] = ENV["MONGODB_URI"], "mongodb://127.0.0.1:21017/production"
174
+
175
+ logger = double('logger')
176
+ path = File.expand_path('../../config/erb.yml', __FILE__)
177
+ MongoMapper.should_receive(:config=).with({
178
+ "production" => { "uri" => "mongodb://127.0.0.1:21017/production" },
179
+ "development" => { "host" => "127.0.0.1:21017", "database" => "development" },
180
+ "test" => { "host" => "127.0.0.1:21017", "database" => "test" },
181
+ })
182
+ MongoMapper.should_receive(:connect).with('development', { :logger => logger })
183
+ MongoMapper.should_receive(:handle_passenger_forking).once
184
+ MongoMapper.setup_with_config_file(path, 'development', :logger => logger)
185
+ ensure
186
+ ENV["MONGODB_URI"] = old_mongodb_uri
187
+ end
188
+ end
189
+ end
190
+
143
191
  context "options" do
144
192
  it "should sets/returns filtered_attributes correctly" do
145
193
  MongoMapper.filter_attributes.should == []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-11 00:00:00.000000000 Z
13
+ date: 2026-10-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongo
@@ -184,6 +184,7 @@ files:
184
184
  - lib/mongo_mapper/plugins/embedded_callbacks.rb
185
185
  - lib/mongo_mapper/plugins/embedded_document.rb
186
186
  - lib/mongo_mapper/plugins/equality.rb
187
+ - lib/mongo_mapper/plugins/global_id.rb
187
188
  - lib/mongo_mapper/plugins/identity_map.rb
188
189
  - lib/mongo_mapper/plugins/indexes.rb
189
190
  - lib/mongo_mapper/plugins/inspect.rb
@@ -220,6 +221,9 @@ files:
220
221
  - lib/rails/generators/mongo_mapper/config/templates/mongo.yml
221
222
  - lib/rails/generators/mongo_mapper/model/model_generator.rb
222
223
  - lib/rails/generators/mongo_mapper/model/templates/model.rb
224
+ - spec/config/alias.yml
225
+ - spec/config/erb.yml
226
+ - spec/config/simple.yml
223
227
  - spec/examples.txt
224
228
  - spec/functional/accessible_spec.rb
225
229
  - spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb
@@ -248,6 +252,7 @@ files:
248
252
  - spec/functional/embedded_document_spec.rb
249
253
  - spec/functional/equality_spec.rb
250
254
  - spec/functional/extensions_spec.rb
255
+ - spec/functional/global_id_spec.rb
251
256
  - spec/functional/identity_map_spec.rb
252
257
  - spec/functional/indexes_spec.rb
253
258
  - spec/functional/keys_spec.rb
@@ -307,7 +312,11 @@ files:
307
312
  homepage: http://mongomapper.com
308
313
  licenses:
309
314
  - MIT
310
- metadata: {}
315
+ metadata:
316
+ bug_tracker_uri: https://github.com/mongomapper/mongomapper/issues
317
+ changelog_uri: https://github.com/mongomapper/mongomapper/releases/tag/v0.18.0
318
+ documentation_uri: https://www.rubydoc.info/gems/mongomapper/0.18.0
319
+ source_code_uri: https://github.com/mongomapper/mongomapper/tree/v0.18.0
311
320
  post_install_message:
312
321
  rdoc_options: []
313
322
  require_paths:
@@ -323,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
332
  - !ruby/object:Gem::Version
324
333
  version: '0'
325
334
  requirements: []
326
- rubygems_version: 3.3.7
335
+ rubygems_version: 3.5.9
327
336
  signing_key:
328
337
  specification_version: 4
329
338
  summary: A Ruby Object Mapper for Mongo