unidata 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -1
- data/lib/unidata/connection.rb +6 -0
- data/lib/unidata/model.rb +8 -0
- data/lib/unidata/version.rb +1 -1
- data/spec/unidata/connection_spec.rb +24 -0
- data/spec/unidata/model_spec.rb +31 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -90,6 +90,19 @@ Or, you can just check if a record exists:
|
|
90
90
|
Product.exists?(12345)
|
91
91
|
```
|
92
92
|
|
93
|
+
### Deleting records:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
product = Product.find(12345)
|
97
|
+
product.destroy
|
98
|
+
```
|
99
|
+
|
100
|
+
Or, you can delete without retrieving first:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Product.delete(12345)
|
104
|
+
```
|
105
|
+
|
93
106
|
Contributing
|
94
107
|
------------
|
95
108
|
|
@@ -121,4 +134,4 @@ Please use GitHub's [issue tracker](http://github.com/jisraelsen/unidata/issues)
|
|
121
134
|
Author
|
122
135
|
------
|
123
136
|
|
124
|
-
[Jeremy Israelsen](http://github.com/jisraelsen)
|
137
|
+
[Jeremy Israelsen](http://github.com/jisraelsen)
|
data/lib/unidata/connection.rb
CHANGED
data/lib/unidata/model.rb
CHANGED
@@ -82,6 +82,10 @@ module Unidata
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
def delete(id)
|
86
|
+
connection.delete_record(filename, id)
|
87
|
+
end
|
88
|
+
|
85
89
|
private
|
86
90
|
def define_attribute_accessor(attribute_name)
|
87
91
|
class_eval <<-end_eval
|
@@ -118,6 +122,10 @@ module Unidata
|
|
118
122
|
self.class.connection.write(self.class.filename, id, record)
|
119
123
|
end
|
120
124
|
|
125
|
+
def destroy
|
126
|
+
self.class.connection.delete_record(self.class.filename, id)
|
127
|
+
end
|
128
|
+
|
121
129
|
private
|
122
130
|
def initialize_attributes
|
123
131
|
@attributes = {}
|
data/lib/unidata/version.rb
CHANGED
@@ -273,4 +273,28 @@ describe Unidata::Connection do
|
|
273
273
|
connection.write_field('TEST', 123, 'value', 5)
|
274
274
|
end
|
275
275
|
end
|
276
|
+
|
277
|
+
describe '#delete_record' do
|
278
|
+
before(:each) do
|
279
|
+
@file = double('UniFile', :close => nil, :delete_record => nil)
|
280
|
+
@session.stub(:open).and_return(@file)
|
281
|
+
|
282
|
+
connection.open
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'opens file with filename' do
|
286
|
+
@session.should_receive(:open).with('TEST')
|
287
|
+
connection.delete_record('TEST', 123)
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'deletes record from file' do
|
291
|
+
@file.should_receive(:delete_record).with(123)
|
292
|
+
connection.delete_record('TEST', 123)
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'closes file' do
|
296
|
+
@file.should_receive(:close)
|
297
|
+
connection.delete_record('TEST', 123)
|
298
|
+
end
|
299
|
+
end
|
276
300
|
end
|
data/spec/unidata/model_spec.rb
CHANGED
@@ -230,6 +230,16 @@ describe Unidata::Model do
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
+
describe '.delete' do
|
234
|
+
it 'deletes record from file' do
|
235
|
+
connection = double('connection', :delete_record => nil)
|
236
|
+
Unidata.stub(:connection).and_return(connection)
|
237
|
+
|
238
|
+
connection.should_receive(:delete_record).with('TEST', '1234')
|
239
|
+
Record.delete('1234')
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
233
243
|
describe '#initialize' do
|
234
244
|
it 'captures provied attributes' do
|
235
245
|
instance = Record.new(:id => '123', :name => 'John Doe', :status => 'inactive')
|
@@ -289,5 +299,26 @@ describe Unidata::Model do
|
|
289
299
|
obj.save
|
290
300
|
end
|
291
301
|
end
|
302
|
+
|
303
|
+
describe '#destroy' do
|
304
|
+
it 'deletes record from file' do
|
305
|
+
connection = double('connection', :delete_record => nil)
|
306
|
+
Unidata.stub(:connection).and_return(connection)
|
307
|
+
|
308
|
+
obj = Record.new(
|
309
|
+
:id => '1234',
|
310
|
+
:name => 'John Doe',
|
311
|
+
:age => 25,
|
312
|
+
:birth_date => Date.today,
|
313
|
+
:employer => 'Awesome Company',
|
314
|
+
:job_title => 'Manager',
|
315
|
+
:salary => BigDecimal.new('60_000.00'),
|
316
|
+
:status => 'inactive'
|
317
|
+
)
|
318
|
+
|
319
|
+
connection.should_receive(:delete_record).with('TEST', '1234')
|
320
|
+
obj.destroy
|
321
|
+
end
|
322
|
+
end
|
292
323
|
end
|
293
324
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: unidata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremy Israelsen
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|