mongodb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/mongodb/object/object_helper.rb +2 -2
- data/readme.md +56 -129
- data/spec/object/crud_spec.rb +1 -1
- metadata +8 -36
- data/lib/mongodb/integration/locales.rb +0 -4
- data/lib/mongodb/integration/locales/activemodel/ru.yml +0 -27
- data/lib/mongodb/model.rb +0 -26
- data/lib/mongodb/model/assignment.rb +0 -65
- data/lib/mongodb/model/attribute_convertors.rb +0 -54
- data/lib/mongodb/model/callbacks.rb +0 -36
- data/lib/mongodb/model/crud.rb +0 -57
- data/lib/mongodb/model/db.rb +0 -53
- data/lib/mongodb/model/misc.rb +0 -33
- data/lib/mongodb/model/model.rb +0 -11
- data/lib/mongodb/model/query.rb +0 -36
- data/lib/mongodb/model/scope.rb +0 -99
- data/lib/mongodb/model/spec.rb +0 -12
- data/lib/mongodb/model/support/types.rb +0 -110
- data/lib/mongodb/model/validation.rb +0 -5
- data/spec/integration/am_conversion_spec.rb +0 -1
- data/spec/integration/am_validation_spec.rb +0 -34
- data/spec/integration/validatable2_spec.rb +0 -40
- data/spec/model/assignment_spec.rb +0 -80
- data/spec/model/attribute_convertors_spec.rb +0 -73
- data/spec/model/callbacks_spec.rb +0 -47
- data/spec/model/crud_spec.rb +0 -151
- data/spec/model/db_spec.rb +0 -63
- data/spec/model/misc_spec.rb +0 -58
- data/spec/model/query_spec.rb +0 -47
- data/spec/model/scope_spec.rb +0 -149
- data/spec/model/spec_helper.rb +0 -4
- data/spec/model/validation_spec.rb +0 -37
data/spec/model/misc_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'model/spec_helper'
|
2
|
-
|
3
|
-
describe 'Model Miscellaneous' do
|
4
|
-
with_mongo_model
|
5
|
-
|
6
|
-
before do
|
7
|
-
class User
|
8
|
-
inherit Mongo::Model
|
9
|
-
collection :users
|
10
|
-
end
|
11
|
-
end
|
12
|
-
after{remove_constants :Unit3, :User}
|
13
|
-
|
14
|
-
it "timestamps" do
|
15
|
-
class Unit3
|
16
|
-
inherit Mongo::Model
|
17
|
-
collection :units
|
18
|
-
|
19
|
-
attr_accessor :name
|
20
|
-
|
21
|
-
timestamps!
|
22
|
-
end
|
23
|
-
|
24
|
-
unit = Unit3.build name: 'Zeratul'
|
25
|
-
unit.save!
|
26
|
-
|
27
|
-
unit = Unit3.first
|
28
|
-
unit.created_at.should_not be_nil
|
29
|
-
unit.updated_at.should_not be_nil
|
30
|
-
created_at,updated_at = unit.created_at, unit.updated_at
|
31
|
-
|
32
|
-
unit.save!
|
33
|
-
unit.created_at.should == created_at
|
34
|
-
unit.updated_at.should > updated_at
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'cache' do
|
38
|
-
class Unit3
|
39
|
-
inherit Mongo::Model
|
40
|
-
end
|
41
|
-
u = Unit3.new
|
42
|
-
u._cache.should == {}
|
43
|
-
end
|
44
|
-
|
45
|
-
it "to_param" do
|
46
|
-
u = User.new
|
47
|
-
u.to_param.should == ''
|
48
|
-
u.save!
|
49
|
-
u.to_param.should_not be_empty
|
50
|
-
end
|
51
|
-
|
52
|
-
it "dom_id" do
|
53
|
-
u = User.new
|
54
|
-
u.dom_id.should == ''
|
55
|
-
u.save!
|
56
|
-
u.dom_id.should_not be_empty
|
57
|
-
end
|
58
|
-
end
|
data/spec/model/query_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'model/spec_helper'
|
2
|
-
require 'object/crud_shared'
|
3
|
-
|
4
|
-
describe "Model Query" do
|
5
|
-
with_mongo_model
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
class Unit
|
9
|
-
inherit Mongo::Model
|
10
|
-
collection :units
|
11
|
-
|
12
|
-
attr_accessor :name
|
13
|
-
end
|
14
|
-
end
|
15
|
-
after(:all){remove_constants :Unit}
|
16
|
-
|
17
|
-
before{@zeratul = Unit.build name: 'Zeratul'}
|
18
|
-
|
19
|
-
it 'exist?' do
|
20
|
-
Unit.should_not exist(name: 'Zeratul')
|
21
|
-
@zeratul.save!
|
22
|
-
Unit.should exist(name: 'Zeratul')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'first, first!' do
|
26
|
-
Unit.first.should be_nil
|
27
|
-
-> {Unit.first!}.should raise_error(Mongo::NotFound)
|
28
|
-
@zeratul.save
|
29
|
-
Unit.first.should_not be_nil
|
30
|
-
Unit.first!.should_not be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'all, each' do
|
34
|
-
list = []; Unit.each{|o| list << o}
|
35
|
-
list.size.should == 0
|
36
|
-
|
37
|
-
@zeratul.save
|
38
|
-
list = []; Unit.each{|o| list << o}
|
39
|
-
list.size.should == 1
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'dynamic finders integration' do
|
43
|
-
Unit.first_by_name('Zeratul').should be_nil
|
44
|
-
Unit.build(name: 'Zeratul').save!
|
45
|
-
Unit.first_by_name('Zeratul').name.should == 'Zeratul'
|
46
|
-
end
|
47
|
-
end
|
data/spec/model/scope_spec.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'model/spec_helper'
|
2
|
-
|
3
|
-
describe "Scope" do
|
4
|
-
with_mongo_model
|
5
|
-
|
6
|
-
before do
|
7
|
-
class Unit
|
8
|
-
inherit Mongo::Model
|
9
|
-
collection :units
|
10
|
-
|
11
|
-
attr_accessor :name, :status, :race
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
after{remove_constants :Unit, :Protoss}
|
16
|
-
|
17
|
-
describe 'current scope' do
|
18
|
-
it "should affect finders" do
|
19
|
-
Unit.build(name: 'Zeratul', status: 'alive').save!
|
20
|
-
Unit.build(name: 'Jim', status: 'alive').save!
|
21
|
-
Unit.build(name: 'Tassadar', status: 'dead').save!
|
22
|
-
|
23
|
-
Unit.count.should == 3
|
24
|
-
Unit.all.size.should == 3
|
25
|
-
Unit.first(name: 'Tassadar').should_not be_nil
|
26
|
-
Unit.first!(name: 'Tassadar').should_not be_nil
|
27
|
-
|
28
|
-
Unit.stub!(:current_scope).and_return(status: 'alive')
|
29
|
-
|
30
|
-
Unit.count.should == 2
|
31
|
-
Unit.all.size.should == 2
|
32
|
-
Unit.first(name: 'Tassadar').should be_nil
|
33
|
-
-> {Unit.first!(name: 'Tassadar')}.should raise_error(Mongo::NotFound)
|
34
|
-
|
35
|
-
# should be merged with finders
|
36
|
-
Unit.count(status: 'dead').should == 1
|
37
|
-
Unit.all(status: 'dead').size.should == 1
|
38
|
-
Unit.first(name: 'Tassadar', status: 'dead').should_not be_nil
|
39
|
-
Unit.first!(name: 'Tassadar', status: 'dead').should_not be_nil
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'default scope' do
|
44
|
-
it "should not affect objects without default_scope" do
|
45
|
-
Unit.current_scope.should == {}
|
46
|
-
end
|
47
|
-
|
48
|
-
it "definition" do
|
49
|
-
Unit.default_scope status: 'alive'
|
50
|
-
Unit.current_scope.should == {status: 'alive'}
|
51
|
-
|
52
|
-
Unit.default_scope do
|
53
|
-
{status: 'alive'}
|
54
|
-
end
|
55
|
-
Unit.current_scope.should == {status: 'alive'}
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be inherited" do
|
59
|
-
Unit.default_scope status: 'alive'
|
60
|
-
|
61
|
-
class Protoss < Unit; end
|
62
|
-
Protoss.current_scope.should == {status: 'alive'}
|
63
|
-
|
64
|
-
Protoss.default_scope status: 'dead'
|
65
|
-
Unit.current_scope.should == {status: 'alive'}
|
66
|
-
Protoss.current_scope.should == {status: 'dead'}
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'scope' do
|
71
|
-
it "definition" do
|
72
|
-
Unit.scope :alive, status: 'alive'
|
73
|
-
Unit.alive.current_scope.should == {status: 'alive'}
|
74
|
-
|
75
|
-
Unit.scope :alive do
|
76
|
-
{status: 'alive'}
|
77
|
-
end
|
78
|
-
Unit.alive.current_scope.should == {status: 'alive'}
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'scope should affect current scope' do
|
82
|
-
Unit.scope :alive, status: 'alive'
|
83
|
-
|
84
|
-
Unit.current_scope.should == {}
|
85
|
-
|
86
|
-
Unit.alive.current_scope.should == {status: 'alive'}
|
87
|
-
Unit.alive.should == Unit
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should be merged with default scope' do
|
91
|
-
Unit.default_scope race: 'Protoss'
|
92
|
-
Unit.scope :alive, status: 'alive'
|
93
|
-
Unit.alive.current_scope.should == {race: 'Protoss', status: 'alive'}
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should allow to chain scopes' do
|
97
|
-
Unit.scope :alive, status: 'alive'
|
98
|
-
Unit.scope :protosses, race: 'Protoss'
|
99
|
-
Unit.alive.protosses.current_scope.should == {race: 'Protoss', status: 'alive'}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe 'with_scope' do
|
104
|
-
it "shouldn't allow to nest exclusive scope" do
|
105
|
-
-> {
|
106
|
-
Unit.with_exclusive_scope do
|
107
|
-
Unit.with_exclusive_scope{}
|
108
|
-
end
|
109
|
-
}.should raise_error(/exclusive scope already applied/)
|
110
|
-
|
111
|
-
-> {
|
112
|
-
Unit.with_exclusive_scope do
|
113
|
-
Unit.with_scope{}
|
114
|
-
end
|
115
|
-
}.should raise_error(/exclusive scope already applied/)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "with_exclusive_scope should clear other scopes" do
|
119
|
-
Unit.default_scope status: 'alive'
|
120
|
-
|
121
|
-
Unit.with_scope race: 'Protoss' do
|
122
|
-
Unit.current_scope.should == {status: 'alive', race: 'Protoss'}
|
123
|
-
|
124
|
-
Unit.with_exclusive_scope do
|
125
|
-
Unit.current_scope.should == {}
|
126
|
-
end
|
127
|
-
|
128
|
-
Unit.with_exclusive_scope race: 'Terran' do
|
129
|
-
Unit.current_scope.should == {race: 'Terran'}
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "usage" do
|
135
|
-
Unit.with_scope status: 'alive' do
|
136
|
-
Unit.current_scope.should == {status: 'alive'}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should merge scope" do
|
141
|
-
Unit.default_scope status: 'alive'
|
142
|
-
Unit.with_scope race: 'Protoss' do
|
143
|
-
Unit.with_scope name: 'Zeratul' do
|
144
|
-
Unit.current_scope.should == {name: 'Zeratul', race: 'Protoss', status: 'alive'}
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
data/spec/model/spec_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'model/spec_helper'
|
2
|
-
|
3
|
-
describe "Validations" do
|
4
|
-
with_mongo_model
|
5
|
-
|
6
|
-
before do
|
7
|
-
class Unit
|
8
|
-
inherit Mongo::Model
|
9
|
-
collection :units
|
10
|
-
|
11
|
-
attr_accessor :errors
|
12
|
-
|
13
|
-
attr_accessor :name
|
14
|
-
end
|
15
|
-
end
|
16
|
-
after{remove_constants :Unit}
|
17
|
-
|
18
|
-
it "should not save model with errors" do
|
19
|
-
unit = Unit.build name: 'Zeratul'
|
20
|
-
unit.save.should be_true
|
21
|
-
|
22
|
-
unit.errors = []
|
23
|
-
unit.save.should be_true
|
24
|
-
|
25
|
-
unit.errors = ['hairy error']
|
26
|
-
unit.save.should be_false
|
27
|
-
|
28
|
-
unit.errors = {name: 'hairy error'}
|
29
|
-
unit.save.should be_false
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should check :errors only and ignore valid? method" do
|
33
|
-
unit = Unit.build name: 'Zeratul'
|
34
|
-
unit.should_not_receive(:valid?)
|
35
|
-
unit.save.should be_true
|
36
|
-
end
|
37
|
-
end
|