mongodb_model 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo/model/assignment.rb +5 -0
- data/lib/mongo/model/crud.rb +2 -2
- data/lib/mongo/model/misc.rb +1 -1
- data/lib/mongo/model/model.rb +18 -0
- data/spec/assignment_spec.rb +2 -2
- data/spec/equality_spec.rb +32 -0
- metadata +13 -12
data/lib/mongo/model/crud.rb
CHANGED
@@ -6,7 +6,7 @@ module Mongo::Model::Crud
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def save! *args
|
9
|
-
save(*args) || raise(Mongo::Error, "can't save #{self.
|
9
|
+
save(*args) || raise(Mongo::Error, "can't save invalid model (#{self.errors})!")
|
10
10
|
end
|
11
11
|
|
12
12
|
def destroy options = {}
|
@@ -16,7 +16,7 @@ module Mongo::Model::Crud
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def destroy! *args
|
19
|
-
destroy(*args) || raise(Mongo::Error, "can't destroy #{self.
|
19
|
+
destroy(*args) || raise(Mongo::Error, "can't destroy invalid model #{self.errors}!")
|
20
20
|
end
|
21
21
|
|
22
22
|
module ClassMethods
|
data/lib/mongo/model/misc.rb
CHANGED
data/lib/mongo/model/model.rb
CHANGED
@@ -6,6 +6,24 @@ module Mongo::Model
|
|
6
6
|
def _id?; !!_id end
|
7
7
|
def new_record?; !_id end
|
8
8
|
|
9
|
+
inherited do
|
10
|
+
alias_method :eql?, :model_eql?
|
11
|
+
alias_method :==, :model_eq?
|
12
|
+
end
|
13
|
+
|
14
|
+
def model_eql? o
|
15
|
+
return true if equal? o
|
16
|
+
self.class == o.class and self == o
|
17
|
+
end
|
18
|
+
|
19
|
+
def model_eq? o
|
20
|
+
return true if equal? o
|
21
|
+
|
22
|
+
variables = {}; ::Mongo::Object.each_object_instance_variable(self){|n, v| variables[n] = v}
|
23
|
+
o_variables = {}; ::Mongo::Object.each_object_instance_variable(o){|n, v| o_variables[n] = v}
|
24
|
+
variables == o_variables
|
25
|
+
end
|
26
|
+
|
9
27
|
class << self
|
10
28
|
attr_accessor :db, :connection
|
11
29
|
attr_required :db, :connection
|
data/spec/assignment_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe 'Model callbacks' do
|
|
27
27
|
name String, true
|
28
28
|
has_mail Boolean, true
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
assign do
|
32
32
|
age Integer, true
|
33
33
|
position true
|
@@ -43,7 +43,7 @@ describe 'Model callbacks' do
|
|
43
43
|
u.set! banned: '0'
|
44
44
|
u.banned.should == false
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "should inherit assignment rules" do
|
48
48
|
class User
|
49
49
|
inherit Mongo::Model
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Model equality' do
|
4
|
+
with_mongo_model
|
5
|
+
|
6
|
+
after{remove_constants :Player}
|
7
|
+
|
8
|
+
it "integration smoke test" do
|
9
|
+
class Player
|
10
|
+
inherit Mongo::Model
|
11
|
+
|
12
|
+
attr_accessor :name, :mission
|
13
|
+
|
14
|
+
class Mission
|
15
|
+
inherit Mongo::Model
|
16
|
+
|
17
|
+
attr_accessor :name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
player1 = Player.new name: 'Alex'
|
22
|
+
player1.mission = Player::Mission.new name: 'First Strike'
|
23
|
+
|
24
|
+
player2 = Player.new name: 'Alex'
|
25
|
+
player2.mission = Player::Mission.new name: 'First Strike'
|
26
|
+
|
27
|
+
player1.should == player2
|
28
|
+
|
29
|
+
player1.mission.name = 'Into the Flames'
|
30
|
+
player1.should_not == player2
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &2781050 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.5'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2781050
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongodb
|
27
|
-
requirement: &
|
27
|
+
requirement: &2780760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2780760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: file_model
|
38
|
-
requirement: &
|
38
|
+
requirement: &2780460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2780460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: validatable2
|
49
|
-
requirement: &
|
49
|
+
requirement: &2780160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2780160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: ruby_ext
|
60
|
-
requirement: &
|
60
|
+
requirement: &2779870 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2779870
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- spec/callbacks_spec.rb
|
98
98
|
- spec/crud_spec.rb
|
99
99
|
- spec/db_spec.rb
|
100
|
+
- spec/equality_spec.rb
|
100
101
|
- spec/file_model_spec.rb
|
101
102
|
- spec/misc_spec.rb
|
102
103
|
- spec/query_spec.rb
|