activerecord_unload_all_fixtures 0.1.3 → 0.1.4
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/VERSION +1 -1
- data/lib/activerecord_unload_all_fixtures.rb +22 -13
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -10,34 +10,43 @@ module ActiveRecord
|
|
10
10
|
# iterate over all ActiveRecord models associated with db tables, deleting all rows
|
11
11
|
# if we're inside a transaction, use delete, otherwise use truncate
|
12
12
|
def unload_all_fixtures()
|
13
|
-
if
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
klass.table_name
|
21
|
-
end
|
22
|
-
end.flatten.to_set.to_a
|
13
|
+
if UnloadAllFixtures::ordered_active_record_table_names.nil? ||
|
14
|
+
UnloadAllFixtures::ordered_active_record_table_names.empty?
|
15
|
+
UnloadAllFixtures::ordered_active_record_table_names = activerecord_model_tables
|
16
|
+
else
|
17
|
+
# add newly defined models onto the end of the ordered list
|
18
|
+
UnloadAllFixtures::ordered_active_record_table_names += activerecord_model_tables - UnloadAllFixtures::ordered_active_record_table_names
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
# get latest list of all tables
|
22
|
+
UnloadAllFixtures::table_name_set = ActiveRecord::Base::connection.tables.to_set
|
26
23
|
|
27
24
|
# start with the last successful delete ordering, only re-ordering if new foreign key dependencies are found
|
28
25
|
ActiveRecord::Base::without_foreign_key_checks do
|
29
|
-
|
26
|
+
UnloadAllFixtures::ordered_active_record_table_names = delete_rows( UnloadAllFixtures::ordered_active_record_table_names,
|
30
27
|
ActiveRecord::Base.connection.open_transactions == 0 )
|
31
28
|
end
|
32
29
|
|
33
30
|
true
|
34
31
|
end
|
35
32
|
|
33
|
+
# all tables associated with ActiveRecord models, not marked for skip_unload_fixtures
|
34
|
+
def activerecord_model_tables
|
35
|
+
klasses = ActiveRecord::Base.send(:subclasses).reject{ |klass| klass.skip_unload_fixtures if klass.respond_to?(:skip_unload_fixtures) }
|
36
|
+
klasses.map do |klass|
|
37
|
+
if defined?(ActiveRecord::WormTable) && klass.ancestors.include?(ActiveRecord::WormTable)
|
38
|
+
[klass.switch_table_name] + klass.table_version_names
|
39
|
+
else
|
40
|
+
klass.table_name
|
41
|
+
end
|
42
|
+
end.flatten.to_set.to_a
|
43
|
+
end
|
44
|
+
|
36
45
|
def delete_rows(table_names, truncate=false, shift_counter=table_names.size)
|
37
46
|
processed = []
|
38
47
|
table_names.each_with_index{ |table_name,i|
|
39
48
|
begin
|
40
|
-
if
|
49
|
+
if UnloadAllFixtures::table_name_set.include?(table_name)
|
41
50
|
if truncate
|
42
51
|
ActiveRecord::Base.connection.execute("truncate table #{table_name}")
|
43
52
|
else
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- mccraig mccraig of the clan mccraig
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|