mongo_db 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo_db/gems.rb +6 -2
- data/lib/mongo_db/model.rb +2 -7
- data/lib/mongo_db/object/object_helper.rb +16 -8
- data/spec/integration/am_validation_spec.rb +34 -34
- data/spec/integration/validatable2_spec.rb +34 -0
- data/spec/object/crud_spec.rb +5 -0
- metadata +27 -6
- data/lib/mongo_db/integration/locales/mongo_mapper/en.yml +0 -4
- data/lib/mongo_db/integration/locales/mongo_mapper/ru.yml +0 -4
data/lib/mongo_db/gems.rb
CHANGED
data/lib/mongo_db/model.rb
CHANGED
@@ -34,20 +34,28 @@ module Mongo::ObjectHelper
|
|
34
34
|
::Mongo::ObjectSerializer.new(arg).remove opts, self
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def save! doc, opts = {}
|
39
|
+
save(doc, opts) || raise(Mongo::Error, "can't save #{doc.inspect}!")
|
40
|
+
end
|
37
41
|
|
38
42
|
|
39
43
|
#
|
40
44
|
# Querying
|
41
45
|
#
|
42
|
-
def first
|
43
|
-
|
44
|
-
|
46
|
+
def first selector = {}, opts = {}, &block
|
47
|
+
opts = opts.clone
|
48
|
+
object = (opts.delete(:object) == false) ? false : true
|
49
|
+
doc = super selector, opts, &block
|
50
|
+
object ? ::Mongo::ObjectSerializer.build(doc) : doc
|
45
51
|
end
|
46
|
-
|
47
|
-
def each
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
|
53
|
+
def each selector = {}, opts = {}, &block
|
54
|
+
opts = opts.clone
|
55
|
+
object = (opts.delete(:object) == false) ? false : true
|
56
|
+
super selector, opts do |doc|
|
57
|
+
doc = ::Mongo::ObjectSerializer.build(doc) if object
|
58
|
+
block.call doc
|
51
59
|
end
|
52
60
|
nil
|
53
61
|
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require 'model/spec_helper'
|
2
|
-
require 'active_model'
|
3
|
-
|
4
|
-
describe "Validations" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
1
|
+
# require 'model/spec_helper'
|
2
|
+
# require 'active_model'
|
3
|
+
#
|
4
|
+
# describe "Validations" do
|
5
|
+
# with_mongo_model
|
6
|
+
#
|
7
|
+
# before do
|
8
|
+
# class Unit
|
9
|
+
# inherit Mongo::Model
|
10
|
+
# collection :units
|
11
|
+
#
|
12
|
+
# include ActiveModel::Validations
|
13
|
+
#
|
14
|
+
# attr_accessor :name, :status
|
15
|
+
#
|
16
|
+
# validates_presence_of :name
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# after{remove_constants :Unit}
|
21
|
+
#
|
22
|
+
# it "ActiveModel integration smoke test" do
|
23
|
+
# unit = Unit.new
|
24
|
+
# unit.should be_invalid
|
25
|
+
# unit.errors.size.should == 1
|
26
|
+
# unit.errors.first.first.should == :name
|
27
|
+
# unit.save.should be_false
|
28
|
+
#
|
29
|
+
# unit.name = 'Zeratul'
|
30
|
+
# unit.should be_valid
|
31
|
+
# unit.errors.should be_empty
|
32
|
+
# unit.save.should be_true
|
33
|
+
# end
|
34
|
+
# end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'model/spec_helper'
|
2
|
+
require 'validatable'
|
3
|
+
|
4
|
+
describe "Integration with validatable2" do
|
5
|
+
with_mongo_model
|
6
|
+
|
7
|
+
before do
|
8
|
+
class Unit
|
9
|
+
inherit Mongo::Model
|
10
|
+
collection :units
|
11
|
+
|
12
|
+
include Validatable
|
13
|
+
|
14
|
+
attr_accessor :name, :status
|
15
|
+
|
16
|
+
validates_presence_of :name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after{remove_constants :Unit}
|
21
|
+
|
22
|
+
it "ActiveModel integration smoke test" do
|
23
|
+
unit = Unit.new
|
24
|
+
unit.should_not be_valid
|
25
|
+
unit.errors.size.should == 1
|
26
|
+
unit.errors.first.first.should == :name
|
27
|
+
unit.save.should be_false
|
28
|
+
|
29
|
+
unit.name = 'Zeratul'
|
30
|
+
unit.should be_valid
|
31
|
+
unit.errors.should be_empty
|
32
|
+
unit.save.should be_true
|
33
|
+
end
|
34
|
+
end
|
data/spec/object/crud_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
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-08-
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongo
|
16
|
-
requirement: &
|
16
|
+
requirement: &2847970 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,29 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2847970
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: i18n
|
27
|
+
requirement: &2850730 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.5'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2850730
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: ruby_ext
|
38
|
+
requirement: &2851810 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2851810
|
25
47
|
description:
|
26
48
|
email:
|
27
49
|
executables: []
|
@@ -37,8 +59,6 @@ files:
|
|
37
59
|
- lib/mongo_db/driver.rb
|
38
60
|
- lib/mongo_db/gems.rb
|
39
61
|
- lib/mongo_db/integration/locales/activemodel/ru.yml
|
40
|
-
- lib/mongo_db/integration/locales/mongo_mapper/en.yml
|
41
|
-
- lib/mongo_db/integration/locales/mongo_mapper/ru.yml
|
42
62
|
- lib/mongo_db/integration/locales.rb
|
43
63
|
- lib/mongo_db/migration/definition.rb
|
44
64
|
- lib/mongo_db/migration/migration.rb
|
@@ -69,6 +89,7 @@ files:
|
|
69
89
|
- spec/driver/spec_helper.rb
|
70
90
|
- spec/integration/am_conversion_spec.rb
|
71
91
|
- spec/integration/am_validation_spec.rb
|
92
|
+
- spec/integration/validatable2_spec.rb
|
72
93
|
- spec/migration/migration_spec.rb
|
73
94
|
- spec/model/assignment_spec.rb
|
74
95
|
- spec/model/attribute_convertors_spec.rb
|