Rails test error: no such table: files_users: DELETE FROM “files_users”

问题内容:

Hello I am studying rails on ruby and am completely new to coding itself.
I apologize in advanced if this is a super easy problem to fix.

I keep getting an error on the following title when I run rails test.
I am incorporating fixtures to integration tests and I am quite unsure what these errors mean. If I incorporate test, is there another step to take?

I have 11 errors based on the same but brought one for example:

    Error:
    UserTest#test_name_is_Bob_Builder:
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: files_users: DELETE FROM "files_users"


bin/rails test test/models/user_test.rb:12

On my users.yml:

<% salt = BCrypt::Engine.generate_salt %>
<% password = 'abc123' %>

bob:
  name: 'Bob Builder'
  email: 'bob@builder.com'
  password_hash: <%= BCrypt::Engine.hash_secret(password, salt) %>
  password_salt: <%= salt %>

On my user_test.rb

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  test 'can create user' do
    before = User.all.size
    User.create
    after = User.all.size

    assert after = before + 1
  end

  test 'name is Bob Builder' do
    user = users(:bob)
    assert user.name == 'Bob Builder'
  end

  test 'can authenticate user' do
    user = User.authenticate('bob@builder.com', 'abc123')
    assert user == users(:bob)
  end
end

问题评论:

答案:

答案1:

You have not migrate your database in test environment. so migrate database in test environment

rake db:migrate RAILS_ENV=test

答案评论:

    
Thanks for your reply. It gives me back DEPRECATION WARNING: ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2.
– Sarah Kim
10 hours ago

答案2:

SOLVED
I had to change users to user and move the file user.yml to a different location

Thanks

答案评论:

原文地址:

https://stackoverflow.com/questions/47747177/rails-test-error-no-such-table-files-users-delete-from-files-users

添加评论

友情链接:蝴蝶教程