archive_2s 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Archive2s
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/archive_2s.rb CHANGED
@@ -27,23 +27,7 @@ module Archive2s
27
27
  if self.archive_2s_args[:include_by_default]
28
28
  singleton.module_eval do
29
29
  def find(*args)
30
- begin
31
- #might as well try AR first
32
- super.find(*args)
33
- rescue Exception => e
34
- #can only fetch archived by ids so don't attempt if there were extra args
35
- if args.flatten! && args.length != args.select{|i| i == i.to_i}.length
36
- raise e
37
- else
38
- items = self.all(:conditions => ["id IN (#{(['?'] * args.length).join(',')})", *args])
39
- items += [self.find_archived(*args - items.collect(&:id))].flatten
40
- if args.length == items.length
41
- items
42
- else
43
- raise e
44
- end
45
- end
46
- end
30
+ self.find_with_archived(*args)
47
31
  end
48
32
  end
49
33
  end
@@ -88,6 +72,26 @@ module Archive2s
88
72
  archived_models.first
89
73
  end
90
74
  end
75
+
76
+ def find_with_archived(*args)
77
+ begin
78
+ #might as well try AR first
79
+ super.find(*args)
80
+ rescue Exception => e
81
+ #can only fetch archived by ids so don't attempt if there were extra args
82
+ if args.flatten! && args.length != args.select{|i| i == i.to_i}.length
83
+ raise e
84
+ else
85
+ items = self.all(:conditions => ["id IN (#{(['?'] * args.length).join(',')})", *args])
86
+ items += [self.find_archived(*args - items.collect(&:id))].flatten
87
+ if args.length == items.length
88
+ items
89
+ else
90
+ raise e
91
+ end
92
+ end
93
+ end
94
+ end
91
95
  end
92
96
  end
93
97
 
@@ -71,6 +71,17 @@ describe Archive2s do
71
71
  end
72
72
  end
73
73
 
74
+ it "find_with_archived should return archived items too" do
75
+ item_one = Item.create(:name => 'Item One', :description => 'foo')
76
+ item_two = Item.create(:name => 'Item Two', :description => 'bar')
77
+ ids = [item_one.id, item_two.id]
78
+ item_two.destroy
79
+ items = Item.find_with_archived(ids)
80
+
81
+ items.length.should == 2
82
+ items.collect(&:id).include?(ids.last).should be_true
83
+ end
84
+
74
85
  it "should archive the default to_s" do
75
86
  thing_one = Thing.create(:name => 'Thing One', :description => 'foo')
76
87
  t_to_s = thing_one.to_s
@@ -94,6 +105,10 @@ describe Archive2s do
94
105
  archived_thing.readonly?.should be_true
95
106
  end
96
107
 
108
+ it "should not error when no params are passed in" do
109
+ lambda{class Foo < ActiveRecord::Base;archive_2s;end}.should_not raise_error
110
+ end
111
+
97
112
  #reload should do nothing, not sure how to test that though
98
113
 
99
114
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archive_2s
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - SmashTank Apps, LLC