mordor 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -114,6 +114,16 @@ module Mordor
114
114
  to_hash.merge(:_id => _id).to_json(*args)
115
115
  end
116
116
 
117
+ def destroyed?
118
+ @destroyed ||= false
119
+ end
120
+
121
+ def destroy
122
+ collection.remove({:_id => _id})
123
+ self.class.ensure_indices
124
+ @destroyed = true
125
+ end
126
+
117
127
  module ClassMethods
118
128
  def create(attributes = {})
119
129
  resource = self.new(attributes)
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
2
2
  s.name = "mordor"
3
3
 
4
4
  # Do not set the version and date field manually, this is done by the release script
5
- s.version = "0.2.10"
6
- s.date = "2012-01-19"
5
+ s.version = "0.2.11"
6
+ s.date = "2012-01-20"
7
7
 
8
8
  s.summary = "mordor"
9
9
  s.description = <<-eos
@@ -243,6 +243,13 @@ describe "with respect to resources" do
243
243
  TestResource.ensure_count.should == 2 # For each index
244
244
  end
245
245
 
246
+ it "should call ensure_index on the collection whenever a resource is destroyed" do
247
+ resource = TestResource.create({:first => 'first', :second => 'second', :third => 'third'})
248
+ TestResource.reset_ensure_count
249
+ resource.destroy
250
+ TestResource.ensure_count.should == 2 # For each index
251
+ end
252
+
246
253
  it "should call ensure index for each index attribute on creation" do
247
254
  TestResource2.class_eval do
248
255
  attribute :test_attribute, :index => true
@@ -272,6 +279,35 @@ describe "with respect to resources" do
272
279
  end
273
280
  end
274
281
 
282
+ context "with respect to destroying" do
283
+ before :each do
284
+ clean_sheet
285
+ @resource = TestResource.create({:first => "first", :second => "second", :third => "third"})
286
+ end
287
+
288
+ it "should not create destroyed resources" do
289
+ @resource.should_not be_destroyed
290
+ end
291
+
292
+ it "should be possible to destroy a resource" do
293
+ @resource.should_not be_destroyed
294
+ @resource.destroy
295
+ @resource.should be_destroyed
296
+ end
297
+
298
+ it "should not be possible to retrieve a resource after it has been destroyed" do
299
+ @resource.destroy
300
+ res = TestResource.get(@resource._id)
301
+ res.should be_nil
302
+ end
303
+
304
+ it "should only destroy the current resource" do
305
+ resource2 = TestResource.create({:first => "first2", :second => "second2", :third => "third2"})
306
+ @resource.destroy
307
+ TestResource.get(resource2._id).should_not be_nil
308
+ end
309
+ end
310
+
275
311
  context "with respect to saving and retrieving" do
276
312
  before :each do
277
313
  clean_sheet
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mordor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 10
10
- version: 0.2.10
9
+ - 11
10
+ version: 0.2.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan-Willem Koelewijn
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-01-19 00:00:00 +01:00
19
+ date: 2012-01-20 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency