uorm 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +0,0 @@
1
- module Uorm
2
- VERSION = '0.0.10'
3
- end
@@ -1,176 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'em-mongo'
4
- require 'em-synchrony/em-mongo'
5
-
6
- Uorm::Mongo::DB.name = 'uorm_test'
7
-
8
- class AMongoModel
9
- include Uorm::Model
10
- include Uorm::Mongo
11
-
12
- field :reference, type: Uorm::Type::ObjectId
13
- field :name, type: Uorm::Type::String
14
- field :count, type: Uorm::Type::Integer
15
- field :dollars, type: Uorm::Type::Float
16
- field :favorite, type: Uorm::Type::Boolean
17
- field :created, type: Uorm::Type::Time
18
- end
19
-
20
- describe AMongoModel do
21
- after { AMongoModel.collection.remove }
22
-
23
- let(:attributes) do
24
- {
25
- reference: '50995b8c15529d4676000001',
26
- name: 'whatever',
27
- count: 5.to_s,
28
- dollars: 2.3.to_s,
29
- favorite: true.to_s,
30
- created: Time.utc(0).to_s
31
- }
32
- end
33
-
34
- describe '.new' do
35
- subject { AMongoModel.new attributes }
36
-
37
- its(:reference) { should == BSON::ObjectId('50995b8c15529d4676000001') }
38
- its(:name) { should == 'whatever' }
39
- its(:count) { should == 5 }
40
- its(:dollars) { should == 2.3 }
41
- its(:favorite) { should be_true }
42
- its(:created) { should == Time.utc(0) }
43
-
44
- its(:as_json) do
45
- should == {
46
- reference: '50995b8c15529d4676000001',
47
- name: "whatever",
48
- count: 5,
49
- dollars: 2.3,
50
- favorite: true,
51
- created: Time.utc(0).to_i,
52
- id: nil
53
- }
54
- end
55
- end
56
-
57
- describe '.all' do
58
- it 'returns a collection of all objects' do
59
- AMongoModel.collection.insert name: 'findme'
60
-
61
- AMongoModel.all.should be_collection_of AMongoModel
62
- end
63
-
64
- it 'returns a collection of objects with the query' do
65
- AMongoModel.collection.insert name: 'findme'
66
-
67
- AMongoModel.all(name: 'findme').should be_collection_of AMongoModel
68
- end
69
-
70
- it 'converts time strings into time objects' do
71
- AMongoModel.collection.insert created: Time.parse('2001-01-02')
72
-
73
- AMongoModel.all(created: { '$gt' => '2001-01-01' }).
74
- should be_collection_of AMongoModel
75
-
76
- AMongoModel.all(created: { '$lt' => Time.parse('2001-01-01')}).
77
- should be_empty
78
- end
79
-
80
- it 'converts reference strings into BSON::ObjectId objects' do
81
- AMongoModel.collection.insert reference: BSON::ObjectId('50995b8c15529d4676000001')
82
-
83
- AMongoModel.all(reference: '50995b8c15529d4676000001').
84
- should be_collection_of AMongoModel
85
- end
86
-
87
- it 'converts multiple query parameters' do
88
- AMongoModel.collection.insert reference: BSON::ObjectId('50995b8c15529d4676000001'), created: Time.parse('2003-01-01')
89
-
90
- AMongoModel.all(reference: '50995b8c15529d4676000001', created: '2003-01-01').
91
- should be_collection_of AMongoModel
92
- end
93
-
94
- it 'runs async given a block' do
95
- AMongoModel.collection.insert reference: BSON::ObjectId('50995b8c15529d4676000001')
96
- AMongoModel.all { |model| model.should be_instance_of AMongoModel }
97
- end
98
- end
99
-
100
- describe '.find' do
101
- it 'returns the first object with the given id' do
102
- model = AMongoModel.create attributes
103
- AMongoModel.find(model.id).should be_instance_of AMongoModel
104
- end
105
-
106
- it 'converts id BSON::ObjectId' do
107
- model = AMongoModel.create attributes
108
- AMongoModel.find(model.id.to_s).should be_instance_of AMongoModel
109
- end
110
-
111
- it 'runs async given a block' do
112
- model = AMongoModel.create attributes
113
- AMongoModel.find(model.id) { |model| model.should be_instance_of AMongoModel }
114
- end
115
- end
116
-
117
- describe '.create' do
118
- it 'adds the object to the collection' do
119
- expect { AMongoModel.create attributes }.to change { AMongoModel.collection.count }
120
- end
121
-
122
- it 'returns an object with the newly created attributes' do
123
- AMongoModel.create(attributes).should be_instance_of AMongoModel
124
- end
125
-
126
- it 'runs given block passing the created object if its creation was flawless' do
127
- called = false
128
- AMongoModel.create(attributes) do |model|
129
- model.should be_instance_of AMongoModel
130
- called = true
131
- end
132
- called.should be_true
133
- end
134
-
135
- it 'does not run given block if the creation failed' do
136
- called = false
137
- first = AMongoModel.create(attributes)
138
- AMongoModel.create(first.attributes) do |model|
139
- called = true
140
- end
141
- called.should be_false
142
- end
143
- end
144
-
145
- describe '#save' do
146
- it 'creates the object if it does not have an id' do
147
- model = AMongoModel.new attributes
148
- expect { model.save }.to change { model.id }
149
- end
150
-
151
- it 'updates the object if it does exist' do
152
- model = AMongoModel.create attributes
153
- expect { model.save }.to_not change { model.id }
154
- end
155
- end
156
-
157
- describe '#update' do
158
- it 'updates the object with the given attributes' do
159
- model = AMongoModel.create attributes
160
- expect { model.update name: 'new' }.to change { model.name }
161
- end
162
-
163
- it 'updates the collection with the given attributes' do
164
- model = AMongoModel.create attributes
165
- expect { model.update name: 'another' }.
166
- to change { AMongoModel.collection.find(name: 'another').count }
167
- end
168
- end
169
-
170
- describe '#delete' do
171
- it 'removes the object from the collection' do
172
- model = AMongoModel.create attributes
173
- expect { model.delete }.to change { AMongoModel.collection.count }
174
- end
175
- end
176
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'redis'
4
- require 'hiredis'
5
-
6
- Uorm::Redis::DB.nr = 15 #last one for safety
7
-
8
- class ARedisModel
9
- include Uorm::DSL
10
- include Uorm::Attributes
11
- include Uorm::Redis
12
-
13
- field :reference, type: Uorm::Type::String
14
- field :name, type: Uorm::Type::String
15
- field :count, type: Uorm::Type::Integer
16
- field :dollars, type: Uorm::Type::Float
17
- field :favorite, type: Uorm::Type::Boolean
18
- field :created, type: Uorm::Type::Time
19
- end
20
-
21
- describe ARedisModel do
22
- after { ARedisModel.collection.flushdb }
23
-
24
- let(:attributes) do
25
- {
26
- reference: '2d931510-d99f-494a-8c67-87feb05e1594',
27
- name: 'whatever',
28
- count: 5.to_s,
29
- dollars: 2.3.to_s,
30
- favorite: true.to_s,
31
- created: Time.utc(0).to_s
32
- }
33
- end
34
-
35
- describe '.new' do
36
- subject { ARedisModel.new attributes }
37
-
38
- its(:reference) { should == '2d931510-d99f-494a-8c67-87feb05e1594' }
39
- its(:name) { should == 'whatever' }
40
- its(:count) { should == 5 }
41
- its(:dollars) { should == 2.3 }
42
- its(:favorite) { should be_true }
43
- its(:created) { should == Time.utc(0) }
44
-
45
- its(:as_json) do
46
- should == {
47
- reference: '2d931510-d99f-494a-8c67-87feb05e1594',
48
- name: "whatever",
49
- count: 5,
50
- dollars: 2.3,
51
- favorite: true,
52
- created: Time.utc(0).to_i,
53
- id: nil
54
- }
55
- end
56
- end
57
-
58
- describe '.all' do
59
- it 'returns a collection of all objects' do
60
- ARedisModel.create attributes
61
- ARedisModel.all.should be_collection_of ARedisModel
62
- end
63
-
64
- it 'returns an empty array if the collection is empty' do
65
- ARedisModel.all.should =~ []
66
- end
67
- end
68
-
69
- describe '.find' do
70
- it 'returns the first object with the given id' do
71
- model = ARedisModel.create attributes
72
- ARedisModel.find(model.id).should be_instance_of ARedisModel
73
- end
74
- end
75
-
76
- describe '.create' do
77
- it 'adds the object to the collection' do
78
- expect { ARedisModel.create attributes }.to change { ARedisModel.collection.dbsize }
79
- end
80
-
81
- it 'returns an object with the newly created attributes' do
82
- ARedisModel.create(attributes).should be_instance_of ARedisModel
83
- end
84
- end
85
-
86
- describe '#save' do
87
- it 'creates the object if it does not have an id' do
88
- model = ARedisModel.new attributes
89
- expect { model.save }.to change { model.id }
90
- end
91
-
92
- it 'updates the object if it does exist' do
93
- model = ARedisModel.create attributes
94
- expect { model.save }.to_not change { model.id }
95
- end
96
- end
97
-
98
- describe '#update' do
99
- it 'updates the object with the given attributes' do
100
- model = ARedisModel.create attributes
101
- expect { model.update name: 'new' }.to change { model.name }
102
- end
103
-
104
- it 'updates the collection with the given attributes' do
105
- model = ARedisModel.create attributes
106
- expect { model.update name: 'another' }.
107
- to change { ARedisModel.find(model.id).name }
108
- end
109
- end
110
-
111
- describe '#delete' do
112
- it 'removes the object from the collection' do
113
- model = ARedisModel.create attributes
114
- expect { model.delete }.to change { ARedisModel.collection.dbsize }
115
- end
116
- end
117
- end