mongo_mapper 0.13.0 → 0.15.1

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.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/README.md +61 -0
  4. data/examples/keys.rb +1 -1
  5. data/examples/modifiers/set.rb +1 -1
  6. data/examples/querying.rb +1 -1
  7. data/examples/safe.rb +2 -2
  8. data/examples/scopes.rb +1 -1
  9. data/lib/mongo_mapper.rb +7 -0
  10. data/lib/mongo_mapper/connection.rb +16 -37
  11. data/lib/mongo_mapper/document.rb +4 -0
  12. data/lib/mongo_mapper/extensions/array.rb +14 -6
  13. data/lib/mongo_mapper/extensions/hash.rb +15 -3
  14. data/lib/mongo_mapper/extensions/object.rb +4 -0
  15. data/lib/mongo_mapper/extensions/object_id.rb +5 -1
  16. data/lib/mongo_mapper/extensions/string.rb +13 -5
  17. data/lib/mongo_mapper/extensions/symbol.rb +18 -0
  18. data/lib/mongo_mapper/plugins/accessible.rb +15 -5
  19. data/lib/mongo_mapper/plugins/associations.rb +7 -6
  20. data/lib/mongo_mapper/plugins/associations/base.rb +27 -14
  21. data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +10 -1
  22. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
  23. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
  24. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
  25. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +60 -29
  26. data/lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb +136 -0
  27. data/lib/mongo_mapper/plugins/associations/many_association.rb +4 -2
  28. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
  29. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
  30. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
  31. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
  32. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
  33. data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
  34. data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
  35. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
  36. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
  37. data/lib/mongo_mapper/plugins/associations/proxy.rb +36 -29
  38. data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -4
  39. data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
  40. data/lib/mongo_mapper/plugins/counter_cache.rb +97 -0
  41. data/lib/mongo_mapper/plugins/dirty.rb +29 -37
  42. data/lib/mongo_mapper/plugins/document.rb +1 -1
  43. data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
  44. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +18 -17
  45. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +2 -1
  46. data/lib/mongo_mapper/plugins/embedded_document.rb +1 -1
  47. data/lib/mongo_mapper/plugins/identity_map.rb +4 -2
  48. data/lib/mongo_mapper/plugins/indexes.rb +14 -7
  49. data/lib/mongo_mapper/plugins/keys.rb +170 -151
  50. data/lib/mongo_mapper/plugins/keys/key.rb +27 -16
  51. data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
  52. data/lib/mongo_mapper/plugins/modifiers.rb +64 -38
  53. data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
  54. data/lib/mongo_mapper/plugins/persistence.rb +13 -8
  55. data/lib/mongo_mapper/plugins/protected.rb +6 -5
  56. data/lib/mongo_mapper/plugins/querying.rb +85 -42
  57. data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +20 -15
  58. data/lib/mongo_mapper/plugins/rails.rb +1 -0
  59. data/lib/mongo_mapper/plugins/safe.rb +10 -4
  60. data/lib/mongo_mapper/plugins/sci.rb +0 -0
  61. data/lib/mongo_mapper/plugins/scopes.rb +78 -7
  62. data/lib/mongo_mapper/plugins/stats.rb +17 -0
  63. data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
  64. data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
  65. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  66. data/lib/mongo_mapper/railtie.rb +4 -3
  67. data/lib/mongo_mapper/utils.rb +2 -2
  68. data/lib/mongo_mapper/version.rb +1 -1
  69. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
  70. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
  71. data/spec/examples.txt +1717 -0
  72. data/spec/functional/accessible_spec.rb +19 -13
  73. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +13 -13
  74. data/spec/functional/associations/belongs_to_proxy_spec.rb +36 -20
  75. data/spec/functional/associations/in_array_proxy_spec.rb +145 -10
  76. data/spec/functional/associations/in_foreign_array_proxy_spec.rb +321 -0
  77. data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
  78. data/spec/functional/associations/many_documents_proxy_spec.rb +85 -14
  79. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +13 -13
  80. data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
  81. data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
  82. data/spec/functional/associations/one_as_proxy_spec.rb +10 -10
  83. data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
  84. data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
  85. data/spec/functional/associations/one_proxy_spec.rb +10 -10
  86. data/spec/functional/associations_spec.rb +3 -3
  87. data/spec/functional/binary_spec.rb +2 -2
  88. data/spec/functional/caching_spec.rb +8 -15
  89. data/spec/functional/callbacks_spec.rb +89 -2
  90. data/spec/functional/counter_cache_spec.rb +235 -0
  91. data/spec/functional/dirty_spec.rb +63 -46
  92. data/spec/functional/document_spec.rb +30 -5
  93. data/spec/functional/dumpable_spec.rb +1 -1
  94. data/spec/functional/embedded_document_spec.rb +17 -17
  95. data/spec/functional/identity_map_spec.rb +29 -16
  96. data/spec/functional/indexes_spec.rb +19 -18
  97. data/spec/functional/keys_spec.rb +86 -28
  98. data/spec/functional/logger_spec.rb +3 -3
  99. data/spec/functional/modifiers_spec.rb +81 -19
  100. data/spec/functional/partial_updates_spec.rb +577 -0
  101. data/spec/functional/protected_spec.rb +14 -14
  102. data/spec/functional/querying_spec.rb +77 -28
  103. data/spec/functional/safe_spec.rb +23 -27
  104. data/spec/functional/sci_spec.rb +9 -9
  105. data/spec/functional/scopes_spec.rb +235 -2
  106. data/spec/functional/static_keys_spec.rb +153 -0
  107. data/spec/functional/stats_spec.rb +86 -0
  108. data/spec/functional/strong_parameters_spec.rb +49 -0
  109. data/spec/functional/touch_spec.rb +1 -1
  110. data/spec/functional/validations_spec.rb +51 -57
  111. data/spec/quality_spec.rb +51 -0
  112. data/spec/spec_helper.rb +37 -9
  113. data/spec/support/matchers.rb +5 -14
  114. data/spec/unit/associations/base_spec.rb +12 -12
  115. data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
  116. data/spec/unit/associations/many_association_spec.rb +2 -2
  117. data/spec/unit/associations/one_association_spec.rb +2 -2
  118. data/spec/unit/associations/proxy_spec.rb +19 -20
  119. data/spec/unit/clone_spec.rb +1 -1
  120. data/spec/unit/document_spec.rb +8 -8
  121. data/spec/unit/dynamic_finder_spec.rb +8 -8
  122. data/spec/unit/embedded_document_spec.rb +18 -19
  123. data/spec/unit/extensions_spec.rb +41 -17
  124. data/spec/unit/identity_map_middleware_spec.rb +65 -96
  125. data/spec/unit/key_spec.rb +28 -26
  126. data/spec/unit/keys_spec.rb +20 -11
  127. data/spec/unit/model_generator_spec.rb +0 -0
  128. data/spec/unit/mongo_mapper_spec.rb +38 -85
  129. data/spec/unit/rails_spec.rb +5 -0
  130. data/spec/unit/serialization_spec.rb +1 -1
  131. data/spec/unit/time_zones_spec.rb +2 -2
  132. data/spec/unit/validations_spec.rb +46 -33
  133. metadata +66 -37
  134. data/README.rdoc +0 -59
  135. data/lib/mongo_mapper/connections/10gen.rb +0 -0
  136. data/lib/mongo_mapper/connections/moped.rb +0 -0
  137. data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
File without changes
@@ -3,23 +3,28 @@ require 'spec_helper'
3
3
  class Address; end
4
4
 
5
5
  describe "MongoMapper" do
6
- it "should be able to write and read connection" do
7
- conn = Mongo::MongoClient.new
6
+ it "should be able to write and read connection", :without_connection do
7
+ conn = Mongo::Client.new(['127.0.0.1:27001'])
8
8
  MongoMapper.connection = conn
9
9
  MongoMapper.connection.should == conn
10
10
  end
11
11
 
12
- it "should default connection to new mongo ruby driver" do
12
+ it "should default connection to new mongo ruby driver", :without_connection do
13
13
  MongoMapper.connection = nil
14
- MongoMapper.connection.should be_instance_of(Mongo::MongoClient)
14
+ MongoMapper.connection.should be_instance_of(Mongo::Client)
15
15
  end
16
16
 
17
- it "should be able to write and read default database" do
18
- MongoMapper.database = 'test'
19
- MongoMapper.database.should be_instance_of(Mongo::DB)
17
+ it "should be able to read default database" do
18
+ MongoMapper.database.should be_instance_of(Mongo::Database)
20
19
  MongoMapper.database.name.should == 'test'
21
20
  end
22
21
 
22
+ it "should be able to write default database", :without_connection do
23
+ MongoMapper.database = 'test-2'
24
+ MongoMapper.database.should be_instance_of(Mongo::Database)
25
+ MongoMapper.database.name.should == 'test-2'
26
+ end
27
+
23
28
  it "should have document not found error" do
24
29
  lambda {
25
30
  MongoMapper::DocumentNotFound
@@ -35,96 +40,64 @@ describe "MongoMapper" do
35
40
  MongoMapper.config.should == config
36
41
  end
37
42
 
38
- context "connecting to environment from config" do
39
- it "should work without authentication" do
40
- MongoMapper.config = {
41
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
42
- }
43
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, {})
44
- MongoMapper.should_receive(:database=).with('test')
45
- Mongo::DB.any_instance.should_receive(:authenticate).never
46
- MongoMapper.connect('development')
47
- end
43
+ context "connecting to environment from config", :without_connection do
48
44
 
49
45
  it "should work without authentication using uri" do
50
46
  MongoMapper.config = {
51
47
  'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
52
48
  }
53
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, {})
54
- MongoMapper.should_receive(:database=).with('test')
55
- Mongo::DB.any_instance.should_receive(:authenticate).never
49
+ Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', {})
56
50
  MongoMapper.connect('development')
57
51
  end
58
52
 
59
- it "should work with sinatra environment symbol" do
53
+ it "should work without authentication using hosts" do
60
54
  MongoMapper.config = {
61
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
55
+ 'development' => {'hosts' => ['127.0.0.1:27017']}
62
56
  }
63
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, {})
64
- MongoMapper.should_receive(:database=).with('test')
65
- Mongo::DB.any_instance.should_receive(:authenticate).never
66
- MongoMapper.connect(:development)
67
- end
68
-
69
- it "should work with options" do
70
- MongoMapper.config = {
71
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
72
- }
73
- connection, logger = double('connection'), double('logger')
74
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger)
75
- MongoMapper.connect('development', :logger => logger)
76
- end
77
-
78
- it "should pass along ssl when true" do
79
- MongoMapper.config = {
80
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => true}
81
- }
82
- connection, logger = double('connection'), double('logger')
83
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => true)
84
- MongoMapper.connect('development', :logger => logger)
57
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
58
+ MongoMapper.connect('development')
85
59
  end
86
60
 
87
- it "should pass along ssl when false" do
61
+ it "should work without authentication using host" do
88
62
  MongoMapper.config = {
89
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => false}
63
+ 'development' => {'host' => '127.0.0.1:27017'}
90
64
  }
91
- connection, logger = double('connection'), double('logger')
92
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => false)
93
- MongoMapper.connect('development', :logger => logger)
65
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
66
+ MongoMapper.connect('development')
94
67
  end
95
68
 
96
69
  it "should convert read preferences to symbols" do
97
70
  MongoMapper.config = {
98
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'options' => {'read' => 'primary'}}
71
+ 'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'read' => 'primary'}
99
72
  }
100
- connection, logger = double('connection'), double('logger')
101
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :read => :primary)
73
+ logger = double('logger')
74
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :logger => logger, :read => :primary, :database => 'test')
102
75
  MongoMapper.connect('development', :logger => logger)
103
76
  end
104
77
 
105
78
  it "should work with options from config" do
106
79
  MongoMapper.config = {
107
- 'development' => {'host' => '192.168.1.1', 'port' => 2222, 'database' => 'test', 'options' => {'safe' => true}}
80
+ 'development' => {'hosts' => ['192.168.1.1:2222'], 'database' => 'test', 'safe' => true}
108
81
  }
109
- connection, logger = double('connection'), double('logger')
110
- Mongo::MongoClient.should_receive(:new).with('192.168.1.1', 2222, :logger => logger, :safe => true)
82
+ logger = double('logger')
83
+ Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], :logger => logger, :safe => true, :database => 'test')
111
84
  MongoMapper.connect('development', :logger => logger)
112
85
  end
113
86
 
114
87
  it "should work with options using uri" do
115
88
  MongoMapper.config = {
116
- 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
89
+ 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test', 'options'=> {:foo => 1}}
117
90
  }
118
- connection, logger = double('connection'), double('logger')
119
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger)
91
+ logger = double('logger')
92
+ Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', :logger => logger, :foo => 1)
120
93
  MongoMapper.connect('development', :logger => logger)
121
94
  end
122
95
 
123
96
  it "should work with authentication" do
124
97
  MongoMapper.config = {
125
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'username' => 'john', 'password' => 'secret'}
98
+ 'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'user' => 'john', 'password' => 'secret'}
126
99
  }
127
- Mongo::DB.any_instance.should_receive(:authenticate).with('john', 'secret')
100
+ Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :database => 'test', :user => 'john', :password => 'secret')
128
101
  MongoMapper.connect('development')
129
102
  end
130
103
 
@@ -132,7 +105,7 @@ describe "MongoMapper" do
132
105
  MongoMapper.config = {
133
106
  'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
134
107
  }
135
- Mongo::DB.any_instance.should_receive(:authenticate).with('john', 'secret')
108
+ Mongo::Client.should_receive(:new).with('mongodb://john:secret@127.0.0.1:27017/test', {})
136
109
  MongoMapper.connect('development')
137
110
  end
138
111
 
@@ -140,36 +113,16 @@ describe "MongoMapper" do
140
113
  MongoMapper.config = {
141
114
  'development' => {'uri' => 'mysql://127.0.0.1:5336/foo'}
142
115
  }
143
- expect { MongoMapper.connect('development') }.to raise_error(MongoMapper::InvalidScheme)
116
+ lambda { MongoMapper.connect('development') }.should raise_error(Mongo::Error::InvalidURI)
144
117
  end
145
118
 
146
- it "should create a replica set connection if config contains multiple hosts in the old format" do
119
+ it 'should forbid use of port' do
147
120
  MongoMapper.config = {
148
- 'development' => {
149
- 'hosts' => [ ['127.0.0.1', 27017], ['localhost', 27017] ],
150
- 'database' => 'test'
151
- }
121
+ 'development' => {'host' => '192.168.1.1', 'port' => '27017', 'database' => 'test', 'safe' => true}
152
122
  }
153
-
154
- Mongo::MongoReplicaSetClient.should_receive(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {'read_secondary' => true} )
155
- MongoMapper.should_receive(:database=).with('test')
156
- Mongo::DB.any_instance.should_receive(:authenticate).never
157
- MongoMapper.connect('development', 'read_secondary' => true)
123
+ lambda { MongoMapper.connect('development') }.should raise_error(RuntimeError)
158
124
  end
159
125
 
160
- it "should create a replica set connection if config contains multiple hosts in the new format" do
161
- MongoMapper.config = {
162
- 'development' => {
163
- 'hosts' => ['127.0.0.1:27017', 'localhost:27017'],
164
- 'database' => 'test'
165
- }
166
- }
167
-
168
- Mongo::MongoReplicaSetClient.should_receive(:new).with( ['127.0.0.1:27017', 'localhost:27017'], {'read_secondary' => true} )
169
- MongoMapper.should_receive(:database=).with('test')
170
- Mongo::DB.any_instance.should_receive(:authenticate).never
171
- MongoMapper.connect('development', 'read_secondary' => true)
172
- end
173
126
  end
174
127
 
175
128
  context "setup" do
@@ -66,6 +66,11 @@ describe "Rails integration" do
66
66
  @klass.new(:bar => 'Setting Foo').foo.should == 'Setting Foo'
67
67
  end
68
68
 
69
+ it "should return the type casted value from write attribute" do
70
+ obj = @klass.new
71
+ obj.write_attribute(:foo, true).should == "true"
72
+ end
73
+
69
74
  context '#to_param' do
70
75
  it "should be nil if not persisted" do
71
76
  @klass.new.tap do |doc|
@@ -151,7 +151,7 @@ module Serialization
151
151
 
152
152
  @instance.name.should == unserialized.name
153
153
  @instance.age.should == unserialized.age
154
- unserialized.awesome.should be_false
154
+ unserialized.awesome.should be_falsey
155
155
  unserialized.created_at.should be_nil
156
156
  end
157
157
 
@@ -25,7 +25,7 @@ describe "TimeZones" do
25
25
  Time.zone = 'UTC'
26
26
 
27
27
  doc = @document.new(:created_at => "2009-08-15 14:00:00")
28
- doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_true
28
+ doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_truthy
29
29
  doc.created_at.should == Time.utc(2009, 8, 15, 14)
30
30
 
31
31
  Time.zone = nil
@@ -35,7 +35,7 @@ describe "TimeZones" do
35
35
  Time.zone = 'Hawaii'
36
36
 
37
37
  doc = @document.new(:created_at => "2009-08-15 14:00:00")
38
- doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_true
38
+ doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_truthy
39
39
  doc.created_at.should == Time.utc(2009, 8, 16)
40
40
 
41
41
  Time.zone = nil
@@ -27,7 +27,7 @@ describe "Validations" do
27
27
  doc = @document.new
28
28
  doc.password = 'foobar'
29
29
  doc.password_confirmation = 'foobar1'
30
- doc.should have_error_on(:password_confirmation).or(:password)
30
+ doc.should have_error_on(:password).or(have_error_on(:password_confirmation))
31
31
 
32
32
  doc.password_confirmation = 'foobar'
33
33
  doc.should_not have_error_on(:password)
@@ -157,19 +157,19 @@ describe "Validations" do
157
157
  end # numericality of
158
158
 
159
159
  context "validating presence of" do
160
- it "should work with validates_presence_of macro" do
161
- @document.key :name, String
162
- @document.validates_presence_of :name
163
- doc = @document.new
164
- doc.should have_error_on(:name)
165
- end
166
-
167
- it "should work with :required shortcut on key definition" do
168
- @document.key :name, String, :required => true
169
- doc = @document.new
170
- doc.should have_error_on(:name)
171
- end
172
- end
160
+ it "should work with validates_presence_of macro" do
161
+ @document.key :name, String
162
+ @document.validates_presence_of :name
163
+ doc = @document.new
164
+ doc.should have_error_on(:name)
165
+ end
166
+
167
+ it "should work with :required shortcut on key definition" do
168
+ @document.key :name, String, :required => true
169
+ doc = @document.new
170
+ doc.should have_error_on(:name)
171
+ end
172
+ end
173
173
 
174
174
  context "validating exclusion of" do
175
175
  it "should throw error if enumerator not provided" do
@@ -190,7 +190,8 @@ describe "Validations" do
190
190
  doc.should_not have_error_on(:action)
191
191
 
192
192
  doc.action = 'kick'
193
- doc.should have_error_on(:action, 'is reserved')
193
+ doc.should have_error_on(:action)
194
+ doc.errors[:action].should == ['is reserved']
194
195
  end
195
196
 
196
197
  it "should work with :not_in shortcut on key definition" do
@@ -203,7 +204,8 @@ describe "Validations" do
203
204
  doc.should_not have_error_on(:action)
204
205
 
205
206
  doc.action = 'kick'
206
- doc.should have_error_on(:action, 'is reserved')
207
+ doc.should have_error_on(:action)
208
+ doc.errors[:action].should == ['is reserved']
207
209
  end
208
210
 
209
211
  it "should not have error if allow nil is true and value is nil" do
@@ -236,10 +238,12 @@ describe "Validations" do
236
238
  @document.validates_inclusion_of :action, :in => %w(kick run)
237
239
 
238
240
  doc = @document.new
239
- doc.should have_error_on(:action, 'is not included in the list')
241
+ doc.should have_error_on(:action)
242
+ doc.errors[:action].should == ['is not included in the list']
240
243
 
241
244
  doc.action = 'fart'
242
- doc.should have_error_on(:action, 'is not included in the list')
245
+ doc.should have_error_on(:action)
246
+ doc.errors[:action].should == ['is not included in the list']
243
247
 
244
248
  doc.action = 'kick'
245
249
  doc.should_not have_error_on(:action)
@@ -249,10 +253,12 @@ describe "Validations" do
249
253
  @document.key :action, String, :in => %w(kick run)
250
254
 
251
255
  doc = @document.new
252
- doc.should have_error_on(:action, 'is not included in the list')
256
+ doc.should have_error_on(:action)
257
+ doc.errors[:action].should == ['is not included in the list']
253
258
 
254
259
  doc.action = 'fart'
255
- doc.should have_error_on(:action, 'is not included in the list')
260
+ doc.should have_error_on(:action)
261
+ doc.errors[:action].should == ['is not included in the list']
256
262
 
257
263
  doc.action = 'kick'
258
264
  doc.should_not have_error_on(:action)
@@ -262,7 +268,8 @@ describe "Validations" do
262
268
  @document.key :flag, Boolean, :required => true
263
269
 
264
270
  doc = @document.new
265
- doc.should have_error_on(:flag, 'is not included in the list')
271
+ doc.should have_error_on(:flag)
272
+ doc.errors[:flag].should == ['is not included in the list']
266
273
 
267
274
  doc.flag = true
268
275
  doc.should_not have_error_on(:action)
@@ -313,7 +320,7 @@ describe "Validations" do
313
320
  doc = @embedded_doc.new
314
321
  doc.password = 'foobar'
315
322
  doc.password_confirmation = 'foobar1'
316
- doc.should have_error_on(:password).or(:password_confirmation)
323
+ doc.should have_error_on(:password).or(have_error_on(:password_confirmation))
317
324
  doc.password_confirmation = 'foobar'
318
325
  doc.should_not have_error_on(:password)
319
326
  end
@@ -429,19 +436,19 @@ describe "Validations" do
429
436
  end # numericality of
430
437
 
431
438
  context "validating presence of" do
432
- it "should work with validates_presence_of macro" do
439
+ it "should work with validates_presence_of macro" do
433
440
  @embedded_doc.key :name, String
434
441
  @embedded_doc.validates_presence_of :name
435
442
  doc = @embedded_doc.new
436
443
  doc.should have_error_on(:name)
437
- end
444
+ end
438
445
 
439
- it "should work with :required shortcut on key definition" do
446
+ it "should work with :required shortcut on key definition" do
440
447
  @embedded_doc.key :name, String, :required => true
441
448
  doc = @embedded_doc.new
442
449
  doc.should have_error_on(:name)
443
- end
444
- end
450
+ end
451
+ end
445
452
 
446
453
  context "validating exclusion of" do
447
454
  it "should throw error if enumerator not provided" do
@@ -462,7 +469,8 @@ describe "Validations" do
462
469
  doc.should_not have_error_on(:action)
463
470
 
464
471
  doc.action = 'kick'
465
- doc.should have_error_on(:action, 'is reserved')
472
+ doc.should have_error_on(:action)
473
+ doc.errors[:action].should == ['is reserved']
466
474
  end
467
475
 
468
476
  it "should work with :not_in shortcut on key definition" do
@@ -475,7 +483,8 @@ describe "Validations" do
475
483
  doc.should_not have_error_on(:action)
476
484
 
477
485
  doc.action = 'kick'
478
- doc.should have_error_on(:action, 'is reserved')
486
+ doc.should have_error_on(:action)
487
+ doc.errors[:action].should == ['is reserved']
479
488
  end
480
489
 
481
490
  it "should not have error if allow nil is true and value is nil" do
@@ -508,10 +517,12 @@ describe "Validations" do
508
517
  @embedded_doc.validates_inclusion_of :action, :in => %w(kick run)
509
518
 
510
519
  doc = @embedded_doc.new
511
- doc.should have_error_on(:action, 'is not included in the list')
520
+ doc.should have_error_on(:action)
521
+ doc.errors[:action].should == ['is not included in the list']
512
522
 
513
523
  doc.action = 'fart'
514
- doc.should have_error_on(:action, 'is not included in the list')
524
+ doc.should have_error_on(:action)
525
+ doc.errors[:action].should == ['is not included in the list']
515
526
 
516
527
  doc.action = 'kick'
517
528
  doc.should_not have_error_on(:action)
@@ -521,10 +532,12 @@ describe "Validations" do
521
532
  @embedded_doc.key :action, String, :in => %w(kick run)
522
533
 
523
534
  doc = @embedded_doc.new
524
- doc.should have_error_on(:action, 'is not included in the list')
535
+ doc.should have_error_on(:action)
536
+ doc.errors[:action].should == ['is not included in the list']
525
537
 
526
538
  doc.action = 'fart'
527
- doc.should have_error_on(:action, 'is not included in the list')
539
+ doc.should have_error_on(:action)
540
+ doc.errors[:action].should == ['is not included in the list']
528
541
 
529
542
  doc.action = 'kick'
530
543
  doc.should_not have_error_on(:action)
metadata CHANGED
@@ -1,81 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
+ - Chris Heald
9
+ - Scott Taylor
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2014-05-01 00:00:00.000000000 Z
13
+ date: 2020-10-03 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
- name: activemodel
16
+ name: mongo
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
15
24
  version_requirements: !ruby/object:Gem::Requirement
16
25
  requirements:
17
- - - '>='
26
+ - - "~>"
18
27
  - !ruby/object:Gem::Version
19
- version: 3.0.0
28
+ version: '2.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: plucky
20
31
  requirement: !ruby/object:Gem::Requirement
21
32
  requirements:
22
- - - '>='
33
+ - - "~>"
23
34
  - !ruby/object:Gem::Version
24
- version: 3.0.0
25
- prerelease: false
35
+ version: 0.8.0
26
36
  type: :runtime
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
37
+ prerelease: false
29
38
  version_requirements: !ruby/object:Gem::Requirement
30
39
  requirements:
31
- - - '>='
40
+ - - "~>"
32
41
  - !ruby/object:Gem::Version
33
- version: '3.0'
42
+ version: 0.8.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: activesupport
34
45
  requirement: !ruby/object:Gem::Requirement
35
46
  requirements:
36
- - - '>='
47
+ - - ">="
37
48
  - !ruby/object:Gem::Version
38
- version: '3.0'
39
- prerelease: false
49
+ version: '5.0'
40
50
  type: :runtime
41
- - !ruby/object:Gem::Dependency
42
- name: plucky
51
+ prerelease: false
43
52
  version_requirements: !ruby/object:Gem::Requirement
44
53
  requirements:
45
- - - ~>
54
+ - - ">="
46
55
  - !ruby/object:Gem::Version
47
- version: 0.6.5
56
+ version: '5.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: activemodel
48
59
  requirement: !ruby/object:Gem::Requirement
49
60
  requirements:
50
- - - ~>
61
+ - - ">="
51
62
  - !ruby/object:Gem::Version
52
- version: 0.6.5
53
- prerelease: false
63
+ version: '5.0'
54
64
  type: :runtime
55
- - !ruby/object:Gem::Dependency
56
- name: mongo
65
+ prerelease: false
57
66
  version_requirements: !ruby/object:Gem::Requirement
58
67
  requirements:
59
- - - ~>
68
+ - - ">="
60
69
  - !ruby/object:Gem::Version
61
- version: '1.8'
70
+ version: '5.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: activemodel-serializers-xml
62
73
  requirement: !ruby/object:Gem::Requirement
63
74
  requirements:
64
- - - ~>
75
+ - - "~>"
65
76
  - !ruby/object:Gem::Version
66
- version: '1.8'
67
- prerelease: false
77
+ version: '1.0'
68
78
  type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.0'
69
85
  description: MongoMapper is a Object-Document Mapper for Ruby and Rails
70
86
  email:
71
87
  - nunemaker@gmail.com
88
+ - cheald@gmail.com
89
+ - scott@railsnewbie.com
72
90
  executables:
73
91
  - mmconsole
74
92
  extensions: []
75
93
  extra_rdoc_files: []
76
94
  files:
77
95
  - LICENSE
78
- - README.rdoc
96
+ - README.md
79
97
  - UPGRADES
80
98
  - bin/mmconsole
81
99
  - examples/attr_accessible.rb
@@ -93,8 +111,6 @@ files:
93
111
  - examples/validating/embedded_docs.rb
94
112
  - lib/mongo_mapper.rb
95
113
  - lib/mongo_mapper/connection.rb
96
- - lib/mongo_mapper/connections/10gen.rb
97
- - lib/mongo_mapper/connections/moped.rb
98
114
  - lib/mongo_mapper/document.rb
99
115
  - lib/mongo_mapper/embedded_document.rb
100
116
  - lib/mongo_mapper/exceptions.rb
@@ -109,9 +125,9 @@ files:
109
125
  - lib/mongo_mapper/extensions/nil_class.rb
110
126
  - lib/mongo_mapper/extensions/object.rb
111
127
  - lib/mongo_mapper/extensions/object_id.rb
112
- - lib/mongo_mapper/extensions/ordered_hash.rb
113
128
  - lib/mongo_mapper/extensions/set.rb
114
129
  - lib/mongo_mapper/extensions/string.rb
130
+ - lib/mongo_mapper/extensions/symbol.rb
115
131
  - lib/mongo_mapper/extensions/time.rb
116
132
  - lib/mongo_mapper/locale/en.yml
117
133
  - lib/mongo_mapper/middleware/identity_map.rb
@@ -126,6 +142,7 @@ files:
126
142
  - lib/mongo_mapper/plugins/associations/collection.rb
127
143
  - lib/mongo_mapper/plugins/associations/embedded_collection.rb
128
144
  - lib/mongo_mapper/plugins/associations/in_array_proxy.rb
145
+ - lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb
129
146
  - lib/mongo_mapper/plugins/associations/many_association.rb
130
147
  - lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb
131
148
  - lib/mongo_mapper/plugins/associations/many_documents_proxy.rb
@@ -142,6 +159,7 @@ files:
142
159
  - lib/mongo_mapper/plugins/caching.rb
143
160
  - lib/mongo_mapper/plugins/callbacks.rb
144
161
  - lib/mongo_mapper/plugins/clone.rb
162
+ - lib/mongo_mapper/plugins/counter_cache.rb
145
163
  - lib/mongo_mapper/plugins/dirty.rb
146
164
  - lib/mongo_mapper/plugins/document.rb
147
165
  - lib/mongo_mapper/plugins/dumpable.rb
@@ -155,9 +173,11 @@ files:
155
173
  - lib/mongo_mapper/plugins/inspect.rb
156
174
  - lib/mongo_mapper/plugins/keys.rb
157
175
  - lib/mongo_mapper/plugins/keys/key.rb
176
+ - lib/mongo_mapper/plugins/keys/static.rb
158
177
  - lib/mongo_mapper/plugins/logger.rb
159
178
  - lib/mongo_mapper/plugins/modifiers.rb
160
179
  - lib/mongo_mapper/plugins/pagination.rb
180
+ - lib/mongo_mapper/plugins/partial_updates.rb
161
181
  - lib/mongo_mapper/plugins/persistence.rb
162
182
  - lib/mongo_mapper/plugins/protected.rb
163
183
  - lib/mongo_mapper/plugins/querying.rb
@@ -168,6 +188,8 @@ files:
168
188
  - lib/mongo_mapper/plugins/sci.rb
169
189
  - lib/mongo_mapper/plugins/scopes.rb
170
190
  - lib/mongo_mapper/plugins/serialization.rb
191
+ - lib/mongo_mapper/plugins/stats.rb
192
+ - lib/mongo_mapper/plugins/strong_parameters.rb
171
193
  - lib/mongo_mapper/plugins/timestamps.rb
172
194
  - lib/mongo_mapper/plugins/touch.rb
173
195
  - lib/mongo_mapper/plugins/userstamps.rb
@@ -181,10 +203,12 @@ files:
181
203
  - lib/rails/generators/mongo_mapper/config/templates/mongo.yml
182
204
  - lib/rails/generators/mongo_mapper/model/model_generator.rb
183
205
  - lib/rails/generators/mongo_mapper/model/templates/model.rb
206
+ - spec/examples.txt
184
207
  - spec/functional/accessible_spec.rb
185
208
  - spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb
186
209
  - spec/functional/associations/belongs_to_proxy_spec.rb
187
210
  - spec/functional/associations/in_array_proxy_spec.rb
211
+ - spec/functional/associations/in_foreign_array_proxy_spec.rb
188
212
  - spec/functional/associations/many_documents_as_proxy_spec.rb
189
213
  - spec/functional/associations/many_documents_proxy_spec.rb
190
214
  - spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb
@@ -198,6 +222,7 @@ files:
198
222
  - spec/functional/binary_spec.rb
199
223
  - spec/functional/caching_spec.rb
200
224
  - spec/functional/callbacks_spec.rb
225
+ - spec/functional/counter_cache_spec.rb
201
226
  - spec/functional/dirty_spec.rb
202
227
  - spec/functional/document_spec.rb
203
228
  - spec/functional/dumpable_spec.rb
@@ -211,16 +236,21 @@ files:
211
236
  - spec/functional/logger_spec.rb
212
237
  - spec/functional/modifiers_spec.rb
213
238
  - spec/functional/pagination_spec.rb
239
+ - spec/functional/partial_updates_spec.rb
214
240
  - spec/functional/protected_spec.rb
215
241
  - spec/functional/querying_spec.rb
216
242
  - spec/functional/rails_spec.rb
217
243
  - spec/functional/safe_spec.rb
218
244
  - spec/functional/sci_spec.rb
219
245
  - spec/functional/scopes_spec.rb
246
+ - spec/functional/static_keys_spec.rb
247
+ - spec/functional/stats_spec.rb
248
+ - spec/functional/strong_parameters_spec.rb
220
249
  - spec/functional/timestamps_spec.rb
221
250
  - spec/functional/touch_spec.rb
222
251
  - spec/functional/userstamps_spec.rb
223
252
  - spec/functional/validations_spec.rb
253
+ - spec/quality_spec.rb
224
254
  - spec/spec_helper.rb
225
255
  - spec/support/matchers.rb
226
256
  - spec/support/models.rb
@@ -264,17 +294,16 @@ require_paths:
264
294
  - lib
265
295
  required_ruby_version: !ruby/object:Gem::Requirement
266
296
  requirements:
267
- - - '>='
297
+ - - ">="
268
298
  - !ruby/object:Gem::Version
269
299
  version: '0'
270
300
  required_rubygems_version: !ruby/object:Gem::Requirement
271
301
  requirements:
272
- - - '>='
302
+ - - ">="
273
303
  - !ruby/object:Gem::Version
274
304
  version: '0'
275
305
  requirements: []
276
- rubyforge_project:
277
- rubygems_version: 2.2.2
306
+ rubygems_version: 3.1.4
278
307
  signing_key:
279
308
  specification_version: 4
280
309
  summary: A Ruby Object Mapper for Mongo