fixturease 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/bin/fixturease.rb +21 -0
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ desc 'Default: run unit tests.'
7
7
  task :default => :spec
8
8
 
9
9
 
10
- PKG_VERSION="0.2.5"
10
+ PKG_VERSION="0.2.6"
11
11
  PKG_FILES=["bin/fixturease.rb","Rakefile","spec/database.yml","spec/fixturease_spec.rb"]
12
12
 
13
13
  spec = Gem::Specification.new do |s|
data/bin/fixturease.rb CHANGED
@@ -11,6 +11,26 @@ else
11
11
 
12
12
  $reload_fixtures = false
13
13
 
14
+ def reset_sequence!(mod)
15
+ if (adapter = YAML::load_file(ENV['RAILS_ROOT']+'/config/database.yml')[ENV['RAILS_ENV']]['adapter']) == "mysql"
16
+ ActiveRecord::Base.connection.rollback_db_transaction
17
+ ActiveRecord::Base.send :decrement_open_transactions
18
+ klass = mod.is_a?(Class) ? mod : mod.singularize.camelize.constantize
19
+ max_id = klass.find(:first,:order => "id DESC").id
20
+ ActiveRecord::Base.connection.execute "ALTER TABLE #{klass.table_name} AUTO_INCREMENT=#{max_id}"
21
+ ActiveRecord::Base.send :increment_open_transactions
22
+ ActiveRecord::Base.connection.begin_db_transaction
23
+ else
24
+ puts "Database adapter #{adapter} is not yet supported. Sorry"
25
+ end
26
+ end
27
+
28
+ def reset_sequences!
29
+ Dir[ENV['RAILS_ROOT']+'/'+ENV['FIXTURES_ROOT']+'/*.yml'].each do |fixture_file|
30
+ reset_sequence! File.basename(fixture_file,".yml")
31
+ end
32
+ end
33
+
14
34
  def load_fixtures!
15
35
  $reload_fixtures = true
16
36
  require 'active_record/fixtures'
@@ -56,6 +76,7 @@ else
56
76
  ActiveRecord::Base.send :increment_open_transactions
57
77
  ActiveRecord::Base.connection.begin_db_transaction
58
78
  load_fixtures! if ENV['LOAD_FIXTURES']=='yes'
79
+ reset_sequences!
59
80
  at_exit do
60
81
  vars = {}
61
82
  instance_variables.each {|varname| vars[instance_variable_get(varname)]=varname.gsub(/^@/,"") if instance_variable_get(varname).is_a? ActiveRecord::Base}
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: fixturease
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.5
7
- date: 2007-01-20 00:00:00 +02:00
6
+ version: 0.2.6
7
+ date: 2007-01-21 00:00:00 +02:00
8
8
  summary: Easy fixture creation tool
9
9
  require_paths:
10
10
  - lib