rmodel 0.1.0 → 0.2.0.pre.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -1
- data/examples/advanced_creation_of_repository.rb +15 -0
- data/lib/rmodel/base/repository.rb +12 -0
- data/lib/rmodel/base/repository_ext/sugarable.rb +17 -0
- data/lib/rmodel/{mongo → base}/repository_ext/timestampable.rb +1 -2
- data/lib/rmodel/mongo/repository.rb +6 -11
- data/lib/rmodel/version.rb +1 -1
- data/spec/rmodel/mongo/repository_crud_spec.rb +2 -27
- data/spec/rmodel/mongo/repository_ext/queryable_spec.rb +3 -7
- data/spec/rmodel/mongo/repository_ext/sugarable_spec.rb +14 -0
- data/spec/rmodel/mongo/repository_ext/timestampable_spec.rb +11 -65
- data/spec/rmodel/mongo/repository_initialize_spec.rb +27 -6
- data/spec/rmodel/mongo/simple_factory_spec.rb +1 -1
- data/spec/shared/repository_ext/sugarable.rb +46 -0
- data/spec/shared/repository_ext/timestampable.rb +69 -0
- metadata +14 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44999ed4c612599521faacd1a1f596d4a2df3d6a
|
4
|
+
data.tar.gz: 550ec35f4c18a10085fe3e9db5551d4e284fca6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e29bbc798c026d05c25cfa267cbdc635843b6961d031f957a3746673768d6553c93dfbdd63ce93f3184bffb2c7b6a749c264910a517c9f6834d0e7e2f653a05
|
7
|
+
data.tar.gz: 78423c914c99491860007d0d59a9b4b7f2850c3dcccec63d4da249d5ca483416f5f420d2114c929a68bbf66f94d343c242cae00989c26fd74c6c9b9332dca89f
|
data/README.md
CHANGED
@@ -2,8 +2,18 @@
|
|
2
2
|
|
3
3
|
# Rmodel
|
4
4
|
|
5
|
+
* [Installation](#installation)
|
6
|
+
* [Usage](#usage)
|
7
|
+
* [CRUD](#crud)
|
8
|
+
* [Scopes](#scopes)
|
9
|
+
* [Timestamps](#timestamps)
|
10
|
+
* [Sugar methods](#sugar-methods)
|
11
|
+
* [Advanced creation of repository](#advanced-creation-of-repository)
|
12
|
+
|
5
13
|
Rmodel is an ORM library, which tends to follow the SOLID principles.
|
6
14
|
|
15
|
+
**Currently works with MongoDB only.**
|
16
|
+
|
7
17
|
The main thoughts behind it are:
|
8
18
|
|
9
19
|
* let you models be simple and independent of the persistent layer,
|
@@ -116,7 +126,6 @@ userRepository.remove(bob)
|
|
116
126
|
|
117
127
|
p userRepository.find(john.id) # #<User:0x000000037237d0 @name="John Smith" ... >
|
118
128
|
p userRepository.find(bob.id) # nil
|
119
|
-
p userRepository.find!(bob.id) # raises Rmodel::NotFound
|
120
129
|
```
|
121
130
|
|
122
131
|
### Scopes
|
@@ -184,6 +193,41 @@ p thing.updated_at
|
|
184
193
|
|
185
194
|
To enable time tracking just add attributes `created_at` and `updated_at` or one of them to your entity.
|
186
195
|
|
196
|
+
### Sugar methods
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
repo.save(thing)
|
200
|
+
repo.find!(1)
|
201
|
+
```
|
202
|
+
|
203
|
+
The `save` method can be used instead of `insert` and `update`.
|
204
|
+
If the object has no not-nil id then it gets inserted. Otherwise it gets updated.
|
205
|
+
|
206
|
+
The `find!` method works like the simple `find`
|
207
|
+
, but instead of nil it raises the Rmodel::NotFound error.
|
208
|
+
|
209
|
+
### Advanced creation of repository
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
require 'rmodel'
|
213
|
+
|
214
|
+
class Thing
|
215
|
+
attr_accessor :id, :name
|
216
|
+
end
|
217
|
+
|
218
|
+
class ThingRepository < Rmodel::Mongo::Repository
|
219
|
+
end
|
220
|
+
|
221
|
+
client = Mongo::Client.new([ 'localhost:27017' ], database: 'test')
|
222
|
+
collection = :things
|
223
|
+
factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name)
|
224
|
+
|
225
|
+
repo = ThingRepository.new(client, collection, factory)
|
226
|
+
repo.find(1)
|
227
|
+
```
|
228
|
+
|
229
|
+
The `factory` is an object, which has 2 methods: `#fromHash(hash)` and `#toHash(object)`.
|
230
|
+
|
187
231
|
## Contributing
|
188
232
|
|
189
233
|
1. Fork it ( https://github.com/alexei-lexx/rmodel/fork )
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rmodel'
|
2
|
+
|
3
|
+
class Thing
|
4
|
+
attr_accessor :id, :name
|
5
|
+
end
|
6
|
+
|
7
|
+
class ThingRepository < Rmodel::Mongo::Repository
|
8
|
+
end
|
9
|
+
|
10
|
+
client = Mongo::Client.new([ 'localhost:27017' ], database: 'test')
|
11
|
+
collection = :things
|
12
|
+
factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name)
|
13
|
+
|
14
|
+
repo = ThingRepository.new(client, collection, factory)
|
15
|
+
p repo.find(1)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rmodel/base/repository_ext/sugarable'
|
2
|
+
require 'rmodel/base/repository_ext/timestampable'
|
3
|
+
|
4
|
+
module Rmodel::Base
|
5
|
+
class Repository
|
6
|
+
include RepositoryExt::Sugarable
|
7
|
+
|
8
|
+
def self.inherited(subclass)
|
9
|
+
subclass.prepend RepositoryExt::Timestampable
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rmodel::Base
|
2
|
+
module RepositoryExt
|
3
|
+
module Sugarable
|
4
|
+
def find!(id)
|
5
|
+
find(id) or raise Rmodel::NotFound.new(self, { id: id })
|
6
|
+
end
|
7
|
+
|
8
|
+
def save(object)
|
9
|
+
if object.id.nil?
|
10
|
+
insert(object)
|
11
|
+
else
|
12
|
+
update(object)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
require 'mongo'
|
2
|
+
require 'rmodel/base/repository'
|
2
3
|
require 'active_support/inflector'
|
3
4
|
require 'rmodel/mongo/repository_ext/queryable'
|
4
|
-
require 'rmodel/mongo/repository_ext/timestampable'
|
5
5
|
|
6
6
|
module Rmodel::Mongo
|
7
|
-
class Repository
|
7
|
+
class Repository < Rmodel::Base::Repository
|
8
8
|
include RepositoryExt::Queryable
|
9
|
-
prepend RepositoryExt::Timestampable
|
10
9
|
|
11
|
-
def initialize
|
12
|
-
@client = Rmodel.setup.establish_mongo_client(self.class.client_name || :default) or
|
10
|
+
def initialize(client = nil, collection = nil, factory = nil)
|
11
|
+
@client = client || Rmodel.setup.establish_mongo_client(self.class.client_name || :default) or
|
13
12
|
raise ArgumentError.new('Client driver is not setup')
|
14
13
|
|
15
|
-
@collection = self.class.setting_collection ||
|
14
|
+
@collection = collection || self.class.setting_collection ||
|
16
15
|
self.class.collection_by_convention or
|
17
16
|
raise ArgumentError.new('Collection can not be guessed')
|
18
17
|
|
19
|
-
@factory = self.class.setting_factory or
|
18
|
+
@factory = factory || self.class.setting_factory or
|
20
19
|
raise ArgumentError.new('Factory can not be guessed')
|
21
20
|
end
|
22
21
|
|
@@ -25,10 +24,6 @@ module Rmodel::Mongo
|
|
25
24
|
result && @factory.fromHash(result)
|
26
25
|
end
|
27
26
|
|
28
|
-
def find!(id)
|
29
|
-
find(id) or raise Rmodel::NotFound.new(self, { id: id })
|
30
|
-
end
|
31
|
-
|
32
27
|
def insert(object)
|
33
28
|
object.id ||= BSON::ObjectId.new
|
34
29
|
@client[@collection].insert_one(@factory.toHash(object, true))
|
data/lib/rmodel/version.rb
CHANGED
@@ -3,16 +3,11 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
3
3
|
|
4
4
|
before do
|
5
5
|
stub_const('User', Struct.new(:id, :name, :email))
|
6
|
-
stub_const('UserRepository', Class.new(Rmodel::Mongo::Repository)
|
7
|
-
simple_factory User, :name, :email
|
8
|
-
})
|
9
|
-
Rmodel.setup do
|
10
|
-
client :default, hosts: [ 'localhost' ], database: 'rmodel_test'
|
11
|
-
end
|
6
|
+
stub_const('UserRepository', Class.new(Rmodel::Mongo::Repository))
|
12
7
|
end
|
13
8
|
|
14
9
|
let(:factory) { Rmodel::Mongo::SimpleFactory.new(User, :name, :email) }
|
15
|
-
subject(:repo) { UserRepository.new }
|
10
|
+
subject(:repo) { UserRepository.new(mongo_session, :users, factory) }
|
16
11
|
|
17
12
|
describe '#find' do
|
18
13
|
context 'when an existent id is given' do
|
@@ -32,26 +27,6 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
|
-
describe '#find!' do
|
36
|
-
context 'when an existent id is given' do
|
37
|
-
before do
|
38
|
-
mongo_session[:users].insert_one(_id: 1, name: 'John', email: 'john@example.com')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns the right instance' do
|
42
|
-
expect(repo.find!(1)).not_to be_nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when a non-existent id is given' do
|
47
|
-
it 'raises the NotFound error' do
|
48
|
-
expect {
|
49
|
-
repo.find!(1)
|
50
|
-
}.to raise_error Rmodel::NotFound
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
30
|
describe '#insert' do
|
56
31
|
context 'when the id is not provided' do
|
57
32
|
let(:user) { User.new(nil, 'John', 'john@example.com') }
|
@@ -2,16 +2,12 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
2
2
|
include_context 'clean Mongo database'
|
3
3
|
|
4
4
|
before do
|
5
|
-
Rmodel.setup do
|
6
|
-
client :default, hosts: [ 'localhost' ], database: 'rmodel_test'
|
7
|
-
end
|
8
5
|
stub_const('Thing', Struct.new(:id, :a, :b))
|
9
|
-
stub_const('ThingRepository', Class.new(Rmodel::Mongo::Repository)
|
10
|
-
simple_factory Thing, :a, :b
|
11
|
-
})
|
6
|
+
stub_const('ThingRepository', Class.new(Rmodel::Mongo::Repository))
|
12
7
|
end
|
13
8
|
|
14
|
-
let(:
|
9
|
+
let(:factory) { Rmodel::Mongo::SimpleFactory.new(Thing, :a, :b) }
|
10
|
+
let(:repo) { ThingRepository.new(mongo_session, :things, factory) }
|
15
11
|
|
16
12
|
before do
|
17
13
|
repo.insert(Thing.new(nil, 2, 3))
|
@@ -0,0 +1,14 @@
|
|
1
|
+
RSpec.describe Rmodel::Mongo::Repository do
|
2
|
+
include_examples 'sugarable repository' do
|
3
|
+
include_context 'clean Mongo database'
|
4
|
+
|
5
|
+
before do
|
6
|
+
stub_const('ThingRepository', Class.new(Rmodel::Mongo::Repository))
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name)
|
11
|
+
ThingRepository.new(mongo_session, :things, factory)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,73 +1,19 @@
|
|
1
1
|
RSpec.describe Rmodel::Mongo::Repository do
|
2
|
-
|
3
|
-
|
2
|
+
include_examples 'timestampable repository' do
|
3
|
+
include_context 'clean Mongo database'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
stub_const('Thing', Struct.new(:id, :name, :created_at, :updated_at))
|
8
|
-
stub_const('ThingRepository', Class.new(Rmodel::Mongo::Repository) {
|
9
|
-
simple_factory Thing, :name, :created_at, :updated_at
|
10
|
-
})
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when we insert(object)' do
|
14
|
-
context 'and the object.created_at is already set' do
|
15
|
-
let(:thing) { Thing.new(nil, 'chair', Time.now) }
|
16
|
-
|
17
|
-
it 'doesnt change the value of created_at' do
|
18
|
-
set_created_at = thing.created_at
|
19
|
-
repo.insert(thing)
|
20
|
-
expect(thing.created_at).to eq set_created_at
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'and the object.created_at is not set yet' do
|
25
|
-
let(:thing) { Thing.new(nil, 'chair') }
|
26
|
-
|
27
|
-
it 'sets the value of created_at' do
|
28
|
-
repo.insert(thing)
|
29
|
-
expect(thing.created_at).not_to be_nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when we update(object)' do
|
35
|
-
let(:thing) { Thing.new(nil, 'chair') }
|
36
|
-
before { repo.insert(thing) }
|
37
|
-
|
38
|
-
it 'sets the value of created_at' do
|
39
|
-
thing.name = 'table'
|
40
|
-
repo.update(thing)
|
41
|
-
expect(thing.updated_at).not_to be_nil
|
42
|
-
end
|
43
|
-
end
|
5
|
+
before do
|
6
|
+
stub_const('ThingRepository', Class.new(Rmodel::Mongo::Repository))
|
44
7
|
end
|
45
8
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
simple_factory Thing, :name
|
51
|
-
})
|
52
|
-
end
|
53
|
-
let(:thing) { Thing.new(nil, 'chair') }
|
54
|
-
|
55
|
-
context 'when we insert(object)' do
|
56
|
-
it 'does nothing special' do
|
57
|
-
repo.insert(thing)
|
58
|
-
expect(thing.respond_to?(:created_at)).to be false
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when we update(object)' do
|
63
|
-
before { repo.insert(thing) }
|
9
|
+
let(:repo_w_timestamps) do
|
10
|
+
factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name, :created_at, :updated_at)
|
11
|
+
ThingRepository.new(mongo_session, :things, factory)
|
12
|
+
end
|
64
13
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
expect(thing.respond_to?(:updated_at)).to be false
|
69
|
-
end
|
70
|
-
end
|
14
|
+
let(:repo_wo_timestamps) do
|
15
|
+
factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name)
|
16
|
+
ThingRepository.new(mongo_session, :things, factory)
|
71
17
|
end
|
72
18
|
end
|
73
19
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
RSpec.describe Rmodel::Mongo::Repository do
|
2
2
|
before do
|
3
|
-
Rmodel.setup.clear
|
4
3
|
stub_const('User', Struct.new(:id, :name, :email))
|
5
4
|
end
|
6
5
|
|
7
|
-
subject { UserRepository.new }
|
8
|
-
|
9
6
|
describe '.client(name)' do
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
subject { UserRepository.new }
|
8
|
+
|
9
|
+
before { Rmodel::Setup.send :public, :client }
|
10
|
+
|
13
11
|
context 'when it is called with an existent name' do
|
14
12
|
before do
|
15
13
|
Rmodel.setup do
|
@@ -22,6 +20,7 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
22
20
|
attr_reader :client
|
23
21
|
})
|
24
22
|
end
|
23
|
+
after { Rmodel::setup.clear }
|
25
24
|
|
26
25
|
it 'sets the appropriate #client' do
|
27
26
|
expect(subject.client).to be_an_instance_of Mongo::Client
|
@@ -56,6 +55,7 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
56
55
|
client :default, { hosts: [ 'localhost' ] }
|
57
56
|
end
|
58
57
|
end
|
58
|
+
after { Rmodel::setup.clear }
|
59
59
|
|
60
60
|
it 'sets #client to be default' do
|
61
61
|
expect(subject.client).to be_an_instance_of Mongo::Client
|
@@ -71,11 +71,14 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe '.collection(name)' do
|
74
|
+
subject { UserRepository.new }
|
75
|
+
|
74
76
|
before do
|
75
77
|
Rmodel.setup do
|
76
78
|
client :default, { hosts: [ 'localhost' ] }
|
77
79
|
end
|
78
80
|
end
|
81
|
+
after { Rmodel::setup.clear }
|
79
82
|
|
80
83
|
context 'when the :people collection is given' do
|
81
84
|
before do
|
@@ -106,11 +109,14 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
106
109
|
end
|
107
110
|
|
108
111
|
describe '.simple_factory(klass, attribute1, attribute2, ...)' do
|
112
|
+
subject { UserRepository.new }
|
113
|
+
|
109
114
|
before do
|
110
115
|
Rmodel.setup do
|
111
116
|
client :default, { hosts: [ 'localhost' ] }
|
112
117
|
end
|
113
118
|
end
|
119
|
+
after { Rmodel::setup.clear }
|
114
120
|
|
115
121
|
context 'when it is called' do
|
116
122
|
before do
|
@@ -137,4 +143,19 @@ RSpec.describe Rmodel::Mongo::Repository do
|
|
137
143
|
end
|
138
144
|
end
|
139
145
|
end
|
146
|
+
|
147
|
+
describe '#initialize(client, collection, factory)' do
|
148
|
+
context 'when all constructor arguments are passed' do
|
149
|
+
before do
|
150
|
+
stub_const('UserRepository', Class.new(Rmodel::Mongo::Repository))
|
151
|
+
end
|
152
|
+
let(:factory) { Rmodel::Mongo::SimpleFactory.new(User, :name, :email) }
|
153
|
+
|
154
|
+
it 'works!' do
|
155
|
+
expect {
|
156
|
+
UserRepository.new(Object.new, :users, factory)
|
157
|
+
}.not_to raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
140
161
|
end
|
@@ -2,7 +2,7 @@ RSpec.describe Rmodel::Mongo::SimpleFactory do
|
|
2
2
|
context 'when the User(id, name, email) class is defined' do
|
3
3
|
before { stub_const('User', Struct.new(:id, :name, :email)) }
|
4
4
|
|
5
|
-
subject(:factory) {
|
5
|
+
subject(:factory) { described_class.new(User, :name, :email) }
|
6
6
|
|
7
7
|
describe '#fromHash' do
|
8
8
|
context 'when the hash with _id, name and email is given' do
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.shared_examples 'sugarable repository' do
|
2
|
+
describe Rmodel::Base::RepositoryExt::Sugarable do
|
3
|
+
before do
|
4
|
+
stub_const('Thing', Struct.new(:id, :name))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe '#find!' do
|
8
|
+
context 'when an existent id is given' do
|
9
|
+
before { subject.insert(Thing.new(1)) }
|
10
|
+
|
11
|
+
it 'returns the right instance' do
|
12
|
+
expect(subject.find!(1)).not_to be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when a non-existent id is given' do
|
17
|
+
it 'raises NotFound' do
|
18
|
+
expect {
|
19
|
+
subject.find!(1)
|
20
|
+
}.to raise_error Rmodel::NotFound
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'save' do
|
26
|
+
let(:thing) { Thing.new }
|
27
|
+
|
28
|
+
context 'when a new object is given' do
|
29
|
+
it 'gets inserted' do
|
30
|
+
subject.save(thing)
|
31
|
+
expect(subject.find(thing.id)).not_to be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when an existent object is given' do
|
36
|
+
before { subject.insert(thing) }
|
37
|
+
|
38
|
+
it 'gets updated' do
|
39
|
+
thing.name = 'chair'
|
40
|
+
subject.save(thing)
|
41
|
+
expect(subject.find(thing.id).name).to eq 'chair'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
RSpec.shared_examples 'timestampable repository' do
|
2
|
+
describe Rmodel::Base::RepositoryExt::Timestampable do
|
3
|
+
context 'when the entity object has attributes created_at and updated_at' do
|
4
|
+
before do
|
5
|
+
stub_const('Thing', Struct.new(:id, :name, :created_at, :updated_at))
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { repo_w_timestamps }
|
9
|
+
|
10
|
+
context 'when we insert(object)' do
|
11
|
+
context 'and the object.created_at is already set' do
|
12
|
+
let(:thing) { Thing.new(nil, 'chair', Time.now) }
|
13
|
+
|
14
|
+
it 'doesnt change the value of created_at' do
|
15
|
+
set_created_at = thing.created_at
|
16
|
+
subject.insert(thing)
|
17
|
+
expect(thing.created_at).to eq set_created_at
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'and the object.created_at is not set yet' do
|
22
|
+
let(:thing) { Thing.new(nil, 'chair') }
|
23
|
+
|
24
|
+
it 'sets the value of created_at' do
|
25
|
+
subject.insert(thing)
|
26
|
+
expect(thing.created_at).not_to be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when we update(object)' do
|
32
|
+
let(:thing) { Thing.new(nil, 'chair') }
|
33
|
+
before { subject.insert(thing) }
|
34
|
+
|
35
|
+
it 'sets the value of created_at' do
|
36
|
+
thing.name = 'table'
|
37
|
+
subject.update(thing)
|
38
|
+
expect(thing.updated_at).not_to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when the entity has no attributes :created_at and updated_at' do
|
44
|
+
before do
|
45
|
+
stub_const('Thing', Struct.new(:id, :name))
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:thing) { Thing.new(nil, 'chair') }
|
49
|
+
subject { repo_wo_timestamps }
|
50
|
+
|
51
|
+
context 'when we insert(object)' do
|
52
|
+
it 'does nothing special' do
|
53
|
+
subject.insert(thing)
|
54
|
+
expect(thing.respond_to?(:created_at)).to be false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when we update(object)' do
|
59
|
+
before { subject.insert(thing) }
|
60
|
+
|
61
|
+
it 'does nothing special' do
|
62
|
+
thing.name = 'table'
|
63
|
+
subject.update(thing)
|
64
|
+
expect(thing.respond_to?(:updated_at)).to be false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre.dev
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -108,14 +108,17 @@ files:
|
|
108
108
|
- LICENSE.txt
|
109
109
|
- README.md
|
110
110
|
- Rakefile
|
111
|
+
- examples/advanced_creation_of_repository.rb
|
111
112
|
- examples/timestamps.rb
|
112
113
|
- examples/user.rb
|
113
114
|
- lib/rmodel.rb
|
115
|
+
- lib/rmodel/base/repository.rb
|
116
|
+
- lib/rmodel/base/repository_ext/sugarable.rb
|
117
|
+
- lib/rmodel/base/repository_ext/timestampable.rb
|
114
118
|
- lib/rmodel/errors.rb
|
115
119
|
- lib/rmodel/mongo/repository.rb
|
116
120
|
- lib/rmodel/mongo/repository_ext/query.rb
|
117
121
|
- lib/rmodel/mongo/repository_ext/queryable.rb
|
118
|
-
- lib/rmodel/mongo/repository_ext/timestampable.rb
|
119
122
|
- lib/rmodel/mongo/setup.rb
|
120
123
|
- lib/rmodel/mongo/simple_factory.rb
|
121
124
|
- lib/rmodel/setup.rb
|
@@ -123,11 +126,14 @@ files:
|
|
123
126
|
- rmodel.gemspec
|
124
127
|
- spec/rmodel/mongo/repository_crud_spec.rb
|
125
128
|
- spec/rmodel/mongo/repository_ext/queryable_spec.rb
|
129
|
+
- spec/rmodel/mongo/repository_ext/sugarable_spec.rb
|
126
130
|
- spec/rmodel/mongo/repository_ext/timestampable_spec.rb
|
127
131
|
- spec/rmodel/mongo/repository_initialize_spec.rb
|
128
132
|
- spec/rmodel/mongo/simple_factory_spec.rb
|
129
133
|
- spec/rmodel/setup_spec.rb
|
130
134
|
- spec/shared/clean_moped.rb
|
135
|
+
- spec/shared/repository_ext/sugarable.rb
|
136
|
+
- spec/shared/repository_ext/timestampable.rb
|
131
137
|
- spec/spec_helper.rb
|
132
138
|
homepage: https://github.com/alexei-lexx/rmodel
|
133
139
|
licenses:
|
@@ -144,9 +150,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
150
|
version: '0'
|
145
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
152
|
requirements:
|
147
|
-
- - "
|
153
|
+
- - ">"
|
148
154
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
155
|
+
version: 1.3.1
|
150
156
|
requirements: []
|
151
157
|
rubyforge_project:
|
152
158
|
rubygems_version: 2.4.5
|
@@ -156,9 +162,12 @@ summary: Rmodel is an ORM library, which tends to follow the SOLID principles.
|
|
156
162
|
test_files:
|
157
163
|
- spec/rmodel/mongo/repository_crud_spec.rb
|
158
164
|
- spec/rmodel/mongo/repository_ext/queryable_spec.rb
|
165
|
+
- spec/rmodel/mongo/repository_ext/sugarable_spec.rb
|
159
166
|
- spec/rmodel/mongo/repository_ext/timestampable_spec.rb
|
160
167
|
- spec/rmodel/mongo/repository_initialize_spec.rb
|
161
168
|
- spec/rmodel/mongo/simple_factory_spec.rb
|
162
169
|
- spec/rmodel/setup_spec.rb
|
163
170
|
- spec/shared/clean_moped.rb
|
171
|
+
- spec/shared/repository_ext/sugarable.rb
|
172
|
+
- spec/shared/repository_ext/timestampable.rb
|
164
173
|
- spec/spec_helper.rb
|