acts_as_archival 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +22 -0
- data/README.md +112 -0
- data/Rakefile +13 -0
- data/acts_as_archival.gemspec +47 -0
- data/init.rb +3 -0
- data/lib/acts_as_archival.rb +7 -0
- data/lib/acts_as_archival/version.rb +3 -0
- data/lib/expected_behavior/acts_as_archival.rb +141 -0
- data/lib/expected_behavior/acts_as_archival_active_record_methods.rb +20 -0
- data/test/ambiguous_table_test.rb +12 -0
- data/test/associations_test.rb +102 -0
- data/test/basic_test.rb +64 -0
- data/test/column_test.rb +15 -0
- data/test/database.yml +8 -0
- data/test/deep_nesting_test.rb +29 -0
- data/test/fixtures/archival.rb +15 -0
- data/test/fixtures/archival_grandkid.rb +4 -0
- data/test/fixtures/archival_kid.rb +5 -0
- data/test/fixtures/exploder.rb +5 -0
- data/test/fixtures/independent_archival.rb +9 -0
- data/test/fixtures/mass_attribute_protected.rb +4 -0
- data/test/fixtures/missing_archive_number.rb +3 -0
- data/test/fixtures/missing_archived_at.rb +3 -0
- data/test/fixtures/plain.rb +5 -0
- data/test/fixtures/poly.rb +9 -0
- data/test/fixtures/readonly_when_archived.rb +3 -0
- data/test/mass_attribute_test.rb +18 -0
- data/test/polymorphic_test.rb +25 -0
- data/test/readonly_when_archived_test.rb +22 -0
- data/test/responds_test.rb +13 -0
- data/test/schema.rb +67 -0
- data/test/scope_test.rb +50 -0
- data/test/script/db_setup +57 -0
- data/test/test_helper.rb +60 -0
- data/test/through_association_test.rb +25 -0
- data/test/transaction_test.rb +32 -0
- metadata +235 -0
data/test/scope_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ActsAsArchivalTest < ActiveSupport::TestCase
|
4
|
+
test "simple unarchived scope" do
|
5
|
+
Archival.create!
|
6
|
+
Archival.create!
|
7
|
+
|
8
|
+
assert_equal 2, Archival.unarchived.count
|
9
|
+
end
|
10
|
+
|
11
|
+
test "simple archived scope" do
|
12
|
+
Archival.create!.archive
|
13
|
+
Archival.create!.archive
|
14
|
+
|
15
|
+
assert_equal 2, Archival.archived.count
|
16
|
+
end
|
17
|
+
|
18
|
+
test "mixed scopes" do
|
19
|
+
Archival.create!
|
20
|
+
Archival.create!.archive
|
21
|
+
|
22
|
+
assert_equal 1, Archival.archived.count
|
23
|
+
assert_equal 1, Archival.unarchived.count
|
24
|
+
end
|
25
|
+
|
26
|
+
test "simple archived_from_archive_number" do
|
27
|
+
archive_number = "TEST-IT"
|
28
|
+
Archival.create!.archive(archive_number)
|
29
|
+
Archival.create!.archive(archive_number)
|
30
|
+
|
31
|
+
assert_equal 2, Archival.archived_from_archive_number(archive_number).count
|
32
|
+
end
|
33
|
+
|
34
|
+
test "negative archived_from_archive_number" do
|
35
|
+
archive_number = "TEST-IT"
|
36
|
+
bogus_number = "BROKE-IT"
|
37
|
+
Archival.create!.archive(archive_number)
|
38
|
+
Archival.create!.archive(archive_number)
|
39
|
+
|
40
|
+
assert_equal 0, Archival.archived_from_archive_number(bogus_number).count
|
41
|
+
end
|
42
|
+
|
43
|
+
test "mixed archived_from_archive_number" do
|
44
|
+
archive_number = "TEST-IT"
|
45
|
+
Archival.create!.archive(archive_number)
|
46
|
+
Archival.create!.archive
|
47
|
+
|
48
|
+
assert_equal 1, Archival.archived_from_archive_number(archive_number).count
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "yaml"
|
4
|
+
require 'highline/import'
|
5
|
+
|
6
|
+
def read_database_config
|
7
|
+
database_file = File.join(File.dirname(__FILE__), "/../", "database.yml")
|
8
|
+
$DB_CONFIG = YAML.load(File.read(database_file))
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_root_password
|
12
|
+
$ROOT_PW = ask("Provide root mySQL password to setup '#{$DB_CONFIG["database"]}': ") { |q| q.echo = false}
|
13
|
+
if !$ROOT_PW || $ROOT_PW.empty?
|
14
|
+
puts "error reading password"
|
15
|
+
exit 4
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_root_password
|
20
|
+
password_check = "echo 'show databases;' | mysql -u root -p'#{$ROOT_PW}' > /dev/null"
|
21
|
+
unless system password_check
|
22
|
+
puts "incorrect password"
|
23
|
+
exit 7
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute_mysql(message, statement, user = nil, password = nil)
|
28
|
+
puts message
|
29
|
+
`echo '#{statement}' | mysql -u #{user} -p'#{password}'`
|
30
|
+
end
|
31
|
+
|
32
|
+
def drop_existing(db, user, pass)
|
33
|
+
drop_statement = "drop database if exists #{db};"
|
34
|
+
execute_mysql("dropping #{db}", drop_statement, user, pass)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_db(db, user, pass)
|
38
|
+
create_statement = "create database #{db};"
|
39
|
+
execute_mysql("creating #{db}", create_statement, user, pass)
|
40
|
+
end
|
41
|
+
|
42
|
+
def grant_permission_on_db(db, user, pass)
|
43
|
+
grant_statement = "grant all on `#{db}`.* to `#{$DB_CONFIG["username"]}`@`localhost` identified by \"#{$DB_CONFIG["password"]}\";"
|
44
|
+
execute_mysql("granting on #{db}", grant_statement, user, pass)
|
45
|
+
end
|
46
|
+
|
47
|
+
read_database_config
|
48
|
+
get_root_password
|
49
|
+
check_root_password
|
50
|
+
|
51
|
+
db = $DB_CONFIG["database"]
|
52
|
+
user = "root"
|
53
|
+
pass = $ROOT_PW
|
54
|
+
|
55
|
+
drop_existing(db, user, pass)
|
56
|
+
create_db(db, user, pass)
|
57
|
+
grant_permission_on_db(db, user, pass)
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
require "bundler/setup"
|
3
|
+
require "test/unit"
|
4
|
+
require "active_record"
|
5
|
+
require "assertions"
|
6
|
+
require "database_cleaner"
|
7
|
+
require "acts_as_archival"
|
8
|
+
|
9
|
+
def prepare_for_tests
|
10
|
+
setup_logging if ENV["LOGGING_ENABLED"]
|
11
|
+
setup_active_record
|
12
|
+
setup_database_cleaner
|
13
|
+
create_test_tables
|
14
|
+
require_test_classes
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_logging
|
18
|
+
require "logger"
|
19
|
+
logfile = File.dirname(__FILE__) + "/debug.log"
|
20
|
+
ActiveRecord::Base.logger = Logger.new(logfile)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_active_record
|
24
|
+
dbconfig_file = File.dirname(__FILE__) + "/database.yml"
|
25
|
+
dbconfig = YAML.load File.read(dbconfig_file)
|
26
|
+
ActiveRecord::Base.establish_connection(dbconfig)
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_database_cleaner
|
30
|
+
DatabaseCleaner.strategy = :truncation
|
31
|
+
ActiveSupport::TestCase.send(:setup) do
|
32
|
+
DatabaseCleaner.clean
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_test_tables
|
37
|
+
schema_file = File.dirname(__FILE__) + "/schema.rb"
|
38
|
+
load(schema_file) if File.exist?(schema_file)
|
39
|
+
end
|
40
|
+
|
41
|
+
def require_test_classes
|
42
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
43
|
+
inflect.irregular "poly", "polys"
|
44
|
+
end
|
45
|
+
|
46
|
+
[:archival,
|
47
|
+
:archival_kid,
|
48
|
+
:archival_grandkid,
|
49
|
+
:independent_archival,
|
50
|
+
:exploder,
|
51
|
+
:plain,
|
52
|
+
:mass_attribute_protected,
|
53
|
+
:readonly_when_archived,
|
54
|
+
:missing_archived_at,
|
55
|
+
:missing_archive_number,
|
56
|
+
:poly
|
57
|
+
].each {|test_class_file| require_relative "fixtures/#{test_class_file}"}
|
58
|
+
end
|
59
|
+
|
60
|
+
prepare_for_tests
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ThroughAssociationTest < ActiveSupport::TestCase
|
4
|
+
test "archive a through associated object whose 'bridge' is archival" do
|
5
|
+
archival = Archival.create!
|
6
|
+
bridge = archival.archival_kids.create!
|
7
|
+
through = bridge.archival_grandkids.create!
|
8
|
+
archival.archive
|
9
|
+
|
10
|
+
assert archival.reload.archived?
|
11
|
+
assert bridge.reload.archived?
|
12
|
+
assert through.reload.archived?
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO Make something like this pass
|
16
|
+
# test "archive a through associated object whose 'bridge' is not archival" do
|
17
|
+
# archival = Archival.create!
|
18
|
+
# bridge = archival.independent_archival_kids.create!
|
19
|
+
# through = bridge.archival_grandkids.create!
|
20
|
+
# archival.archive
|
21
|
+
|
22
|
+
# assert archival.reload.archived?
|
23
|
+
# assert through.reload.archived?
|
24
|
+
# end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "rr"
|
3
|
+
|
4
|
+
class TransactionTest < ActiveSupport::TestCase
|
5
|
+
include RR::Adapters::TestUnit
|
6
|
+
|
7
|
+
test "archiving is transactional" do
|
8
|
+
archival = Archival.create!
|
9
|
+
exploder = archival.exploders.create!
|
10
|
+
any_instance_of(Exploder) do |exploder|
|
11
|
+
stub(exploder).archive { raise "Rollback Imminent" }
|
12
|
+
end
|
13
|
+
archival.archive
|
14
|
+
|
15
|
+
assert_not archival.archived?, "If this failed, you might be trying to test on a system that doesn't support nested transactions"
|
16
|
+
assert_not exploder.reload.archived?
|
17
|
+
end
|
18
|
+
|
19
|
+
test "unarchiving is transactional" do
|
20
|
+
archival = Archival.create!
|
21
|
+
exploder = archival.exploders.create!
|
22
|
+
any_instance_of(Exploder) do |exploder|
|
23
|
+
stub(exploder).unarchive { raise "Rollback Imminent" }
|
24
|
+
end
|
25
|
+
archival.archive
|
26
|
+
archival.unarchive
|
27
|
+
|
28
|
+
assert archival.reload.archived?
|
29
|
+
assert exploder.reload.archived?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_archival
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joel Meador
|
9
|
+
- Michael Kuehl
|
10
|
+
- Matthew Gordon
|
11
|
+
- Vojtech Salbaba
|
12
|
+
- David Jones
|
13
|
+
- Dave Woodward
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
date: 2012-03-04 00:00:00.000000000 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: activerecord
|
21
|
+
requirement: &70256103651080 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
type: :runtime
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: *70256103651080
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: &70256103650640 !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: *70256103650640
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: assertions-eb
|
43
|
+
requirement: &70256103650140 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: *70256103650140
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rake
|
54
|
+
requirement: &70256103649660 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *70256103649660
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mysql2
|
65
|
+
requirement: &70256103648960 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: *70256103648960
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: highline
|
76
|
+
requirement: &70256103648360 !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: *70256103648360
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rr
|
87
|
+
requirement: &70256103647620 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: *70256103647620
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: database_cleaner
|
98
|
+
requirement: &70256103646620 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: *70256103646620
|
107
|
+
description: ! 'We had the problem that acts_as_paranoid and similar plugins/gems
|
108
|
+
always work on
|
109
|
+
|
110
|
+
a record by record basis and made it very difficult to restore records
|
111
|
+
|
112
|
+
atomically (or archive them, for that matter).
|
113
|
+
|
114
|
+
|
115
|
+
Because the archive and unarchive methods are in transactions, and every
|
116
|
+
|
117
|
+
archival record involved gets the same archive number upon archiving, you can
|
118
|
+
|
119
|
+
easily restore or remove an entire set of records without having to worry about
|
120
|
+
|
121
|
+
partial deletion or restoration.
|
122
|
+
|
123
|
+
|
124
|
+
Additionally, other plugins generally screw with how destroy/delete work. We
|
125
|
+
|
126
|
+
don''t because we actually want to be able to destroy records.
|
127
|
+
|
128
|
+
'
|
129
|
+
email:
|
130
|
+
- joel@expectedbehavior.com
|
131
|
+
- michael@expectedbehavior.com
|
132
|
+
- matt@expectedbehavior.com
|
133
|
+
executables: []
|
134
|
+
extensions: []
|
135
|
+
extra_rdoc_files: []
|
136
|
+
files:
|
137
|
+
- .gitignore
|
138
|
+
- .rvmrc
|
139
|
+
- CHANGELOG.md
|
140
|
+
- Gemfile
|
141
|
+
- Gemfile.lock
|
142
|
+
- LICENSE
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- acts_as_archival.gemspec
|
146
|
+
- init.rb
|
147
|
+
- lib/acts_as_archival.rb
|
148
|
+
- lib/acts_as_archival/version.rb
|
149
|
+
- lib/expected_behavior/acts_as_archival.rb
|
150
|
+
- lib/expected_behavior/acts_as_archival_active_record_methods.rb
|
151
|
+
- test/ambiguous_table_test.rb
|
152
|
+
- test/associations_test.rb
|
153
|
+
- test/basic_test.rb
|
154
|
+
- test/column_test.rb
|
155
|
+
- test/database.yml
|
156
|
+
- test/deep_nesting_test.rb
|
157
|
+
- test/fixtures/archival.rb
|
158
|
+
- test/fixtures/archival_grandkid.rb
|
159
|
+
- test/fixtures/archival_kid.rb
|
160
|
+
- test/fixtures/exploder.rb
|
161
|
+
- test/fixtures/independent_archival.rb
|
162
|
+
- test/fixtures/mass_attribute_protected.rb
|
163
|
+
- test/fixtures/missing_archive_number.rb
|
164
|
+
- test/fixtures/missing_archived_at.rb
|
165
|
+
- test/fixtures/plain.rb
|
166
|
+
- test/fixtures/poly.rb
|
167
|
+
- test/fixtures/readonly_when_archived.rb
|
168
|
+
- test/mass_attribute_test.rb
|
169
|
+
- test/polymorphic_test.rb
|
170
|
+
- test/readonly_when_archived_test.rb
|
171
|
+
- test/responds_test.rb
|
172
|
+
- test/schema.rb
|
173
|
+
- test/scope_test.rb
|
174
|
+
- test/script/db_setup
|
175
|
+
- test/test_helper.rb
|
176
|
+
- test/through_association_test.rb
|
177
|
+
- test/transaction_test.rb
|
178
|
+
homepage: http://expectedbehavior.com
|
179
|
+
licenses: []
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
segments:
|
191
|
+
- 0
|
192
|
+
hash: -1239227818634757629
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
hash: -1239227818634757629
|
202
|
+
requirements: []
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 1.8.16
|
205
|
+
signing_key:
|
206
|
+
specification_version: 3
|
207
|
+
summary: Atomic archiving/unarchiving for ActiveRecord-based apps
|
208
|
+
test_files:
|
209
|
+
- test/ambiguous_table_test.rb
|
210
|
+
- test/associations_test.rb
|
211
|
+
- test/basic_test.rb
|
212
|
+
- test/column_test.rb
|
213
|
+
- test/database.yml
|
214
|
+
- test/deep_nesting_test.rb
|
215
|
+
- test/fixtures/archival.rb
|
216
|
+
- test/fixtures/archival_grandkid.rb
|
217
|
+
- test/fixtures/archival_kid.rb
|
218
|
+
- test/fixtures/exploder.rb
|
219
|
+
- test/fixtures/independent_archival.rb
|
220
|
+
- test/fixtures/mass_attribute_protected.rb
|
221
|
+
- test/fixtures/missing_archive_number.rb
|
222
|
+
- test/fixtures/missing_archived_at.rb
|
223
|
+
- test/fixtures/plain.rb
|
224
|
+
- test/fixtures/poly.rb
|
225
|
+
- test/fixtures/readonly_when_archived.rb
|
226
|
+
- test/mass_attribute_test.rb
|
227
|
+
- test/polymorphic_test.rb
|
228
|
+
- test/readonly_when_archived_test.rb
|
229
|
+
- test/responds_test.rb
|
230
|
+
- test/schema.rb
|
231
|
+
- test/scope_test.rb
|
232
|
+
- test/script/db_setup
|
233
|
+
- test/test_helper.rb
|
234
|
+
- test/through_association_test.rb
|
235
|
+
- test/transaction_test.rb
|