perimeter-activerecord 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/lib/perimeter/backend/adapters/active_record.rb +35 -0
- data/lib/perimeter/repository/adapters/active_record.rb +101 -0
- data/lib/perimeter-activerecord.rb +4 -0
- data/perimeter-activerecord.gemspec +24 -0
- data/spec/lib/perimeter/repository/adapters/active_record_spec.rb +342 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/models/my/game.rb +12 -0
- data/spec/support/models/my/games/backend.rb +21 -0
- data/spec/support/models/my/games.rb +9 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7af5977060e52a58d7eecacbc8f0360330887840
|
4
|
+
data.tar.gz: 311283970195ae921755d753c49afafa3e8f3230
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1e7804603a2cb9e2dfca15100f38842c22df849776a21dcd29f13904643742ac13c47ae5e3d137af06f74fb4649e35cc1fd1a471e447e78cf298154720e713f
|
7
|
+
data.tar.gz: b48686441ee6c0d54e2a7583f1c2ff329b0b6dade726d2eb18bc41ab6c4eb31e5262b60b8eddeb97f461ee17a213864a48c1c7242037d9edaa09a185a9a6b6dc
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, cmd: 'rspec --fail-fast' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bukowskis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Perimeter
|
2
|
+
|
3
|
+
An ActiveRecord adapter for [Perimeter](https://github.com/bukowskis/perimeter).
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'perimeter/repository/adapters/active_record'
|
7
|
+
|
8
|
+
# Repository
|
9
|
+
module Books
|
10
|
+
include Perimeter::Repository::Adapters::ActiveRecord
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'perimeter/backend/adapters/active_record'
|
16
|
+
|
17
|
+
# Backend
|
18
|
+
module Books
|
19
|
+
class Backend < ActiveRecord::Base
|
20
|
+
include Perimeter::Backend::Adapters::ActiveRecord
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
# License
|
26
|
+
|
27
|
+
See `MIT-LICENSE` for details.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Perimeter
|
4
|
+
module Backend
|
5
|
+
module Adapters
|
6
|
+
module ActiveRecord
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
begin
|
11
|
+
# ActiveRecord >= 3.2.1
|
12
|
+
self.table_name = perimeter_table_name
|
13
|
+
rescue NoMethodError => e
|
14
|
+
# ActiveRecord < 3.2.1
|
15
|
+
set_table_name perimeter_table_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
def perimeter_table_name(*args)
|
22
|
+
@perimeter_table_name = args.first unless args.empty?
|
23
|
+
@perimeter_table_name || default_perimeter_table_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_perimeter_table_name
|
27
|
+
name.split('::')[-2].underscore
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'operation'
|
2
|
+
require 'perimeter/repository'
|
3
|
+
require 'perimeter/repository/adapters/abstract'
|
4
|
+
require 'active_support/concern'
|
5
|
+
|
6
|
+
module Perimeter
|
7
|
+
module Repository
|
8
|
+
module Adapters
|
9
|
+
module ActiveRecord
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
include Perimeter::Repository
|
13
|
+
include Perimeter::Repository::Adapters::Abstract
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def find(id)
|
18
|
+
record = backend.find id
|
19
|
+
entity = record_to_entity record
|
20
|
+
Operations.success :record_found, object: entity
|
21
|
+
|
22
|
+
rescue ::ActiveRecord::RecordNotFound => exception
|
23
|
+
Operations.failure :record_not_found, object: exception
|
24
|
+
|
25
|
+
rescue Exception => exception
|
26
|
+
::Trouble.notify exception
|
27
|
+
Operations.failure :backend_error, object: exception
|
28
|
+
end
|
29
|
+
|
30
|
+
def create(attributes)
|
31
|
+
record = attributes_to_record attributes
|
32
|
+
|
33
|
+
if record.invalid?
|
34
|
+
return Operations.failure(:validation_failed, object: record_to_entity(record))
|
35
|
+
end
|
36
|
+
|
37
|
+
id = record.id.presence || attributes[:id].presence || attributes['id'].presence
|
38
|
+
if id && backend.find_by_id(id)
|
39
|
+
return Operations.failure :record_already_exists
|
40
|
+
end
|
41
|
+
|
42
|
+
if record.save
|
43
|
+
Operations.success :record_created, object: record_to_entity(record)
|
44
|
+
else
|
45
|
+
Operations.failure :creation_failed, object: record_to_entity(record)
|
46
|
+
end
|
47
|
+
|
48
|
+
rescue Exception => exception
|
49
|
+
::Trouble.notify exception
|
50
|
+
Operations.failure :backend_error, object: exception
|
51
|
+
end
|
52
|
+
|
53
|
+
# ––––––––
|
54
|
+
# Updating
|
55
|
+
# ––––––––
|
56
|
+
|
57
|
+
def update(id, attributes)
|
58
|
+
unless record = backend.find_by_id(id)
|
59
|
+
return Operations.failure :record_not_found
|
60
|
+
end
|
61
|
+
|
62
|
+
record.assign_attributes attributes
|
63
|
+
|
64
|
+
if record.invalid?
|
65
|
+
entity = record_to_entity record
|
66
|
+
return Operations.failure(:validation_failed, object: entity)
|
67
|
+
end
|
68
|
+
|
69
|
+
if record.save
|
70
|
+
Operations.success :record_updated, object: record_to_entity(record)
|
71
|
+
else
|
72
|
+
Operations.failure :update_failed
|
73
|
+
end
|
74
|
+
|
75
|
+
rescue Exception => exception
|
76
|
+
::Trouble.notify exception
|
77
|
+
Operations.failure :backend_error, object: exception
|
78
|
+
end
|
79
|
+
|
80
|
+
def destroy(id)
|
81
|
+
unless record = backend.find_by_id(id)
|
82
|
+
return Operations.success(:nothing_to_destroy)
|
83
|
+
end
|
84
|
+
|
85
|
+
if record.destroy
|
86
|
+
Operations.success :record_destroyed, object: record_to_entity(record)
|
87
|
+
else
|
88
|
+
Operations.failure :destruction_failed
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue Exception => exception
|
92
|
+
::Trouble.notify exception
|
93
|
+
Operations.failure :backend_error, object: exception
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'perimeter-activerecord'
|
6
|
+
spec.version = '0.0.1'
|
7
|
+
spec.authors = %w{ Bukowskis }
|
8
|
+
spec.description = %q{Repository/Entity pattern conventions. This is an adapter for ActiveRecord.}
|
9
|
+
spec.summary = %q{Repository/Entity pattern conventions. This is an adapter for ActiveRecord.}
|
10
|
+
spec.homepage = 'https://github.com/bukowskis/perimeter-activerecord'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/) - ['.travis.yml']
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = %w{ lib }
|
17
|
+
|
18
|
+
spec.add_dependency 'perimeter', '~> 0.0.1'
|
19
|
+
|
20
|
+
spec.add_development_dependency 'activerecord'
|
21
|
+
spec.add_development_dependency 'guard-rspec'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'sqlite3'
|
24
|
+
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'perimeter/repository/adapters/active_record'
|
3
|
+
require 'my/games'
|
4
|
+
|
5
|
+
describe Perimeter::Repository::Adapters::ActiveRecord do
|
6
|
+
|
7
|
+
let(:repository) { My::Games }
|
8
|
+
let(:frontend) { My::Game }
|
9
|
+
let(:backend) { My::Games::Backend }
|
10
|
+
|
11
|
+
describe '.find' do
|
12
|
+
let(:finding) { repository.find 1 }
|
13
|
+
|
14
|
+
context 'the record exists' do
|
15
|
+
before do
|
16
|
+
backend.create! name: 'Star Wars', genre: 'Classic'
|
17
|
+
expect( Trouble ).to_not receive :notify
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'is an Operation' do
|
21
|
+
expect( finding ).to be_instance_of Operation
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'succeeds' do
|
25
|
+
expect( finding ).to be_success
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has an informative code' do
|
29
|
+
expect( finding.code ).to eq :record_found
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'holds the Entity' do
|
33
|
+
expect( finding.object ).to be_instance_of frontend
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'has all attributes on the Entity' do
|
37
|
+
expect( finding.object.attributes ).to eq id: 1, name: 'Star Wars', genre: 'Classic', director: 'Gene Roddenberry'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'the record does not exist' do
|
42
|
+
before do
|
43
|
+
expect( Trouble ).to_not receive :notify
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'is an Operation' do
|
47
|
+
expect( finding ).to be_instance_of Operation
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'fails' do
|
51
|
+
expect( finding ).to be_failure
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has an informative code' do
|
55
|
+
expect( finding.code ).to eq :record_not_found
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'holds the exception' do
|
59
|
+
expect( finding.object ).to be_instance_of ::ActiveRecord::RecordNotFound
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'the repository had problems' do
|
64
|
+
before do
|
65
|
+
allow( repository::Backend ).to receive(:find).and_raise NoMemoryError
|
66
|
+
expect( Trouble ).to receive(:notify)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'is an Operation' do
|
70
|
+
expect( finding ).to be_instance_of Operation
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'fails' do
|
74
|
+
expect( finding ).to be_failure
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has an informative code' do
|
78
|
+
expect( finding.code ).to eq :backend_error
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'holds the exception' do
|
82
|
+
expect( finding.object ).to be_instance_of NoMemoryError
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.find!' do
|
88
|
+
let(:finding) { repository.find! 1 }
|
89
|
+
|
90
|
+
context 'the record exists' do
|
91
|
+
before do
|
92
|
+
backend.create! name: 'Casablanca', genre: 'Retro'
|
93
|
+
expect( Trouble ).to_not receive :notify
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'is an Entity' do
|
97
|
+
expect( finding ).to be_instance_of frontend
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'has all attributes on the Entity' do
|
101
|
+
expect( finding.attributes ).to eq id: 1, name: 'Casablanca', genre: 'Retro', director: 'Gene Roddenberry'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'the record does not exist' do
|
106
|
+
before do
|
107
|
+
expect( Trouble ).to_not receive :notify
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'raises an Exception' do
|
111
|
+
expect { finding }.to raise_error Perimeter::Repository::FindingError
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'the repository had problems' do
|
116
|
+
before do
|
117
|
+
allow( repository::Backend ).to receive(:find).and_raise IOError
|
118
|
+
expect( Trouble ).to receive(:notify)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'raises an Exception' do
|
122
|
+
expect { finding }.to raise_error Perimeter::Repository::FindingError
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '.create' do
|
128
|
+
|
129
|
+
context 'the Record is invalid' do
|
130
|
+
let(:creation) { repository.create name: 'Star Trek' }
|
131
|
+
|
132
|
+
before do
|
133
|
+
expect( Trouble ).to_not receive :notify
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'is an Operation' do
|
137
|
+
expect( creation ).to be_instance_of Operation
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'fails' do
|
141
|
+
expect( creation ).to be_failure
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'has an informative code' do
|
145
|
+
expect( creation.code ).to eq :validation_failed
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'knows the validation that failed on the Entity' do
|
149
|
+
expect( creation.object.errors.count ).to eq 1
|
150
|
+
expect( creation.object.errors[:genre] ).to be_present
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'has all attributes on the Entity' do
|
154
|
+
expect( creation.object.attributes ).to eq id: nil, name: 'Star Trek', genre: nil, director: 'Gene Roddenberry'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'record already exists' do
|
159
|
+
let(:creation) { repository.create id: 1, name: 'The Matrix Reloaded', genre: 'Documentary' }
|
160
|
+
|
161
|
+
before do
|
162
|
+
backend.create! name: 'The Matrix', genre: 'Documentary'
|
163
|
+
expect( Trouble ).to_not receive :notify
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'is an Operation' do
|
167
|
+
expect( creation ).to be_instance_of Operation
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'fails' do
|
171
|
+
expect( creation ).to be_failure
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'has an informative code' do
|
175
|
+
expect( creation.code ).to eq :record_already_exists
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'persistence fails' do
|
180
|
+
let(:creation) { repository.create id: 55, genre: 'Film Noir' }
|
181
|
+
|
182
|
+
before do
|
183
|
+
allow( backend ).to receive(:find_by_id) do
|
184
|
+
# This is a suitable place to hook in something that will cause the Record#save operation to fail...
|
185
|
+
ActiveRecord::Migration.drop_table :games
|
186
|
+
nil
|
187
|
+
end
|
188
|
+
expect( Trouble ).to receive :notify
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'is an Operation' do
|
192
|
+
expect( creation ).to be_instance_of Operation
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'fails' do
|
196
|
+
expect( creation ).to be_failure
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'has an informative code' do
|
200
|
+
expect( creation.code ).to eq :backend_error
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'persistence succeeds' do
|
205
|
+
let(:creation) { repository.create genre: 'Slapstick' }
|
206
|
+
|
207
|
+
before do
|
208
|
+
expect( Trouble ).to_not receive :notify
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'is an Operation' do
|
212
|
+
expect( creation ).to be_instance_of Operation
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'succeeds' do
|
216
|
+
expect( creation ).to be_success
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'has an informative code' do
|
220
|
+
expect( creation.code ).to eq :record_created
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'holds the Entity' do
|
224
|
+
expect( creation.object ).to be_instance_of frontend
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'has all attributes on the Entity' do
|
228
|
+
expect( creation.object.attributes ).to eq id: 1, name: nil, genre: 'Slapstick', director: 'Gene Roddenberry'
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '.update' do
|
235
|
+
context 'record does not exist' do
|
236
|
+
let(:updating) { repository.update 1, {} }
|
237
|
+
|
238
|
+
before do
|
239
|
+
expect( Trouble ).to_not receive :notify
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'is an Operation' do
|
243
|
+
expect( updating ).to be_instance_of Operation
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'fails' do
|
247
|
+
expect( updating ).to be_failure
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'has an informative code' do
|
251
|
+
expect( updating.code ).to eq :record_not_found
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'the Record is invalid' do
|
256
|
+
let(:updating) { repository.update 1, name: 'Pac Man', genre: ' ' }
|
257
|
+
|
258
|
+
before do
|
259
|
+
backend.create! genre: 'RPG'
|
260
|
+
expect( Trouble ).to_not receive :notify
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'is an Operation' do
|
264
|
+
expect( updating ).to be_instance_of Operation
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'fails' do
|
268
|
+
expect( updating ).to be_failure
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'has an informative code' do
|
272
|
+
expect( updating.code ).to eq :validation_failed
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'knows the validation that failed on the Entity' do
|
276
|
+
expect( updating.object.errors.count ).to eq 1
|
277
|
+
expect( updating.object.errors[:genre] ).to be_present
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'has all attributes on the Entity' do
|
281
|
+
expect( updating.object.attributes ).to eq id: 1, name: 'Pac Man', genre: ' ', director: 'Gene Roddenberry'
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context 'persistence fails' do
|
286
|
+
let(:updating) { repository.update 1, name: 'Atomic Bomberman' }
|
287
|
+
|
288
|
+
before do
|
289
|
+
backend.create! genre: 'RTS'
|
290
|
+
allow( backend ).to receive(:find_by_id) do |id|
|
291
|
+
# This is a suitable place to hook in something that will cause the Record#save operation to fail...
|
292
|
+
record = backend.find id
|
293
|
+
ActiveRecord::Migration.drop_table :games
|
294
|
+
record
|
295
|
+
end
|
296
|
+
expect( Trouble ).to receive :notify
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'is an Operation' do
|
300
|
+
expect( updating ).to be_instance_of Operation
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'fails' do
|
304
|
+
expect( updating ).to be_failure
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'has an informative code' do
|
308
|
+
expect( updating.code ).to eq :backend_error
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context 'persistence succeeds' do
|
313
|
+
let(:updating) { repository.update 1, name: 'Alice and Bob' }
|
314
|
+
|
315
|
+
before do
|
316
|
+
backend.create! genre: 'Romance'
|
317
|
+
expect( Trouble ).to_not receive :notify
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'is an Operation' do
|
321
|
+
expect( updating ).to be_instance_of Operation
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'succeeds' do
|
325
|
+
expect( updating ).to be_success
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'has an informative code' do
|
329
|
+
expect( updating.code ).to eq :record_updated
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'holds the Entity' do
|
333
|
+
expect( updating.object ).to be_instance_of frontend
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'has all attributes on the Entity' do
|
337
|
+
expect( updating.object.attributes ).to eq id: 1, name: 'Alice and Bob', genre: 'Romance', director: 'Gene Roddenberry'
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../support/models', __FILE__)
|
2
|
+
|
3
|
+
require 'perimeter-activerecord'
|
4
|
+
|
5
|
+
require 'sqlite3'
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
|
10
|
+
config.before(:each) do
|
11
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define do
|
14
|
+
create_table :games do |table|
|
15
|
+
table.column :genre, :string
|
16
|
+
table.column :name, :string
|
17
|
+
table.column :director, :string
|
18
|
+
table.column :year, :integer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'perimeter/backend/adapters/active_record'
|
2
|
+
|
3
|
+
module My
|
4
|
+
module Games
|
5
|
+
class Backend < ActiveRecord::Base
|
6
|
+
|
7
|
+
include Perimeter::Backend::Adapters::ActiveRecord
|
8
|
+
|
9
|
+
validates :genre, presence: true
|
10
|
+
|
11
|
+
before_validation :set_director
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_director
|
16
|
+
self.director = 'Gene Roddenberry'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: perimeter-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bukowskis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: perimeter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Repository/Entity pattern conventions. This is an adapter for ActiveRecord.
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- Gemfile
|
92
|
+
- Guardfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- lib/perimeter-activerecord.rb
|
96
|
+
- lib/perimeter/backend/adapters/active_record.rb
|
97
|
+
- lib/perimeter/repository/adapters/active_record.rb
|
98
|
+
- perimeter-activerecord.gemspec
|
99
|
+
- spec/lib/perimeter/repository/adapters/active_record_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/support/models/my/game.rb
|
102
|
+
- spec/support/models/my/games.rb
|
103
|
+
- spec/support/models/my/games/backend.rb
|
104
|
+
homepage: https://github.com/bukowskis/perimeter-activerecord
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Repository/Entity pattern conventions. This is an adapter for ActiveRecord.
|
128
|
+
test_files:
|
129
|
+
- spec/lib/perimeter/repository/adapters/active_record_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/models/my/game.rb
|
132
|
+
- spec/support/models/my/games.rb
|
133
|
+
- spec/support/models/my/games/backend.rb
|