File tree Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -18,22 +18,24 @@ class Doc < ActiveRecord::Base
18
18
# * nil if none found
19
19
#
20
20
def self . retrieve id , options = { }
21
- validate_options ( options , [ :rev ] )
22
- case id
23
- when Symbol
24
- if id == :all
25
- docs = self . find ( id )
21
+ with_scope ( :find => { :conditions => { :archived_at => nil } } ) do
22
+ validate_options ( options , [ :rev ] )
23
+ case id
24
+ when Symbol
25
+ if id == :all
26
+ docs = self . find ( id )
27
+ else
28
+ docs = [ self . find ( id ) ]
29
+ end
26
30
else
27
- docs = [ self . find ( id ) ]
31
+ docs = self . find_all_by_id ( id )
28
32
end
29
- else
30
- docs = self . find_all_by_id ( id )
31
- end
32
- unless docs . empty?
33
- res = ( id . is_a? ( Array ) or id == :all ) ? docs . map { |doc | doc . retrieve } : docs . first . retrieve ( options [ :rev ] ||0 )
34
- # a = docs.map {|doc| doc.retrieve} #: docs.first.retrieve(options[:rev]||0)
33
+ unless docs . empty?
34
+ res = ( id . is_a? ( Array ) or id == :all ) ? docs . map { |doc | doc . retrieve } : docs . first . retrieve ( options [ :rev ] ||0 )
35
+ # a = docs.map {|doc| doc.retrieve} #: docs.first.retrieve(options[:rev]||0)
36
+ end
37
+ return res
35
38
end
36
- return res
37
39
end
38
40
39
41
# Stores or updates a document into the database
@@ -130,6 +132,7 @@ def self.remove id, options=nil
130
132
131
133
def remove # :nodoc:
132
134
stores . update_all ( { :rev => rev } , { :rev => 0 } )
135
+ update_attribute ( :archived_at , Time . now )
133
136
end
134
137
135
138
def retrieve ( revision = 0 ) # :nodoc:
Original file line number Diff line number Diff line change
1
+ class AddArchivedAtToDoc < ActiveRecord ::Migration
2
+ def self . up
3
+ add_column :docs , :archived_at , :datetime
4
+ end
5
+
6
+ def self . down
7
+ remove_column :docs , :archived_at
8
+ end
9
+ end
Original file line number Diff line number Diff line change 9
9
#
10
10
# It's strongly recommended to check this file into your version control system.
11
11
12
- ActiveRecord ::Schema . define ( :version => 20081115093653 ) do
12
+ ActiveRecord ::Schema . define ( :version => 20081122110526 ) do
13
13
14
14
create_table "docs" , :force => true do |t |
15
15
t . integer "rev"
16
16
t . datetime "created_at"
17
17
t . datetime "updated_at"
18
+ t . datetime "archived_at"
18
19
end
19
20
20
21
create_table "fields" , :force => true do |t |
Original file line number Diff line number Diff line change @@ -52,6 +52,13 @@ def test_retrieve_when_id_does_not_exist
52
52
assert_nil Doc . retrieve ( [ id , id +1 ] )
53
53
end
54
54
55
+ def test_retrieve_when_id_is_archived
56
+ id = Doc . last . id
57
+ Doc . remove id
58
+
59
+ assert_nil Doc . retrieve ( id )
60
+ end
61
+
55
62
56
63
# Update
57
64
def test_update
@@ -236,6 +243,7 @@ def test_remove
236
243
assert_equal [ doc . id ] , ret
237
244
doc . stores . each { |item | assert item . rev != 0 }
238
245
assert_equal store_1 . rev , Store . find ( store_1 . id ) . rev
246
+ assert ( !doc . reload . archived_at . nil? )
239
247
end
240
248
end
241
249
You can’t perform that action at this time.
0 commit comments