Forum: Ruby on Rails Resetting sequences in unit tests with pg

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel B. (Guest)
on 2006-01-25 19:00
(Received via mailing list)
Hi all,

Rails 1.0
Postgresql 8.1
Ruby 1.8.4

Is there a way to reset sequences in unit tests when loading fixture
data?  I
came across mention of a "Fixtures.reset_sequences method here:

http://api.rubyonrails.com/files/vendor/rails/acti...

However, when I tried to call Fixtures.reset_sequences in the setup
method, I
got a NoMethodError.

Any ideas?

Thanks,

Dan
Daniel B. (Guest)
on 2006-01-25 19:27
(Received via mailing list)
Daniel B. wrote:
>
> However, when I tried to call Fixtures.reset_sequences in the setup
> method, I got a NoMethodError.
>
> Any ideas?
>
> Thanks,
>
> Dan

A little further research indicates that the self.create_fixtures method
in
fixtures.rb does this:

if connection.respond_to?(:reset_pk_sequence!)
    table_names.each do |table_name|
       connection.reset_pk_sequence!(table_name)
    end
end

However, reset_pk_seqence! in the postgresql adapter has this comment:

# Resets sequence to the max value of the table's pk if present.

So...if I want to reset the pk to the min, I'll have to do that
manually.

Any reason this isn't set to the minimum in the first place?  Just
curious.

Regards,

Dan
Jeremy K. (Guest)
on 2006-01-25 19:43
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jan 25, 2006, at 9:24 AM, Daniel B. wrote:
> However, reset_pk_seqence! in the postgresql adapter has this comment:
>
> # Resets sequence to the max value of the table's pk if present.
>
> So...if I want to reset the pk to the min, I'll have to do that
> manually.
>
> Any reason this isn't set to the minimum in the first place?  Just
> curious.

To account for fixtures inserted without incrementing the sequence
(since
the fixture may specify a primary key.)

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFD17glAQHALep9HFYRAuWKAJsFrz6xd6ST7jN5KGItM6JBwLTD0gCfVYpW
bY744RktgL5Wb2iL3qk1GF4=
=DNo1
-----END PGP SIGNATURE-----
Daniel B. (Guest)
on 2006-01-25 19:52
(Received via mailing list)
Jeremy K. wrote:
>> manually.
>>
>> Any reason this isn't set to the minimum in the first place?  Just
>> curious.
>
>
> To account for fixtures inserted without incrementing the sequence  (since
> the fixture may specify a primary key.)
>
> jeremy

Ah, thanks Jeremy.  Makes sense.

Dan
This topic is locked and can not be replied to.