Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

In your model set this keyword:

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

OBS: (Rails >= 5)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top