8

At the minute all my fixtures have the same name as the table that they are intended for, because of a recent issue with rails it doesn't seem possible to have a fixture beginning with the word 'test'

Does anyone know of a way to have a different fixture name and then map it to the correct table?

Thanks, Andy

3 Answers3

4

You can set the class of a given fixture manually like so:

class SomeTest < ActiveSupport::TestCase

  set_fixture_class widgets: 'Module::ClassInAModule'
  fixtures :widgets # or fixtures :all if you’ve defined all the mappings required

  test 'widgets can be found' do
    assert Module::ClassInAModule.all.any?, 'there should be widgets'
  end

end

Depending on how your tests/test helpers are set up, you may want to move this call to a parent class or something.

Leo
  • 4,217
  • 4
  • 25
  • 41
2

In your model set this keyword:

class Anywhere < ApplicationRecord
    self.table_name = "singular_table"
end

OBS: (Rails >= 5)

Darlan Dieterich
  • 2,369
  • 1
  • 27
  • 37
0

This blog post looks similar to what you want to do.

notapatch
  • 6,569
  • 6
  • 41
  • 45
pjammer
  • 9,489
  • 5
  • 46
  • 56