jeudi 2 juillet 2015

Rails test fixtures not using generated ID as primary key

I have created fixtures on a has_many through relationship like this.

package_groups.yml

server_pg:
  name: "server development"
  uuid: "4f9eea2a-a124-497e-8492-828b6d938aaa"
  description: "server packages"

mammals_pg:
  name: "mammals"
  uuid: "4f9eea2a-a124-497e-8492-828b64444abc"
  description: "all kind of mammals"

repository.yml

foo_x86_64_dev:
  name:                 Foo x86_64
  content_type:         yum
  library_instance:     Foo_x86_64
  label:                Foo_dev_label

repository_package_groups.yml

server:
  package_group_id: <%= ActiveRecord::Fixtures.identify(:server_pg) %>
  repository_id: <%= ActiveRecord::Fixtures.identify(:foo_x86_64_dev) %>
  created_at: <%= Time.now %>
  updated_at: <%= Time.now %>

mammals:
  package_group_id: <%= ActiveRecord::Fixtures.identify(:mammals_pg) %>
  repository_id: <%= ActiveRecord::Fixtures.identify(:foo_x86_64_dev) %>
  created_at: <%= Time.now %>
  updated_at: <%= Time.now %>

package_group.rb

has_many :repositories, :through => :repository_package_groups
has_many :repository_package_groups, :dependent => :destroy, :inverse_of => :package_group

repository.rb

 has_many :repository_package_groups, :dependent => :destroy
 has_many :package_groups, :through => :repository_package_groups

but when I call my tests they are not working as expected. When I do a little digging I find this in the test database (postgres)

-PackageGroup
id...name
1 server development
2 mammals

-RepositoryPackageGroup
id.. package_group_id repository_id
1....441261589............920815232
2....283985760............920815232

-Repository
id................name
920815232 Foo x86_64

so my question is, why are my package group test fixtures loaded with the ids of 1 and 2 instead of the generated ones? I've tried resetting the test database. It is preventing me from running @repo.package_groups in my tests.

Aucun commentaire:

Enregistrer un commentaire