public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Added work-around for PostgreSQL and the problem of getting fixtures to be 
created from id 1 on each test case. This only works for auto-incrementing 
primary keys called "id" for now #359 [Scott Baron]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@257 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Wed Dec 22 15:09:30 -0800 2004
commit  2ec81dcd28ece609bf837b7869696bba0af5507b
tree    e0e48c6db025d91a8a04518297f884cddada8838
parent  d91405a415819a626427373437e0929b19914cf4
...
1
2
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
0
@@ -1,5 +1,8 @@
0
 *SVN*
0
 
0
+* Added work-around for PostgreSQL and the problem of getting fixtures to be created from id 1 on each test case.
0
+ This only works for auto-incrementing primary keys called "id" for now #359 [Scott Baron]
0
+
0
 * Added Base#clear_association_cache to empty all the cached associations #347 [Tobias Luetke]
0
 
0
 * Added more informative exceptions in establish_connection #356 [bitsweat]
...
166
167
168
 
 
169
170
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
173
174
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
0
@@ -166,9 +166,27 @@
0
         fixtures.each { |fixture| fixture.insert_fixtures }
0
       end
0
 
0
+ reset_sequences(connection, table_names) if ActiveRecord::ConnectionAdapters::PostgreSQLAdapter === connection
0
+
0
       return fixtures.size > 1 ? fixtures : fixtures.first
0
     ensure
0
       ActiveRecord::Base.logger.level = old_logger_level
0
+ end
0
+ end
0
+
0
+ # Work around for PostgreSQL to have new fixtures created from id 1 and running.
0
+ def self.reset_sequences(connection, table_names)
0
+ table_names.flatten.each do |table|
0
+ table_class = Inflector.classify(table.to_s)
0
+ if Object.const_defined?(table_class)
0
+ pk = eval("#{table_class}::primary_key")
0
+ if pk == 'id'
0
+ connection.execute(
0
+ "SELECT setval('public.#{table.to_s}_id_seq', (SELECT MAX(id) FROM #{table.to_s}), true)",
0
+ 'Setting Sequence'
0
+ )
0
+ end
0
+ end
0
     end
0
   end
0
 

Comments

    No one has commented yet.