fixture_background 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixture_background/generator.rb +18 -10
- data/lib/fixture_background/version.rb +1 -1
- metadata +3 -3
@@ -9,8 +9,12 @@ module FixtureBackground
|
|
9
9
|
|
10
10
|
transaction_with_rollback do
|
11
11
|
(ActiveRecord::Base.connection.tables - ["schema_migrations"]).each do |table_name|
|
12
|
-
|
13
|
-
|
12
|
+
begin
|
13
|
+
klass = table_name.classify.constantize
|
14
|
+
klass.delete_all
|
15
|
+
rescue NameError # do not die on tables that have no model
|
16
|
+
puts "cannot delete from #{table_name} as no model exists"
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
bm = Benchmark.realtime do
|
@@ -70,17 +74,21 @@ module FixtureBackground
|
|
70
74
|
|
71
75
|
def dump_fixtures
|
72
76
|
(ActiveRecord::Base.connection.tables - ["schema_migrations"]).each do |table_name|
|
73
|
-
|
77
|
+
begin
|
78
|
+
klass = table_name.classify.constantize
|
74
79
|
|
75
|
-
|
80
|
+
records = klass.all
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
fixtures = {}
|
83
|
+
records.each do |record|
|
84
|
+
fixtures[table_name + record.id.to_s] = record.instance_variable_get(:@attributes)
|
85
|
+
end
|
81
86
|
|
82
|
-
|
83
|
-
|
87
|
+
File.open("#{@background_dir}/#{table_name}.yml", 'w+') do |f|
|
88
|
+
YAML.dump(fixtures, f)
|
89
|
+
end
|
90
|
+
rescue NameError # do not die on tables that have no model
|
91
|
+
puts "cannot dump from #{table_name} as no model exists"
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 4
|
9
|
+
version: 0.9.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thies C. Arntzen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-31 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|