mongo_mapper 0.13.1 → 0.14.0.rc1

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 (103) hide show
  1. checksums.yaml +13 -5
  2. data/README.rdoc +3 -6
  3. data/lib/mongo_mapper.rb +1 -0
  4. data/lib/mongo_mapper/document.rb +2 -0
  5. data/lib/mongo_mapper/extensions/array.rb +14 -6
  6. data/lib/mongo_mapper/extensions/hash.rb +15 -3
  7. data/lib/mongo_mapper/extensions/object.rb +4 -0
  8. data/lib/mongo_mapper/extensions/string.rb +13 -5
  9. data/lib/mongo_mapper/plugins/accessible.rb +12 -11
  10. data/lib/mongo_mapper/plugins/associations.rb +7 -6
  11. data/lib/mongo_mapper/plugins/associations/base.rb +13 -12
  12. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
  13. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
  14. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
  15. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +24 -23
  16. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
  17. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
  18. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
  19. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
  20. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
  21. data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
  22. data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
  23. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
  24. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
  25. data/lib/mongo_mapper/plugins/associations/proxy.rb +29 -26
  26. data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
  27. data/lib/mongo_mapper/plugins/counter_cache.rb +23 -4
  28. data/lib/mongo_mapper/plugins/dirty.rb +2 -2
  29. data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
  30. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +17 -16
  31. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -1
  32. data/lib/mongo_mapper/plugins/identity_map.rb +1 -1
  33. data/lib/mongo_mapper/plugins/indexes.rb +1 -1
  34. data/lib/mongo_mapper/plugins/keys.rb +158 -158
  35. data/lib/mongo_mapper/plugins/keys/key.rb +16 -10
  36. data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
  37. data/lib/mongo_mapper/plugins/modifiers.rb +27 -26
  38. data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
  39. data/lib/mongo_mapper/plugins/persistence.rb +7 -6
  40. data/lib/mongo_mapper/plugins/protected.rb +6 -5
  41. data/lib/mongo_mapper/plugins/querying.rb +80 -43
  42. data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +14 -9
  43. data/lib/mongo_mapper/plugins/scopes.rb +78 -7
  44. data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
  45. data/lib/mongo_mapper/plugins/validations.rb +0 -0
  46. data/lib/mongo_mapper/version.rb +1 -1
  47. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
  48. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
  49. data/spec/functional/accessible_spec.rb +12 -12
  50. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +11 -11
  51. data/spec/functional/associations/belongs_to_proxy_spec.rb +14 -15
  52. data/spec/functional/associations/in_array_proxy_spec.rb +6 -6
  53. data/spec/functional/associations/many_documents_proxy_spec.rb +89 -18
  54. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +11 -11
  55. data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
  56. data/spec/functional/associations/one_as_proxy_spec.rb +14 -14
  57. data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
  58. data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
  59. data/spec/functional/associations/one_proxy_spec.rb +14 -14
  60. data/spec/functional/caching_spec.rb +8 -8
  61. data/spec/functional/callbacks_spec.rb +87 -0
  62. data/spec/functional/counter_cache_spec.rb +89 -0
  63. data/spec/functional/dirty_spec.rb +41 -41
  64. data/spec/functional/document_spec.rb +3 -3
  65. data/spec/functional/embedded_document_spec.rb +18 -18
  66. data/spec/functional/identity_map_spec.rb +28 -15
  67. data/spec/functional/indexes_spec.rb +4 -4
  68. data/spec/functional/keys_spec.rb +12 -3
  69. data/spec/functional/logger_spec.rb +1 -1
  70. data/spec/functional/modifiers_spec.rb +2 -2
  71. data/spec/functional/partial_updates_spec.rb +577 -0
  72. data/spec/functional/protected_spec.rb +13 -13
  73. data/spec/functional/querying_spec.rb +11 -10
  74. data/spec/functional/safe_spec.rb +2 -2
  75. data/spec/functional/sci_spec.rb +3 -3
  76. data/spec/functional/scopes_spec.rb +234 -1
  77. data/spec/functional/static_keys_spec.rb +153 -0
  78. data/spec/functional/stats_spec.rb +0 -4
  79. data/spec/functional/touch_spec.rb +1 -1
  80. data/spec/functional/validations_spec.rb +59 -57
  81. data/spec/quality_spec.rb +1 -1
  82. data/spec/spec_helper.rb +7 -3
  83. data/spec/support/matchers.rb +4 -13
  84. data/spec/unit/associations/base_spec.rb +12 -12
  85. data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
  86. data/spec/unit/associations/many_association_spec.rb +2 -2
  87. data/spec/unit/associations/one_association_spec.rb +2 -2
  88. data/spec/unit/associations/proxy_spec.rb +13 -15
  89. data/spec/unit/document_spec.rb +5 -5
  90. data/spec/unit/dynamic_finder_spec.rb +8 -8
  91. data/spec/unit/embedded_document_spec.rb +14 -14
  92. data/spec/unit/extensions_spec.rb +17 -17
  93. data/spec/unit/identity_map_middleware_spec.rb +5 -5
  94. data/spec/unit/key_spec.rb +24 -21
  95. data/spec/unit/keys_spec.rb +5 -5
  96. data/spec/unit/mongo_mapper_spec.rb +26 -26
  97. data/spec/unit/rails_spec.rb +2 -2
  98. data/spec/unit/serialization_spec.rb +1 -1
  99. data/spec/unit/time_zones_spec.rb +2 -2
  100. data/spec/unit/validations_spec.rb +28 -15
  101. metadata +16 -14
  102. data/lib/mongo_mapper/connections/10gen.rb +0 -0
  103. data/lib/mongo_mapper/connections/moped.rb +0 -0
@@ -36,7 +36,7 @@ module IdentityMapSpec
36
36
  [200, {}, nil]
37
37
  }
38
38
  mw.call({})
39
- called.should be_true
39
+ called.should be_truthy
40
40
  end
41
41
 
42
42
  it "should enable identity map during delegation" do
@@ -86,14 +86,14 @@ module IdentityMapSpec
86
86
 
87
87
  context "with a successful request" do
88
88
  it "should clear the identity map" do
89
- MongoMapper::Plugins::IdentityMap.should_receive(:clear).twice
89
+ expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).twice
90
90
  get '/'
91
91
  end
92
92
  end
93
93
 
94
94
  context "when the request raises an error" do
95
95
  it "should clear the identity map" do
96
- MongoMapper::Plugins::IdentityMap.should_receive(:clear).once
96
+ expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).once
97
97
  get '/fail' rescue nil
98
98
  end
99
99
  end
@@ -117,14 +117,14 @@ module IdentityMapSpec
117
117
 
118
118
  # context "with a successful request" do
119
119
  # it "should clear the identity map" do
120
- # MongoMapper::Plugins::IdentityMap.should_receive(:clear).twice
120
+ # expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).twice
121
121
  # get '/'
122
122
  # end
123
123
  # end
124
124
 
125
125
  # context "when the request raises an error" do
126
126
  # it "should clear the identity map" do
127
- # MongoMapper::Plugins::IdentityMap.should_receive(:clear).twice
127
+ # expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).twice
128
128
  # get '/fail' rescue nil
129
129
  # end
130
130
  # end
@@ -50,13 +50,13 @@ describe "Key" do
50
50
  key = Key.new(:foo, String, :required => true)
51
51
  key.name.should == 'foo'
52
52
  key.type.should == String
53
- key.options[:required].should be_true
53
+ key.options[:required].should be_truthy
54
54
  end
55
55
 
56
56
  it "should work with name and options" do
57
57
  key = Key.new(:foo, :required => true)
58
58
  key.name.should == 'foo'
59
- key.options[:required].should be_true
59
+ key.options[:required].should be_truthy
60
60
  end
61
61
 
62
62
  it "should not permit reserved names" do
@@ -90,20 +90,20 @@ describe "Key" do
90
90
  end
91
91
 
92
92
  it "should know if it is a embedded_document" do
93
- Key.new(:name, EDoc()).embeddable?.should be_true
93
+ Key.new(:name, EDoc()).embeddable?.should be_truthy
94
94
  end
95
95
 
96
96
  it "should know if it is not a embedded_document" do
97
- Key.new(:name, String).embeddable?.should be_false
97
+ Key.new(:name, String).embeddable?.should be_falsey
98
98
  end
99
99
 
100
100
  it "should know if it is a number" do
101
- Key.new(:age, Integer).number?.should be_true
102
- Key.new(:age, Float).number?.should be_true
101
+ Key.new(:age, Integer).number?.should be_truthy
102
+ Key.new(:age, Float).number?.should be_truthy
103
103
  end
104
104
 
105
105
  it "should know if it is not a number" do
106
- Key.new(:age, String).number?.should be_false
106
+ Key.new(:age, String).number?.should be_falsey
107
107
  end
108
108
  end
109
109
 
@@ -148,31 +148,34 @@ describe "Key" do
148
148
 
149
149
  context "with :read" do
150
150
  let(:accessor) { :read }
151
- its(:read_accessor?) { should be_true }
152
- its(:write_accessor?) { should be_false }
153
- its(:predicate_accessor?) { should be_false }
151
+
152
+ it { expect( subject.read_accessor? ).to be_truthy }
153
+ it { expect( subject.write_accessor? ).to be_falsey }
154
+ it { expect( subject.predicate_accessor? ).to be_falsey }
154
155
  end
155
156
 
156
157
  context "with :write" do
157
158
  let(:accessor) { :write }
158
- its(:read_accessor?) { should be_false }
159
- its(:write_accessor?) { should be_true }
160
- its(:predicate_accessor?) { should be_false }
159
+
160
+ it { expect( subject.read_accessor? ).to be_falsey }
161
+ it { expect( subject.write_accessor? ).to be_truthy }
162
+ it { expect( subject.predicate_accessor? ).to be_falsey }
161
163
  end
162
164
 
163
165
  context "with :predicate" do
164
166
  let(:accessor) { :predicate }
165
- its(:read_accessor?) { should be_false }
166
- its(:write_accessor?) { should be_false }
167
- its(:predicate_accessor?) { should be_true }
167
+
168
+ it { expect( subject.read_accessor? ).to be_falsey }
169
+ it { expect( subject.write_accessor? ).to be_falsey }
170
+ it { expect( subject.predicate_accessor? ).to be_truthy }
168
171
  end
169
172
 
170
173
  context "with an array of options" do
171
174
  let(:accessor) { [:read, :write] }
172
175
 
173
- its(:read_accessor?) { should be_true }
174
- its(:write_accessor?) { should be_true }
175
- its(:predicate_accessor?) { should be_false }
176
+ it { expect( subject.read_accessor? ).to be_truthy }
177
+ it { expect( subject.write_accessor? ).to be_truthy }
178
+ it { expect( subject.predicate_accessor? ).to be_falsey }
176
179
  end
177
180
  end
178
181
 
@@ -254,11 +257,11 @@ describe "Key" do
254
257
  end
255
258
 
256
259
  it "should work with Boolean type and false value" do
257
- Key.new(:active, Boolean, :default => false).default_value.should be_false
260
+ Key.new(:active, Boolean, :default => false).default_value.should be_falsey
258
261
  end
259
262
 
260
263
  it "should work with Boolean type and true value" do
261
- Key.new(:active, Boolean, :default => true).default_value.should be_true
264
+ Key.new(:active, Boolean, :default => true).default_value.should be_truthy
262
265
  end
263
266
 
264
267
  it "should work with Array values" do
@@ -16,11 +16,11 @@ describe "Key" do
16
16
 
17
17
  context ".key?(:symbol)" do
18
18
  it "should be true if document has key" do
19
- Address.key?(:city).should be_true
19
+ Address.key?(:city).should be_truthy
20
20
  end
21
21
 
22
22
  it "should be false if document does not have key" do
23
- Address.key?(:foo).should be_false
23
+ Address.key?(:foo).should be_falsey
24
24
  end
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ describe "Key" do
30
30
  key :_id, Integer
31
31
  end
32
32
  doc = klass.new
33
- doc.should_receive(:warn).once
33
+ expect(doc).to receive(:warn).once
34
34
  doc.assign({:x => :y})
35
35
  end
36
36
  end
@@ -59,11 +59,11 @@ describe "Key" do
59
59
 
60
60
  context ".key?('string')" do
61
61
  it "should be true if document has key" do
62
- Address.key?('city').should be_true
62
+ Address.key?('city').should be_truthy
63
63
  end
64
64
 
65
65
  it "should be false if document does not have key" do
66
- Address.key?('foo').should be_false
66
+ Address.key?('foo').should be_falsey
67
67
  end
68
68
  end
69
69
 
@@ -40,9 +40,9 @@ describe "MongoMapper" do
40
40
  MongoMapper.config = {
41
41
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
42
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
43
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, {})
44
+ expect(MongoMapper).to receive(:database=).with('test')
45
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
46
46
  MongoMapper.connect('development')
47
47
  end
48
48
 
@@ -50,9 +50,9 @@ describe "MongoMapper" do
50
50
  MongoMapper.config = {
51
51
  'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
52
52
  }
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
53
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, {})
54
+ expect(MongoMapper).to receive(:database=).with('test')
55
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
56
56
  MongoMapper.connect('development')
57
57
  end
58
58
 
@@ -60,9 +60,9 @@ describe "MongoMapper" do
60
60
  MongoMapper.config = {
61
61
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
62
62
  }
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
63
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, {})
64
+ expect(MongoMapper).to receive(:database=).with('test')
65
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
66
66
  MongoMapper.connect(:development)
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ describe "MongoMapper" do
71
71
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
72
72
  }
73
73
  connection, logger = double('connection'), double('logger')
74
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger)
74
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger)
75
75
  MongoMapper.connect('development', :logger => logger)
76
76
  end
77
77
 
@@ -80,7 +80,7 @@ describe "MongoMapper" do
80
80
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => true}
81
81
  }
82
82
  connection, logger = double('connection'), double('logger')
83
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => true)
83
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => true)
84
84
  MongoMapper.connect('development', :logger => logger)
85
85
  end
86
86
 
@@ -89,7 +89,7 @@ describe "MongoMapper" do
89
89
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => false}
90
90
  }
91
91
  connection, logger = double('connection'), double('logger')
92
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => false)
92
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => false)
93
93
  MongoMapper.connect('development', :logger => logger)
94
94
  end
95
95
 
@@ -98,7 +98,7 @@ describe "MongoMapper" do
98
98
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'options' => {'read' => 'primary'}}
99
99
  }
100
100
  connection, logger = double('connection'), double('logger')
101
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :read => :primary)
101
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger, :read => :primary)
102
102
  MongoMapper.connect('development', :logger => logger)
103
103
  end
104
104
 
@@ -107,7 +107,7 @@ describe "MongoMapper" do
107
107
  'development' => {'host' => '192.168.1.1', 'port' => 2222, 'database' => 'test', 'options' => {'safe' => true}}
108
108
  }
109
109
  connection, logger = double('connection'), double('logger')
110
- Mongo::MongoClient.should_receive(:new).with('192.168.1.1', 2222, :logger => logger, :safe => true)
110
+ expect(Mongo::MongoClient).to receive(:new).with('192.168.1.1', 2222, :logger => logger, :safe => true)
111
111
  MongoMapper.connect('development', :logger => logger)
112
112
  end
113
113
 
@@ -116,7 +116,7 @@ describe "MongoMapper" do
116
116
  'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
117
117
  }
118
118
  connection, logger = double('connection'), double('logger')
119
- Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger)
119
+ expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger)
120
120
  MongoMapper.connect('development', :logger => logger)
121
121
  end
122
122
 
@@ -124,7 +124,7 @@ describe "MongoMapper" do
124
124
  MongoMapper.config = {
125
125
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'username' => 'john', 'password' => 'secret'}
126
126
  }
127
- Mongo::DB.any_instance.should_receive(:authenticate).with('john', 'secret')
127
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).with('john', 'secret')
128
128
  MongoMapper.connect('development')
129
129
  end
130
130
 
@@ -132,7 +132,7 @@ describe "MongoMapper" do
132
132
  MongoMapper.config = {
133
133
  'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
134
134
  }
135
- Mongo::DB.any_instance.should_receive(:authenticate).with('john', 'secret')
135
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).with('john', 'secret')
136
136
  MongoMapper.connect('development')
137
137
  end
138
138
 
@@ -151,9 +151,9 @@ describe "MongoMapper" do
151
151
  }
152
152
  }
153
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
154
+ expect(Mongo::MongoReplicaSetClient).to receive(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {'read_secondary' => true} )
155
+ expect(MongoMapper).to receive(:database=).with('test')
156
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
157
157
  MongoMapper.connect('development', 'read_secondary' => true)
158
158
  end
159
159
 
@@ -165,9 +165,9 @@ describe "MongoMapper" do
165
165
  }
166
166
  }
167
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
168
+ expect(Mongo::MongoReplicaSetClient).to receive(:new).with( ['127.0.0.1:27017', 'localhost:27017'], {'read_secondary' => true} )
169
+ expect(MongoMapper).to receive(:database=).with('test')
170
+ expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
171
171
  MongoMapper.connect('development', 'read_secondary' => true)
172
172
  end
173
173
  end
@@ -175,9 +175,9 @@ describe "MongoMapper" do
175
175
  context "setup" do
176
176
  it "should work as shortcut for setting config, environment and options" do
177
177
  config, logger = double('config'), double('logger')
178
- MongoMapper.should_receive(:config=).with(config)
179
- MongoMapper.should_receive(:connect).with('development', :logger => logger)
180
- MongoMapper.should_receive(:handle_passenger_forking).once
178
+ expect(MongoMapper).to receive(:config=).with(config)
179
+ expect(MongoMapper).to receive(:connect).with('development', :logger => logger)
180
+ expect(MongoMapper).to receive(:handle_passenger_forking).once
181
181
  MongoMapper.setup(config, 'development', :logger => logger)
182
182
  end
183
183
  end
@@ -163,7 +163,7 @@ describe "Rails integration" do
163
163
 
164
164
  it "should array representation of id if persisted" do
165
165
  @klass.new.tap do |doc|
166
- doc.should_receive(:persisted?).and_return(true)
166
+ expect(doc).to receive(:persisted?).and_return(true)
167
167
  doc.to_param.should == doc.id.to_s
168
168
  end
169
169
  end
@@ -178,7 +178,7 @@ describe "Rails integration" do
178
178
 
179
179
  it "should array representation of id if persisted" do
180
180
  @klass.new.tap do |doc|
181
- doc.should_receive(:persisted?).and_return(true)
181
+ expect(doc).to receive(:persisted?).and_return(true)
182
182
  doc.to_key.should == [doc.id]
183
183
  end
184
184
  end
@@ -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)
@@ -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
@@ -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)