customink / secondbase

Seamless second database integration for Rails.
MIT License
220 stars 31 forks source link

Fixtures not loaded in the correct DB (Rails 5.0.0.1) #39

Closed gbarillot closed 2 months ago

gbarillot commented 7 years ago

Hi,

Thanks for this awesome Gem! I got it to work fine in the browser using development ENV. The problem is when I try to load YML fixtures in any of the second_base table while testing. Looks like Rails is always attempting to load them into the main DB, and not the second one. (No problem if the fixture belongs to the main DB.)

The error message I get when I launch the test :

Register Feature Test#test_0002_gets current_state:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 8:                WHERE a.attrelid = '"users"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
             (SELECT c.collname FROM pg_collation c, pg_type t
               WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation),
                     col_description(a.attrelid, a.attnum) AS comment
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"users"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

In this example, the users table belongs to the second_base, and I do have this table in /db/second_base/schema.rb.

Test_helper.rb also include "require 'second_base/test_help'". (No significant changes if I remove it at that point)

Thank you if you can give me some pointers, for now I'm stuck...

hmadison commented 7 years ago

Try using set_fixture_class to explicitly set the model for the fixture.

gbarillot commented 7 years ago

Like this? Doesn't work :-/

class ActiveSupport::TestCase

  set_fixture_class :users => User

end
metaskills commented 7 years ago

I thought this was a regression bug in Rails 5 that was recently fixed?

metaskills commented 7 years ago

I just did a quick read through - is your issue related to this? https://github.com/rails/rails/pull/27355

gbarillot commented 7 years ago

Unfortunately (and surprisingly), Rails upgrade to 5.0.1 (from current Github master as of today) didn't fix it. Sorry, still exactly the same error message. Is there something I'm missing or a real bug with Rails 5?

Anyone able to reproduce it?

metaskills commented 7 years ago

@gbarillot Sorry for the slow reply, but what was the name of the model for the users table? Is it User?

metaskills commented 7 years ago

@gbarillot I have a little integration app that I use to sanity check multiple databases including SecondBase. I just updated the secondbaserails50 branch there with the latest Rails 5.0 and did this commit (https://github.com/customink/encom_dbs/commit/0bf0e640e6c1700729592206e26b81d5fa44de2f) to show that fixtures do indeed work as expected. Can you take a look?