dan-manges / unit-record

Enables testing ActiveRecord classes without hitting the database.
MIT License
110 stars 4 forks source link

unit_record does not work correct with postgresql adapter. #1

Open jarl-dk opened 14 years ago

jarl-dk commented 14 years ago

Hi. I am using postgresql.

Now I wanted to use unit_record to speed up my tests. However I realise that it fails with NoMethodError: undefined method `indexes' for #ActiveRecord::ConnectionAdapters::UnitRecordAdapter:0x7fa18f27ba90

It seems like the postgresql_adapter implements this method, and it is called when invoking ActiveRecord::Base#Count

However If I monkeypatch like this (in unit_test_helper.rb) class ActiveRecord::ConnectionAdapters::UnitRecordAdapter def indexes(table_name, name = nil) [] end end

I get the correct behaviour "RuntimeError: ActiveRecord is disconnected; database access is unavailable in unit tests."

jarl-dk commented 14 years ago

Seems like the formatting of the monkey patch went wrong: class ActiveRecord::ConnectionAdapters::UnitRecordAdapter def indexes(table_name, name = nil) [] end end

dan-manges commented 14 years ago

Thanks for reporting this bug. Which version of Rails / ActiveRecord?

jarl-dk commented 14 years ago

Rails version 2.3.5 activerecord 2.3.5

Notice that unit_record is intercepting calls to the adapter, and aparently when using postgresql adapter (and aparently only when using postgresql adapter) activerecord directly (or indirectly) calls a #indexes method.

I have no idea why.

jarl-dk commented 14 years ago

Dan, do you have any updates on this issue?

dan-manges commented 14 years ago

I'll get this fixed and released this week.