mongodb 0.0.1 → 0.0.2

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 (74) hide show
  1. data/Rakefile +3 -5
  2. data/lib/mongodb/driver.rb +33 -0
  3. data/lib/mongodb/driver/collection.rb +156 -0
  4. data/lib/mongodb/driver/database.rb +6 -0
  5. data/lib/mongodb/driver/dynamic_finders.rb +41 -0
  6. data/lib/{mongo_db → mongodb}/driver/spec.rb +12 -12
  7. data/lib/mongodb/gems.rb +6 -0
  8. data/lib/mongodb/integration/locales.rb +4 -0
  9. data/lib/mongodb/integration/locales/activemodel/ru.yml +27 -0
  10. data/lib/mongodb/migration.rb +8 -0
  11. data/lib/mongodb/migration/definition.rb +19 -0
  12. data/lib/mongodb/migration/migration.rb +68 -0
  13. data/lib/mongodb/migration/tasks.rb +19 -0
  14. data/lib/mongodb/model.rb +26 -0
  15. data/lib/mongodb/model/assignment.rb +65 -0
  16. data/lib/mongodb/model/attribute_convertors.rb +54 -0
  17. data/lib/mongodb/model/callbacks.rb +36 -0
  18. data/lib/mongodb/model/crud.rb +57 -0
  19. data/lib/mongodb/model/db.rb +53 -0
  20. data/lib/mongodb/model/misc.rb +33 -0
  21. data/lib/mongodb/model/model.rb +11 -0
  22. data/lib/mongodb/model/query.rb +36 -0
  23. data/lib/mongodb/model/scope.rb +99 -0
  24. data/lib/mongodb/model/spec.rb +12 -0
  25. data/lib/mongodb/model/support/types.rb +110 -0
  26. data/lib/mongodb/model/validation.rb +5 -0
  27. data/lib/mongodb/object.rb +18 -0
  28. data/lib/mongodb/object/object_helper.rb +62 -0
  29. data/lib/mongodb/object/object_serializer.rb +273 -0
  30. data/readme.md +261 -6
  31. data/spec/driver/collection_spec.rb +83 -0
  32. data/spec/{mongo_model/hash → driver}/crud_spec.rb +30 -29
  33. data/spec/driver/database_spec.rb +9 -0
  34. data/spec/driver/dynamic_finders_spec.rb +50 -0
  35. data/spec/driver/fixes_spec.rb +12 -0
  36. data/spec/driver/hash_helper_spec.rb +24 -0
  37. data/spec/driver/spec_helper.rb +28 -0
  38. data/spec/integration/am_conversion_spec.rb +1 -0
  39. data/spec/integration/am_validation_spec.rb +34 -0
  40. data/spec/integration/validatable2_spec.rb +40 -0
  41. data/spec/migration/migration_spec.rb +60 -0
  42. data/spec/model/assignment_spec.rb +80 -0
  43. data/spec/model/attribute_convertors_spec.rb +73 -0
  44. data/spec/model/callbacks_spec.rb +47 -0
  45. data/spec/model/crud_spec.rb +151 -0
  46. data/spec/model/db_spec.rb +63 -0
  47. data/spec/model/misc_spec.rb +58 -0
  48. data/spec/model/query_spec.rb +47 -0
  49. data/spec/model/scope_spec.rb +149 -0
  50. data/spec/model/spec_helper.rb +4 -0
  51. data/spec/model/validation_spec.rb +37 -0
  52. data/spec/object/callbacks_spec.rb +97 -0
  53. data/spec/object/crud_shared.rb +53 -0
  54. data/spec/object/crud_spec.rb +55 -0
  55. data/spec/object/spec_helper.rb +14 -0
  56. data/spec/{mongo_model/object → object}/validation_spec.rb +38 -36
  57. metadata +92 -25
  58. data/lib/mongo_db.rb +0 -3
  59. data/lib/mongo_db/driver.rb +0 -5
  60. data/lib/mongo_db/driver/connection.rb +0 -0
  61. data/lib/mongo_db/driver/database.rb +0 -5
  62. data/lib/mongo_db/gems.rb +0 -2
  63. data/lib/mongo_db/model.rb +0 -0
  64. data/spec/mongo_ext/migration_spec.rb +0 -0
  65. data/spec/mongo_ext/misc_spec.rb +0 -10
  66. data/spec/mongo_ext/spec_helper.rb +0 -4
  67. data/spec/mongo_model/model/crud_spec.rb +0 -123
  68. data/spec/mongo_model/model/query_spec.rb +0 -0
  69. data/spec/mongo_model/object/callbacks_spec.rb +0 -100
  70. data/spec/mongo_model/object/crud_shared.rb +0 -53
  71. data/spec/mongo_model/object/crud_spec.rb +0 -45
  72. data/spec/mongo_model/spec_helper.rb +0 -1
  73. data/spec/query_spec.rb +0 -0
  74. data/spec/test_spec.rb +0 -5
@@ -1,3 +0,0 @@
1
- require 'mongo_db/gems'
2
- require 'mongo_db/driver'
3
- require 'mongo_db/model'
@@ -1,5 +0,0 @@
1
- require 'mongo'
2
-
3
- %w(
4
- database
5
- ).each{|f| require "mongo_model/support/#{f}"}
File without changes
@@ -1,5 +0,0 @@
1
- class Mongo::DB
2
- def method_missing collection_name
3
- self[collection_name]
4
- end
5
- end
@@ -1,2 +0,0 @@
1
- gem 'activemodel', '~> 3.0'
2
- gem 'mongo', '~> 1.3'
File without changes
File without changes
@@ -1,10 +0,0 @@
1
- require 'mongo_ext/spec_helper'
2
-
3
- describe "Mongo Extensions" do
4
- with_mongo
5
-
6
- it "should provide handy access to collections" do
7
- mongo.db['collection1']
8
- mongo.db.collection1
9
- end
10
- end
@@ -1,4 +0,0 @@
1
- require 'mongo_ext'
2
-
3
- require 'rspec_ext'
4
- require 'mongo_ext/spec'
@@ -1,123 +0,0 @@
1
- require 'spec_helper'
2
- require 'object/crud_shared'
3
-
4
- describe "Model CRUD" do
5
- with_mongo_model
6
-
7
- describe 'simple' do
8
- before do
9
- class Person
10
- inherit Mongo::Model
11
- collection{db.heroes}
12
-
13
- def initialize name, info; @name, @info = name, info end
14
- attr_accessor :name, :info
15
- def == o; [self.class, name, info] == [o.class, o.respond_to(:name), o.respond_to(:info)] end
16
- end
17
-
18
- @zeratul = User.new 'Zeratul', 'Dark Templar'
19
- end
20
- after{remove_constants :Person}
21
-
22
- it_should_behave_like "object CRUD"
23
-
24
- it 'model crud' do
25
- # read
26
- Person.count.should == 0
27
- Person.all.should == []
28
- Person.first.should == nil
29
-
30
- # create
31
- @zeratul.save.should be_true
32
- @zeratul._id.should be_present
33
-
34
- # read
35
- Person.count.should == 1
36
- Person.all.should == [@zeratul]
37
- Person.first.should == @zeratul
38
- Person.first.object_id.should_not == @zeratul.object_id
39
-
40
- # update
41
- @zeratul.info = 'Killer of Cerebrates'
42
- @zeratul.save.should be_true
43
- Person.count.should == 1
44
- Person.first(name: 'Zeratul').info.should == 'Killer of Cerebrates'
45
-
46
- # destroy
47
- @zeratul.destroy.should be_true
48
- Person.count.should == 0
49
- end
50
-
51
- it 'should be able to save to another collection' do
52
- # create
53
- @zeratul.save(collection: db.protosses).should be_true
54
- @zeratul._id.should be_present
55
-
56
- # read
57
- Person.count.should == 0
58
- db.protosses.count.should == 1
59
- db.protosses.should == @zeratul
60
- db.protosses.object_id.should_not == @zeratul.object_id
61
-
62
- # update
63
- @zeratul.info = 'Killer of Cerebrates'
64
- @zeratul.save(collection: db.protosses).should be_true
65
- Person.count.should == 0
66
- db.protosses.count.should == 1
67
- db.protosses.first(name: 'Zeratul').info.should == 'Killer of Cerebrates'
68
-
69
- # destroy
70
- @zeratul.destroy(collection: db.protosses).should be_true
71
- db.protosses.count.should == 0
72
- end
73
- end
74
-
75
- describe 'embedded' do
76
- before do
77
- class Player
78
- inherit Mongo::Model
79
- attr_accessor :missions
80
- def == o; [self.class, self.missions] = [o.class, o.respond_to(:missions)] end
81
-
82
- class Mission
83
- inherit Mongo::Model
84
- def initialize name, stats; @name, @stats = name, stats end
85
- attr_accessor :name, :stats
86
- def == o; [self.class, self.name, self.stats] = [o.class, o.respond_to(:name), o.respond_to(:stats)] end
87
- end
88
- end
89
-
90
- @player = Player.new
91
- @player.missions = [
92
- Player::Mission.new('Wasteland', {buildings: 5, units: 10}),
93
- Player::Mission.new('Backwater Station', {buildings: 8, units: 25}),
94
- ]
95
- end
96
- after{remove_constants :Player}
97
-
98
- it_should_behave_like 'shared object CRUD'
99
-
100
- it 'crud' do
101
- # create
102
- @player.save.should be_true
103
- @player._id.should be_present
104
-
105
- # read
106
- Player.count.should == 1
107
- Player.first.should == @player
108
- Player.first.object_id.should_not == @players.object_id
109
-
110
- # update
111
- @player.missions.first.stats[:units] = 9
112
- @player.missions << Player::Mission.new('Desperate Alliance', {buildings: 11, units: 40}),
113
- @player.save.should be_true
114
- Player.count.should == 1
115
- Player.first.should == @player
116
- Player.first.object_id.should_not == @player.object_id
117
-
118
- # destroy
119
- @player.destroy.should be_true
120
- Player.count.should == 0
121
- end
122
- end
123
- end
File without changes
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Object callbacks' do
4
- with_mongo_model
5
-
6
- before do
7
- class Player
8
- attr_accessor :missions
9
-
10
- class Mission
11
- end
12
- end
13
-
14
- @mission = Player::Mission.new
15
- @player = Player.new
16
- @player.missions = [@mission]
17
- end
18
- after{remove_constants :Player}
19
-
20
- it 'create' do
21
- [
22
- :before_validation,
23
- :after_validation,
24
- :before_save,
25
- :before_create,
26
- :after_create,
27
- :after_save
28
- ].each do |name|
29
- @player.should_receive(name).ordered
30
- @misson.should_receive(name).ordered
31
- end
32
-
33
- db.players.save @player
34
- end
35
-
36
- it 'update' do
37
- db.players.save @player
38
-
39
- [
40
- :before_validation,
41
- :validate,
42
- :after_validation,
43
- :before_save,
44
- :before_update,
45
- :after_update,
46
- :after_save
47
- ].each do |name|
48
- @player.should_receive(name).ordered
49
- @misson.should_receive(name).ordered
50
- end
51
- db.players.save @player
52
- end
53
-
54
- it 'destroy' do
55
- db.players.save @player
56
-
57
- [
58
- :before_validation,
59
- :validate,
60
- :after_validation,
61
- :before_destroy,
62
- :after_destroy,
63
- ].each do |name|
64
- @player.should_receive(name).ordered
65
- @misson.should_receive(name).ordered
66
- end
67
- db.players.destroy @player
68
- end
69
-
70
- it 'should be able interrupt CRUD' do
71
- @misson.stub!(:before_save).and_return(false)
72
- db.players.save(@player).should be_false
73
- db.players.count.should == 0
74
- end
75
-
76
- it 'should be able skip callbacks' do
77
- [
78
- :before_validation,
79
- :after_validation,
80
- :before_save,
81
- :before_create,
82
- :after_create,
83
- :after_save,
84
- :before_update,
85
- :after_update,
86
- :before_destroy,
87
- :after_destroy
88
- ].each do |name|
89
- @player.should_not_receive(name)
90
- @misson.should_receive(name)
91
- end
92
-
93
- db.players.save @player, callbacks: false
94
- db.players.count.should == 1
95
- db.players.save @player, callbacks: false
96
- db.players.count.should == 1
97
- db.players.destroy @player, callbacks: false
98
- db.players.count.should == 0
99
- end
100
- end
@@ -1,53 +0,0 @@
1
- shared_examples_for 'object CRUD' do
2
- it 'crud' do
3
- # read
4
- db.heroes.count.should == 0
5
- db.heroes.all.should == []
6
- db.heroes.first.should == nil
7
-
8
- # create
9
- db.heroes.save(@zeratul).should be_true
10
- @zeratul.instance_variable_get(:@_id).should be_present
11
-
12
- # read
13
- db.heroes.count.should == 1
14
- db.heroes.all.should == [@zeratul]
15
- db.heroes.first.should == @zeratul
16
- db.heroes.first.object_id.should_not == @zeratul.object_id
17
-
18
- # update
19
- @zeratul.info = 'Killer of Cerebrates'
20
- db.heroes.save(@zeratul).should be_true
21
- db.heroes.count.should == 1
22
- db.heroes.first(name: 'Zeratul').info.should == 'Killer of Cerebrates'
23
-
24
- # destroy
25
- db.heroes.destroy(@zeratul).should be_true
26
- db.heroes.count.should == 0
27
- end
28
- end
29
-
30
- shared_examples_for 'embedded object CRUD' do
31
- it 'crud' do
32
- # create
33
- db.players.save(@player)
34
- @player.instance_variable_get(:@_id).should be_present
35
-
36
- # read
37
- db.players.count.should == 1
38
- db.players.first.should == @player
39
- db.players.first.object_id.should_not == @players.object_id
40
-
41
- # update
42
- @player.missions.first.stats[:units] = 9
43
- @player.missions << Player::Mission.new('Desperate Alliance', {buildings: 11, units: 40}),
44
- db.players.save @player
45
- db.players.count.should == 1
46
- db.players.first.should == @player
47
- db.players.first.object_id.should_not == @player.object_id
48
-
49
- # destroy
50
- db.players.destroy @player
51
- db.players.count.should == 0
52
- end
53
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
- require 'object/crud_shared'
3
-
4
- describe "Object CRUD" do
5
- with_mongo_model
6
-
7
- describe 'simple' do
8
- before do
9
- class Person
10
- def initialize name, info; @name, @info = name, info end
11
- attr_accessor :name, :info
12
- def == o; [self.class, name, info] == [o.class, o.respond_to(:name), o.respond_to(:info)] end
13
- end
14
-
15
- @zeratul = User.new 'Zeratul', 'Dark Templar'
16
- end
17
- after{remove_constants :Person}
18
-
19
- it_should_behave_like "object CRUD"
20
- end
21
-
22
- describe 'embedded' do
23
- before do
24
- class Player
25
- attr_accessor :missions
26
- def == o; [self.class, self.missions] = [o.class, o.respond_to(:missions)] end
27
-
28
- class Mission
29
- def initialize name, stats; @name, @stats = name, stats end
30
- attr_accessor :name, :stats
31
- def == o; [self.class, self.name, self.stats] = [o.class, o.respond_to(:name), o.respond_to(:stats)] end
32
- end
33
- end
34
-
35
- @player = Player.new
36
- @player.missions = [
37
- Player::Mission.new('Wasteland', {buildings: 5, units: 10}),
38
- Player::Mission.new('Backwater Station', {buildings: 8, units: 25}),
39
- ]
40
- end
41
- after{remove_constants :Player}
42
-
43
- it_should_behave_like 'embedded object CRUD'
44
- end
45
- end
@@ -1 +0,0 @@
1
- require 'mongo_model'
File without changes
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- db = Mongo::Connection.new("localhost").db("default_test")
4
- p db.class
5
- puts db.methods.sort