thoughtbot / factory_bot

A library for setting up Ruby objects as test data.
https://thoughtbot.com
MIT License
7.9k stars 2.6k forks source link

Factory girl vs postgres schemas vs set_table_name in models #558

Closed CloCkWeRX closed 10 years ago

CloCkWeRX commented 11 years ago

pg (0.15.1) factory_girl (4.2.0) activesupport (>= 3.0.0)

We're seeing behaviour where we have a model with a primary key/table name set:

class PropertyService::AusAddressDetail < ActiveRecord::Base

  self.table_name = "gnaf.aus_address_details"
  self.primary_key = 'address_detail_pid'
end

Unfortunately factory girl does not seem to be aware of what it made. We will create but later that same model is not destroyed as we'd expect.

joshuaclayton commented 11 years ago

@CloCkWeRX does this work without using FactoryGirl? FactoryGirl does virtually nothing relating to ActiveRecord and doesn't care what table name or primary key you're using. If your factory is set to the correct class, you should be all set.

factory :aus_address_detail, class: PropertyService::AusAddressDetail do
  # ... attribute assignments
end

If you fire up rails console and try to persist a record, does it work as expected or do you see the same error?

joshuaclayton commented 11 years ago

@CloCkWeRX any updates? Thanks!