mongodb 0.0.13 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,79 +0,0 @@
1
- require 'object/spec_helper'
2
-
3
- describe 'Object validation' do
4
- with_mongo
5
-
6
- before :all do
7
- class Player
8
- include Mongo::Object
9
-
10
- attr_accessor :missions
11
-
12
- class Mission
13
- include Mongo::Object
14
- end
15
- end
16
- end
17
- after(:all){remove_constants :Player}
18
-
19
- before do
20
- @mission = Player::Mission.new
21
- @player = Player.new
22
- @player.missions = [@mission]
23
- end
24
-
25
- it 'should not save/update/destroy invalid objects' do
26
- # create
27
- @player.stub!(:valid?).and_return(false)
28
- db.players.save(@player).should be_false
29
-
30
- @player.stub!(:valid?).and_return(true)
31
- db.players.save(@player).should be_true
32
-
33
- # update
34
- @player.stub!(:valid?).and_return(false)
35
- db.players.save(@player).should be_false
36
-
37
- @player.stub!(:valid?).and_return(true)
38
- db.players.save(@player).should be_true
39
-
40
- # destroy
41
- @player.stub!(:valid?).and_return(false)
42
- db.players.destroy(@player).should be_false
43
-
44
- @player.stub!(:valid?).and_return(true)
45
- db.players.destroy(@player).should be_true
46
- end
47
-
48
- it 'should not save/update/destroy invalid embedded objects' do
49
- # create
50
- @mission.stub!(:valid?).and_return(false)
51
- db.players.save(@player).should be_false
52
-
53
- @mission.stub!(:valid?).and_return(true)
54
- db.players.save(@player).should be_true
55
-
56
- # update
57
- @mission.stub!(:valid?).and_return(false)
58
- db.players.save(@player).should be_false
59
-
60
- @mission.stub!(:valid?).and_return(true)
61
- db.players.save(@player).should be_true
62
-
63
- # destroy
64
- @mission.stub!(:valid?).and_return(false)
65
- db.players.destroy(@player).should be_false
66
-
67
- @mission.stub!(:valid?).and_return(true)
68
- db.players.destroy(@player).should be_true
69
- end
70
-
71
- it "should be able skip validation" do
72
- @player.stub!(:valid?).and_return(false)
73
- db.players.save(@player, validate: false).should be_true
74
-
75
- @player.stub!(:valid?).and_return(true)
76
- @mission.stub!(:valid?).and_return(false)
77
- db.players.save(@player, validate: false).should be_true
78
- end
79
- end