6

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

4

3 回答 3

3

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.

于 2014-03-03T13:28:01.927 回答
1

In your model set this keyword:

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

OBS: (Rails >= 5)

于 2019-02-06T13:21:57.963 回答
0

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

于 2009-12-29T01:16:40.753 回答