Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (65 sloc) 2.275 kb
9f2c954 @winton The great rewrite has begun (Rails 3 coming soon!)
authored
1 require 'spec_helper'
2
3 describe ActsAsArchive do
7622898 @winton Specs mostly complete, ready to start testing frameworks
authored
4
5 before(:each) do
079d585 @winton Automatically generating associations that have a dependent option for A...
authored
6 [ 8, 0, 8 ].each { |v| $db.migrate(v) }
7622898 @winton Specs mostly complete, ready to start testing frameworks
authored
7
8 @record = Record.create :belongs_to_id => BelongsTo.create.id
9
10 HasOne.create :record_id => @record.id
11
12 HasMany.create :record_id => @record.id
13 HasMany.create :record_id => @record.id
14
15 Record.first.has_many_throughs.create
16 Record.first.has_many_throughs.create
17
18 Record.first.create_has_one_through_through.create_has_one_through
19
20 @lengths = {
21 :record => 1,
22 :belongs_to => 1,
23 :has_one => 1,
24 :has_many => 2,
25 :has_many_through => 2,
26 :has_many_through_through => 2,
27 :has_one_through => 1,
28 :has_one_through_through => 1
29 }
30
31 @zero_lengths = @lengths.inject({}) do |hash, (key, value)|
32 hash[key] = 0
33 hash
34 end
9f2c954 @winton The great rewrite has begun (Rails 3 coming soon!)
authored
35 end
7622898 @winton Specs mostly complete, ready to start testing frameworks
authored
36
37 it "should create records" do
38 original, archive = all_records
39 verify_lengths original, @lengths
40 verify_attributes original
41 end
42
43 %w(delete delete_all destroy destroy_all).each do |type|
44 describe type do
45 it "should move records to archive tables" do
46 case type
47 when 'delete', 'destroy'
48 @record.send type
49 when 'delete_all', 'destroy_all'
50 Record.send type
51 end
52
53 original, archive = all_records
54
55 case type
56 when 'delete', 'delete_all'
57 archive[:record].length.should == 1
58 original[:record].length.should == 0
59
60 verify_lengths archive, @zero_lengths, :exclude => [ :record ]
61 verify_lengths original, @lengths, :exclude => [ :record ]
62
63 verify_attributes archive, :only => [ :record ]
64
65 when 'destroy', 'destroy_all'
66 verify_lengths archive, @lengths
67 verify_lengths original, @zero_lengths
68
69 verify_attributes archive
70 end
71 end
72
73 it "should move records back to original tables" do
74 @record.destroy
75 Record::Archive.first.destroy
76
77 original, archive = all_records
78
79 verify_lengths original, @lengths
80 verify_lengths archive, @zero_lengths
81
82 verify_attributes original
83 end
84 end
85 end
86 end
Something went wrong with that request. Please try again.