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 CHANGED
@@ -1,2 +1,6 @@
1
- # gem 'activemodel', '~> 3.0'
2
- gem 'mongo', '~> 1.3'
1
+ gem 'mongo', '~> 1.3'
2
+ gem 'i18n', '>= 0.5'
3
+
4
+ if respond_to? :fake_gem
5
+ fake_gem 'ruby_ext'
6
+ end
@@ -1,11 +1,6 @@
1
- begin
2
- require 'ruby_ext'
3
- rescue LoadError => e
4
- warn 'Model requires the ruby_ext gem, please install it'
5
- raise e
6
- end
7
-
8
1
  require 'mongo_db/object'
2
+ require 'ruby_ext'
3
+ require 'i18n'
9
4
 
10
5
  module Mongo::Model; end
11
6
 
@@ -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 *args, &block
43
- doc = super *args, &block
44
- ::Mongo::ObjectSerializer.build(doc)
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 *args, &block
48
- super *args do |doc|
49
- obj = ::Mongo::ObjectSerializer.build(doc)
50
- block.call obj
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
- 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
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
@@ -19,6 +19,11 @@ describe "Object CRUD" do
19
19
  end
20
20
 
21
21
  it_should_behave_like "object CRUD"
22
+
23
+ it "should allow to read object as hash" do
24
+ db.units.save! @zeratul
25
+ db.units.first({}, object: false).class.should == Hash
26
+ end
22
27
  end
23
28
 
24
29
  describe 'embedded' do
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.11
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-23 00:00:00.000000000Z
12
+ date: 2011-08-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
16
- requirement: &753720 !ruby/object:Gem::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: *753720
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
@@ -1,4 +0,0 @@
1
- en:
2
- errors:
3
- messages:
4
- taken: "has already been taken"
@@ -1,4 +0,0 @@
1
- ru:
2
- errors:
3
- messages:
4
- taken: "уже занято"