My model is CWB::Account
(they are namespaced because I inherited this project and they used a few reserved words as model names)
I'm using minitest-spec-rails gem for testing and I'm getting this error -
ActiveRecord::FxitureClassNotFound: No class attached to find.
test/test-helper.rb
...
class ActiveSupport::TestCase
fixtures :all
end
...
test/controllers/sessions_controller_test.rb
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
before do
account_one = Accounts(:account_one)
register(account_one)
end
...
test/fixtures/accounts.yml
account_one:
id: 1
name: testnameone
email: [email protected]
password_hash: passwordone
...
If I do this in test_helper.rb
set_fixture_class :accounts => 'CWB::Account'
fixtures :all
I get error - StandardError no fixture named <CWB::Account:0x0000004bdf32> found for fixture set 'accounts'
EDIT
Interesting update, if I put account.yml in fixtures/cwb/accounts.yml I get a bunch of errors about circular dependencies
but if I put it in fixture/CWB/accounts.yml (notice uppercase) I get an error saying
undefined method accounts for ...
1) put your fixture in /test/fixtures/cwb/accounts.yml
2) call cwb_accounts(:account_one) to get the record
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
before do
account_one = cwb_accounts(:account_one)
register(account_one)
end
...
I had the same error and have combined everything I did to resolve it into this answer.
From Brett Allred's answer, but loading just the specific named fixture: (after putting the fixture in /test/fixtures/cwb/accounts.yml)
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
fixtures: 'cwb/accounts'
before do
account_one = cwb_accounts(:account_one)
...
From infused's answer, but assuming namespaced table names (as in a full engine):
set_fixture_class 'cwb/accounts' => CWB::Account
I'm actually using rspec and namespaced table names. I think the only difference for the OP would be
set_fixture_class 'accounts' => CWB::Account
as his table is not namespaced (just the model)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With